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/routes/workspace/layout.tsx

127 lines5,677 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." },
34 people: {
35 title: "Members",
36 about: "Members create repositories, push, manage issues and merge pull requests. Owners also manage members, tokens, billing and integrations.",
37 },
38 tokens: {
39 title: "Access tokens",
40 about: "Tokens that belong to the workspace, not a person: for CI, integrations and agents that work for the whole team.",
41 },
42 usage: { title: "Usage", about: "What the workspace's agents cost, run by run, by repository, pull request and model." },
43 billing: { title: "Billing and plans", about: "Paid plans, agent credit, and every charge against it." },
44 agents: {
45 title: "Agent fleet",
46 about: "Every agent at work across the workspace's projects: what each holds, what it is doing now, and what it has cost.",
47 },
48 memory: {
49 title: "Workspace memory",
50 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.",
51 },
52 context: {
53 title: "Context",
54 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.",
55 },
56 audit: {
57 title: "Audit log",
58 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.",
59 },
60 guardrails: {
61 title: "Guardrails",
62 about: "What agents may reach, run, spend and take in every project's sandboxes. Each project can override these under its settings.",
63 },
64 webhooks: {
65 title: "Webhooks",
66 about: "Every repository's events, sent to your own addresses as they happen. A repository can also have its own, under its settings.",
67 },
68 secrets: {
69 title: "Secrets and variables",
70 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.",
71 },
72 integrations: {
73 title: "Integrations",
74 about: "Model providers, alerts and trackers. Secrets are sealed when saved, and agents never see them.",
75 },
76};
77
78export default function WorkspaceLayout({ loaderData }: Route.ComponentProps) {
79 const { workspace, role } = loaderData;
80 // The sidebar finds the workspace's pages, for everyone, so its pages
81 // need a title, not the workspace's whole header again.
82 const page = PAGES[useLocation().pathname.split("/-/")[1]?.split("/")[0] ?? ""];
83 if (page) {
84 return (
85 <div className="mx-auto max-w-5xl px-4 py-10 sm:px-8">
86 <header className="mb-8 border-b border-line pb-6">
87 <h1 className="text-2xl font-semibold tracking-tight">{page.title}</h1>
88 <p className="mt-1.5 text-sm text-muted">{page.about}</p>
89 </header>
90 <Outlet />
91 </div>
92 );
93 }
94 return (
95 <>
96 {/* The workspace's own header band. */}
97 <div className="border-b border-line bg-surface/60">
98 <div className="mx-auto max-w-6xl px-4 pt-8 pb-8">
99 <div className="flex flex-wrap items-center gap-4">
100 <Avatar name={workspace.slug} image={workspace.avatar} size={52} square />
101 <div className="min-w-0 grow">
102 <div className="flex flex-wrap items-center gap-2.5">
103 <h1 className="truncate text-2xl font-semibold tracking-tight">
104 {workspace.name}
105 </h1>
106 {role && <Pill>{role}</Pill>}
107 </div>
108 <p className="font-mono text-sm text-muted">g1t.sh/{workspace.slug}</p>
109 </div>
110 {role && (
111 <ButtonLink to={`/new?workspace=${workspace.slug}`}>
112 <Plus size={15} />
113 New project
114 </ButtonLink>
115 )}
116 </div>
117 {workspace.description && (
118 <p className="mt-4 max-w-2xl text-sm text-muted">{workspace.description}</p>
119 )}
120 </div>
121 </div>
122 <div className="mx-auto max-w-6xl px-4 py-8">
123 <Outlet />
124 </div>
125 </>
126 );
127}