flagon-io/g1t

public

Where people and agents ship software together. The open-source git platform for the whole job: issues, agents, checks and deploys to the edge.

g1t/apps/web/app/lib/project-nav.ts

88 lines2,725 bytesCodeBlame
1/**
2 * A project's pages and the tabs within them, in one place: the sidebar
3 * lists the pages, and a page with more than one view shows them as tabs
4 * across its top, the way GitHub and Vercel do. Soon tabs come from the
5 * roadmap and open its page for them, under the same tabs.
6 */
7import { type RoadmapItem, roadmapIn } from "./roadmap";
8
9export type Tab = {
10 label: string;
11 /** Under the project, without a leading slash; "" is its overview. */
12 path: string;
13 /** Other paths under which this tab is the current one. */
14 also?: string[];
15 soon?: boolean;
16 about?: string;
17 /** Members only. */
18 members?: boolean;
19};
20
21export type Section = {
22 key: RoadmapItem["section"] | "Workflows" | "Settings";
23 tabs: Tab[];
24};
25
26function soon(section: RoadmapItem["section"]): Tab[] {
27 return roadmapIn(section).map((item) => ({ label: item.title, path: `soon/${item.key}`, soon: true, about: item.summary }));
28}
29
30export const SECTIONS: Section[] = [
31 {
32 key: "Code",
33 tabs: [
34 { label: "Files", path: "code", also: ["tree", "blob"] },
35 { label: "Commits", path: "commits", also: ["commit"] },
36 ...soon("Code"),
37 ],
38 },
39 {
40 key: "Issues",
41 tabs: [
42 { label: "Issues", path: "issues" },
43 { label: "Outcomes", path: "plans", members: true },
44 ...soon("Issues"),
45 ],
46 },
47 {
48 key: "Agents",
49 tabs: soon("Agents"),
50 },
51 {
52 key: "Deployments",
53 tabs: [{ label: "Deployments", path: "deployments", members: true }, ...soon("Deployments")],
54 },
55 { key: "Observability", tabs: soon("Observability") },
56 { key: "Security", tabs: soon("Security") },
57 { key: "Insights", tabs: soon("Insights") },
58];
59
60/** Pull requests and the merge queue share a page's tabs too. */
61export const PULLS: Section = {
62 key: "Code",
63 tabs: [
64 { label: "Pull requests", path: "pulls", also: ["pull"] },
65 { label: "Merge queue", path: "queue" },
66 ],
67};
68
69function matches(rest: string, tab: Tab): boolean {
70 return [tab.path, ...(tab.also ?? [])].some((path) => path !== "" && (rest === path || rest.startsWith(`${path}/`)));
71}
72
73/**
74 * The tabs for the page at `rest` (the path under the project), if it
75 * belongs to a page with more than one view.
76 */
77export function tabsFor(rest: string, member: boolean): Tab[] | null {
78 for (const section of [...SECTIONS, PULLS]) {
79 const visible = section.tabs.filter((tab) => member || !tab.members);
80 if (visible.length > 1 && visible.some((tab) => matches(rest, tab))) return visible;
81 }
82 return null;
83}
84
85/** The first page of a section, for its sidebar link: a built one if any. */
86export function entryOf(key: Section["key"]): Tab | undefined {
87 return SECTIONS.find((section) => section.key === key)?.tabs[0];
88}