43 lines
1.4 KiB
TypeScript
43 lines
1.4 KiB
TypeScript
import type { HousekeepingDomainId } from "../migration/types";
|
|
import { satisfiesCapability } from "./capability-context";
|
|
import type {
|
|
HousekeepingCapabilityContext,
|
|
HousekeepingDomainManifest,
|
|
HousekeepingSurface,
|
|
} from "./contracts";
|
|
import type { HousekeepingRegistry } from "./registry";
|
|
import { toHousekeepingHref } from "./routing/href";
|
|
|
|
export interface HousekeepingNavigationDomain {
|
|
id: HousekeepingDomainId;
|
|
href: string;
|
|
iconId: HousekeepingDomainManifest["iconId"];
|
|
label: string;
|
|
description: string;
|
|
items: readonly { id: string; href: string; label: string }[];
|
|
}
|
|
|
|
export function buildHousekeepingNavigation(
|
|
registry: HousekeepingRegistry,
|
|
context: HousekeepingCapabilityContext,
|
|
surface: HousekeepingSurface,
|
|
translate: (key: string) => string,
|
|
): readonly HousekeepingNavigationDomain[] {
|
|
return registry.domains
|
|
.filter((domain) => satisfiesCapability(context, domain.capability))
|
|
.map((domain) => ({
|
|
id: domain.id,
|
|
href: toHousekeepingHref(domain.canonicalHref, surface),
|
|
iconId: domain.iconId,
|
|
label: translate(domain.labelKey),
|
|
description: translate(domain.descriptionKey),
|
|
items: domain.routes
|
|
.filter((route) => satisfiesCapability(context, route.capability))
|
|
.map((route) => ({
|
|
id: route.id,
|
|
href: toHousekeepingHref(route.href, surface),
|
|
label: translate(route.labelKey),
|
|
})),
|
|
}));
|
|
}
|