All files / apps/developer-portal/app/utils apps.ts

93.33% Statements 14/15
100% Branches 6/6
90% Functions 9/10
91.66% Lines 11/12

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48          34x                                   34x       1380x       3588x 3588x   1380x   3535x     34x       274x 3535x 3535x    
import type { AppEntry } from "~/types/AppEntry";
import type { AppGroup } from "~/types/AppGroup";
import type { NavLink } from "~/types/NavLink";
import type { Translate } from "~/types/Translate";
 
const APPS: readonly Omit<AppGroup, "label">[] = [
    { id: "home", icon: "i-lucide-house", items: ["overview"] },
    { id: "catalog", icon: "i-lucide-boxes", items: ["projects", "graph", "changelog"] },
    {
        id: "docs",
        icon: "i-lucide-book-open",
        items: ["docs", "decisions", "audits", "benchmarks"],
    },
    { id: "work", icon: "i-lucide-kanban", items: ["workflows", "issues"] },
    {
        id: "health",
        icon: "i-lucide-heart-pulse",
        items: ["coverage", "deps", "telemetry"],
        tabs: true,
    },
];
 
/** Each app with the entries its layers declare; an app left with none is dropped. */
export const appEntries = (
    nav: Record<string, NavLink | undefined>,
    t: Translate,
): (AppGroup & { entries: AppEntry[] })[] =>
    APPS.map((app) => ({
        ...app,
        label: t(`app.apps.${app.id}`),
        entries: app.items.flatMap((key) => {
            const link = nav[key];
            return link ? [{ key, ...link, label: t(`app.nav.${key}`) }] : [];
        }),
    })).filter((app) => app.entries.length > 0);
 
const owns = (to: string, path: string): boolean => path === to || path.startsWith(`${to}/`);
 
/** The app and entry a path belongs to, by the longest entry route that contains it. */
export const locate = <T extends { entries: AppEntry[] }>(
    apps: T[],
    path: string,
): { app: T; entry: AppEntry } | null =>
    apps
        .flatMap((app) => app.entries.map((entry) => ({ app, entry })))
        .filter(({ entry }) => owns(entry.to, path))
        .toSorted((a, b) => b.entry.to.length - a.entry.to.length)[0] ?? null;