Files
archie/ui/src/events/tab-selection.ts
T
sam 76ba97895f feat(webui): make Events one page with three tabs
Inspector, Bindings and Mappings were three sibling destinations in a
dropdown, for what is one chain read in order: an event, the mapping that
names its fields, the binding that decides what runs. They are now three
tabs on /events, and the bar carries Events as a link rather than a menu
with one child sharing its name.

The navigation entry is always live and the tabs prune themselves: each is
a separate capability, so a composition that can back only some of them
still reaches the ones it can, and an unreported section stays visible.
Which tabs exist, and which one is showing, lives in tab-selection.ts and
is unit-tested without a browser; the page owns the components and the
address bar. The old paths survive as bookmarks that redirect to their tab,
so a link or a learned URL still lands somewhere that works.

Three pages become tab panels: they lose their page-level headers -- the
page names the page -- and keep their own actions in a right-aligned row.
CapturesHeader.vue is absorbed into the Inspector panel, which is where its
stream status belongs.
2026-09-22 04:21:36 +10:00

45 lines
1.7 KiB
TypeScript

/**
* Which Events tabs a composition offers, and which one is showing.
*
* Held apart from EventsPage so it can be tested without a browser: the page
* owns the components and the query string, this owns the decision. It imports
* nothing at all, which is what the test harness needs -- no Vue, no alias, no
* component load.
*/
export interface EventsTabSpec {
id: string;
label: string;
/** The capability this tab needs, as GET /api/capabilities names it. */
section: string;
}
/** The tabs, in reading order: what arrived, where its fields go wrong, what
* runs. */
export const EVENTS_TABS: EventsTabSpec[] = [
{ id: "inspector", label: "Inspector", section: "captures" },
{ id: "bindings", label: "Bindings", section: "bindings" },
{ id: "mappings", label: "Mappings", section: "mappings" },
];
/**
* availableTabs keeps the tabs the serving composition can back. A section the
* server did not mention -- an older server, a failed read, a section added
* after this build -- stays visible, because a tab that says "unavailable" is
* recoverable and one that silently vanished is not.
*/
export function availableTabs(sections: Record<string, boolean> | null | undefined): EventsTabSpec[] {
if (!sections) return [...EVENTS_TABS];
return EVENTS_TABS.filter((tab) => sections[tab.section] !== false);
}
/**
* activeTab is the tab the URL asks for when that tab exists here, else the
* first one that does. An empty result means this composition backs none of
* them, which the page renders as an empty state rather than a broken tab.
*/
export function activeTab(requested: string, available: EventsTabSpec[]): string {
if (available.some((tab) => tab.id === requested)) return requested;
return available[0]?.id ?? "";
}