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.

240 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: { title: "General", about: "The workspace's name, icon, address and description, two-factor authentication, where its data lives, and deleting it." },
61 people: {
62 title: "People",
63 about: "Everyone in the workspace, in one directory: who they are, what they own, the teams they're on and who's around.",
64 },
65 members: {
66 title: "Members",
67 about: "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.",
68 },
69 "members/invitations": {
70 title: "Invitations",
71 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.",
72 },
73 permissions: {
74 title: "Permissions",
75 about: "Who may do what in the workspace, part by part: repositories, teams, chat, artifacts, deployments and packages. Owners only.",
76 },
77 projects: {
78 title: "Projects",
79 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.",
80 },
81 teams: {
82 title: "Teams",
83 about: "People with a lead, a channel and roles on repositories. Everyone on a team knows who their teammates are.",
84 },
85 repositories: {
86 title: "Repositories",
87 about: "Every repository in the workspace: who can see it, whether it is archived, and the ones deleted recently.",
88 },
89 tokens: {
90 title: "Access tokens",
91 about: "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.",
92 },
93 "personal-access-tokens": {
94 title: "Personal access tokens",
95 about: "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.",
96 },
97 packages: {
98 title: "Packages",
99 about: "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.",
100 },
101 insights: { title: "Insights", about: "Delivery, review times, work in progress and costs across your workspace." },
102 usage: { title: "Usage", about: "What the workspace used and what it cost, by product, project and day." },
103 billing: { title: "Billing and plans", about: "The g1t plan, the trial, your spend limit, prepaying, and every charge." },
104 audit: {
105 title: "Audit log",
106 about: "Every change people, tokens and g1t's own runs made: by whom, on whose behalf, to what, and whether it was allowed.",
107 },
108 guardrails: {
109 title: "Guardrails",
110 about: "How long every project's runs may take. Each project can override these under its settings.",
111 },
112 webhooks: {
113 title: "Webhooks",
114 about: "Every repository's events, sent to your own addresses as they happen. A repository can also have its own, under its settings.",
115 },
116 secrets: {
117 title: "Secrets and variables",
118 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.",
119 },
120 security: {
121 title: "Security",
122 about: "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.",
123 },
124 integrations: {
125 title: "Integrations",
126 about:
127 "The tools your team works with, connected once for everyone in the workspace. Secrets are sealed when saved, and never shown again.",
128 },
129};
130
131/** A workspace page's heading: its title and what it is for. */
132function PageHeader({ title, about }: { title: string; about: string }) {
133 return (
134 <header className="mb-8 border-b border-line pb-6">
135 <h1 className="text-2xl font-semibold tracking-tight">{title}</h1>
136 <p className="mt-1.5 text-sm text-muted">{about}</p>
137 </header>
138 );
139}
140
141/** Artifacts' pages that are lists, not one artifact. */
142const ARTIFACT_LISTS = new Set(["new", "templates", "trash", "stale", "spaces"]);
143
144/** Whether the page (its path after `/-/`, in parts) is one artifact or a project's doc file. */
145function isArtifactPage(parts: string[]): boolean {
146 if (parts[0] !== "artifacts" || parts.length < 2) return false;
147 if (parts[1] === "repo") return true;
148 return !ARTIFACT_LISTS.has(parts[1]!) && parts.length === 2;
149}
150
151export default function WorkspaceLayout({ loaderData }: Route.ComponentProps) {
152 const { workspace, role, welcome } = loaderData;
153 const { pathname } = useLocation();
154 const going = useNavigation().location;
155 // The workspace's own page is its overview. Its other pages are found
156 // from the sidebar, which lights the one you are on, and the top bar's
157 // trail leads back here; each has a heading of its own.
158 const here = workspacePage(pathname, workspace.slug);
159 // On the way to another of its pages: that page's heading and shape
160 // until it arrives.
161 const next = going && going.pathname !== pathname ? workspacePage(going.pathname, workspace.slug) : null;
162 const shown = next ?? here;
163 const parts = (pathname.split("/-/")[1] ?? "").split("/").filter(Boolean);
164 // Chat fills the page edge to edge: its conversation, thread and details
165 // are columns of their own (components/chat/channel.tsx).
166 if (parts[0] === "chat" && !next) return <Outlet />;
167 // Code's Overview lays itself out, as Mission control did.
168 if (parts[0] === "overview" && parts.length === 1 && !next) return <Outlet />;
169 // An open artifact, or a project's doc, fills the panel: its header runs edge to edge right under
170 // the top bar (components/folios/shell.tsx), and its page sets its own width.
171 if (isArtifactPage(parts) && !next) {
172 return (
173 <div className="px-4 pb-10 sm:px-6 lg:px-8">
174 <Outlet />
175 </div>
176 );
177 }
178 if (shown !== "overview") {
179 // A page of its own under another's address (Invitations under Members) has its own heading.
180 const whole = parts.join("/");
181 const key = shown ?? (PAGES[whole] ? whole : (parts[0] ?? ""));
182 const heading = PAGES[key];
183 // Pages within one (a single package or team) have headings of their own.
184 const titled = heading && (shown != null || parts.length === 1 || key === whole);
185 return (
186 <div className="mx-auto max-w-5xl px-4 py-10 sm:px-8">
187 {titled && (
188 <PageHeader title={heading.title} about={heading.about} />
189 )}
190 {next ? <WorkspacePageSkeleton page={next} /> : <Outlet />}
191 </div>
192 );
193 }
194 return (
195 <>
196 {/* The workspace's own header band, above its overview. */}
197 <div className="border-b border-line bg-surface/60">
198 <div className="mx-auto max-w-6xl px-4 py-8">
199 {welcome && (
200 <div className="mb-6">
201 <WelcomeBanner title={`You're in ${workspace.name}`}>
202 You joined as a {role}. Its projects, issues and people are all here.
203 </WelcomeBanner>
204 </div>
205 )}
206 <div className="flex flex-wrap items-center gap-4">
207 <Avatar name={workspace.slug} image={workspace.avatar} size={52} square />
208 <div className="min-w-0 grow">
209 <div className="flex flex-wrap items-center gap-2.5">
210 <h1 className="truncate text-2xl font-semibold tracking-tight">
211 {workspace.name}
212 </h1>
213 <Badge size="md">Workspace</Badge>
214 {role && <Badge size="md">{role}</Badge>}
215 </div>
216 <p className="font-mono text-sm text-muted">g1t.sh/{workspace.slug}</p>
217 </div>
218 {role ? (
219 <ButtonLink to={`/new?workspace=${workspace.slug}`}>
220 <Plus size={15} />
221 New project
222 </ButtonLink>
223 ) : (
224 <ButtonLink to={`/${workspace.slug}/-/packages`} variant="outline" prefetch="intent">
225 <Package size={15} />
226 Packages
227 </ButtonLink>
228 )}
229 </div>
230 {workspace.description && (
231 <p className="mt-4 max-w-2xl text-sm text-muted">{workspace.description}</p>
232 )}
233 </div>
234 </div>
235 <div className="mx-auto max-w-6xl px-4 py-8">
236 {next ? <WorkspacePageSkeleton page="overview" /> : <Outlet />}
237 </div>
238 </>
239 );
240}