From 75e243f3bb85c626adba6216de498950015e741a Mon Sep 17 00:00:00 2001 From: ngqile Date: Wed, 2 Dec 2026 00:19:18 +0800 Subject: [PATCH] feat: sidebar groups pages into Events, Leads, Access and System Labelled sections replace the single Administration divider, Login security gets its own lock icon, and the icon map drops the babyboo icons Co-Lite does not use. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM --- .../changes/group-sidebar-categories/tasks.md | 11 ++- solvway-admin-portal/DESIGN.md | 2 +- .../components/app/Sidebar.sections.test.tsx | 66 ++++++++++----- .../app/components/app/Sidebar.test.tsx | 13 +-- .../app/components/app/Sidebar.tsx | 61 ++++++++------ .../components/app/icon-map.activity.test.tsx | 13 --- .../app/components/app/icon-map.test.tsx | 83 ++++--------------- .../app/components/app/icon-map.ts | 83 ++++--------------- solvway-admin-portal/app/lib/aclSidebar.ts | 28 ++++++- .../app/lib/i18n/defaultMessages.ts | 5 +- 10 files changed, 156 insertions(+), 209 deletions(-) delete mode 100644 solvway-admin-portal/app/components/app/icon-map.activity.test.tsx diff --git a/openspec/changes/group-sidebar-categories/tasks.md b/openspec/changes/group-sidebar-categories/tasks.md index 23930c1..be5686c 100644 --- a/openspec/changes/group-sidebar-categories/tasks.md +++ b/openspec/changes/group-sidebar-categories/tasks.md @@ -2,8 +2,13 @@ Portal only. TDD, then the review gate. Verify: `cd solvway-admin-portal && npx vitest run; echo VITEST=$? && npx tsc --noEmit && npm run lint` (check the vitest exit code). -- [ ] 1.1 Category map, `groupSidebar`, the icon override, section rendering in `SidebarNav` (full, drawer and rail), and the label keys. The "Administration" label and `ADMIN_MODULES` go. +- [x] 1.1 Category map, `groupSidebar`, the icon override, section rendering in `SidebarNav` (full, drawer and rail), and the label keys. The "Administration" label and `ADMIN_MODULES` go. - Scope: `solvway-admin-portal/app/lib/aclSidebar*`, `solvway-admin-portal/app/components/app/Sidebar*`, `solvway-admin-portal/app/lib/i18n/defaultMessages.ts` -- [ ] 1.2 Trim the icon map to the icons Co-Lite uses. +- [x] 1.2 Trim the icon map to the icons Co-Lite uses. - Scope: the icon map file and its tests -- [ ] 1.3 DESIGN.md Navigation updated, and a Playwright check at 1280 px (full and rail) and 360 px (drawer) as a super admin, plus a staff user with event pages only. +- [x] 1.3 DESIGN.md Navigation updated, and a Playwright check at 1280 px (full and rail) and 360 px (drawer) as a super admin, plus a staff user with event pages only. + - Done 2026-12-02 on the local stack: + - Playwright as super admin: the full sidebar at 1280 px (Dashboard, then Events, Leads, Access and System with labels and dividers), the collapsed rail (dividers only, Login security with its lock icon), and the drawer at 360 px. + - The staff-only scenario (event pages only) is covered by `Sidebar.sections.test.tsx`. No browser sign-in was done for it, because no local staff user has only those modules. + - Icon map trimmed to Co-Lite's 12 icons. The babyboo-only icon tests were removed, and the Activity-group test file was deleted. + - Portal verify: vitest 1572 passed (exit 0), tsc 0, lint 0 errors. diff --git a/solvway-admin-portal/DESIGN.md b/solvway-admin-portal/DESIGN.md index 3b480b4..b3be69c 100644 --- a/solvway-admin-portal/DESIGN.md +++ b/solvway-admin-portal/DESIGN.md @@ -237,7 +237,7 @@ Quiet, compact, unmistakable. - Live inside a card or an 8px framed container. Header row in slate tint, 40px tall, 12px semibold uppercase muted labels with sort chevrons; cells 14px with 8px padding; rows separated by hairlines, hovering at 50% slate tint. The pager below reads "1-7 of 7" left and outline Previous / Next right. ### Navigation -- **Sidebar:** white, right hairline. Items are 44px tall, 8px radius, 20px outline icon plus 14px medium label. Idle: muted slate, hover slate tint with ink. Active: blue tint with deep blue ink, `aria-current="page"`. Groups expand with a rotating chevron and indent children behind a left hairline. The collapsed rail shows icons only, with groups opening as a side popover. Admin pages (Users, Roles, Emails, Login security, Audit log, Companies) sit below a hairline divider and a 12px semibold muted "Administration" label; the rail keeps the divider only, and a section with nothing to open is not drawn. +- **Sidebar:** white, right hairline. Items are 44px tall, 8px radius, 20px outline icon plus 14px medium label. Idle: muted slate, hover slate tint with ink. Active: blue tint with deep blue ink, `aria-current="page"`. Groups expand with a rotating chevron and indent children behind a left hairline. The collapsed rail shows icons only, with groups opening as a side popover. Pages are grouped into always-open sections: Dashboard alone, then Events (Events, Event leads), Leads (Leads, Interests), Access (Users, Roles, Login security) and System (Companies, Emails, Audit log). Each later section starts with a hairline divider and a 12px semibold muted label; the rail keeps the dividers only, a section with nothing to open is not drawn, and a page the map does not know trails in a last unlabelled section. Every page has its own icon. - **Header:** white, bottom hairline, 56px; the link back to the parent page left (sub-pages only); company picker (a styled select), locale switcher, theme toggle and user menu (blue avatar initial) right. ### Data States diff --git a/solvway-admin-portal/app/components/app/Sidebar.sections.test.tsx b/solvway-admin-portal/app/components/app/Sidebar.sections.test.tsx index 329a28d..f836ac9 100644 --- a/solvway-admin-portal/app/components/app/Sidebar.sections.test.tsx +++ b/solvway-admin-portal/app/components/app/Sidebar.sections.test.tsx @@ -9,46 +9,70 @@ vi.mock("@/app/lib/useAclSidebar", () => ({ useAclSidebar: () => state.links })) import { SidebarNav } from "./Sidebar"; -const link = (name: string): SidebarLink => ({ name, url: `/${name}`, children: [] }); +const link = (name: string): SidebarLink => ({ name, url: `/${name}`, iconName: "Users", 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", ); +const linkNames = (list: HTMLElement) => within(list).getAllByRole("link").map((a) => a.getAttribute("href")?.slice(1)); describe("Sidebar sections", () => { - it("lists work pages above the Administration label and admin pages below it", () => { - state.links = ALL; + it("lists Dashboard, then Events, Leads, Access and System sections in order", () => { + state.links = [...ALL].reverse(); 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(); + const lists = screen.getAllByRole("list"); + expect(lists).toHaveLength(5); + expect(linkNames(lists[0])).toEqual(["BO_DASHBOARD"]); + expect(linkNames(screen.getByRole("list", { name: "Events" }))).toEqual(["BO_EVENTS", "BO_EVENT_LEADS"]); + expect(linkNames(screen.getByRole("list", { name: "Leads" }))).toEqual(["BO_LEADS", "BO_INTERESTS"]); + expect(linkNames(screen.getByRole("list", { name: "Access" }))).toEqual(["BO_USERS", "BO_ROLES", "BO_LOGIN_SECURITY"]); + expect(linkNames(screen.getByRole("list", { name: "System" }))).toEqual(["BO_COMPANIES", "BO_EMAILS", "BO_AUDIT_LOG"]); 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", () => { + it("shows only the sections the user has pages in", () => { state.links = names("BO_EVENTS", "BO_EVENT_LEADS"); const { container } = render(); - expect(screen.queryByText("Administration")).toBeNull(); + expect(screen.getByRole("list", { name: "Events" })).toBeTruthy(); + for (const label of ["Leads", "Access", "System"]) expect(screen.queryByText(label)).toBeNull(); expect(container.querySelector("[data-slot='sidebar-divider']")).toBeNull(); }); - it("shows only the divider in the collapsed rail", () => { + it("puts a divider between sections but not above the first", () => { + state.links = ALL; + const { container } = render(); + expect(container.querySelectorAll("[data-slot='sidebar-divider']")).toHaveLength(4); + expect(container.querySelector("nav")!.firstElementChild!.tagName).toBe("UL"); + }); + + it("lists an unknown page after System without a label", () => { + state.links = [...ALL, link("BO_NEW_THING")]; + const { container } = render(); + const lists = screen.getAllByRole("list"); + expect(lists).toHaveLength(6); + const last = lists[5]; + expect(linkNames(last)).toEqual(["BO_NEW_THING"]); + expect(last.getAttribute("aria-labelledby")).toBeNull(); + expect(last.getAttribute("aria-label")).toBeNull(); + expect(container.querySelectorAll("[data-slot='sidebar-divider']")).toHaveLength(5); + }); + + it("shows dividers and no labels in the collapsed rail", () => { state.links = ALL; const { container } = render(); - expect(screen.queryByText("Administration")).toBeNull(); - expect(container.querySelector("[data-slot='sidebar-divider']")).not.toBeNull(); + for (const label of ["Events", "Leads", "Access", "System"]) expect(screen.queryByText(label)).toBeNull(); + expect(container.querySelectorAll("[data-slot='sidebar-divider']")).toHaveLength(4); + expect(screen.getByRole("list", { name: "Access" })).toBeTruthy(); expect(screen.getAllByRole("link")).toHaveLength(11); }); + + it("renders Login security with a different icon than Roles", () => { + state.links = [{ ...link("BO_ROLES"), iconName: "Shield" }, { ...link("BO_LOGIN_SECURITY"), iconName: "Shield" }]; + render(); + const icon = (name: string) => document.querySelector(`a[href='/${name}'] svg`)!.getAttribute("class"); + expect(icon("BO_ROLES")).toContain("lucide-shield"); + expect(icon("BO_LOGIN_SECURITY")).toContain("lucide-lock-keyhole"); + }); }); diff --git a/solvway-admin-portal/app/components/app/Sidebar.test.tsx b/solvway-admin-portal/app/components/app/Sidebar.test.tsx index ec770f6..6745f78 100644 --- a/solvway-admin-portal/app/components/app/Sidebar.test.tsx +++ b/solvway-admin-portal/app/components/app/Sidebar.test.tsx @@ -24,12 +24,13 @@ vi.mock("@/app/lib/useAclSidebar", () => ({ import Sidebar from "./Sidebar"; +// Icons are Co-Lite seed icons (group-sidebar-categories trimmed the babyboo-only ones). const BO_FIXTURE: SidebarLink[] = [ { name: "Dashboard", url: "/", iconName: "LayoutDashboard", children: [] }, { name: "Members", url: "/members", iconName: "Users", children: [] }, - { name: "Reports", url: "/reports", iconName: "FileText", children: [] }, - { name: "Network", url: "/network", iconName: "Network", children: [] }, - { name: "Messages", url: "/messages", iconName: "Languages", children: [] }, + { name: "Reports", url: "/reports", iconName: "Mail", children: [] }, + { name: "Network", url: "/network", iconName: "ScrollText", children: [] }, + { name: "Messages", url: "/messages", iconName: "Tags", children: [] }, ]; describe("Sidebar icon rendering", () => { @@ -41,9 +42,9 @@ describe("Sidebar icon rendering", () => { expect(screen.getByText("Messages")).toBeInTheDocument(); expect(container.querySelector("svg.lucide-layout-dashboard")).not.toBeNull(); expect(container.querySelector("svg.lucide-users")).not.toBeNull(); - expect(container.querySelector("svg.lucide-file-text")).not.toBeNull(); - expect(container.querySelector("svg.lucide-network")).not.toBeNull(); - expect(container.querySelector("svg.lucide-languages")).not.toBeNull(); + expect(container.querySelector("svg.lucide-mail")).not.toBeNull(); + expect(container.querySelector("svg.lucide-scroll-text")).not.toBeNull(); + expect(container.querySelector("svg.lucide-tags")).not.toBeNull(); }); it("renders the neutral fallback icon, and does not throw, for an unknown or absent iconName", () => { diff --git a/solvway-admin-portal/app/components/app/Sidebar.tsx b/solvway-admin-portal/app/components/app/Sidebar.tsx index 117f993..4657ed4 100644 --- a/solvway-admin-portal/app/components/app/Sidebar.tsx +++ b/solvway-admin-portal/app/components/app/Sidebar.tsx @@ -1,11 +1,11 @@ "use client"; -import { useEffect, useId, useState } from "react"; +import { Fragment, useEffect, useId, useState } from "react"; import Link from "next/link"; import { usePathname } from "next/navigation"; import { ChevronDown, PanelLeftClose, PanelLeftOpen } from "lucide-react"; import { useAclSidebar } from "@/app/lib/useAclSidebar"; -import { ADMIN_MODULES, currentTrail, type SidebarLink } from "@/app/lib/aclSidebar"; +import { currentTrail, groupSidebar, type SidebarLink } from "@/app/lib/aclSidebar"; import { useT } from "@/app/lib/i18n/MessagesProvider"; import { iconFor } from "./icon-map"; import { cn } from "@/app/lib/utils"; @@ -215,39 +215,48 @@ function RailGroup({ export function SidebarNav({ onNavigate, collapsed = false }: { onNavigate?: () => void; collapsed?: boolean }) { 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 sections = groupSidebar(links); + // Trail from the grouped links: groupSidebar copies them, and active matching is by identity. + const trail = currentTrail(sections.flatMap((s) => s.links), usePathname()); + const idBase = useId(); 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/components/app/icon-map.activity.test.tsx b/solvway-admin-portal/app/components/app/icon-map.activity.test.tsx deleted file mode 100644 index f97fc4c..0000000 --- a/solvway-admin-portal/app/components/app/icon-map.activity.test.tsx +++ /dev/null @@ -1,13 +0,0 @@ -import { render } from "@testing-library/react"; -import { describe, it, expect } from "vitest"; -import { iconFor } from "./icon-map"; - -// add-online-users: the Activity group (BO_NAV_ACTIVITY), Online users and Audit log seed icons. -describe("iconFor — Activity group", () => { - it.each(["Activity", "UserCheck", "ScrollText"])("resolves %s to a real (non-fallback) icon", (name) => { - const Icon = iconFor(name); - const { container } = render(