From 5ac248cee76582e65f818803995654c4f611c46c Mon Sep 17 00:00:00 2001 From: ngqile Date: Tue, 1 Dec 2026 22:48:00 +0800 Subject: [PATCH] feat: sidebar lists admin pages under an Administration divider Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM --- .../refine-visitor-pages-and-shell/tasks.md | 4 +- .../components/app/Sidebar.sections.test.tsx | 54 +++++++++++++++++++ .../app/components/app/Sidebar.tsx | 40 ++++++++++---- solvway-admin-portal/app/lib/aclSidebar.ts | 3 ++ .../app/lib/i18n/defaultMessages.ts | 1 + 5 files changed, 90 insertions(+), 12 deletions(-) create mode 100644 solvway-admin-portal/app/components/app/Sidebar.sections.test.tsx diff --git a/openspec/changes/refine-visitor-pages-and-shell/tasks.md b/openspec/changes/refine-visitor-pages-and-shell/tasks.md index 8a77343..30b51d2 100644 --- a/openspec/changes/refine-visitor-pages-and-shell/tasks.md +++ b/openspec/changes/refine-visitor-pages-and-shell/tasks.md @@ -9,7 +9,7 @@ Verify for every task: `cd solvway-admin-portal && npx vitest run; echo VITEST=$ - [x] 1.1 Header trail without repeats: `Breadcrumbs` shows nothing on a page whose URL is the matched leaf's own URL, and shows the leaf as a link on a sub-page. - Depends on: none - Scope: `solvway-admin-portal/app/components/app/Breadcrumbs*` -- [ ] 1.2 Sidebar sections: an `ADMIN_MODULES` list in `aclSidebar.ts`, the work and Administration split in `Sidebar` (full sidebar and drawer: divider and label; rail: divider only; no section when it has no items), and the "Administration" label in `defaultMessages.ts`. +- [x] 1.2 Sidebar sections: an `ADMIN_MODULES` list in `aclSidebar.ts`, the work and Administration split in `Sidebar` (full sidebar and drawer: divider and label; rail: divider only; no section when it has no items), and the "Administration" label in `defaultMessages.ts`. - Depends on: 1.1 - Scope: `solvway-admin-portal/app/lib/aclSidebar*`, `solvway-admin-portal/app/components/app/Sidebar*`, `solvway-admin-portal/app/lib/i18n/defaultMessages.ts` - [ ] 1.3 Table scroll cue: a scroll-shadow utility in `globals.css` applied to the `table-container`, with colours from tokens only (the design-tokens test stays green). @@ -30,7 +30,7 @@ Verify for every task: `cd solvway-admin-portal && npx vitest run; echo VITEST=$ - [ ] 3.1 My QR codes as cards: the event name as the title, dates and location, the switched-off badge in the card header, the QR and a wrapping button row. - Depends on: 2.2 - Scope: `solvway-admin-portal/app/my-qr/**`, `solvway-admin-portal/app/components/registration/QrCodeItem*` -- [ ] 3.2 Reset password uses the login page's two-column frame. Remove the stale brown and gold comments in login. +- [x] 3.2 Reset password uses the login page's two-column frame. Remove the stale brown and gold comments in login. - Depends on: 3.1 - Scope: `solvway-admin-portal/app/reset-password/**`, `solvway-admin-portal/app/login/**` diff --git a/solvway-admin-portal/app/components/app/Sidebar.sections.test.tsx b/solvway-admin-portal/app/components/app/Sidebar.sections.test.tsx new file mode 100644 index 0000000..329a28d --- /dev/null +++ b/solvway-admin-portal/app/components/app/Sidebar.sections.test.tsx @@ -0,0 +1,54 @@ +import { render, screen, within } from "@testing-library/react"; +import { describe, it, expect, vi } from "vitest"; +import type { SidebarLink } from "@/app/lib/aclSidebar"; + +const state = vi.hoisted(() => ({ links: [] as SidebarLink[] })); + +vi.mock("next/navigation", () => ({ usePathname: () => "/" })); +vi.mock("@/app/lib/useAclSidebar", () => ({ useAclSidebar: () => state.links })); + +import { SidebarNav } from "./Sidebar"; + +const link = (name: string): SidebarLink => ({ name, url: `/${name}`, children: [] }); +const names = (...n: string[]) => n.map(link); + +const ALL = names( + "BO_DASHBOARD", "BO_EVENTS", "BO_EVENT_LEADS", "BO_INTERESTS", "BO_LEADS", + "BO_USERS", "BO_ROLES", "BO_EMAILS", "BO_LOGIN_SECURITY", "BO_AUDIT_LOG", "BO_COMPANIES", +); + +describe("Sidebar sections", () => { + it("lists work pages above the Administration label and admin pages below it", () => { + state.links = ALL; + render(); + const label = screen.getByText("Administration"); + const before = (el: HTMLElement) => label.compareDocumentPosition(el) & Node.DOCUMENT_POSITION_PRECEDING; + const after = (el: HTMLElement) => label.compareDocumentPosition(el) & Node.DOCUMENT_POSITION_FOLLOWING; + const hrefs = (re: RegExp) => screen.getAllByRole("link").filter((a) => re.test(a.getAttribute("href") ?? "")); + for (const a of hrefs(/DASHBOARD|EVENTS|EVENT_LEADS|INTERESTS|LEADS/)) expect(before(a)).toBeTruthy(); + for (const a of hrefs(/USERS|ROLES|EMAILS|LOGIN_SECURITY|AUDIT_LOG|COMPANIES/)) expect(after(a)).toBeTruthy(); + expect(screen.getAllByRole("link")).toHaveLength(11); + }); + + it("names the admin list by the label", () => { + state.links = ALL; + render(); + const list = screen.getByRole("list", { name: "Administration" }); + expect(within(list).getAllByRole("link")).toHaveLength(6); + }); + + it("shows no Administration label or divider when no admin module is available", () => { + state.links = names("BO_EVENTS", "BO_EVENT_LEADS"); + const { container } = render(); + expect(screen.queryByText("Administration")).toBeNull(); + expect(container.querySelector("[data-slot='sidebar-divider']")).toBeNull(); + }); + + it("shows only the divider in the collapsed rail", () => { + state.links = ALL; + const { container } = render(); + expect(screen.queryByText("Administration")).toBeNull(); + expect(container.querySelector("[data-slot='sidebar-divider']")).not.toBeNull(); + expect(screen.getAllByRole("link")).toHaveLength(11); + }); +}); diff --git a/solvway-admin-portal/app/components/app/Sidebar.tsx b/solvway-admin-portal/app/components/app/Sidebar.tsx index a809ad4..117f993 100644 --- a/solvway-admin-portal/app/components/app/Sidebar.tsx +++ b/solvway-admin-portal/app/components/app/Sidebar.tsx @@ -5,7 +5,7 @@ import Link from "next/link"; import { usePathname } from "next/navigation"; import { ChevronDown, PanelLeftClose, PanelLeftOpen } from "lucide-react"; import { useAclSidebar } from "@/app/lib/useAclSidebar"; -import { currentTrail, type SidebarLink } from "@/app/lib/aclSidebar"; +import { ADMIN_MODULES, currentTrail, type SidebarLink } from "@/app/lib/aclSidebar"; import { useT } from "@/app/lib/i18n/MessagesProvider"; import { iconFor } from "./icon-map"; import { cn } from "@/app/lib/utils"; @@ -216,18 +216,38 @@ export function SidebarNav({ onNavigate, collapsed = false }: { onNavigate?: () const t = useT(); const links = useAclSidebar(); const trail = currentTrail(links, usePathname()); + const adminLabelId = useId(); + + const work = links.filter((l) => !ADMIN_MODULES.includes(l.name)); + const admin = links.filter((l) => ADMIN_MODULES.includes(l.name)); + const render = (link: SidebarLink) => + collapsed ? ( + + ) : ( + + ); + const listClass = cn("space-y-1", collapsed ? "px-2 py-3" : "p-3"); return ( ); } diff --git a/solvway-admin-portal/app/lib/aclSidebar.ts b/solvway-admin-portal/app/lib/aclSidebar.ts index d4cbe52..480ddda 100644 --- a/solvway-admin-portal/app/lib/aclSidebar.ts +++ b/solvway-admin-portal/app/lib/aclSidebar.ts @@ -12,6 +12,9 @@ export interface SidebarLink { children: SidebarLink[]; } +// ponytail: fixed list; a new admin module falls into the work section until added here. +export const ADMIN_MODULES = ["BO_USERS", "BO_ROLES", "BO_EMAILS", "BO_LOGIN_SECURITY", "BO_AUDIT_LOG", "BO_COMPANIES"]; + const byId = (nodes: AdminModule[] | undefined) => [...(nodes ?? [])].sort((a, b) => (a.id ?? 0) - (b.id ?? 0)); /** diff --git a/solvway-admin-portal/app/lib/i18n/defaultMessages.ts b/solvway-admin-portal/app/lib/i18n/defaultMessages.ts index bf461fd..90b9051 100644 --- a/solvway-admin-portal/app/lib/i18n/defaultMessages.ts +++ b/solvway-admin-portal/app/lib/i18n/defaultMessages.ts @@ -86,6 +86,7 @@ export const DEFAULT_MESSAGES: Record = { HeaderSwitchToDark: "Switch to dark theme", LocaleSwitcherChange: "Change language", SidebarMainNav: "Main", + SidebarAdministration: "Administration", UiBreadcrumb: "breadcrumb", UiMore: "More", UiColumns: "Columns",