Removing the old services' pages left their entries in the sidebar specs, and a nav entry with no route threw during the first render, so the shell drew nothing and every page was blank. The chat browser test caught it, which is the failure #2148 recorded; it passes again. The spec list moves to ui/src/lib/nav-specs.ts, which imports nothing, so a test can check every address it names against the generated page catalogue. That is the guard: deleting a page without updating the sidebars now fails the gate instead of the browser.
52 lines
1.7 KiB
TypeScript
52 lines
1.7 KiB
TypeScript
import { routes } from "@/router";
|
|
import { hiddenRoutes, type CapabilitySections } from "./capabilities";
|
|
import {
|
|
buildNav,
|
|
flattenRoutes,
|
|
type NavNode,
|
|
type NavRouteNode,
|
|
} from "./nav-tree";
|
|
import { orgSpecs, settings, specs, unlisted } from "./nav-specs";
|
|
|
|
export type { NavEntry, NavNode } from "./nav-tree";
|
|
|
|
const table = flattenRoutes(routes as NavRouteNode[]);
|
|
|
|
/** hiddenPaths lists the routes this composition cannot back. */
|
|
export function hiddenPaths(sections: CapabilitySections | null): string[] {
|
|
return hiddenRoutes(sections, table);
|
|
}
|
|
|
|
export function navTree(hidden: string[] = []): NavNode[] {
|
|
return buildNav(table, specs, hidden).tree;
|
|
}
|
|
|
|
/** navEntries lists every destination Jump to can reach. */
|
|
export function navEntries(hidden: string[] = []) {
|
|
return buildNav(table, [...specs, ...orgSpecs, settings], hidden, unlisted)
|
|
.jumpTargets;
|
|
}
|
|
|
|
/** orgNav is the Organisation sidebar; its first section labels its items. */
|
|
export function orgNav(hidden: string[] = []) {
|
|
return buildNav(table, orgSpecs, hidden).jumpTargets;
|
|
}
|
|
|
|
/** settingsNav is the Instance sidebar; each section labels its first item. */
|
|
export function settingsNav(hidden: string[] = []) {
|
|
const nodes = buildNav(table, [settings], hidden).tree;
|
|
const group = nodes.find((node) => node.kind === "group");
|
|
return group?.kind === "group" ? group.items : [];
|
|
}
|
|
|
|
/**
|
|
* activeNavPath maps the current route onto the nav entry that should read as
|
|
* current, so /tasks/42 keeps Tasks lit rather than lighting nothing.
|
|
*/
|
|
export function activeNavPath(path: string): string {
|
|
const route = table.find((r) => r.path === path);
|
|
const navPath = route?.meta?.navPath;
|
|
if (typeof navPath === "string") return navPath;
|
|
return path;
|
|
}
|