fix: no Retry on refused deletes; visible Sort by placeholder on phones

Found in the live check: a refused or failed delete showed the list's Retry,
which can only fail again; the phone sort select was blank until used.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
This commit is contained in:
ngqileandClaude Opus 5.5 committed 2026-12-02 10:02:19 +08:00
1 parent 1b8110dbbf
commit 7533163931
6 files changed
+33 -7

No files matched your search

@@ -65,7 +65,7 @@ describe("DataTable phone sort select", () => {
renderTable({ onSortingChange: () => {} }); renderTable({ onSortingChange: () => {} });
const select = screen.getByRole("combobox", { name: "Sort by" }); const select = screen.getByRole("combobox", { name: "Sort by" });
const texts = Array.from(select.querySelectorAll("option")).map(o => o.textContent); const texts = Array.from(select.querySelectorAll("option")).map(o => o.textContent);
expect(texts).toEqual(["", "Name ↑", "Name ↓", "Company ↑", "Company ↓"]); expect(texts).toEqual(["Sort by", "Name ↑", "Name ↓", "Company ↑", "Company ↓"]);
}); });
it("reflects the current sorting and reports changes", () => { it("reflects the current sorting and reports changes", () => {
@@ -182,7 +182,7 @@ export function DataTable<TData>({
onSortingChange!(id ? [{ id, desc: dir === 'desc' }] : []) onSortingChange!(id ? [{ id, desc: dir === 'desc' }] : [])
}} }}
> >
<option value="" /> <option value="">{t("UiSortBy")}</option>
{sortableColumns.flatMap(c => [ {sortableColumns.flatMap(c => [
<option key={`${c.id}:asc`} value={`${c.id}:asc`}>{labelOf(c) ?? c.id} ↑</option>, <option key={`${c.id}:asc`} value={`${c.id}:asc`}>{labelOf(c) ?? c.id} ↑</option>,
<option key={`${c.id}:desc`} value={`${c.id}:desc`}>{labelOf(c) ?? c.id} ↓</option>, <option key={`${c.id}:desc`} value={`${c.id}:desc`}>{labelOf(c) ?? c.id} ↓</option>,
@@ -45,6 +45,15 @@ describe("Interests delete and confirmations", () => {
await waitFor(() => expect(screen.queryByText("Workshop")).toBeNull()); await waitFor(() => expect(screen.queryByText("Workshop")).toBeNull());
}); });
it("a failed delete offers no Retry, only the message", async () => {
mocks.apiDelete.mockRejectedValue(new Error("boom"));
render(<InterestsPage />);
await userEvent.click(within(await rowOf("Workshop")).getByRole("button", { name: "Delete" }));
await userEvent.click(within(screen.getByRole("dialog")).getByRole("button", { name: "Delete" }));
expect(await screen.findByText("Failed to delete interest.")).toBeInTheDocument();
expect(screen.queryByRole("button", { name: /retry/i })).toBeNull();
});
it("styles the row Delete as destructive-outline", async () => { it("styles the row Delete as destructive-outline", async () => {
render(<InterestsPage />); render(<InterestsPage />);
expect(within(await rowOf("Workshop")).getByRole("button", { name: "Delete" })).toHaveAttribute("data-variant", "destructive-outline"); expect(within(await rowOf("Workshop")).getByRole("button", { name: "Delete" })).toHaveAttribute("data-variant", "destructive-outline");
+6 -2
View File
@@ -148,6 +148,7 @@ function InterestsPageContent() {
const [interests, setInterests] = useState<AdminInterestEntity[]>([]); const [interests, setInterests] = useState<AdminInterestEntity[]>([]);
const [loading, setLoading] = useState(true); const [loading, setLoading] = useState(true);
const [error, setError] = useState<string | null>(null); const [error, setError] = useState<string | null>(null);
const [actionError, setActionError] = useState<string | null>(null);
const [reloadKey, setReloadKey] = useState(0); const [reloadKey, setReloadKey] = useState(0);
const [dialog, setDialog] = useState<FormState | null>(null); const [dialog, setDialog] = useState<FormState | null>(null);
const [confirm, setConfirm] = useState<{ kind: "delete" | "deactivate"; item: AdminInterestEntity } | null>(null); const [confirm, setConfirm] = useState<{ kind: "delete" | "deactivate"; item: AdminInterestEntity } | null>(null);
@@ -226,7 +227,7 @@ function InterestsPageContent() {
await saveAdminInterest({ id: row.original.id, active: true }); await saveAdminInterest({ id: row.original.id, active: true });
refetch(); refetch();
} catch { } catch {
setError("IntActivateFailed"); setActionError("IntActivateFailed");
} }
}} }}
> >
@@ -249,12 +250,13 @@ function InterestsPageContent() {
if (!confirm) return; if (!confirm) return;
const { kind, item } = confirm; const { kind, item } = confirm;
setConfirm(null); setConfirm(null);
setActionError(null);
try { try {
if (kind === "delete") await deleteAdminInterest(item.id!); if (kind === "delete") await deleteAdminInterest(item.id!);
else await saveAdminInterest({ id: item.id, active: false }); else await saveAdminInterest({ id: item.id, active: false });
refetch(); refetch();
} catch { } catch {
setError(kind === "delete" ? "IntDeleteFailed" : "IntDeactivateFailed"); setActionError(kind === "delete" ? "IntDeleteFailed" : "IntDeactivateFailed");
} }
} }
@@ -271,6 +273,8 @@ function InterestsPageContent() {
/> />
{error && <ErrorState message={t(error)} onRetry={refetch} className="mb-4" />} {error && <ErrorState message={t(error)} onRetry={refetch} className="mb-4" />}
{/* An action that failed: retrying the list would not help, so no Retry. */}
{actionError && <ErrorState message={t(actionError)} className="mb-4" />}
<DataTable <DataTable
label={t("BO_INTERESTS")} label={t("BO_INTERESTS")}
@@ -60,6 +60,15 @@ describe("Roles delete", () => {
expect(await screen.findByText("Users holding this role: 3. Remove it from them first.")).toBeInTheDocument(); expect(await screen.findByText("Users holding this role: 3. Remove it from them first.")).toBeInTheDocument();
}); });
it("offers no Retry on a refused delete: retrying cannot succeed", async () => {
mocks.apiDelete.mockRejectedValue(new ApiError("ROLE_IN_USE", 409, { code: "ROLE_IN_USE", details: { users: 3 } }));
render(<RolesPage />);
await openDelete();
await userEvent.click(within(screen.getByRole("dialog")).getByRole("button", { name: "Delete" }));
await screen.findByText("Users holding this role: 3. Remove it from them first.");
expect(screen.queryByRole("button", { name: /retry/i })).toBeNull();
});
it("styles the row Delete as destructive-outline", async () => { it("styles the row Delete as destructive-outline", async () => {
render(<RolesPage />); render(<RolesPage />);
expect(within(await rowOf("ROLE_HQ")).getByRole("button", { name: "Delete" })).toHaveAttribute("data-variant", "destructive-outline"); expect(within(await rowOf("ROLE_HQ")).getByRole("button", { name: "Delete" })).toHaveAttribute("data-variant", "destructive-outline");
+7 -3
View File
@@ -102,6 +102,7 @@ function RolesPageContent() {
const [roles, setRoles] = useState<AdminRoleEntity[]>([]); const [roles, setRoles] = useState<AdminRoleEntity[]>([]);
const [loading, setLoading] = useState(true); const [loading, setLoading] = useState(true);
const [error, setError] = useState<string | null>(null); const [error, setError] = useState<string | null>(null);
const [actionError, setActionError] = useState<string | null>(null);
const [reloadKey, setReloadKey] = useState(0); const [reloadKey, setReloadKey] = useState(0);
const [sorting, setSorting] = useState<SortingState>([]); const [sorting, setSorting] = useState<SortingState>([]);
const [dialog, setDialog] = useState<FormState | null>(null); const [dialog, setDialog] = useState<FormState | null>(null);
@@ -191,14 +192,15 @@ function RolesPageContent() {
if (!confirmDelete) return; if (!confirmDelete) return;
const role = confirmDelete; const role = confirmDelete;
setConfirmDelete(null); setConfirmDelete(null);
setActionError(null);
try { try {
await deleteAdminRole(role.id!); await deleteAdminRole(role.id!);
refetch(); refetch();
} catch (err) { } catch (err) {
const data = (err as { data?: { code?: string; details?: { users?: number } } }).data; const data = (err as { data?: { code?: string; details?: { users?: number } } }).data;
if (data?.code === "ROLE_IN_USE") setError(t("RolInUse", { n: data.details?.users ?? 0 })); if (data?.code === "ROLE_IN_USE") setActionError(t("RolInUse", { n: data.details?.users ?? 0 }));
else if (data?.code === "ROLE_PROTECTED") setError("RolProtected"); else if (data?.code === "ROLE_PROTECTED") setActionError("RolProtected");
else setError("RolDeleteFailed"); else setActionError("RolDeleteFailed");
} }
} }
@@ -215,6 +217,8 @@ function RolesPageContent() {
/> />
{error && <ErrorState message={t(error)} onRetry={refetch} className="mb-4" />} {error && <ErrorState message={t(error)} onRetry={refetch} className="mb-4" />}
{/* An action that failed: retrying the list would not help, so no Retry. */}
{actionError && <ErrorState message={t(actionError)} className="mb-4" />}
<DataTable <DataTable
label={t("BO_ROLES")} label={t("BO_ROLES")}