pr_01m47d15m3e54sn21z27rpy5n9/apps/web/app/routes/workspace/layout.tsx

131 lines5,922 bytesCodeBlame
1import { Plus } from "lucide-react";
2import { Outlet, data, useLocation } from "react-router";
3
4import type { Route } from "./+types/layout";
5import { page } from "../../lib/meta";
6import { Avatar, ButtonLink, Pill } from "../../components/ui";
7import { notFound } from "../../lib/not-found.server";
8import { redirectIfRenamed } from "../../lib/renamed.server";
9import { rememberWorkspace } from "../../lib/workspace-choice";
10import { identity } from "../../lib/services.server";
11import { getViewer, roleIn } from "../../lib/session.server";
12
13export function meta({ loaderData, params, ...args }: Route.MetaArgs) {
14 return page(args, { title: `${loaderData?.workspace.name ?? params.owner} · g1t` });
15}
16
17export async function loader({ params, context, request }: Route.LoaderArgs) {
18 const workspace = await identity.getWorkspace(params.owner);
19 if (!workspace) {
20 // A workspace's old name, after a rename: its pages are at the new one.
21 await redirectIfRenamed(request, params.owner);
22 throw notFound("workspace");
23 }
24 const role = roleIn(getViewer(context), workspace.slug);
25 // Opening one of your workspaces makes it the one you are in.
26 if (!role) return { workspace, role };
27 const secure = new URL(request.url).protocol === "https:";
28 return data({ workspace, role }, { headers: { "Set-Cookie": rememberWorkspace(workspace.slug, secure) } });
29}
30
31/** A workspace's own pages, each with its title and what it is for. */
32const PAGES: Record<string, { title: string; about: string }> = {
33 settings: { title: "General", about: "The workspace's name, icon, address and description, and deleting it." },
34 people: {
35 title: "Members",
36 about: "Members create repositories and have the base permission on each one. Owners are Admins on every repository, and also manage members, tokens, billing and integrations.",
37 },
38 repositories: {
39 title: "Repositories",
40 about: "Every repository in the workspace: who can see it, whether it is archived, and the ones deleted recently.",
41 },
42 tokens: {
43 title: "Access tokens",
44 about: "Tokens that belong to the workspace, not a person: for CI, integrations and agents that work for the whole team.",
45 },
46 usage: { title: "Usage", about: "What the workspace's agents cost, run by run, by repository, pull request and model." },
47 billing: { title: "Billing and plans", about: "The g1t plan, the trial, your spend limit and caps, prepaying, and every charge." },
48 agents: {
49 title: "Agent fleet",
50 about: "Every agent at work across the workspace's projects: what each holds, what it is doing now, and what it has cost.",
51 },
52 memory: {
53 title: "Workspace memory",
54 about: "What holds across all of the workspace's projects, given to every agent in every one of them, beside each project's own memory.",
55 },
56 context: {
57 title: "Context",
58 about: "Everything the workspace builds and runs, and what it knows: a catalog built from its projects, memory with a review queue, one search over all of it, and a scorecard for each project.",
59 },
60 audit: {
61 title: "Audit log",
62 about: "Every action agents took with their run credentials, and every change people and tokens made: by whom, on whose behalf, to what, and whether it was allowed.",
63 },
64 guardrails: {
65 title: "Guardrails",
66 about: "What agents may reach, run, spend and take in every project's sandboxes. Each project can override these under its settings.",
67 },
68 webhooks: {
69 title: "Webhooks",
70 about: "Every repository's events, sent to your own addresses as they happen. A repository can also have its own, under its settings.",
71 },
72 secrets: {
73 title: "Secrets and variables",
74 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.",
75 },
76 integrations: {
77 title: "Integrations",
78 about: "Model providers, alerts and trackers. Secrets are sealed when saved, and agents never see them.",
79 },
80};
81
82export default function WorkspaceLayout({ loaderData }: Route.ComponentProps) {
83 const { workspace, role } = loaderData;
84 // The sidebar finds the workspace's pages, for everyone, so its pages
85 // need a title, not the workspace's whole header again.
86 const page = PAGES[useLocation().pathname.split("/-/")[1]?.split("/")[0] ?? ""];
87 if (page) {
88 return (
89 <div className="mx-auto max-w-5xl px-4 py-10 sm:px-8">
90 <header className="mb-8 border-b border-line pb-6">
91 <h1 className="text-2xl font-semibold tracking-tight">{page.title}</h1>
92 <p className="mt-1.5 text-sm text-muted">{page.about}</p>
93 </header>
94 <Outlet />
95 </div>
96 );
97 }
98 return (
99 <>
100 {/* The workspace's own header band. */}
101 <div className="border-b border-line bg-surface/60">
102 <div className="mx-auto max-w-6xl px-4 pt-8 pb-8">
103 <div className="flex flex-wrap items-center gap-4">
104 <Avatar name={workspace.slug} image={workspace.avatar} size={52} square />
105 <div className="min-w-0 grow">
106 <div className="flex flex-wrap items-center gap-2.5">
107 <h1 className="truncate text-2xl font-semibold tracking-tight">
108 {workspace.name}
109 </h1>
110 {role && <Pill>{role}</Pill>}
111 </div>
112 <p className="font-mono text-sm text-muted">g1t.sh/{workspace.slug}</p>
113 </div>
114 {role && (
115 <ButtonLink to={`/new?workspace=${workspace.slug}`}>
116 <Plus size={15} />
117 New project
118 </ButtonLink>
119 )}
120 </div>
121 {workspace.description && (
122 <p className="mt-4 max-w-2xl text-sm text-muted">{workspace.description}</p>
123 )}
124 </div>
125 </div>
126 <div className="mx-auto max-w-6xl px-4 py-8">
127 <Outlet />
128 </div>
129 </>
130 );
131}