Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions docs/frontend.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ nextjs-frontend/
app/openapi-client/ generated from the API's OpenAPI schema; never edit by hand
```

## Navigation

The nav rail (`components/app-shell/nav-config.ts`) is in four groups, each named above its first item (a line when
the rail is collapsed to icons): what people use every day (Home, Library, Search, Chat, Notes), **Explore** what Lens
found (Entities, Topics, Graph, Podcasts, Reports), **Automate** what runs by itself (Pipelines, Routines, Extensions,
Sensors, or Sources for people who aren't admins), and **Manage** Lens (Costs, Analytics, Settings, Admin). Every page
stays one click from Home; ⌘K reaches every page, recording and setting by name.

## Design system

Colour is semantic, never decorative: blue means working, selected or a link; green means ready or succeeded; red
Expand Down
31 changes: 31 additions & 0 deletions nextjs-frontend/__tests__/nav-groups.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { render, screen } from "@testing-library/react";
import "@testing-library/jest-dom";

import { Nav } from "@/components/app-shell/nav";
import { TooltipProvider } from "@/components/ui/tooltip";

jest.mock("next/navigation", () => ({ usePathname: () => "/settings/llm" }));
jest.mock("@/components/notes/notes-tree", () => ({ NotesTree: () => null }));

const nav = (collapsed: boolean) =>
render(
<TooltipProvider>
<Nav admin collapsed={collapsed} counts={{}} />
</TooltipProvider>,
);

test("names each group above its first item", () => {
nav(false);
const text = screen.getByRole("navigation", { name: "Primary" }).textContent ?? "";
expect(text.indexOf("Explore")).toBeLessThan(text.indexOf("Entities"));
expect(text.indexOf("Notes")).toBeLessThan(text.indexOf("Explore"));
expect(text.indexOf("Automate")).toBeLessThan(text.indexOf("Pipelines"));
expect(text.indexOf("Manage")).toBeLessThan(text.indexOf("Costs"));
expect(screen.getByRole("link", { name: "Settings" })).toHaveAttribute("aria-current", "page");
});

test("collapsed to icons, the groups are lines rather than names", () => {
nav(true);
expect(screen.queryByText("Explore")).not.toBeInTheDocument();
expect(screen.getByRole("link", { name: "Entities" })).toBeInTheDocument();
});
13 changes: 13 additions & 0 deletions nextjs-frontend/__tests__/navigation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,19 @@ describe("navigation", () => {
);
});

it("keeps each group together, in order: every day, Explore, Automate, Manage", () => {
for (const admin of [true, false]) {
const groups = navFor(admin).map((i) => i.group);
const order = groups.filter((g, i) => g !== groups[i - 1]);
expect(order).toEqual(["", "Explore", "Automate", "Manage"]);
}
expect(
navFor(true)
.filter((i) => i.group === "Manage")
.map((i) => i.label),
).toEqual(["Costs", "Analytics", "Settings", "Admin"]);
});

it("matches the active section", () => {
expect(isActive("/", "/")).toBe(true);
expect(isActive("/library", "/")).toBe(false);
Expand Down
46 changes: 25 additions & 21 deletions nextjs-frontend/components/app-shell/nav-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,38 +31,42 @@ export type NavItem = {
membersOnly?: boolean;
/** A count shown next to the label (library size, speakers to review in Settings). */
countKey?: "recordings" | "reviews";
/** Draw a divider after this item. */
divider?: boolean;
/** The group it's in, named above its first item; the first group (what people use every day) has no name. */
group: NavGroup;
};

/** Primary navigation, in the design's order (Nav.dc.html). */
export type NavGroup = "" | "Explore" | "Automate" | "Manage";

/** Primary navigation, in the design's order (Nav.dc.html), in groups: what people use every day, what Lens found in
* it, what runs by itself, and running Lens. */
export const NAV: NavItem[] = [
{ label: "Home", href: "/", icon: House },
{ label: "Home", href: "/", icon: House, group: "" },
{
label: "Library",
href: "/library",
icon: LibraryBig,
countKey: "recordings",
group: "",
},
{ label: "Search", href: "/search", icon: Search },
{ label: "Chat", href: "/chat", icon: MessagesSquare },
{ label: "Notes", href: "/notes", icon: NotebookPen },
{ label: "Entities", href: "/entities", icon: Shapes },
{ label: "Topics", href: "/topics", icon: Tags },
{ label: "Graph", href: "/graph", icon: Waypoints },
{ label: "Podcasts", href: "/podcasts", icon: Podcast },
{ label: "Reports", href: "/reports", icon: ChartNoAxesColumn },
{ label: "Costs", href: "/costs", icon: Wallet, divider: true },
{ label: "Pipelines", href: "/pipelines", icon: Workflow },
{ label: "Routines", href: "/routines", icon: CalendarClock, adminOnly: true },
{ label: "Extensions", href: "/extensions", icon: Blocks },
{ label: "Search", href: "/search", icon: Search, group: "" },
{ label: "Chat", href: "/chat", icon: MessagesSquare, group: "" },
{ label: "Notes", href: "/notes", icon: NotebookPen, group: "" },
{ label: "Entities", href: "/entities", icon: Shapes, group: "Explore" },
{ label: "Topics", href: "/topics", icon: Tags, group: "Explore" },
{ label: "Graph", href: "/graph", icon: Waypoints, group: "Explore" },
{ label: "Podcasts", href: "/podcasts", icon: Podcast, group: "Explore" },
{ label: "Reports", href: "/reports", icon: ChartNoAxesColumn, group: "Explore" },
{ label: "Pipelines", href: "/pipelines", icon: Workflow, group: "Automate" },
{ label: "Routines", href: "/routines", icon: CalendarClock, adminOnly: true, group: "Automate" },
{ label: "Extensions", href: "/extensions", icon: Blocks, group: "Automate" },
// Admins see every source as a sensor; members see the watched folders feeding their namespaces.
{ label: "Sensors", href: "/sensors", icon: RadioTower, adminOnly: true },
{ label: "Sources", href: "/sources", icon: HardDriveDownload, membersOnly: true },
{ label: "Analytics", href: "/analytics", icon: ChartLine, adminOnly: true },
{ label: "Sensors", href: "/sensors", icon: RadioTower, adminOnly: true, group: "Automate" },
{ label: "Sources", href: "/sources", icon: HardDriveDownload, membersOnly: true, group: "Automate" },
{ label: "Costs", href: "/costs", icon: Wallet, group: "Manage" },
{ label: "Analytics", href: "/analytics", icon: ChartLine, adminOnly: true, group: "Manage" },
// Everyone has Settings: members find Speakers there, admins the archive's settings too.
{ label: "Settings", href: "/settings", icon: Settings, countKey: "reviews" },
{ label: "Admin", href: "/admin", icon: Shield, adminOnly: true },
{ label: "Settings", href: "/settings", icon: Settings, countKey: "reviews", group: "Manage" },
{ label: "Admin", href: "/admin", icon: Shield, adminOnly: true, group: "Manage" },
];

export function navFor(admin: boolean): NavItem[] {
Expand Down
15 changes: 12 additions & 3 deletions nextjs-frontend/components/app-shell/nav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ export function Nav({
<Brand collapsed={collapsed} />
</div>
{top}
{navFor(admin).map((it) => {
{navFor(admin).map((it, i, all) => {
// a group's name goes above its first item; collapsed to icons, a line does
const opens = it.group && it.group !== all[i - 1]?.group;
const on = isActive(pathname, it.href);
const n = it.countKey ? counts[it.countKey] : undefined;
const link = (
Expand All @@ -54,7 +56,7 @@ export function Nav({
onClick={onNavigate}
aria-current={on ? "page" : undefined}
className={cn(
"flex h-[34px] items-center gap-[11px] whitespace-nowrap rounded-sm px-2.5 text-[14px] transition-colors duration-fast",
"flex h-8 items-center gap-[11px] whitespace-nowrap rounded-sm px-2.5 text-[14px] transition-colors duration-fast",
on ? "bg-blue-surface font-bold text-fg-accent" : "font-medium text-fg-strong hover:bg-surface-neutral",
collapsed && "justify-center px-0",
)}
Expand All @@ -72,14 +74,21 @@ export function Nav({
);
return (
<div key={it.href}>
{opens &&
(collapsed ? (
<div className="mx-1.5 my-2 h-px bg-border" />
) : (
<div className="px-2.5 pb-1 pt-2.5 text-[11px] font-bold uppercase leading-none tracking-wide text-fg-muted">
{it.group}
</div>
))}
{collapsed ? (
<Tooltip content={it.label} side="right">
{link}
</Tooltip>
) : (
link
)}
{it.divider && <div className="mx-1.5 my-2 h-px bg-border" />}
</div>
);
})}
Expand Down
Loading