Skip to content

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

253 linesCodeBlameRaw
1import { Package, Plus } from "lucide-react";
2import { Outlet, data, redirect, useLocation, useNavigation } from "react-router";
3
4import type { Route } from "./+types/layout";
5import { page } from "../../lib/meta";
6import { ButtonLink } from "../../components/ui";
7import { Avatar } from "../../components/ui/avatar";
8import { Badge } from "../../components/ui/badge";
9import { WelcomeBanner } from "../../components/welcome";
10import { clearWelcome, welcomes } from "../../lib/invites";
11import { notFound } from "../../lib/not-found.server";
12import { redirectIfRenamed } from "../../lib/renamed.server";
13import { rememberWorkspace } from "../../lib/workspace-choice";
14import { workspacePage, workspaceRedirect } from "../../lib/workspace-nav";
15import { shortcutOf, workspaceProjects } from "../../lib/workspace-projects.server";
16import { WorkspacePageSkeleton } from "../../components/workspace-skeletons";
17import { identity } from "../../lib/services.server";
18import { getViewer, roleIn } from "../../lib/session.server";
19import { isFailed, part } from "../../lib/partial";
20
21export function meta({ loaderData, params, ...args }: Route.MetaArgs) {
22 return page(args, { title: `${loaderData?.workspace.name ?? params.owner} · g1t` });
23}
24
25export async function loader({ params, context, request }: Route.LoaderArgs) {
26 const url = new URL(request.url);
27 // `?tab=projects` and the like, from the tabs this page once had: that
28 // page's own address.
29 const moved = url.search ? workspaceRedirect(url.pathname, url.search) : null;
30 if (moved) throw redirect(moved);
31 const viewer = getViewer(context);
32 const workspace = await identity.getWorkspace(params.owner);
33 if (!workspace) {
34 // A workspace's old name, after a rename: its pages are at the new one.
35 await redirectIfRenamed(request, params.owner);
36 throw notFound("workspace");
37 }
38 const role = roleIn(viewer, workspace.slug);
39 // Opening one of your workspaces makes it the one you are in.
40 if (!role) {
41 // The workspace is what the frame is about; its projects only fill the
42 // sidebar, which goes without them rather than take every page down.
43 const listed = await part(workspaceProjects(workspace.slug, viewer), "Projects");
44 return { workspace, role, welcome: false, projects: !isFailed(listed) && listed.ok ? listed.value.map(shortcutOf) : [] };
45 }
46 const secure = new URL(request.url).protocol === "https:";
47 const headers = new Headers({ "Set-Cookie": rememberWorkspace(workspace.slug, secure) });
48 // Just joined with an invite: welcomed once (routes/invite.tsx).
49 const welcome = welcomes(request.headers.get("cookie"), workspace.slug);
50 if (welcome) headers.append("Set-Cookie", clearWelcome(secure));
51 return data({ workspace, role, welcome }, { headers });
52}
53
54/** A workspace's own pages, each with its title and what it is for. */
55const PAGES: Record<string, { title: string; about: string }> = {
56 workspace: {
57 title: "Workspace",
58 about: "Who is in it, what it is on, and what it has spent this month. Everything about the workspace itself is in this sidebar.",
59 },
60 settings: {
61 title: "General",
62 about: "The workspace's name, icon, address and description, two-factor authentication, where its data lives, and deleting it.",
63 },
64 people: {
65 title: "People",
66 about: "Everyone in the workspace, in one directory: who they are, what they own, the teams they're on and who's around.",
67 },
68 members: {
69 title: "Members",
70 about:
71 "Who is in the workspace and their roles. Owners invite people, manage members and owners, and see the outside collaborators; what members may do is under Permissions.",
72 },
73 "members/invitations": {
74 title: "Invitations",
75 about: "Every invitation to join the workspace: who it is for, who sent it, the role, and where it stands. Send one again, revoke it, or copy its link.",
76 },
77 permissions: {
78 title: "Permissions",
79 about: "Who may do what in the workspace, part by part: repositories, teams, chat, artifacts, deployments and packages. Owners only.",
80 },
81 projects: {
82 title: "Projects",
83 about: "Everything the workspace builds and runs. Search, filter and sort them, and pin the ones you use most to keep them in your sidebar.",
84 },
85 teams: {
86 title: "Teams",
87 about: "People with a lead, a channel and roles on repositories. Everyone on a team knows who their teammates are.",
88 },
89 repositories: {
90 title: "Repositories",
91 about: "Every repository in the workspace: who can see it, whether it is archived, and the ones deleted recently.",
92 },
93 tokens: {
94 title: "Access tokens",
95 about:
96 "Tokens that belong to the workspace, not a person: for CI, integrations and coding agents that work for the whole team. Each has the permissions an owner gives it, in all of the workspace's repositories or the ones chosen.",
97 },
98 "personal-access-tokens": {
99 title: "Personal access tokens",
100 about:
101 "Which of your members' own tokens may reach the workspace and for how long, the tokens made for it that wait for an owner's approval, and every token that can reach it.",
102 },
103 packages: {
104 title: "Packages",
105 about:
106 "What the workspace publishes and installs, beside its code: container images, npm, Composer, Go, Cargo, Maven, NuGet and RubyGems, with the same members, roles and tokens.",
107 },
108 work: {
109 title: "Work",
110 about: "Everything the workspace means to do, features, bugs and chores, numbered once for the whole workspace and linked to the repositories it lands in.",
111 },
112 "work/new": {
113 title: "New work item",
114 about: "Say what should change, and pick the repositories it should land in. Whoever works on it, person or agent, works from this text.",
115 },
116 "work/labels": {
117 title: "Labels",
118 about: "The workspace's labels, shared by every work item and pull request in it.",
119 },
120 "work/milestones": {
121 title: "Milestones",
122 about: "Goals with a due date, that work items and pull requests from every repository of the workspace are gathered under.",
123 },
124 insights: { title: "Insights", about: "Delivery, review times, work in progress and costs across your workspace." },
125 usage: { title: "Usage", about: "What the workspace used and what it cost, by product, project and day." },
126 billing: { title: "Billing and plans", about: "The g1t plan, the trial, your spend limit, prepaying, and every charge." },
127 audit: {
128 title: "Audit log",
129 about: "Every change people, tokens and g1t's own runs made: by whom, on whose behalf, to what, and whether it was allowed.",
130 },
131 guardrails: {
132 title: "Guardrails",
133 about: "How long every project's runs may take. Each project can override these under its settings.",
134 },
135 webhooks: {
136 title: "Webhooks",
137 about: "Every repository's events, sent to your own addresses as they happen. A repository can also have its own, under its settings.",
138 },
139 secrets: {
140 title: "Secrets and variables",
141 about: "Shared with every repository, or the ones you link: read by workflows, deployments, or both. A repository's own row of the same key wins.",
142 },
143 security: {
144 title: "Security",
145 about:
146 "Open alerts in every project: secrets found in pushes and history, and vulnerable dependencies. Each project's Security page has the details and the security update g1t opened for each.",
147 },
148 integrations: {
149 title: "Integrations",
150 about: "The tools your team works with, connected once for everyone in the workspace. Secrets are sealed when saved, and never shown again.",
151 },
152};
153
154/** A workspace page's heading: its title and what it is for. */
155function PageHeader({ title, about }: { title: string; about: string }) {
156 return (
157 <header className="mb-8 border-b border-line pb-6">
158 <h1 className="text-2xl font-semibold tracking-tight">{title}</h1>
159 <p className="mt-1.5 text-sm text-muted">{about}</p>
160 </header>
161 );
162}
163
164/** Artifacts' pages that are lists, not one artifact. */
165const ARTIFACT_LISTS = new Set(["new", "templates", "trash", "stale", "spaces"]);
166
167/** Whether the page (its path after `/-/`, in parts) is one artifact or a project's doc file. */
168function isArtifactPage(parts: string[]): boolean {
169 if (parts[0] !== "artifacts" || parts.length < 2) return false;
170 if (parts[1] === "repo") return true;
171 return !ARTIFACT_LISTS.has(parts[1]!) && parts.length === 2;
172}
173
174export default function WorkspaceLayout({ loaderData }: Route.ComponentProps) {
175 const { workspace, role, welcome } = loaderData;
176 const { pathname } = useLocation();
177 const going = useNavigation().location;
178 // The workspace's own page is its overview. Its other pages are found
179 // from the sidebar, which lights the one you are on, and the top bar's
180 // trail leads back here; each has a heading of its own.
181 const here = workspacePage(pathname, workspace.slug);
182 // On the way to another of its pages: that page's heading and shape
183 // until it arrives.
184 const next = going && going.pathname !== pathname ? workspacePage(going.pathname, workspace.slug) : null;
185 const shown = next ?? here;
186 const parts = (pathname.split("/-/")[1] ?? "").split("/").filter(Boolean);
187 // Chat fills the page edge to edge: its conversation, thread and details
188 // are columns of their own (components/chat/channel.tsx).
189 if (parts[0] === "chat" && !next) return <Outlet />;
190 // Code's Overview lays itself out, as Mission control did.
191 if (parts[0] === "overview" && parts.length === 1 && !next) return <Outlet />;
192 // An open artifact, or a project's doc, fills the panel: its header runs edge to edge right under
193 // the top bar (components/folios/shell.tsx), and its page sets its own width.
194 if (isArtifactPage(parts) && !next) {
195 return (
196 <div className="px-4 pb-10 sm:px-6 lg:px-8">
197 <Outlet />
198 </div>
199 );
200 }
201 if (shown !== "overview") {
202 // A page of its own under another's address (Invitations under Members) has its own heading.
203 const whole = parts.join("/");
204 const key = shown ?? (PAGES[whole] ? whole : (parts[0] ?? ""));
205 const heading = PAGES[key];
206 // Pages within one (a single package or team) have headings of their own.
207 const titled = heading && (shown != null || parts.length === 1 || key === whole);
208 return (
209 <div className="mx-auto max-w-5xl px-4 py-10 sm:px-8">
210 {titled && <PageHeader title={heading.title} about={heading.about} />}
211 {next ? <WorkspacePageSkeleton page={next} /> : <Outlet />}
212 </div>
213 );
214 }
215 return (
216 <>
217 {/* The workspace's own header band, above its overview. */}
218 <div className="border-b border-line bg-surface/60">
219 <div className="mx-auto max-w-6xl px-4 py-8">
220 {welcome && (
221 <div className="mb-6">
222 <WelcomeBanner title={`You're in ${workspace.name}`}>You joined as a {role}. Its projects, work and people are all here.</WelcomeBanner>
223 </div>
224 )}
225 <div className="flex flex-wrap items-center gap-4">
226 <Avatar name={workspace.slug} image={workspace.avatar} size={52} square />
227 <div className="min-w-0 grow">
228 <div className="flex flex-wrap items-center gap-2.5">
229 <h1 className="truncate text-2xl font-semibold tracking-tight">{workspace.name}</h1>
230 <Badge size="md">Workspace</Badge>
231 {role && <Badge size="md">{role}</Badge>}
232 </div>
233 <p className="font-mono text-sm text-muted">g1t.sh/{workspace.slug}</p>
234 </div>
235 {role ? (
236 <ButtonLink to={`/new?workspace=${workspace.slug}`}>
237 <Plus size={15} />
238 New project
239 </ButtonLink>
240 ) : (
241 <ButtonLink to={`/${workspace.slug}/-/packages`} variant="outline" prefetch="intent">
242 <Package size={15} />
243 Packages
244 </ButtonLink>
245 )}
246 </div>
247 {workspace.description && <p className="mt-4 max-w-2xl text-sm text-muted">{workspace.description}</p>}
248 </div>
249 </div>
250 <div className="mx-auto max-w-6xl px-4 py-8">{next ? <WorkspacePageSkeleton page="overview" /> : <Outlet />}</div>
251 </>
252 );
253}