Files
archie/ui/src/lib/capabilities.ts
T
sam 82512b84cd feat(webui): grouped topbar navigation, built from components
Five top-level items instead of eleven flat ones: Dashboard as a link, then
Work, Agent, Events and System as dropdowns, with each item's one-line
description on a hover tooltip. Configuration dissolves into /system/{status,
appearance,tasks,models,repos,advanced} and /settings redirects to the first of
them, so existing bookmarks still land somewhere. Logs gets a nav entry for the
first time.

The bar is composed from named components rather than one file: Brand (Logo,
BrandName), Nav (NavTrigger, NavGroup, NavItem), SearchBar, SupportLink,
ThemeToggle, ProfileDropdown. The nav model reads the route table, so a route
and its nav entry cannot disagree, and a group whose every child is gated off
is dropped while a group left with one child stays a dropdown.

The Go page registry moves with it, which its parse-the-route-table test
enforces.
2026-09-20 18:46:11 +10:00

39 lines
1.2 KiB
TypeScript

import { ref } from "vue";
import { routes } from "@/router";
export type CapabilitySections = Record<string, boolean>;
interface RouteMeta {
section?: string;
}
/** hidden lists the route paths this composition cannot serve. */
export const hidden = ref<string[]>([]);
function hiddenFor(sections: CapabilitySections | undefined): string[] {
if (!sections) return [];
return (routes as Array<{ path: string; meta?: RouteMeta }>)
.filter((route) => {
const section = route.meta?.section;
return typeof section === "string" && sections[section] === false;
})
.map((route) => route.path);
}
/**
* loadCapabilities asks once, after the shell is up: the nav paints immediately
* and loses what this process cannot back a moment later, rather than holding
* the page behind a request. A failed read hides nothing.
*/
export async function loadCapabilities(): Promise<void> {
try {
const response = await fetch("/api/capabilities", { headers: { Accept: "application/json" } });
if (!response.ok) return;
const body = (await response.json()) as { sections?: CapabilitySections } | null;
hidden.value = hiddenFor(body?.sections);
} catch {
// Offline or an older server: every section stays visible.
}
}