g1t/apps/web/app/lib/project-nav.ts
Pick any line to see why it is the way it is: the commit, the pull request and issue it came from, and what the agent was thinking.
| A flat project menu with Code first, views as tabs, and Stripe for every owner | 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 | */ | |
| 7 | import { type RoadmapItem, roadmapIn } from "./roadmap"; | |
| 8 | ||
| 9 | export 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 | ||
| 21 | export type Section = { | |
| 22 | key: RoadmapItem["section"] | "Workflows" | "Settings"; | |
| 23 | tabs: Tab[]; | |
| 24 | }; | |
| 25 | ||
| 26 | function 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 | ||
| 30 | export 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: "Security", tabs: soon("Security") }, | |
| 56 | { key: "Insights", tabs: soon("Insights") }, | |
| 57 | ]; | |
| 58 | ||
| 59 | /** Pull requests and the merge queue share a page's tabs too. */ | |
| 60 | export const PULLS: Section = { | |
| 61 | key: "Code", | |
| 62 | tabs: [ | |
| 63 | { label: "Pull requests", path: "pulls", also: ["pull"] }, | |
| 64 | { label: "Merge queue", path: "queue" }, | |
| 65 | ], | |
| 66 | }; | |
| 67 | ||
| 68 | function matches(rest: string, tab: Tab): boolean { | |
| 69 | return [tab.path, ...(tab.also ?? [])].some((path) => path !== "" && (rest === path || rest.startsWith(`${path}/`))); | |
| 70 | } | |
| 71 | ||
| 72 | /** | |
| 73 | * The tabs for the page at `rest` (the path under the project), if it | |
| 74 | * belongs to a page with more than one view. | |
| 75 | */ | |
| 76 | export function tabsFor(rest: string, member: boolean): Tab[] | null { | |
| 77 | for (const section of [...SECTIONS, PULLS]) { | |
| 78 | const visible = section.tabs.filter((tab) => member || !tab.members); | |
| 79 | if (visible.length > 1 && visible.some((tab) => matches(rest, tab))) return visible; | |
| 80 | } | |
| 81 | return null; | |
| 82 | } | |
| 83 | ||
| 84 | /** The first page of a section, for its sidebar link: a built one if any. */ | |
| 85 | export function entryOf(key: Section["key"]): Tab | undefined { | |
| 86 | return SECTIONS.find((section) => section.key === key)?.tabs[0]; | |
| 87 | } |