From 75331639319a879b9e1f4597b9849be426c7d4b6 Mon Sep 17 00:00:00 2001 From: ngqile Date: Wed, 2 Dec 2026 10:02:19 +0800 Subject: [PATCH] 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 Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM --- .../app/components/ui/data-table.cards.test.tsx | 2 +- solvway-admin-portal/app/components/ui/data-table.tsx | 2 +- .../app/interests/page.delete.test.tsx | 9 +++++++++ solvway-admin-portal/app/interests/page.tsx | 8 ++++++-- solvway-admin-portal/app/roles/page.delete.test.tsx | 9 +++++++++ solvway-admin-portal/app/roles/page.tsx | 10 +++++++--- 6 files changed, 33 insertions(+), 7 deletions(-) diff --git a/solvway-admin-portal/app/components/ui/data-table.cards.test.tsx b/solvway-admin-portal/app/components/ui/data-table.cards.test.tsx index ac638b6..4ad9635 100644 --- a/solvway-admin-portal/app/components/ui/data-table.cards.test.tsx +++ b/solvway-admin-portal/app/components/ui/data-table.cards.test.tsx @@ -65,7 +65,7 @@ describe("DataTable phone sort select", () => { renderTable({ onSortingChange: () => {} }); const select = screen.getByRole("combobox", { name: "Sort by" }); 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", () => { diff --git a/solvway-admin-portal/app/components/ui/data-table.tsx b/solvway-admin-portal/app/components/ui/data-table.tsx index 637f9dc..3619b98 100644 --- a/solvway-admin-portal/app/components/ui/data-table.tsx +++ b/solvway-admin-portal/app/components/ui/data-table.tsx @@ -182,7 +182,7 @@ export function DataTable({ onSortingChange!(id ? [{ id, desc: dir === 'desc' }] : []) }} > - {sortableColumns.flatMap(c => [ , , diff --git a/solvway-admin-portal/app/interests/page.delete.test.tsx b/solvway-admin-portal/app/interests/page.delete.test.tsx index 0b4c975..b250ffe 100644 --- a/solvway-admin-portal/app/interests/page.delete.test.tsx +++ b/solvway-admin-portal/app/interests/page.delete.test.tsx @@ -45,6 +45,15 @@ describe("Interests delete and confirmations", () => { 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(); + 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 () => { render(); expect(within(await rowOf("Workshop")).getByRole("button", { name: "Delete" })).toHaveAttribute("data-variant", "destructive-outline"); diff --git a/solvway-admin-portal/app/interests/page.tsx b/solvway-admin-portal/app/interests/page.tsx index 18aec20..a011227 100644 --- a/solvway-admin-portal/app/interests/page.tsx +++ b/solvway-admin-portal/app/interests/page.tsx @@ -148,6 +148,7 @@ function InterestsPageContent() { const [interests, setInterests] = useState([]); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); + const [actionError, setActionError] = useState(null); const [reloadKey, setReloadKey] = useState(0); const [dialog, setDialog] = useState(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 }); refetch(); } catch { - setError("IntActivateFailed"); + setActionError("IntActivateFailed"); } }} > @@ -249,12 +250,13 @@ function InterestsPageContent() { if (!confirm) return; const { kind, item } = confirm; setConfirm(null); + setActionError(null); try { if (kind === "delete") await deleteAdminInterest(item.id!); else await saveAdminInterest({ id: item.id, active: false }); refetch(); } catch { - setError(kind === "delete" ? "IntDeleteFailed" : "IntDeactivateFailed"); + setActionError(kind === "delete" ? "IntDeleteFailed" : "IntDeactivateFailed"); } } @@ -271,6 +273,8 @@ function InterestsPageContent() { /> {error && } + {/* An action that failed: retrying the list would not help, so no Retry. */} + {actionError && } { 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(); + 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 () => { render(); expect(within(await rowOf("ROLE_HQ")).getByRole("button", { name: "Delete" })).toHaveAttribute("data-variant", "destructive-outline"); diff --git a/solvway-admin-portal/app/roles/page.tsx b/solvway-admin-portal/app/roles/page.tsx index 9bb9444..ab9beba 100644 --- a/solvway-admin-portal/app/roles/page.tsx +++ b/solvway-admin-portal/app/roles/page.tsx @@ -102,6 +102,7 @@ function RolesPageContent() { const [roles, setRoles] = useState([]); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); + const [actionError, setActionError] = useState(null); const [reloadKey, setReloadKey] = useState(0); const [sorting, setSorting] = useState([]); const [dialog, setDialog] = useState(null); @@ -191,14 +192,15 @@ function RolesPageContent() { if (!confirmDelete) return; const role = confirmDelete; setConfirmDelete(null); + setActionError(null); try { await deleteAdminRole(role.id!); refetch(); } catch (err) { 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 })); - else if (data?.code === "ROLE_PROTECTED") setError("RolProtected"); - else setError("RolDeleteFailed"); + if (data?.code === "ROLE_IN_USE") setActionError(t("RolInUse", { n: data.details?.users ?? 0 })); + else if (data?.code === "ROLE_PROTECTED") setActionError("RolProtected"); + else setActionError("RolDeleteFailed"); } } @@ -215,6 +217,8 @@ function RolesPageContent() { /> {error && } + {/* An action that failed: retrying the list would not help, so no Retry. */} + {actionError && }