feat: sidebar lists admin pages under an Administration divider

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-01 22:48:00 +08:00
1 parent d4ae94fcc9
commit 5ac248cee7
5 files changed
+90 -12

No files matched your search

@@ -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/**`
@@ -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(<SidebarNav />);
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(<SidebarNav />);
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(<SidebarNav />);
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(<SidebarNav collapsed />);
expect(screen.queryByText("Administration")).toBeNull();
expect(container.querySelector("[data-slot='sidebar-divider']")).not.toBeNull();
expect(screen.getAllByRole("link")).toHaveLength(11);
});
});
@@ -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 ? (
<RailNode key={link.url || link.name} link={link} trail={trail} />
) : (
<NavNode key={link.url || link.name} link={link} depth={0} trail={trail} onNavigate={onNavigate} />
);
const listClass = cn("space-y-1", collapsed ? "px-2 py-3" : "p-3");
return (
<nav aria-label={t("SidebarMainNav")} className="scrollable flex-1 overflow-x-hidden overflow-y-auto">
<ul className={cn("space-y-1", collapsed ? "px-2 py-3" : "p-3")}>
{links.map((link) =>
collapsed ? (
<RailNode key={link.url || link.name} link={link} trail={trail} />
) : (
<NavNode key={link.url || link.name} link={link} depth={0} trail={trail} onNavigate={onNavigate} />
),
)}
</ul>
{work.length > 0 && <ul className={cn(listClass, admin.length > 0 && "pb-0")}>{work.map(render)}</ul>}
{admin.length > 0 && (
<>
<div data-slot="sidebar-divider" className={cn("mt-3 border-t border-border", collapsed ? "mx-3" : "mx-4")} />
{/* The visible label names the list; the rail has no label, so the list carries the name itself. */}
{!collapsed && (
<p id={adminLabelId} className="px-6 pt-3 text-xs font-semibold text-muted-foreground">
{t("SidebarAdministration")}
</p>
)}
<ul
aria-labelledby={collapsed ? undefined : adminLabelId}
aria-label={collapsed ? t("SidebarAdministration") : undefined}
className={cn(listClass, collapsed ? "pt-3" : "pt-2")}>
{admin.map(render)}
</ul>
</>
)}
</nav>
);
}
@@ -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));
/**
@@ -86,6 +86,7 @@ export const DEFAULT_MESSAGES: Record<string, string> = {
HeaderSwitchToDark: "Switch to dark theme",
LocaleSwitcherChange: "Change language",
SidebarMainNav: "Main",
SidebarAdministration: "Administration",
UiBreadcrumb: "breadcrumb",
UiMore: "More",
UiColumns: "Columns",