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.

g1t.sh
2,213 linesCodeBlameRaw
1import { Activity, BarChart3, Building2, MessagesSquare, Bell, BookMarked, BookOpen, Bookmark, Blocks, Bot, Box, Check, ChevronDown, ChevronLeft, ChevronRight, CircleDot, GripVertical, CircleUserRound, Code2, Coins, Compass, CreditCard, Fingerprint, Gauge, GitBranch, GitPullRequest, Globe, History, Keyboard, KeyRound, Layers, LayoutDashboard, LayoutGrid, LifeBuoy, ListTree, Lock, LogOut, Mail, MonitorCog, MonitorDown, Network, Package, PlayCircle, Plug, Plus, Rocket, Search, ServerCog, Settings, Shapes, Shield, ShieldCheck, Scale, Smile, Sparkles, SlidersHorizontal, House, Ticket, TrendingUp, UserRoundKey, Users, UsersRound, Webhook, X } from "lucide-react";
2import { Fragment, type ReactNode, useCallback, useEffect, useMemo, useRef, useState } from "react";
3import { Link, useFetcher, useLocation, useNavigation, useRouteLoaderData, useSubmit } from "react-router";
4
5import { type Abilities, type ChatSidebarEntry, type InboxCounts, type WorkspaceAgent, type Membership, type Spike, type User, hasCodeAccess, mayCreateTeams, shownUsername } from "@g1t/contracts";
6
7import { InMain } from "./landmark";
8import { CommandPalette, type PaletteCommand, PaletteKey, usePaletteShortcut } from "./command-palette";
9import { NotificationsBell } from "./inbox";
10import { desktopBridge, useDesktopApp, useTitleBarSearch } from "../lib/notify-client";
11import { SpendPill } from "./spend";
12import { PinButton } from "./pin-button";
13import { Hint } from "./ui/hint";
14import { Collapsible, CollapsibleContent, CollapsibleTrigger } from "./ui/collapsible";
15import {
16 Sidebar,
17 SidebarGroup,
18 SidebarGroupAction,
19 SidebarGroupContent,
20 SidebarGroupLabel,
21 SidebarHeader,
22 SidebarMenu,
23 SidebarMenuBadge,
24 SidebarMenuButton,
25 SidebarMenuItem,
26 SidebarMobile,
27 SidebarProvider,
28 SidebarSeparator,
29 SidebarTrigger,
30} from "./ui/sidebar";
31import { StatusDot, useSiteStatus } from "./footer";
32import { Logo, MarkGlyph } from "./logo";
33import { SoonPill } from "./ui";
34import { Avatar } from "./ui/avatar";
35import { Skeleton } from "./ui/skeleton";
36import { Button } from "./ui/button";
37import { Separator } from "./ui/separator";
38import { Breadcrumb, BreadcrumbItem, BreadcrumbLink, BreadcrumbList, BreadcrumbPage, BreadcrumbSeparator } from "./ui/breadcrumb";
39import {
40 DropdownMenu,
41 DropdownMenuContent,
42 DropdownMenuGroup,
43 DropdownMenuItem,
44 DropdownMenuLabel,
45 DropdownMenuSeparator,
46 DropdownMenuTrigger,
47} from "./ui/dropdown-menu";
48import { type RoadmapItem, roadmapIn, roadmapItem } from "../lib/roadmap";
49import { type ModeKey, WORKSPACE_SETTINGS_GROUPS, type WorkspaceSettingsPage, homePagePath, modeOf, workspaceSettingsPage } from "../lib/workspace-nav";
50import { AgentsSidebar } from "./agents-mode";
51import { ChatSidebar } from "./chat/sidebar";
52import { FoliosSidebar } from "./folios/sidebar";
53import { Rail, ShortcutsDialog, WorkspaceSwitcher, sidebarKeyLabel } from "./rail";
54import { BottomBar, isConversation, useVisualViewport } from "./mobile";
55import { useChatSidebar } from "./chat/actions";
56import { unreadTotals } from "../lib/chat";
57import { SETTINGS_CAPABILITY, type ViewerAccess, seesSettings } from "../lib/access";
58import { projectPages } from "../lib/chrome";
59import { ACCOUNT_SETTINGS, type AccountSettingsPage, FIRST_SETTINGS_PAGE, accountSettingsPage } from "../lib/account-settings";
60import { type PinnableApp, sidebarCookie } from "../lib/apps";
61import { REASON_FILTERS, inboxReason, inboxView } from "../lib/inbox";
62import { GithubMark } from "./github";
63import { useInviteOnly } from "../lib/registration";
64import { STATUS_URL, statusTitle } from "../lib/status";
65import { type ShortcutProject, movedPin, recentWith } from "../lib/pins";
66import type { AccountMenuData } from "../routes/settings-menu-json";
67import { useLiveBadges } from "../lib/notify-client";
68import { OwnPresenceDot, OwnPresenceItems, StatusDialog } from "./presence";
69import { THEME_COMMANDS, ThemeMenuSwitch } from "./theme-switch";
70
71/**
72 * What the sidebar needs, worked out by the root loader. For a visitor who
73 * is not signed in there is no workspace, no projects and no usage: only
74 * the project being looked at, if they can see it.
75 */
76export type ShellData = {
77 /** The workspace the sidebar is about: the one being looked at, or their first. */
78 workspace: Membership | null;
79 /** All its projects, by name, for the palette: `name` is the slug in their address. */
80 repos: ShortcutProject[];
81 /** The person's pinned projects in it, in their order (lib/pins.ts). */
82 pinned?: ShortcutProject[];
83 /** What they opened there last, latest first, leaving out the pinned. */
84 recent?: ShortcutProject[];
85 /** Repositories shared with them in workspaces they do not belong to. */
86 shared?: { namespace: string; name: string; isPrivate: boolean }[];
87 /** The project being looked at, if any, whoever owns it. */
88 repo: {
89 namespace: string;
90 name: string;
91 member: boolean;
92 issues: number;
93 pulls: number;
94 } | null;
95 /** Where the workspace stands against its usage limit, if billing is on. */
96 limit: {
97 exposureMicros: number;
98 ceilingMicros: number | null;
99 state: "ok" | "warning" | "stopped";
100 comped: boolean;
101 } | null;
102 /** Whether g1t charges nothing for now, while it is being built out. */
103 free?: boolean;
104 /** What its agents have cost since the start of the month. */
105 /** This month's usage: charged, or at cost while g1t is free. */
106 monthUsageMicros: number | null;
107 /** Whether new compute is paused (a spend spike or a hold), and whether the viewer can answer it. */
108 compute?: { paused: string | null; spike: Spike | null; owner: boolean } | null;
109 /** What is unread in their notifications, for the rail and the bell. Absent for a visitor. */
110 inbox?: InboxCounts | null;
111 /**
112 * Chat, for the rail's badge: what is unread, and the
113 * starred and latest conversations. Null when chat did not answer in time.
114 */
115 chat?: { unread: number; mentions: number; starred?: ChatSidebarEntry[]; recent?: ChatSidebarEntry[] } | null;
116 /** The workspace's agents, g1t first, for the Agents sidebar; null when not known. */
117 agents?: ShellAgent[] | null;
118 /** The apps this person pinned to their rail in the workspace (lib/apps.ts). */
119 pins?: PinnableApp[];
120};
121
122/** An agent as the shell lists it. */
123export type ShellAgent = Pick<
124 WorkspaceAgent,
125 "id" | "handle" | "display_name" | "avatar" | "avatar_seed" | "role" | "status" | "title" | "builtin"
126> & {
127 look?: WorkspaceAgent["look"];
128 scope?: WorkspaceAgent["scope"];
129 /** The visible teams it is on (team memberships); absent when they couldn't be read. */
130 teams?: { slug: string; name: string }[];
131};
132
133/** Whether `pathname` is `to` or a page under it (`end`: only `to` itself), the query left aside. */
134function under(pathname: string, to: string, end = false): boolean {
135 const path = to.split("?")[0]!;
136 return pathname === path || (!end && pathname.startsWith(path.endsWith("/") ? path : `${path}/`));
137}
138
139/**
140 * Where a row is current and where it is on its way to. A row's page is
141 * current under its own address and any `also` prefix, unless the list
142 * says itself (`current`). Rows that differ by query alone (Notifications'
143 * views and reasons) are pending only when the page on its way is that
144 * row's, query and all.
145 */
146function useRowState(to: string, { end, also, current: lit }: { end?: boolean; also?: string | string[]; current?: boolean }) {
147 const { pathname } = useLocation();
148 const going = useNavigation().location;
149 const current = lit ?? (under(pathname, to, end) || [also ?? []].flat().some((prefix) => under(pathname, prefix)));
150 const pending =
151 going != null && !current && (lit === undefined ? under(going.pathname, to, end) : `${going.pathname}${going.search}` === to);
152 return { current, pending };
153}
154
155/**
156 * One row of a mode's sidebar: an icon, its words, how many it lists
157 * (`count`) and, for a row that opens a list of its own (`drill`), a
158 * chevron, always or on hover.
159 */
160function SidebarLink({
161 to,
162 icon,
163 end,
164 count,
165 also,
166 drill,
167 current: lit,
168 action,
169 bare = false,
170 children,
171}: {
172 to: string;
173 icon: ReactNode;
174 end?: boolean;
175 count?: number;
176 /** Other path prefixes under which this link is the current one. */
177 also?: string | string[];
178 /** It opens a list of its own: a chevron says so, always or on hover. */
179 drill?: boolean | "hover";
180 /** Whether it is the current row, when the list works that out itself. */
181 current?: boolean;
182 /** A small button at the row's end, beside the words (a pin). */
183 action?: ReactNode;
184 /** The row alone, for a list item that is drawn by the list (a pinned project, which drags). */
185 bare?: boolean;
186 children: ReactNode;
187}) {
188 const { current, pending } = useRowState(to, { end, also, current: lit });
189 const Item = bare ? Fragment : SidebarMenuItem;
190 return (
191 <Item>
192 <SidebarMenuButton asChild isActive={current} isPending={pending} className={action ? "pr-7" : undefined}>
193 <Link to={to} prefetch="intent" aria-current={current ? "page" : undefined}>
194 {icon}
195 <span className="min-w-0 grow truncate">{children}</span>
196 {count != null && count > 0 && <SidebarMenuBadge>{count}</SidebarMenuBadge>}
197 {drill && (
198 <ChevronRight
199 aria-hidden="true"
200 className={`-mr-0.5 size-3.5! shrink-0 text-faint transition-opacity ${drill === "hover" ? "opacity-0 group-hover/menu-button:opacity-100 group-focus-visible/menu-button:opacity-100" : ""}`}
201 />
202 )}
203 </Link>
204 </SidebarMenuButton>
205 {action}
206 </Item>
207 );
208}
209
210/**
211 * Something a project will have, shown where it will live so people can
212 * see where g1t is going. Not a link: nothing is behind it yet.
213 */
214function SidebarSoon({ icon, children, about }: { icon: ReactNode; children: ReactNode; about: string }) {
215 return (
216 <SidebarMenuItem>
217 <Hint label={about} side="right">
218 <SidebarMenuButton asChild variant="faint">
219 <div aria-disabled="true" className="cursor-default">
220 {icon}
221 <span className="min-w-0 grow truncate">{children}</span>
222 <span className="sr-only">{about}</span>
223 <SoonPill />
224 </div>
225 </SidebarMenuButton>
226 </Hint>
227 </SidebarMenuItem>
228 );
229}
230
231/**
232 * A page that is coming, as a link to its roadmap page: faint, with Soon,
233 * and marked current on any of its section's Soon pages.
234 */
235function SidebarSoonLink({
236 to,
237 also,
238 icon,
239 about,
240 current: lit,
241 children,
242}: {
243 to: string;
244 also?: string[];
245 icon: ReactNode;
246 about: string;
247 /** Whether it is the current row, when the list works that out itself. */
248 current?: boolean;
249 children: ReactNode;
250}) {
251 const { current, pending } = useRowState(to, { also, current: lit });
252 return (
253 <SidebarMenuItem>
254 <Hint label={about} side="right">
255 <SidebarMenuButton asChild variant="faint" isActive={current} isPending={pending}>
256 <Link to={to} prefetch="intent" aria-current={current ? "page" : undefined}>
257 {icon}
258 <span className="min-w-0 grow truncate">{children}</span>
259 <SoonPill />
260 </Link>
261 </SidebarMenuButton>
262 </Hint>
263 </SidebarMenuItem>
264 );
265}
266
267/** The Soon pages of a section, as paths, so its link is current on them. */
268function soonPaths(base: string, section: RoadmapItem["section"]): string[] {
269 return roadmapIn(section).map((item) => `${base}/soon/${item.key}`);
270}
271
272/** A titled group of rows: its name in small capitals, what it makes at the end, and its menu. */
273function NavGroup({
274 title,
275 action,
276 className,
277 children,
278}: {
279 title: string;
280 /** A small button at the label's end, in its row: what the group makes (a `SidebarGroupAction` with `relative top-auto right-auto`). */
281 action?: ReactNode;
282 className?: string;
283 children: ReactNode;
284}) {
285 return (
286 <SidebarGroup className={className}>
287 <div className="flex items-center justify-between gap-2 pr-1">
288 <SidebarGroupLabel asChild>
289 <h2>{title}</h2>
290 </SidebarGroupLabel>
291 {action}
292 </div>
293 <SidebarGroupContent>
294 <SidebarMenu>{children}</SidebarMenu>
295 </SidebarGroupContent>
296 </SidebarGroup>
297 );
298}
299
300/** Rows with no name over them: the first of a list, or a run between rules. */
301function NavRows({ className, children }: { className?: string; children: ReactNode }) {
302 return (
303 <SidebarGroup className={className}>
304 <SidebarGroupContent>
305 <SidebarMenu>{children}</SidebarMenu>
306 </SidebarGroupContent>
307 </SidebarGroup>
308 );
309}
310
311/** What a workspace is called where people read it: its display name, else its slug. */
312function displayName(membership: Membership): string {
313 return membership.name?.trim() || membership.slug;
314}
315
316/**
317 * The fine print, as one quiet row at the foot of the account menu and the
318 * visitor's panel: each link a full-height target, left-aligned. In the
319 * menu each is a menu item, so the arrow keys reach it.
320 */
321const LEGAL_LINKS: [string, string][] = [
322 ["Policies", "/policies"],
323 ["Privacy", "/policies/privacy"],
324 ["Security", "/security"],
325];
326const LEGAL_LINK = "flex h-7 items-center rounded px-1.5 text-xs text-faint outline-none transition-colors";
327
328function MenuLegalRow() {
329 return (
330 <div role="group" aria-label="Legal" className="flex items-center gap-0.5 px-0.5 pt-0.5">
331 {LEGAL_LINKS.map(([label, to], index) => (
332 <span key={to} className="flex items-center gap-0.5">
333 {index > 0 && (
334 <span aria-hidden="true" className="text-[0.625rem] text-line-strong">
335 ·
336 </span>
337 )}
338 <DropdownMenuItem asChild className={`${LEGAL_LINK} py-0 data-highlighted:bg-line data-highlighted:text-fg`}>
339 <Link to={to}>{label}</Link>
340 </DropdownMenuItem>
341 </span>
342 ))}
343 </div>
344 );
345}
346
347/** Status's row: the live dot and two or three words, fetched when the menu opens. */
348function StatusSummary({ open }: { open: boolean }) {
349 const status = useSiteStatus(open);
350 const words = statusTitle(status);
351 return (
352 <span className="ml-auto flex min-w-0 items-center gap-1.5 pl-2 text-xs text-faint">
353 {/* The words say it; the dot's own words for screen readers would repeat them. */}
354 <span aria-hidden="true" className="flex">
355 <StatusDot state={status?.overall.state ?? null} />
356 </span>
357 {words ? <span className="truncate">{words}</span> : <Skeleton className="h-3 w-20" />}
358 </span>
359 );
360}
361
362/** A menu row: an icon, words, and whatever sits at its end. */
363const MENU_ROW = "h-9 gap-2.5 px-2.5 text-[0.8125rem]";
364
365/**
366 * Your account, at the foot of the rail (or in the header, before you have
367 * a workspace): who you are and your status, your profile and settings,
368 * and help: the documentation, support, status and the keyboard's
369 * shortcuts; then signing out and the fine print.
370 */
371function AccountMenu({ user, side = "right" }: { user: User; side?: "right" | "bottom" }) {
372 const submit = useSubmit();
373 const [open, setOpen] = useState(false);
374 const [keys, setKeys] = useState(false);
375 // Inside the desktop app there is nothing to get.
376 const inApp = useDesktopApp();
377 // Your status's dialog: outside the menu, so the menu closes behind it.
378 const [editing, setEditing] = useState(false);
379 // Name, primary address and invites left: asked for once, as soon as the
380 // pointer or focus reaches the button, so they are there when it opens.
381 const details = useFetcher<AccountMenuData | null>({ key: "account-menu" });
382 const prefetch = () => {
383 if (details.state === "idle" && details.data === undefined) details.load("/settings/menu.json");
384 };
385 useEffect(() => {
386 if (open) prefetch();
387 // eslint-disable-next-line react-hooks/exhaustive-deps
388 }, [open]);
389 const me = details.data ?? null;
390 // Still on its way: shapes where the words will be, the same size.
391 const loading = details.data === undefined && details.state !== "idle";
392 // While anyone can sign up, listed once the data says there are invites to look back on.
393 const invitesListed = useInviteOnly() || me?.invites_page === true;
394 const profile = `/u/${user.username}`;
395 return (
396 <>
397 <DropdownMenu open={open} onOpenChange={setOpen}>
398 {/* The avatar alone, with a dot that says how others see you (components/presence.tsx). */}
399 <Hint label={side === "right" ? "Your account" : undefined} side="right">
400 <DropdownMenuTrigger
401 aria-label={`Account menu for ${shownUsername(user)}`}
402 onPointerEnter={prefetch}
403 onFocus={prefetch}
404 className={
405 side === "right"
406 ? // At the foot of the rail: a 40px rounded square, as the rail's icons are.
407 "relative flex size-10 items-center justify-center rounded-[10px] outline-none transition-colors hover:bg-sidebar-accent focus-visible:ring-2 focus-visible:ring-accent data-[state=open]:bg-sidebar-accent"
408 : "relative flex rounded-full outline-none transition-transform hover:scale-[1.04] focus-visible:ring-2 focus-visible:ring-accent data-[state=open]:ring-2 data-[state=open]:ring-line-strong"
409 }
410 >
411 <Avatar name={user.username} image={user.avatar} size={side === "right" ? 40 : 28} square={side === "right"} />
412 <OwnPresenceDot ring={side === "right" ? "var(--color-rail)" : "var(--color-bg)"} className={side === "right" ? "absolute -right-1 -bottom-1" : "absolute -right-0.5 -bottom-0.5"} />
413 </DropdownMenuTrigger>
414 </Hint>
415 <DropdownMenuContent align="end" side={side} sideOffset={side === "right" ? 14 : 6} collisionPadding={8} className="w-70 p-1.5">
416 {/* Who is signed in, and a way to their profile. */}
417 <DropdownMenuItem asChild className="gap-3 px-2 py-2">
418 <Link to={profile} aria-label={`${me?.name ?? shownUsername(user)} (@${shownUsername(user)}), your profile`}>
419 <Avatar name={user.username} image={user.avatar} size={36} />
420 <span className="flex min-w-0 grow flex-col leading-tight" aria-busy={loading}>
421 {loading ? (
422 <Skeleton className="my-0.75 h-3.5 w-28" />
423 ) : (
424 <span className="truncate text-sm font-medium text-fg">{me?.name ?? shownUsername(user)}</span>
425 )}
426 <span className="truncate font-mono text-xs text-muted">@{shownUsername(user)}</span>
427 {loading ? (
428 <Skeleton className="mt-1 h-3 w-40" />
429 ) : (
430 me?.email && <span className="mt-0.5 truncate text-xs text-faint">{me.email}</span>
431 )}
432 </span>
433 </Link>
434 </DropdownMenuItem>
435 <DropdownMenuSeparator className="my-1.5" />
436 {/* Your status, away, and pausing notifications. */}
437 <DropdownMenuGroup>
438 <OwnPresenceItems className="min-h-9 py-1.5 text-[0.8125rem]" onEdit={() => setEditing(true)} />
439 </DropdownMenuGroup>
440 <DropdownMenuSeparator className="my-1.5" />
441 <DropdownMenuGroup>
442 <DropdownMenuItem asChild className={MENU_ROW}>
443 <Link to={profile}>
444 <CircleUserRound />
445 Your profile
446 </Link>
447 </DropdownMenuItem>
448 <DropdownMenuItem asChild className={MENU_ROW}>
449 <Link to={FIRST_SETTINGS_PAGE}>
450 <Settings />
451 Your settings
452 </Link>
453 </DropdownMenuItem>
454 {/* The app's own: starting with the computer, closing to the tray, the badge (apps/desktop). */}
455 {inApp && desktopBridge()?.openSettings && (
456 <DropdownMenuItem className={MENU_ROW} onSelect={() => desktopBridge()?.openSettings?.()}>
457 <MonitorCog />
458 Desktop app settings
459 </DropdownMenuItem>
460 )}
461 {invitesListed && (
462 <DropdownMenuItem asChild className={MENU_ROW}>
463 <Link to="/settings/invites">
464 <Ticket />
465 {ACCOUNT_SETTINGS.invites.title}
466 {loading && <Skeleton className="ml-auto h-4 w-12 rounded-full" />}
467 {me?.invites_left != null && (
468 <span className="ml-auto rounded-full bg-line px-1.5 text-[0.6875rem] tabular-nums text-muted">
469 {me.invites_left} left
470 </span>
471 )}
472 </Link>
473 </DropdownMenuItem>
474 )}
475 </DropdownMenuGroup>
476 <DropdownMenuSeparator className="my-1.5" />
477 {/* Auto, Light or Dark, switched in place (lib/theme.ts). */}
478 <ThemeMenuSwitch />
479 <DropdownMenuSeparator className="my-1.5" />
480 <DropdownMenuGroup>
481 <DropdownMenuItem asChild className={MENU_ROW}>
482 <a href="https://docs.g1t.sh/">
483 <BookOpen />
484 Documentation
485 </a>
486 </DropdownMenuItem>
487 <DropdownMenuItem asChild className={MENU_ROW}>
488 <Link to="/support">
489 <LifeBuoy />
490 Support
491 </Link>
492 </DropdownMenuItem>
493 <DropdownMenuItem asChild className={MENU_ROW}>
494 <a href={STATUS_URL}>
495 <Activity />
496 Status
497 <StatusSummary open={open} />
498 </a>
499 </DropdownMenuItem>
500 <DropdownMenuItem className={MENU_ROW} onSelect={() => setKeys(true)}>
501 <Keyboard />
502 Keyboard shortcuts
503 <PaletteKey className="ml-auto font-sans text-xs text-faint" />
504 </DropdownMenuItem>
505 {!inApp && (
506 <DropdownMenuItem asChild className={MENU_ROW}>
507 <Link to="/download">
508 <MonitorDown />
509 Get the desktop app
510 </Link>
511 </DropdownMenuItem>
512 )}
513 </DropdownMenuGroup>
514 <DropdownMenuSeparator className="my-1.5" />
515 {/* Submitted from here: the menu closes on select, and a button
516 that has left the page cannot submit a form. */}
517 <DropdownMenuItem className={MENU_ROW} onSelect={() => submit(null, { method: "post", action: "/logout" })}>
518 <LogOut />
519 Sign out
520 </DropdownMenuItem>
521 <DropdownMenuSeparator className="my-1.5" />
522 <MenuLegalRow />
523 </DropdownMenuContent>
524 </DropdownMenu>
525 <StatusDialog open={editing} onOpenChange={setEditing} />
526 <ShortcutsDialog open={keys} onOpenChange={setKeys} />
527 </>
528 );
529}
530
531/** A project's settings pages, which the project's menu drills into. */
532const REPO_SETTINGS_PAGE = /^\/([^/]+)\/([^/-][^/]*)\/settings(\/|$)/;
533
534/**
535 * The sidebar's lists are a stack, the way a phone pushes a screen: one
536 * drilled into slides in from the right over the full width, while the one
537 * it covers drifts a quarter of the way left and fades, both on one long
538 * ease-out, the fade quicker than the move so the two never blur together.
539 * Going back reverses it.
540 */
541const LAYER =
542 "absolute inset-0 [transition:translate_380ms_cubic-bezier(0.32,0.72,0,1),opacity_220ms_ease-out] will-change-[translate,opacity] motion-reduce:transition-none";
543/** One list, filling its layer. */
544const PANEL = "h-full overflow-y-auto px-1 pt-1 pb-4 [scrollbar-width:thin]";
545
546/** One list in the stack: what it is, and its rows. */
547type Level = { key: string; node: ReactNode };
548
549/** True once the page has hydrated, so what the server drew never animates in. */
550function useHydrated(): boolean {
551 const [hydrated, setHydrated] = useState(false);
552 useEffect(() => setHydrated(true), []);
553 return hydrated;
554}
555
556/**
557 * Drilling in and out of the sidebar's lists. `trail` is the way from the
558 * main list to the one shown, worked out from the address, so a link
559 * straight to a settings page opens the sidebar already drilled in, and
560 * leaving it comes back out. Lists deeper than the one shown stay in
561 * place, off to the right, so going back slides them away rather than
562 * dropping them. Moving to a list at the same depth (a workspace's settings
563 * to a project) fades the new one in where it is.
564 */
565function Drill({ trail }: { trail: Level[] }) {
566 const depth = trail.length - 1;
567 const hydrated = useHydrated();
568 const stack = useRef<Level[]>(trail);
569 const before = stack.current;
570 const within = trail.every((level, index) => before[index]?.key === level.key);
571 stack.current = within ? [...trail, ...before.slice(trail.length)] : trail;
572 const levels = stack.current;
573 // What was showing last time, to tell drilling in from moving across.
574 const shown = useRef({ depth, keys: levels.map((level) => level.key) });
575 useEffect(() => {
576 shown.current = { depth, keys: levels.map((level) => level.key) };
577 });
578 return (
579 <div className="relative min-h-0 grow overflow-hidden">
580 {levels.map((level, index) => {
581 const current = index === depth;
582 const place =
583 index < depth
584 ? "pointer-events-none -translate-x-1/4 opacity-0"
585 : current
586 ? "translate-x-0 opacity-100"
587 : "pointer-events-none translate-x-full opacity-0";
588 // A list that was not there before arrives: from the right when
589 // drilling in, in place when moving across.
590 const arriving = hydrated && current && !shown.current.keys.includes(level.key);
591 const enter = arriving
592 ? depth > shown.current.depth
593 ? "starting:translate-x-full starting:opacity-0"
594 : "starting:opacity-0"
595 : "";
596 return (
597 <div key={level.key} className={`${LAYER} ${place} ${enter}`} inert={!current} aria-hidden={!current || undefined}>
598 {level.node}
599 </div>
600 );
601 })}
602 </div>
603 );
604}
605
606/**
607 * The row at the top of a list drilled into: the list's name, which goes
608 * back out, and what it belongs to, faint at the end.
609 */
610function BackRow({ to, label, context }: { to: string; label: ReactNode; context?: ReactNode }) {
611 return (
612 <NavRows className="mt-1">
613 <SidebarMenuItem>
614 <SidebarMenuButton asChild className="gap-1.5 pl-1 font-medium text-fg">
615 <Link to={to} prefetch="intent">
616 <ChevronLeft className="text-faint transition-transform group-hover/menu-button:-translate-x-0.5 group-hover/menu-button:text-muted" />
617 <span className="min-w-0 shrink-0 truncate">{label}</span>
618 {context && <span className="ml-auto min-w-0 truncate pl-2 font-mono text-[0.6875rem] font-normal text-faint">{context}</span>}
619 </Link>
620 </SidebarMenuButton>
621 </SidebarMenuItem>
622 </NavRows>
623 );
624}
625
626/** A thin rule between groups of a list. */
627function Rule() {
628 return <SidebarSeparator className="my-1.5" />;
629}
630
631/** A quiet heading inside a group: Pinned, Recent. */
632function SidebarSubhead({ children }: { children: ReactNode }) {
633 return (
634 <SidebarGroupLabel asChild className="h-6 pt-0.5">
635 <h3>{children}</h3>
636 </SidebarGroupLabel>
637 );
638}
639
640/**
641 * The workspace's projects as the sidebar keeps them, however many there
642 * are: the person's pins in their order, what they opened last, and the
643 * way to all of them. Pins move by dragging, or with Alt and the arrow
644 * keys; the projects service keeps the order.
645 */
646function SidebarProjects({ slug, shell, current }: { slug: string; shell: ShellData; current: boolean }) {
647 const reorder = useFetcher({ key: `pins:${slug}` });
648 const saved = shell.pinned ?? [];
649 // While a new order is on its way, it shows as made.
650 const asked = reorder.formData?.get("intent") === "reorder" ? reorder.formData.getAll("slug").map(String) : null;
651 const pinned = asked
652 ? asked.map((name) => saved.find((project) => project.name === name)).filter((project): project is ShortcutProject => project != null)
653 : saved;
654 const active = shell.repo ? { namespace: shell.repo.namespace, name: shell.repo.name, isPrivate: false } : null;
655 const recent = recentWith(shell.recent ?? [], pinned, active, slug);
656 const [dragging, setDragging] = useState<number | null>(null);
657 const move = (from: number, by: number) => {
658 const next = movedPin(pinned, from, by);
659 if (!next) return;
660 const form = new FormData();
661 form.set("intent", "reorder");
662 for (const project of next) form.append("slug", project.name);
663 reorder.submit(form, { method: "post", action: `/${slug}/-/pins` });
664 };
665 // Each row pins or unpins in place: the pin shows on hover or focus, and
666 // stays shown on a pinned row's hover so it reads as "unpin".
667 const row = (project: ShortcutProject, isPinned: boolean) => (
668 <SidebarLink
669 to={`/${project.namespace}/${project.name}`}
670 icon={project.isPrivate ? <Lock /> : <Box />}
671 bare={isPinned}
672 action={
673 // At the row's end, where the row's other actions sit, and only on
674 // hover or keyboard focus: a pin clicked keeps the mouse's focus,
675 // and showing it on any focus left it lit on a row no one was over.
676 <PinButton
677 workspace={slug}
678 slug={project.name}
679 name={project.title ?? project.name}
680 pinned={isPinned}
681 small
682 className="absolute top-1/2 right-1 -translate-y-1/2 opacity-0 transition-opacity group-hover/menu-item:opacity-100 has-focus-visible:opacity-100 [@media(hover:none)]:opacity-100"
683 />
684 }
685 >
686 {project.title ?? project.name}
687 </SidebarLink>
688 );
689 return (
690 <SidebarGroup>
691 {/* The label and its button share a row, so the button stays level with the words at any text size. */}
692 <div className="flex items-center justify-between gap-2 pr-1">
693 <SidebarGroupLabel asChild>
694 <h2>Projects</h2>
695 </SidebarGroupLabel>
696 <Hint label="New project">
697 <SidebarGroupAction asChild className="relative top-auto right-auto">
698 <Link to="/new" aria-label="New project">
699 <Plus />
700 </Link>
701 </SidebarGroupAction>
702 </Hint>
703 </div>
704 <SidebarGroupContent>
705 {/* Only there once something is pinned: each row below has its own pin. */}
706 {pinned.length > 0 && (
707 <>
708 <SidebarSubhead>Pinned</SidebarSubhead>
709 <SidebarMenu aria-label="Pinned projects">
710 {pinned.map((project, index) => (
711 <SidebarMenuItem
712 key={project.name}
713 draggable={pinned.length > 1}
714 onDragStart={(event) => {
715 setDragging(index);
716 event.dataTransfer.effectAllowed = "move";
717 }}
718 onDragOver={(event) => {
719 if (dragging != null) event.preventDefault();
720 }}
721 onDrop={(event) => {
722 event.preventDefault();
723 if (dragging != null && dragging !== index) move(dragging, index - dragging);
724 setDragging(null);
725 }}
726 onDragEnd={() => setDragging(null)}
727 onKeyDown={(event) => {
728 if (!event.altKey || (event.key !== "ArrowUp" && event.key !== "ArrowDown")) return;
729 event.preventDefault();
730 move(index, event.key === "ArrowUp" ? -1 : 1);
731 }}
732 className={`group/pin ${dragging === index ? "opacity-50" : ""}`}
733 >
734 {row(project, true)}
735 {pinned.length > 1 && (
736 <Hint label="Drag, or Alt and an arrow key, to reorder" side="right">
737 <span className="absolute top-1/2 -left-2 -translate-y-1/2 cursor-grab text-faint opacity-0 transition-opacity group-hover/pin:opacity-100">
738 <GripVertical size={12} aria-hidden="true" />
739 </span>
740 </Hint>
741 )}
742 </SidebarMenuItem>
743 ))}
744 </SidebarMenu>
745 </>
746 )}
747 {recent.length > 0 && (
748 <>
749 <SidebarSubhead>Recent</SidebarSubhead>
750 <SidebarMenu aria-label="Recent projects">
751 {recent.map((project) => (
752 <Fragment key={`${project.namespace}/${project.name}`}>{row(project, false)}</Fragment>
753 ))}
754 </SidebarMenu>
755 </>
756 )}
757 <SidebarMenu className="pt-1">
758 <SidebarLink to={`/${slug}/-/projects`} icon={<LayoutGrid />} count={shell.repos.length} current={current}>
759 All projects
760 </SidebarLink>
761 </SidebarMenu>
762 </SidebarGroupContent>
763 </SidebarGroup>
764 );
765}
766
767/** Insights, coming: the workspace's own page says what it will be. */
768const INSIGHTS = roadmapItem("insights");
769
770/**
771 * What the repository menu needs. Known from the address before the page's
772 * data arrives, so the menu is right from the first frame; the counts fill
773 * in once it does.
774 */
775type MenuRepo = {
776 namespace: string;
777 name: string;
778 member: boolean;
779 /** Whether they see its settings; from the repository's page once it loads. */
780 settings?: boolean;
781 /** What they may do there, once the repository's page loads. */
782 can?: Abilities;
783 issues?: number;
784 pulls?: number;
785};
786
787function sameRepo(a: { namespace: string; name: string } | null, b: { namespace: string; name: string } | null) {
788 return (
789 a != null &&
790 b != null &&
791 a.namespace.toLowerCase() === b.namespace.toLowerCase() &&
792 a.name.toLowerCase() === b.name.toLowerCase()
793 );
794}
795
796/**
797 * A project's own list, drilled into while you are in it: everything about
798 * the project, running and its code, and nothing else, with the way back
799 * out to all of them.
800 */
801function RepoMenu({
802 repo,
803 isPrivate,
804 back,
805}: {
806 repo: MenuRepo;
807 isPrivate: boolean;
808 /** Where the way back leads: the workspace's projects, mission control, or Explore. */
809 back: { to: string; label: string };
810}) {
811 const base = `/${repo.namespace}/${repo.name}`;
812 // What a member sees, and what everyone who can see the project does
813 // (lib/chrome.ts).
814 const shows = new Set(projectPages(repo.member, repo.can));
815 const { current: atOverview, pending: toOverview } = useRowState(base, { end: true });
816 return (
817 <nav aria-label={`${repo.namespace}/${repo.name}`} className={PANEL}>
818 <BackRow to={back.to} label={back.label} />
819 <NavRows className="mt-1">
820 <SidebarMenuItem>
821 <Hint label="Overview" side="right">
822 <SidebarMenuButton asChild size="lg" isActive={atOverview} isPending={toOverview} className="gap-2 font-normal">
823 <Link to={base} prefetch="intent" aria-current={atOverview ? "page" : undefined}>
824 <span className="flex size-6 shrink-0 items-center justify-center rounded-md bg-raised text-muted ring-1 ring-line [&>svg]:size-3.5">
825 {isPrivate ? <Lock /> : <Box />}
826 </span>
827 <span className="min-w-0 truncate font-mono text-[0.8125rem]">
828 <span className="text-faint">{repo.namespace}/</span>
829 <span className="font-semibold text-fg">{repo.name}</span>
830 </span>
831 </Link>
832 </SidebarMenuButton>
833 </Hint>
834 </SidebarMenuItem>
835 </NavRows>
836 {/* A project's pages, in the order people use them. A page with more
837 than one view shows them as tabs across its top. */}
838 <Rule />
839 <NavRows>
840 <SidebarLink to={`${base}/code`} also={[`${base}/tree`, `${base}/blob`, `${base}/commits`, `${base}/commit`, `${base}/branches`, `${base}/tags`, `${base}/compare`, ...soonPaths(base, "Code")]} icon={<Code2 size={15} />}>
841 Code
842 </SidebarLink>
843 {shows.has("issues") && (
844 <SidebarLink to={`${base}/issues`} also={[`${base}/plans`, `${base}/milestones`, `${base}/labels`, ...soonPaths(base, "Issues")]} icon={<CircleDot size={15} />} count={repo.issues}>
845 Issues
846 </SidebarLink>
847 )}
848 {shows.has("pulls") && (
849 <SidebarLink to={`${base}/pulls`} also={[`${base}/pull`, `${base}/queue`]} icon={<GitPullRequest size={15} />} count={repo.pulls}>
850 Pull requests
851 </SidebarLink>
852 )}
853 {shows.has("agents") && (
854 <SidebarLink to={`${base}/agents`} also={[`${base}/sessions`, `${base}/memory`, ...soonPaths(base, "Agents")]} icon={<Bot size={15} />}>
855 Agents
856 </SidebarLink>
857 )}
858 {shows.has("actions") && (
859 <SidebarLink to={`${base}/actions`} icon={<PlayCircle size={15} />}>
860 Workflows
861 </SidebarLink>
862 )}
863 </NavRows>
864 <Rule />
865 <NavRows>
866 {shows.has("deployments") ? (
867 <SidebarLink to={`${base}/deployments`} also={soonPaths(base, "Deployments")} icon={<Rocket size={15} />}>
868 Deployments
869 </SidebarLink>
870 ) : null}
871 {shows.has("observability") && (
872 <SidebarLink to={`${base}/observability`} also={soonPaths(base, "Observability")} icon={<Activity size={15} />}>
873 Observability
874 </SidebarLink>
875 )}
876 {shows.has("security") ? (
877 <SidebarLink to={`${base}/security`} also={soonPaths(base, "Security")} icon={<ShieldCheck size={15} />}>
878 Security
879 </SidebarLink>
880 ) : null}
881 <SidebarLink
882 to={`${base}/contributors`}
883 also={[`${base}/activity`, `${base}/stargazers`, ...soonPaths(base, "Insights")]}
884 icon={<BarChart3 size={15} />}
885 >
886 Insights
887 </SidebarLink>
888 </NavRows>
889 {(repo.settings ?? shows.has("settings")) && (
890 <>
891 <Rule />
892 <NavRows>
893 <SidebarLink to={`${base}/settings`} icon={<Settings size={15} />} drill>
894 Settings
895 </SidebarLink>
896 </NavRows>
897 </>
898 )}
899 </nav>
900 );
901}
902
903/**
904 * A project's settings, drilled into from its list: what is about running
905 * it, then its agents, then its code and who can reach it. The way back
906 * leads to the project.
907 */
908function RepoSettingsMenu({ repo }: { repo: MenuRepo }) {
909 const base = `/${repo.namespace}/${repo.name}`;
910 // Each page shows to the roles that can use it, once the role is known.
911 const shows = (page: string) => !repo.can || repo.can[SETTINGS_CAPABILITY[page] ?? "administer"];
912 const running = shows("deployments");
913 const agents = shows("agents") || shows("guardrails");
914 return (
915 <nav aria-label={`${repo.namespace}/${repo.name} settings`} className={PANEL}>
916 <BackRow to={base} label="Settings" context={`${repo.namespace}/${repo.name}`} />
917 {shows("") && (
918 <NavRows className="mt-2">
919 <SidebarLink to={`${base}/settings`} end icon={<Settings size={15} />}>
920 General
921 </SidebarLink>
922 </NavRows>
923 )}
924 {running && (
925 <>
926 {shows("") && <Rule />}
927 <NavRows className={shows("") ? undefined : "mt-2"}>
928 <SidebarLink to={`${base}/settings/deployments`} icon={<Rocket size={15} />}>
929 Deployments
930 </SidebarLink>
931 <SidebarLink to={`${base}/settings/domains`} icon={<Globe size={15} />}>
932 Domains
933 </SidebarLink>
934 </NavRows>
935 </>
936 )}
937 {agents && (
938 <>
939 <Rule />
940 <NavRows>
941 {shows("agents") && (
942 <SidebarLink to={`${base}/settings/agents`} icon={<Bot size={15} />}>
943 Agents
944 </SidebarLink>
945 )}
946 {shows("guardrails") && (
947 <SidebarLink to={`${base}/settings/guardrails`} icon={<ShieldCheck size={15} />}>
948 Guardrails
949 </SidebarLink>
950 )}
951 </NavRows>
952 </>
953 )}
954 <Rule />
955 <NavRows>
956 {shows("repository") && (
957 <SidebarLink to={`${base}/settings/repository`} icon={<BookMarked size={15} />}>
958 Repository
959 </SidebarLink>
960 )}
961 {shows("access") && (
962 <SidebarLink to={`${base}/settings/access`} icon={<Users size={15} />}>
963 Access
964 </SidebarLink>
965 )}
966 {shows("keys") && (
967 <SidebarLink to={`${base}/settings/keys`} icon={<KeyRound size={15} />}>
968 Deploy keys
969 </SidebarLink>
970 )}
971 {shows("branches") && (
972 <SidebarLink to={`${base}/settings/branches`} icon={<GitBranch size={15} />}>
973 Branches and merging
974 </SidebarLink>
975 )}
976 {shows("rules") && (
977 <SidebarLink to={`${base}/settings/rules`} icon={<Scale size={15} />}>
978 Rules
979 </SidebarLink>
980 )}
981 {shows("secrets") && (
982 <SidebarLink to={`${base}/settings/secrets`} icon={<Lock size={15} />}>
983 Secrets and variables
984 </SidebarLink>
985 )}
986 {shows("actions") && (
987 <SidebarLink to={`${base}/settings/actions`} icon={<PlayCircle size={15} />}>
988 Actions
989 </SidebarLink>
990 )}
991 {shows("environments") && (
992 <SidebarLink to={`${base}/settings/environments`} icon={<Layers size={15} />}>
993 Environments
994 </SidebarLink>
995 )}
996 {shows("runners") && (
997 <SidebarLink to={`${base}/settings/runners`} icon={<ServerCog size={15} />}>
998 Runners
999 </SidebarLink>
1000 )}
1001 {shows("webhooks") && (
1002 <SidebarLink to={`${base}/settings/webhooks`} icon={<Webhook size={15} />}>
1003 Webhooks
1004 </SidebarLink>
1005 )}
1006 </NavRows>
1007 </nav>
1008 );
1009}
1010
1011/**
1012 * Whether the menus list Settings → Invites (invites to g1t): always while
1013 * sign-up takes an invite; once anyone can sign up, only for someone with
1014 * invites already made to look back on, which the account menu's data says.
1015 */
1016function useInvitesListed(): boolean {
1017 const inviteOnly = useInviteOnly();
1018 const details = useFetcher<AccountMenuData | null>({ key: "account-menu" });
1019 useEffect(() => {
1020 if (!inviteOnly && details.state === "idle" && details.data === undefined) details.load("/settings/menu.json");
1021 // eslint-disable-next-line react-hooks/exhaustive-deps
1022 }, [inviteOnly]);
1023 return inviteOnly || details.data?.invites_page === true;
1024}
1025
1026/** Your own settings, drilled into from Your settings: one page each. */
1027function AccountSettingsMenu({ username }: { username: string }) {
1028 const invites = useInvitesListed();
1029 const link = (page: AccountSettingsPage, icon: ReactNode) => (
1030 <SidebarLink to={`/settings/${page}`} icon={icon}>
1031 {ACCOUNT_SETTINGS[page].title}
1032 </SidebarLink>
1033 );
1034 return (
1035 <nav aria-label="Your settings" className={PANEL}>
1036 <BackRow to="/" label="Your settings" context={username} />
1037 <NavRows className="mt-2">
1038 {link("profile", <CircleUserRound size={15} />)}
1039 {link("emails", <Mail size={15} />)}
1040 {invites && link("invites", <Ticket size={15} />)}
1041 </NavRows>
1042 <Rule />
1043 <NavRows>
1044 {link("keys", <Fingerprint size={15} />)}
1045 {link("tokens", <KeyRound size={15} />)}
1046 </NavRows>
1047 <Rule />
1048 <NavRows>
1049 {link("integrations", <Blocks size={15} />)}
1050 {link("github", <GithubMark className="size-3.75" />)}
1051 {link("applications", <Plug size={15} />)}
1052 </NavRows>
1053 <Rule />
1054 <NavRows>
1055 {link("two-factor", <ShieldCheck size={15} />)}
1056 {link("security-log", <History size={15} />)}
1057 </NavRows>
1058 </nav>
1059 );
1060}
1061
1062/**
1063 * Code's sidebar: its Overview, the projects, what spans them and what is
1064 * coming; in a project, drilled into the project's own list, and its
1065 * settings one level further in. The address says which, so a link
1066 * straight to a project opens the sidebar already drilled in.
1067 */
1068function CodeSidebar({
1069 user,
1070 shell,
1071 missing = false,
1072}: {
1073 user: User;
1074 shell: ShellData;
1075 /** The page is a 404: the address names nothing the viewer can see. */
1076 missing?: boolean;
1077}) {
1078 const ws = shell.workspace;
1079 const { pathname } = useLocation();
1080 const going = useNavigation().location?.pathname;
1081 // Where the sidebar is drilled to follows the page being gone to, so it
1082 // moves as the link is followed, not once the page arrives.
1083 const target = going ?? pathname;
1084 // On a 404, the address is not a place: no list is drilled into from it,
1085 // except the project's own when the project is real and visible and only
1086 // something inside it is missing (a file, a commit, an issue).
1087 const lost = missing && going == null;
1088 const active = shell.repo;
1089 // In a repository, or on the way into one, its own list.
1090 const repoPath = /^\/([^/]+)\/([^/-][^/]*)(\/|$)/.exec(target);
1091 const reserved = new Set(["settings", "explore", "search", "new", "u", "pricing", "avatars", "workspaces", "login", "logout", "register", "verify", "forgot", "reset", "device", "oauth", "policies", "security", "support", "status", "invite", "notifications", "inbox", ".well-known"]);
1092 // An invitation to a repository is answered before its menu means anything.
1093 const inRepo =
1094 repoPath != null &&
1095 !reserved.has(repoPath[1]) &&
1096 repoPath[2] !== "-" &&
1097 !/^\/[^/]+\/[^/]+\/invitations\/?$/.test(target) &&
1098 (!lost || sameRepo(active, { namespace: repoPath[1]!, name: repoPath[2]! }));
1099 // A project's settings, one level further in.
1100 const inRepoSettings = inRepo && REPO_SETTINGS_PAGE.test(target);
1101 // The repository the menu is for: the one loaded if it is the one being
1102 // gone to, else what the address says, at once.
1103 const targetRepo = inRepo && repoPath ? { namespace: repoPath[1], name: repoPath[2] } : null;
1104 const guessed: MenuRepo | null = targetRepo
1105 ? sameRepo(active, targetRepo)
1106 ? active
1107 : {
1108 ...targetRepo,
1109 member: (user.workspaces ?? []).some((m) => m.slug === targetRepo.namespace.toLowerCase()),
1110 }
1111 : null;
1112 // The viewer's role there, from the repository's page once it has loaded.
1113 const page = useRouteLoaderData("routes/repo/layout") as
1114 | { repo?: { namespace: string; name: string }; access?: ViewerAccess }
1115 | undefined;
1116 const menuRepo: MenuRepo | null =
1117 guessed && page?.access && page.repo && sameRepo(page.repo, guessed)
1118 ? { ...guessed, member: page.access.insider, settings: seesSettings(page.access), can: page.access.can }
1119 : guessed;
1120
1121 // The way from Code's list to the one shown.
1122 const trail: Level[] = [{ key: "main", node: ws ? <CodeMenu shell={shell} slug={ws.slug} /> : null }];
1123 if (menuRepo) {
1124 const key = `repo:${menuRepo.namespace}/${menuRepo.name}`.toLowerCase();
1125 // Out of a project: to its workspace's projects when they are yours.
1126 const home = (user.workspaces ?? []).find((m) => m.slug === menuRepo.namespace.toLowerCase());
1127 const back = home ? { to: `/${home.slug}/-/projects`, label: "All projects" } : { to: ws ? `/${ws.slug}/-/overview` : "/explore", label: "Code" };
1128 trail.push({
1129 key,
1130 node: (
1131 <RepoMenu
1132 repo={menuRepo}
1133 isPrivate={[...shell.repos, ...(shell.shared ?? [])].some((repo) => sameRepo(repo, menuRepo) && repo.isPrivate)}
1134 back={back}
1135 />
1136 ),
1137 });
1138 if (inRepoSettings) trail.push({ key: `${key}:settings`, node: <RepoSettingsMenu repo={menuRepo} /> });
1139 }
1140
1141 return (
1142 <div className="flex h-full flex-col">
1143 <ModeHeader title="Code" />
1144 <Drill trail={trail} />
1145 </div>
1146 );
1147}
1148
1149/**
1150 * A mode's sidebar heading: its name, quiet, under the workspace's
1151 * switcher, with what it makes at the end.
1152 */
1153export function ModeHeader({ title, action }: { title: ReactNode; action?: ReactNode }) {
1154 return (
1155 <div className="flex h-8 shrink-0 items-center gap-1 pr-2 pl-3">
1156 <SidebarGroupLabel asChild className="min-w-0 grow truncate px-1">
1157 <h2>{title}</h2>
1158 </SidebarGroupLabel>
1159 {action}
1160 </div>
1161 );
1162}
1163
1164/**
1165 * Code's own list (beside the rail): only code. Its Overview (Mission
1166 * control's code panels), the projects, what spans them, and what is
1167 * coming. The workspace's people, money and settings are elsewhere;
1168 * agents, context and memory are Agents'.
1169 */
1170function CodeMenu({ shell, slug }: { shell: ShellData; slug: string }) {
1171 const { pathname } = useLocation();
1172 const going = useNavigation().location?.pathname;
1173 const path = going ?? pathname;
1174 const at = (page: string) => path === `/${slug}/-/${page}` || path.startsWith(`/${slug}/-/${page}/`);
1175 const shared = shell.shared ?? [];
1176 return (
1177 <nav aria-label="Code" className={PANEL}>
1178 <NavRows>
1179 <SidebarLink to={`/${slug}/-/overview`} icon={<LayoutDashboard size={15} />} current={at("overview")}>
1180 Overview
1181 </SidebarLink>
1182 </NavRows>
1183 <Rule />
1184 <SidebarProjects slug={slug} shell={shell} current={at("projects")} />
1185 <Rule />
1186 <NavRows>
1187 <SidebarLink to={`/${slug}/-/security`} icon={<ShieldCheck size={15} />} current={at("security") && !at("security/settings")}>
1188 Security
1189 </SidebarLink>
1190 <SidebarLink to={`/${slug}/-/packages`} icon={<Package size={15} />} current={at("packages")}>
1191 Packages
1192 </SidebarLink>
1193 {INSIGHTS && (
1194 <SidebarSoonLink to={`/${slug}/-/insights`} icon={<TrendingUp size={15} />} about={INSIGHTS.summary} current={at("insights")}>
1195 {INSIGHTS.title}
1196 </SidebarSoonLink>
1197 )}
1198 </NavRows>
1199 {shared.length > 0 && (
1200 <>
1201 <Rule />
1202 <NavGroup title="Shared with you">
1203 {shared.map((repo) => (
1204 <SidebarLink
1205 key={`${repo.namespace}/${repo.name}`}
1206 to={`/${repo.namespace}/${repo.name}`}
1207 icon={repo.isPrivate ? <Lock size={15} /> : <Box size={15} />}
1208 drill="hover"
1209 >
1210 <span className="font-mono text-faint">{repo.namespace}/</span>
1211 {repo.name}
1212 </SidebarLink>
1213 ))}
1214 </NavGroup>
1215 </>
1216 )}
1217 </nav>
1218 );
1219}
1220
1221/** The icon of each of Workspace mode's pages, by its key (lib/workspace-nav.ts). */
1222const WORKSPACE_PAGE_ICONS: Record<string, ReactNode> = {
1223 settings: <Settings size={15} />,
1224 members: <Users size={15} />,
1225 invitations: <Mail size={15} />,
1226 permissions: <ShieldCheck size={15} />,
1227 tokens: <KeyRound size={15} />,
1228 "personal-access-tokens": <UserRoundKey size={15} />,
1229 spend: <Coins size={15} />,
1230 usage: <BarChart3 size={15} />,
1231 gateway: <Network size={15} />,
1232 billing: <CreditCard size={15} />,
1233 runners: <ServerCog size={15} />,
1234 repositories: <BookMarked size={15} />,
1235 actions: <PlayCircle size={15} />,
1236 secrets: <Lock size={15} />,
1237 webhooks: <Webhook size={15} />,
1238 deployments: <Rocket size={15} />,
1239 projects: <Layers size={15} />,
1240 "agent-settings": <Bot size={15} />,
1241 "chat-settings": <MessagesSquare size={15} />,
1242 emoji: <Smile size={15} />,
1243 "artifact-settings": <Shapes size={15} />,
1244 "security-settings": <Shield size={15} />,
1245 guardrails: <Gauge size={15} />,
1246 rules: <Scale size={15} />,
1247 audit: <History size={15} />,
1248 integrations: <Plug size={15} />,
1249 applications: <Blocks size={15} />,
1250};
1251
1252/**
1253 * A group of Workspace mode's rows that folds: its name is the button, with
1254 * a chevron that turns when it is open. The group holding the current page
1255 * is always open, and its button does nothing. Every group starts open, so
1256 * the server and the browser draw the same list.
1257 */
1258function FoldingGroup({ title, current, children }: { title: string; current: boolean; children: ReactNode }) {
1259 const [open, setOpen] = useState(true);
1260 return (
1261 <Collapsible open={open || current} onOpenChange={setOpen}>
1262 <SidebarGroup>
1263 <CollapsibleTrigger
1264 disabled={current}
1265 aria-label={`${title}: ${open || current ? "fold" : "unfold"}`}
1266 className="flex h-7 w-full shrink-0 items-center justify-between rounded-md px-2 text-[0.6875rem] font-medium tracking-wide text-faint uppercase hover:text-muted focus-visible:ring-2 focus-visible:ring-accent disabled:cursor-default disabled:text-faint data-[state=open]:[&_svg]:rotate-90"
1267 >
1268 <span>{title}</span>
1269 {!current && <ChevronRight size={12} aria-hidden="true" className="text-faint/70" />}
1270 </CollapsibleTrigger>
1271 <CollapsibleContent>
1272 <SidebarGroupContent>
1273 <SidebarMenu>{children}</SidebarMenu>
1274 </SidebarGroupContent>
1275 </CollapsibleContent>
1276 </SidebarGroup>
1277 </Collapsible>
1278 );
1279}
1280
1281/**
1282 * The Workspace mode's sidebar: the workspace's settings area, every page
1283 * one click away. Its overview, then the groups in lib/workspace-nav.ts
1284 * (General, Access, Money, Compute, Code, Agents, Chat, Artifacts,
1285 * Security, Integrations), each folding, the one you are in held open.
1286 * Pages only owners open are left out for members, and a group with none
1287 * left goes with them; a page that is coming is a Soon row, not a link.
1288 */
1289export function WorkspaceSidebar({ slug, owner }: { slug: string; owner: boolean }) {
1290 const { pathname } = useLocation();
1291 const going = useNavigation().location?.pathname;
1292 const path = going ?? pathname;
1293 const here = workspaceSettingsPage(path, slug);
1294 const overview = path === `/${slug}/-/workspace` || path.startsWith(`/${slug}/-/workspace/`);
1295 const shown = (page: WorkspaceSettingsPage) => owner || !page.owner;
1296 return (
1297 <div className="flex h-full flex-col">
1298 <ModeHeader title="Workspace" />
1299 <nav aria-label="Workspace" className={PANEL}>
1300 <NavRows>
1301 <SidebarLink to={`/${slug}/-/workspace`} icon={<LayoutGrid size={15} />} current={overview}>
1302 Overview
1303 </SidebarLink>
1304 </NavRows>
1305 {WORKSPACE_SETTINGS_GROUPS.filter((group) => group.pages.some(shown)).map((group) => (
1306 <Fragment key={group.key}>
1307 <Rule />
1308 <FoldingGroup title={group.title} current={here?.group === group.key}>
1309 {group.pages.filter(shown).map((page) =>
1310 page.soon ? (
1311 <SidebarSoon key={page.key} icon={WORKSPACE_PAGE_ICONS[page.key] ?? <Sparkles size={15} />} about={page.soon}>
1312 {page.label}
1313 </SidebarSoon>
1314 ) : (
1315 <SidebarLink
1316 key={page.key}
1317 to={`/${slug}/-/${page.path}`}
1318 icon={WORKSPACE_PAGE_ICONS[page.key] ?? <Settings size={15} />}
1319 current={here?.page === page.key}
1320 >
1321 {page.label}
1322 </SidebarLink>
1323 ),
1324 )}
1325 </FoldingGroup>
1326 </Fragment>
1327 ))}
1328 </nav>
1329 </div>
1330 );
1331}
1332
1333/**
1334 * People's sidebar: everyone in the workspace (its people; agents are
1335 * under Agents) and its teams, which agents can be on. Who belongs, and
1336 * inviting people, is the workspace's: Workspace mode's Access group.
1337 */
1338function PeopleSidebar({ slug }: { slug: string }) {
1339 const { pathname } = useLocation();
1340 const going = useNavigation().location?.pathname;
1341 const path = going ?? pathname;
1342 const at = (page: string) => path === `/${slug}/-/${page}` || path.startsWith(`/${slug}/-/${page}/`);
1343 return (
1344 <div className="flex h-full flex-col">
1345 <ModeHeader title="People" />
1346 <nav aria-label="People" className={PANEL}>
1347 <NavRows>
1348 <SidebarLink to={`/${slug}/-/people`} icon={<Users size={15} />} current={at("people")}>
1349 Everyone
1350 </SidebarLink>
1351 <SidebarLink to={`/${slug}/-/teams`} icon={<UsersRound size={15} />} current={at("teams")}>
1352 Teams
1353 </SidebarLink>
1354 </NavRows>
1355 </nav>
1356 </div>
1357 );
1358}
1359
1360/**
1361 * Notifications' sidebar: what you have not finished with, what you saved
1362 * and what is done; then why you were told, which narrows any of them.
1363 */
1364function NotificationsSidebar({ counts }: { counts: InboxCounts | null }) {
1365 const { search } = useLocation();
1366 const params = new URLSearchParams(search);
1367 const view = inboxView(params.get("view"));
1368 const reason = inboxReason(params.get("reason"));
1369 const tab = params.get("tab");
1370 const address = (changes: Record<string, string | null>) => {
1371 const merged: Record<string, string | null> = { tab, view: view === "inbox" ? null : view, reason, ...changes };
1372 const next = new URLSearchParams();
1373 for (const [name, value] of Object.entries(merged)) if (value) next.set(name, value);
1374 const query = next.toString();
1375 return query ? `/notifications?${query}` : "/notifications";
1376 };
1377 const views = [
1378 { view: "inbox", label: "Everything", icon: <Bell size={15} />, count: counts?.unread },
1379 { view: "saved", label: "Saved", icon: <Bookmark size={15} /> },
1380 { view: "done", label: "Done", icon: <Check size={15} /> },
1381 ] as const;
1382 return (
1383 <div className="flex h-full flex-col">
1384 <ModeHeader title="Notifications" />
1385 <nav aria-label="Notifications" className={PANEL}>
1386 <NavRows>
1387 {views.map((entry) => (
1388 <SidebarLink
1389 key={entry.view}
1390 to={address({ view: entry.view === "inbox" ? null : entry.view, before: null })}
1391 icon={entry.icon}
1392 count={"count" in entry ? (entry.count ?? undefined) : undefined}
1393 current={view === entry.view}
1394 >
1395 {entry.label}
1396 </SidebarLink>
1397 ))}
1398 </NavRows>
1399 <Rule />
1400 <NavGroup title="Why you were told">
1401 {REASON_FILTERS.map((entry) => (
1402 <SidebarLink
1403 key={entry.reason ?? "any"}
1404 to={address({ reason: entry.reason, before: null })}
1405 icon={<span className="block size-3.75" />}
1406 current={reason === entry.reason}
1407 >
1408 {entry.reason == null ? "Any reason" : entry.label}
1409 </SidebarLink>
1410 ))}
1411 </NavGroup>
1412 </nav>
1413 </div>
1414 );
1415}
1416
1417/** Your own settings, beside the page: under the account menu, not any workspace's. */
1418export function AccountSidebar({ username }: { username: string }) {
1419 return (
1420 <div className="flex h-full flex-col">
1421 <ModeHeader title="Your account" />
1422 <div className="min-h-0 grow">
1423 <AccountSettingsMenu username={username} />
1424 </div>
1425 </div>
1426 );
1427}
1428
1429/** Words for the sections a path can end in. */
1430const SECTIONS: Record<string, string> = {
1431 issues: "Issues",
1432 milestones: "Milestones",
1433 labels: "Labels",
1434 pulls: "Pull requests",
1435 queue: "Merge queue",
1436 commits: "Commits",
1437 plans: "Outcomes",
1438 actions: "Workflows",
1439 soon: "Soon",
1440 deployments: "Deployments",
1441 repository: "Repository",
1442 access: "Access",
1443 invitations: "Invitation",
1444 repositories: "Repositories",
1445 branches: "Branches",
1446 tags: "Tags",
1447 compare: "Compare",
1448 code: "Files",
1449 secrets: "Secrets and variables",
1450 settings: "Settings",
1451 people: "People",
1452 members: "Members",
1453 permissions: "Permissions",
1454 projects: "Projects",
1455 teams: "Teams",
1456 tokens: "Access tokens",
1457 "personal-access-tokens": "Personal access tokens",
1458 spend: "Spend",
1459 receipts: "Receipts",
1460 usage: "Usage",
1461 gateway: "AI Gateway",
1462 billing: "Billing and plans",
1463 integrations: "Integrations",
1464 webhooks: "Webhooks",
1465 emoji: "Emoji",
1466 domains: "Domains",
1467 guardrails: "Guardrails",
1468 rules: "Rules",
1469 audit: "Audit log",
1470 tree: "Files",
1471 blob: "Files",
1472 agents: "Agents",
1473 context: "Context",
1474 memory: "Memory",
1475 security: "Security",
1476 packages: "Packages",
1477 runners: "Runners",
1478 environments: "Environments",
1479 workflows: "Workflows",
1480 observability: "Observability",
1481 insights: "Insights",
1482 sessions: "Sessions",
1483 chat: "Chat",
1484 artifacts: "Artifacts",
1485 home: "Home",
1486 apps: "Apps",
1487 customize: "Customize",
1488 "code-access": "Code access",
1489 overview: "Overview",
1490 workspace: "Workspace",
1491};
1492
1493/** Settings pages whose name differs from the section's of the same word. */
1494const SETTINGS_SECTIONS: Record<string, string> = { branches: "Branches and merging", actions: "Actions" };
1495
1496/** Where the page is, as a trail of links: workspace / repository / section. */
1497function Breadcrumbs({
1498 pathname,
1499 missing,
1500 repo,
1501 workspace,
1502}: {
1503 pathname: string;
1504 missing?: boolean;
1505 repo?: ShellData["repo"];
1506 /** The workspace you are in: the switcher names it, so the trail starts after it. */
1507 workspace: string | null;
1508}) {
1509 // A 404 names nothing from the address, unless the project is real and
1510 // visible and only something inside it is missing.
1511 const visibleRepo = /^\/([^/]+)\/([^/-][^/]*)(\/|$)/.exec(pathname);
1512 if (missing && !(visibleRepo && sameRepo(repo ?? null, { namespace: visibleRepo[1]!, name: visibleRepo[2]! }))) {
1513 return <Here>Not found</Here>;
1514 }
1515 const parts = pathname.split("/").filter(Boolean);
1516 const reserved = ["settings", "explore", "new", "search", "workspaces", "policies", "security", "support", "status", "invite", "notifications"];
1517 if (parts.length === 0) return <Here>Home</Here>;
1518 // Your settings: Settings / Emails.
1519 if (parts[0] === "settings") {
1520 const page = accountSettingsPage(pathname);
1521 return <Trail trail={[{ label: "Settings", to: FIRST_SETTINGS_PAGE }, ...(page ? [{ label: ACCOUNT_SETTINGS[page].title, to: `/settings/${page}` }] : [])]} />;
1522 }
1523 if (reserved.includes(parts[0]!)) {
1524 const words: Record<string, string> = {
1525 settings: "Account",
1526 explore: "Explore",
1527 new: "New project",
1528 search: "Search",
1529 workspaces: "New workspace",
1530 policies: "Policies",
1531 security: "Security",
1532 support: "Support",
1533 status: "Status",
1534 invite: "Invite",
1535 notifications: "Notifications",
1536 };
1537 return <Here>{words[parts[0]!]}</Here>;
1538 }
1539 // A person's profile, by their handle.
1540 if (parts[0] === "u" && parts[1]) return <ProfileCrumb username={parts[1]} />;
1541 const [owner, second, third, fourth] = parts;
1542 const ours = workspace != null && owner!.toLowerCase() === workspace.toLowerCase();
1543 const trail: Crumb[] = ours ? [] : [{ label: owner!, to: `/${owner}`, mono: true }];
1544 if (second === "-") {
1545 const page = `/${owner}/-/${third}`;
1546 if (third === "settings" && fourth === "chat") {
1547 // Chat settings is a page of its own, not one of General's.
1548 trail.push({ label: "Chat settings", to: `${page}/chat` });
1549 } else if (third) {
1550 // The workspace's settings pages each stand alone: General, Members, Permissions.
1551 trail.push({ label: third === "settings" ? "General" : (SECTIONS[third] ?? third), to: page });
1552 // Customize names its tab (Customize / Plugins), Agents its templates, and Members its invitations.
1553 const tabs: Record<string, string> =
1554 third === "customize"
1555 ? { skills: "Skills", connectors: "Connectors", plugins: "Plugins", marketplaces: "Marketplaces", requests: "Requests" }
1556 : third === "agents"
1557 ? { templates: "Templates" }
1558 : third === "members"
1559 ? { invitations: "Invitations" }
1560 : {};
1561 const tab = fourth ? tabs[fourth] : undefined;
1562 if (tab) trail.push({ label: tab, to: `${page}/${fourth}` });
1563 }
1564 } else if (second) {
1565 const repo = `/${owner}/${second}`;
1566 trail.push({ label: second, to: repo, mono: true });
1567 if (third === "pull" && fourth) trail.push({ label: `Pull request #${fourth}`, short: `#${fourth}`, to: `${repo}/pull/${fourth}` });
1568 else if (third === "issues" && fourth && fourth !== "new") trail.push({ label: `Issue #${fourth}`, short: `#${fourth}`, to: `${repo}/issues/${fourth}` });
1569 else if (third === "commit" && fourth) trail.push({ label: fourth.slice(0, 7), to: `${repo}/commit/${fourth}`, mono: true });
1570 else if (third && SECTIONS[third]) {
1571 trail.push({ label: SECTIONS[third]!, to: `${repo}/${third}` });
1572 // A settings page names which one: Settings / Secrets and variables.
1573 if (third === "settings" && fourth && SECTIONS[fourth]) {
1574 trail.push({ label: SETTINGS_SECTIONS[fourth] ?? SECTIONS[fourth]!, to: `${repo}/settings/${fourth}` });
1575 }
1576 }
1577 }
1578 if (trail.length === 0) trail.push({ label: "Overview", to: `/${owner}` });
1579 return <Trail trail={trail} />;
1580}
1581
1582/** A profile's place in the top bar: the person's avatar and @handle, from the page once it has loaded. */
1583function ProfileCrumb({ username }: { username: string }) {
1584 const page = useRouteLoaderData("routes/user") as { profile?: { username: string; displayUsername?: string | null; avatar: string | null } } | undefined;
1585 const profile = page?.profile?.username.toLowerCase() === username.toLowerCase() ? page.profile : null;
1586 return (
1587 <Breadcrumb className="min-w-0">
1588 <BreadcrumbList>
1589 <BreadcrumbItem>
1590 <BreadcrumbPage asChild className="flex items-center gap-2 hover:bg-raised">
1591 <Link to={`/u/${profile?.username ?? username}`}>
1592 <Avatar name={profile?.username ?? username} image={profile?.avatar ?? null} size={20} />
1593 <span className="truncate font-mono text-[0.8125rem]">@{profile ? shownUsername(profile) : username}</span>
1594 </Link>
1595 </BreadcrumbPage>
1596 </BreadcrumbItem>
1597 </BreadcrumbList>
1598 </Breadcrumb>
1599 );
1600}
1601
1602/** A page with no trail to it, such as Today or Search: its name alone. */
1603function Here({ children }: { children: ReactNode }) {
1604 return (
1605 <Breadcrumb className="min-w-0">
1606 <BreadcrumbList>
1607 <BreadcrumbItem>
1608 <BreadcrumbPage>{children}</BreadcrumbPage>
1609 </BreadcrumbItem>
1610 </BreadcrumbList>
1611 </Breadcrumb>
1612 );
1613}
1614
1615/** One link of the trail; `short` is what a phone shows when it is the page itself. */
1616type Crumb = { label: string; to: string; mono?: boolean; short?: string };
1617
1618/**
1619 * The trail of links. On a phone there is room for one: the page itself,
1620 * with a way back to where it sits; the whole trail from a wider screen up.
1621 */
1622function Trail({ trail }: { trail: Crumb[] }) {
1623 // Up on a phone, unless up is the workspace itself: its pages are the tabs.
1624 const up = trail.length > 1 && !/^\/[^/]+$/.test(trail[trail.length - 2]!.to) ? trail[trail.length - 2]! : null;
1625 return (
1626 <Breadcrumb className="flex min-w-0 items-center">
1627 {up && (
1628 <Button asChild variant="ghost" size="icon-bar" className="-ml-1 sm:hidden">
1629 <Link to={up.to} prefetch="intent" aria-label={`Back to ${up.label}`}>
1630 <ChevronLeft size={16} />
1631 </Link>
1632 </Button>
1633 )}
1634 <BreadcrumbList>
1635 {trail.map((crumb, index) => {
1636 const last = index === trail.length - 1;
1637 const label =
1638 last && crumb.short ? (
1639 <>
1640 <span className="sm:hidden">{crumb.short}</span>
1641 <span className="hidden sm:inline">{crumb.label}</span>
1642 </>
1643 ) : (
1644 crumb.label
1645 );
1646 const mono = crumb.mono ? "font-mono text-[0.8125rem]" : "";
1647 return (
1648 <Fragment key={index}>
1649 {index > 0 && <BreadcrumbSeparator className="max-sm:hidden" />}
1650 <BreadcrumbItem className={last ? "" : "max-sm:hidden"}>
1651 {last ? (
1652 // The page you are on is still a link: to its own top, as the trail always was.
1653 <BreadcrumbPage asChild className={`hover:bg-raised ${mono}`}>
1654 <Link to={crumb.to} prefetch="intent">
1655 {label}
1656 </Link>
1657 </BreadcrumbPage>
1658 ) : (
1659 <BreadcrumbLink asChild className={mono}>
1660 <Link to={crumb.to} prefetch="intent">
1661 {label}
1662 </Link>
1663 </BreadcrumbLink>
1664 )}
1665 </BreadcrumbItem>
1666 </Fragment>
1667 );
1668 })}
1669 </BreadcrumbList>
1670 </Breadcrumb>
1671 );
1672}
1673
1674type Command = PaletteCommand;
1675
1676/** Everything the palette can jump to, from what the sidebar already knows. */
1677function commandsFor(user: User, shell: ShellData): Command[] {
1678 const ws = shell.workspace;
1679 const commands: Command[] = [
1680 ...(ws
1681 ? [
1682 { label: "Home", to: homePagePath(ws.slug), icon: <House size={15} /> },
1683 { label: "Chat", to: `/${ws.slug}/-/chat`, icon: <MessagesSquare size={15} /> },
1684 { label: "Agents", to: `/${ws.slug}/-/agents`, icon: <Sparkles size={15} /> },
1685 ...(hasCodeAccess(ws) ? [{ label: "Code overview", to: `/${ws.slug}/-/overview`, icon: <Code2 size={15} /> }] : []),
1686 { label: "Artifacts", to: `/${ws.slug}/-/artifacts`, icon: <Shapes size={15} /> },
1687 { label: "Apps", hint: "Everything installed that you can use", to: `/${ws.slug}/-/apps`, icon: <LayoutGrid size={15} /> },
1688 { label: "Customize", hint: "Skills, connectors and plugins", to: `/${ws.slug}/-/customize`, icon: <SlidersHorizontal size={15} /> },
1689 { label: "Agent templates", hint: "Starting points for a new agent", to: `/${ws.slug}/-/agents/templates`, icon: <Bot size={15} /> },
1690 { label: "Workspace", hint: "Billing, policies, settings", to: `/${ws.slug}/-/workspace`, icon: <Building2 size={15} /> },
1691 ]
1692 : []),
1693 { label: "Explore repositories", to: "/explore", icon: <Compass size={15} /> },
1694 { label: "Search g1t", hint: "Repositories, code, issues, people", to: "/search", icon: <Search size={15} /> },
1695 { label: "Notifications", hint: "What needs you", to: "/notifications", icon: <Bell size={15} /> },
1696 { label: "New project", to: "/new", icon: <Plus size={15} /> },
1697 { label: "Your settings", to: FIRST_SETTINGS_PAGE, icon: <Settings size={15} /> },
1698 ...(Object.keys(ACCOUNT_SETTINGS) as AccountSettingsPage[])
1699 .filter((page) => page !== "profile")
1700 .map((page) => ({ label: ACCOUNT_SETTINGS[page].title, hint: "Your settings", to: `/settings/${page}`, icon: <Settings size={15} /> })),
1701 ...THEME_COMMANDS,
1702 ];
1703 const repo = shell.repo;
1704 if (repo) {
1705 const base = `/${repo.namespace}/${repo.name}`;
1706 const name = `${repo.namespace}/${repo.name}`;
1707 commands.unshift(
1708 { label: "Overview", hint: name, to: base, icon: <LayoutGrid size={15} /> },
1709 { label: "Code", hint: name, to: `${base}/code`, icon: <Code2 size={15} /> },
1710 { label: "Issues", hint: name, to: `${base}/issues`, icon: <CircleDot size={15} /> },
1711 { label: "New issue", hint: name, to: `${base}/issues/new`, icon: <Plus size={15} /> },
1712 ...(repo.member
1713 ? [{ label: `Put an agent on ${repo.name}`, hint: name, to: `${base}/issues/new?agent=1`, icon: <Sparkles size={15} /> }]
1714 : []),
1715 { label: "Pull requests", hint: name, to: `${base}/pulls`, icon: <GitPullRequest size={15} /> },
1716 { label: "Commits", hint: name, to: `${base}/commits`, icon: <History size={15} /> },
1717 ...(repo.member
1718 ? [
1719 { label: "Plan work", hint: name, to: `${base}/plans`, icon: <ListTree size={15} /> },
1720 { label: "Deployments", hint: name, to: `${base}/deployments`, icon: <Rocket size={15} /> },
1721 { label: "Secrets and variables", hint: name, to: `${base}/settings/secrets`, icon: <Lock size={15} /> },
1722 { label: "Project settings", hint: name, to: `${base}/settings`, icon: <Settings size={15} /> },
1723 { label: "Repository settings", hint: name, to: `${base}/settings/repository`, icon: <Settings size={15} /> },
1724 ]
1725 : []),
1726 );
1727 }
1728 for (const membership of user.workspaces ?? []) {
1729 commands.push(
1730 { label: displayName(membership), hint: `Workspace · ${membership.slug}`, to: `/${membership.slug}`, icon: <Avatar name={membership.slug} image={membership.avatar} size={15} square /> },
1731 { label: "All projects", hint: membership.slug, to: `/${membership.slug}/-/projects`, icon: <LayoutGrid size={15} /> },
1732 { label: "People", hint: membership.slug, to: `/${membership.slug}/-/people`, icon: <Users size={15} /> },
1733 { label: "Spend", hint: `${membership.slug} · Budgets and receipts`, to: `/${membership.slug}/-/spend`, icon: <Coins size={15} /> },
1734 { label: "Usage", hint: membership.slug, to: `/${membership.slug}/-/usage`, icon: <BarChart3 size={15} /> },
1735 { label: "AI Gateway", hint: `${membership.slug} · Usage`, to: `/${membership.slug}/-/gateway`, icon: <Network size={15} /> },
1736 { label: "Billing and plans", hint: `${membership.slug} · Settings`, to: `/${membership.slug}/-/billing`, icon: <CreditCard size={15} /> },
1737 { label: "Access tokens", hint: `${membership.slug} · Settings`, to: `/${membership.slug}/-/tokens`, icon: <KeyRound size={15} /> },
1738 { label: "Integrations", hint: membership.slug, to: `/${membership.slug}/-/integrations`, icon: <Plug size={15} /> },
1739 { label: "Members", hint: `${membership.slug} · Access`, to: `/${membership.slug}/-/members`, icon: <Users size={15} /> },
1740 ...(membership.role === "owner"
1741 ? [
1742 { label: "Invitations", hint: `${membership.slug} · Access`, to: `/${membership.slug}/-/members/invitations`, icon: <Mail size={15} /> },
1743 { label: "Permissions", hint: `${membership.slug} · Access`, to: `/${membership.slug}/-/permissions`, icon: <ShieldCheck size={15} /> },
1744 ]
1745 : []),
1746 );
1747 }
1748 for (const listed of shell.repos) {
1749 commands.push({
1750 label: listed.title ?? listed.name,
1751 hint: `${listed.namespace} · Project`,
1752 to: `/${listed.namespace}/${listed.name}`,
1753 icon: <Box size={15} />,
1754 });
1755 }
1756 // "Put an agent on …": one per project, after the projects themselves.
1757 for (const listed of shell.repos) {
1758 if (repo && listed.namespace === repo.namespace && listed.name === repo.name) continue;
1759 commands.push({
1760 label: `Put an agent on ${listed.title ?? listed.name}`,
1761 hint: `${listed.namespace}/${listed.name}`,
1762 to: `/${listed.namespace}/${listed.name}/issues/new?agent=1`,
1763 icon: <Sparkles size={15} />,
1764 });
1765 }
1766 return commands;
1767}
1768
1769/**
1770 * The page while the next one loads: after a moment it dims, under the
1771 * bar below, so it is plainly on its way out rather than frozen, and the
1772 * next page fades up from there. Sending a form does not dim it: the
1773 * form's button says it is working. Spread on the element holding the page.
1774 */
1775export function useLeaving() {
1776 const navigation = useNavigation();
1777 const method = navigation.formMethod?.toUpperCase();
1778 const leaving = navigation.state === "loading" && (method == null || method === "GET");
1779 return {
1780 "aria-busy": leaving || undefined,
1781 className: `transition-opacity motion-reduce:transition-none ${leaving ? "opacity-60 delay-200 duration-300" : "duration-150"}`,
1782 };
1783}
1784
1785/**
1786 * A bar across the top of the page while the next one loads, as GitHub
1787 * has: it appears at once, creeps towards the end while waiting, then fills
1788 * and fades when the page arrives.
1789 */
1790export function Progress() {
1791 const navigation = useNavigation();
1792 const busy = navigation.state !== "idle";
1793 const [width, setWidth] = useState(0);
1794 const [visible, setVisible] = useState(false);
1795 useEffect(() => {
1796 if (busy) {
1797 setVisible(true);
1798 setWidth(12);
1799 // Slows as it goes, never quite arriving until the page does.
1800 const timer = setInterval(() => setWidth((now) => now + (90 - now) * 0.12), 200);
1801 return () => clearInterval(timer);
1802 }
1803 setWidth((now) => (now > 0 ? 100 : 0));
1804 const fade = setTimeout(() => setVisible(false), 250);
1805 const reset = setTimeout(() => setWidth(0), 550);
1806 return () => {
1807 clearTimeout(fade);
1808 clearTimeout(reset);
1809 };
1810 }, [busy]);
1811 return (
1812 <div
1813 aria-hidden="true"
1814 className={`pointer-events-none fixed inset-x-0 top-0 z-60 h-0.75 transition-opacity duration-300 ${
1815 visible ? "opacity-100" : "opacity-0"
1816 }`}
1817 >
1818 <div
1819 className="h-full bg-accent shadow-[0_0_10px_var(--color-accent)] transition-[width] duration-200 ease-out"
1820 style={{ width: `${width}%` }}
1821 />
1822 </div>
1823 );
1824}
1825
1826/**
1827 * The top bar's way to g1t: the direct message with the workspace's
1828 * orchestrator, opened or made. The one tinted control in the bar: the
1829 * lavender pixel 1 bare beside its words, on a wash of the accent.
1830 */
1831function AskG1tButton({ slug }: { slug: string }) {
1832 return (
1833 <Hint label="Ask g1t">
1834 <Button asChild variant="soft" size="bar" className="gap-2 max-md:ring-0 lg:px-3">
1835 <Link to={`/${slug}/-/chat?agent=g1t`} aria-label="Ask g1t">
1836 <MarkGlyph className="h-3.5" />
1837 <span className="max-lg:hidden">Ask g1t</span>
1838 </Link>
1839 </Button>
1840 </Hint>
1841 );
1842}
1843
1844/**
1845 * Which sidebar sits beside the page: each mode's own, or none. Home and
1846 * Apps are pages at full width, and so are g1t's public pages, such as a
1847 * profile, which are no workspace's. Without a workspace, only your own
1848 * settings and Notifications have one.
1849 */
1850function sidebarFor(mode: ModeKey, workspace: boolean): Panel | null {
1851 if (!workspace) return mode === "account" || mode === "notifications" ? mode : null;
1852 if (mode === "home" || mode === "apps" || mode === "site") return null;
1853 return mode;
1854}
1855
1856/** The sidebars that sit beside the page, one per mode that has one. */
1857type Panel = "chat" | "artifacts" | "agents" | "code" | "notifications" | "people" | "workspace" | "account";
1858
1859/** Each sidebar's name, for the button that opens it on a phone. */
1860const MODE_MENU: Record<Panel, string> = {
1861 chat: "Chat",
1862 artifacts: "Artifacts",
1863 agents: "Agents",
1864 code: "Code",
1865 notifications: "Notifications",
1866 people: "People",
1867 workspace: "Workspace",
1868 account: "Your account",
1869};
1870
1871/** Whether a key press happened in something you type into, where Ctrl B is the editor's. */
1872function typing(target: EventTarget | null): boolean {
1873 if (!(target instanceof HTMLElement)) return false;
1874 return target.isContentEditable || target.closest("input, textarea, select, [contenteditable=''], [contenteditable='true'], [role='textbox']") != null;
1875}
1876
1877/** Ctrl B (⌘B on a Mac) shows or hides the sidebar, except while typing. */
1878function useSidebarShortcut(toggle: () => void) {
1879 useEffect(() => {
1880 const onKey = (event: KeyboardEvent) => {
1881 if (event.key.toLowerCase() !== "b" || event.altKey || event.shiftKey || !(event.ctrlKey || event.metaKey)) return;
1882 if (event.defaultPrevented || typing(event.target)) return;
1883 event.preventDefault();
1884 toggle();
1885 };
1886 window.addEventListener("keydown", onKey);
1887 return () => window.removeEventListener("keydown", onKey);
1888 }, [toggle]);
1889}
1890
1891/**
1892 * Search or jump to: the command palette. On a computer it looks like the
1893 * field it opens, with its shortcut; on a phone, a magnifier.
1894 */
1895function SearchButton({ onClick, place }: { onClick: () => void; place: "bar" | "sidebar" }) {
1896 const field = (
1897 <Button
1898 variant="outline"
1899 size="sm"
1900 aria-label="Search or jump to"
1901 onClick={onClick}
1902 className={
1903 place === "sidebar"
1904 ? "w-full justify-start bg-bg font-normal text-faint hover:bg-bg hover:text-muted"
1905 : "mr-1 w-[min(18rem,26vw)] justify-start bg-surface font-normal text-faint hover:bg-surface hover:text-muted max-md:hidden"
1906 }
1907 >
1908 <Search size={15} />
1909 <span className="grow truncate text-left">Search or jump to</span>
1910 <PaletteKey className="px-1.5 text-[0.625rem] leading-4 text-muted" />
1911 </Button>
1912 );
1913 if (place === "sidebar") return field;
1914 return (
1915 <>
1916 <Button variant="ghost" size="icon-bar" aria-label="Search or jump to" onClick={onClick} className="md:hidden">
1917 <Search size={18} />
1918 </Button>
1919 {field}
1920 </>
1921 );
1922}
1923
1924/** The sidebar's shortcut, for the hint on its toggle. */
1925function useSidebarKey(): string {
1926 return sidebarKeyLabel(typeof navigator === "undefined" ? null : navigator.platform);
1927}
1928
1929/**
1930 * The app: three surfaces that never blur together. The rail, a narrow
1931 * column of icons down the window's left edge; the mode's sidebar, flat
1932 * against it with a hairline between, which folds away with Ctrl B and is
1933 * a drawer below 1024px; and the page, flat against the sidebar and
1934 * filling the rest of the window, with its top bar across the top and a
1935 * line under it: the sidebar's toggle, where you are, search, Ask g1t and
1936 * Create new. On a phone the rail is a bar along the bottom and the page
1937 * fills the window above it, flat as well. Only for someone signed in; without a workspace yet, there
1938 * is no rail. The rail and the sidebar are drawn from the sidebar kit
1939 * (components/ui/sidebar.tsx): one provider holds whether the sidebar is
1940 * open on a computer and whether the drawer is.
1941 */
1942export function AppShell({
1943 user,
1944 shell,
1945 missing = false,
1946 banner,
1947 sidebarClosed = false,
1948 children,
1949}: {
1950 user: User;
1951 shell: ShellData;
1952 /** The page is a 404 (see CodeSidebar). */
1953 missing?: boolean;
1954 banner?: ReactNode;
1955 /** Whether the person folded the sidebar away, as their cookie says. */
1956 sidebarClosed?: boolean;
1957 children: ReactNode;
1958}) {
1959 const { pathname } = useLocation();
1960 const [drawer, setDrawer] = useState(false);
1961 const [closed, setClosed] = useState(sidebarClosed);
1962 const [palette, setPalette] = useState(false);
1963 const commands = useMemo(() => commandsFor(user, shell), [user, shell]);
1964
1965 // A new page closes the drawer.
1966 useEffect(() => setDrawer(false), [pathname]);
1967 usePaletteShortcut(() => setPalette((open) => !open));
1968 // In the desktop app, search is in the middle of its title bar, as in Slack, and not in the top bar too.
1969 const titleSearch = useTitleBarSearch(`Search ${shell.workspace?.name ?? shell.workspace?.slug ?? "g1t"}`, () => setPalette(true));
1970 const leaving = useLeaving();
1971 useVisualViewport();
1972 const going = useNavigation().location?.pathname;
1973 const ws = shell.workspace;
1974 const mode = modeOf(going ?? pathname, ws?.slug ?? null);
1975 const panel = sidebarFor(mode, ws != null);
1976 const code = ws ? hasCodeAccess(ws) : false;
1977 const { sidebar: chatSidebar } = useChatSidebar();
1978 // Notify: the feed socket's live counts (lib/notify-client.ts) once it has them; the page's until then.
1979 const live = useLiveBadges(ws?.slug);
1980 const chatUnread = chatSidebar
1981 ? unreadTotals(chatSidebar.entries)
1982 : live?.chat != null
1983 ? { unread: live.chat, mentions: live.mentions ?? 0 }
1984 : (shell.chat ?? { unread: 0, mentions: 0 });
1985 const notificationsUnread = live?.inbox ?? shell.inbox?.unread ?? 0;
1986 const unread = { notifications: notificationsUnread, chat: chatUnread.unread, mentions: chatUnread.mentions };
1987
1988 // Folding the sidebar away on a computer is remembered, so the next page is drawn the same from the server.
1989 const toggleSidebar = useCallback(() => {
1990 if (!window.matchMedia("(min-width: 1024px)").matches) {
1991 setDrawer((open) => !open);
1992 return;
1993 }
1994 setClosed((was) => {
1995 document.cookie = sidebarCookie(!was, window.location.protocol === "https:");
1996 return !was;
1997 });
1998 }, []);
1999 useSidebarShortcut(useCallback(() => {
2000 if (panel) toggleSidebar();
2001 }, [panel, toggleSidebar]));
2002
2003 const inline = panel != null && !closed;
2004 const sidebarNode = () => {
2005 if (!panel) return null;
2006 if (!ws) return panel === "notifications" ? <NotificationsSidebar counts={shell.inbox ?? null} /> : <AccountSidebar username={user.username} />;
2007 switch (panel) {
2008 case "code":
2009 return <CodeSidebar user={user} shell={shell} missing={missing} />;
2010 case "chat":
2011 return <ChatSidebar slug={ws.slug} />;
2012 case "artifacts":
2013 return <FoliosSidebar slug={ws.slug} />;
2014 case "agents":
2015 return <AgentsSidebar slug={ws.slug} shellAgents={shell.agents ?? null} code={code} owner={ws.role === "owner"} />;
2016 case "notifications":
2017 return <NotificationsSidebar counts={shell.inbox ?? null} />;
2018 case "people":
2019 return <PeopleSidebar slug={ws.slug} />;
2020 case "workspace":
2021 return <WorkspaceSidebar slug={ws.slug} owner={ws.role === "owner"} />;
2022 case "account":
2023 return <AccountSidebar username={user.username} />;
2024 }
2025 };
2026 const sidebarKey = useSidebarKey();
2027 // Search or jump to sits at the top of the sidebar, except in Chat and
2028 // Artifacts, whose sidebars search their own lists: there it stays in the bar.
2029 const sidebarSearch = panel != null && panel !== "chat" && panel !== "artifacts";
2030 // The sidebar's head: the workspace and its switcher, the way to fold the
2031 // sidebar or close the drawer, and search, which opens the palette.
2032 const sidebarTop = (inDrawer: boolean) => (
2033 <SidebarHeader className="gap-1 px-2 pt-0 pb-2">
2034 <div className="flex h-14 shrink-0 items-center gap-1">
2035 {ws ? (
2036 <WorkspaceSwitcher user={user} workspace={ws} />
2037 ) : (
2038 <Link to="/" aria-label="g1t" className="mr-auto flex h-9 items-center rounded-md px-2">
2039 <Logo className="text-[1.125rem]" />
2040 </Link>
2041 )}
2042 {inDrawer ? (
2043 <Button type="button" aria-label="Close menu" onClick={() => setDrawer(false)} variant="ghost" size="icon-sm" className="text-faint">
2044 <X size={16} />
2045 </Button>
2046 ) : (
2047 <SidebarTrigger hint={`Hide the sidebar (${sidebarKey})`} className="text-faint" />
2048 )}
2049 </div>
2050 {sidebarSearch && <SearchButton place="sidebar" onClick={() => setPalette(true)} />}
2051 </SidebarHeader>
2052 );
2053
2054 // On a phone (below 768px): the bottom bar, and a conversation full screen.
2055 const conversation = isConversation(going ?? pathname);
2056 // Where the page panel starts: 8px past the rail (56px), or 8px past the sidebar (56 + 240px) when it is open.
2057 // The page starts where the rail (3.5rem) and, open, the sidebar (15rem) end.
2058 const pad = ws ? (inline ? "md:pl-14 lg:pl-[18.5rem]" : "md:pl-14") : inline ? "lg:pl-[15rem]" : "";
2059
2060 return (
2061 <SidebarProvider open={!closed} onOpenChange={(open) => setClosed(!open)} openMobile={drawer} onOpenMobileChange={setDrawer} toggleSidebar={toggleSidebar}>
2062 <Progress />
2063 {ws && (
2064 <div className="fixed top-(--frame-top) bottom-0 left-0 z-40 hidden md:block">
2065 <Rail workspace={ws} pins={shell.pins ?? []} unread={unread} account={<AccountMenu user={user} />} />
2066 </div>
2067 )}
2068 {panel && (
2069 <Sidebar
2070 role="complementary"
2071 aria-label={`${MODE_MENU[panel]} sidebar`}
2072 className={`fixed top-(--frame-top) bottom-0 z-40 max-lg:hidden ${ws ? "left-14" : "left-0"}`}
2073 >
2074 {sidebarTop(false)}
2075 <div className="min-h-0 grow">{sidebarNode()}</div>
2076 </Sidebar>
2077 )}
2078 {/* The drawer is a sheet: a dialog that holds focus, closes on Escape or
2079 a tap outside, and gives focus back to the button that opened it. */}
2080 {panel && (
2081 <SidebarMobile title={`${MODE_MENU[panel]} menu`} className="pb-[env(safe-area-inset-bottom)] max-md:[&_nav_a]:min-h-10">
2082 {sidebarTop(true)}
2083 <div className="min-h-0 grow">{sidebarNode()}</div>
2084 </SidebarMobile>
2085 )}
2086
2087 <div className={`min-h-dvh pt-(--frame-top) pb-(--tabbar-h) ${pad}`}>
2088 {/* The top bar always has its line, so a page's own header (data-page-head: a conversation's, a project's,
2089 a sticky one under an open artifact) sits under it as its own band. */}
2090 <div className="flex min-h-[calc(100dvh-var(--frame-top)-var(--tabbar-h))] min-w-0 flex-col bg-bg">
2091 <header
2092 className={`sticky top-(--frame-top) z-30 flex h-14 items-center gap-1 border-b border-line bg-bg pr-2 pl-2 sm:pr-3 ${inline ? "lg:pl-3.5" : ""} ${conversation ? "max-md:hidden" : ""}`}
2093 >
2094 {panel && (
2095 <SidebarTrigger
2096 hint={`Show the sidebar (${sidebarKey})`}
2097 aria-label={drawer ? "Hide the sidebar" : "Show the sidebar"}
2098 aria-expanded={drawer}
2099 className={`max-md:size-11 ${inline ? "lg:hidden" : ""}`}
2100 />
2101 )}
2102 {ws && (
2103 <span className={`flex min-w-0 shrink items-center gap-1.5 ${inline ? "lg:hidden" : ""}`}>
2104 <WorkspaceSwitcher user={user} workspace={ws} compact />
2105 <span aria-hidden="true" className="text-line-strong">
2106 /
2107 </span>
2108 </span>
2109 )}
2110 <Breadcrumbs pathname={pathname} missing={missing} repo={shell.repo} workspace={ws?.slug ?? null} />
2111 {/* Search, then what's yours (spend, Ask g1t), then the bell and Create new: one height, one rhythm. */}
2112 <div className="ml-auto flex shrink-0 items-center gap-1 md:gap-1.5">
2113 {/* With the sidebar open, search is at its top. */}
2114 {!titleSearch && (
2115 <span className={`flex ${inline && sidebarSearch ? "lg:hidden" : ""}`}>
2116 <SearchButton place="bar" onClick={() => setPalette(true)} />
2117 </span>
2118 )}
2119 {/* Your spend this month, or the workspace's for owners and billing managers; on a phone it is on Spend. */}
2120 {ws && (
2121 <span className="flex max-md:hidden">
2122 <SpendPill slug={ws.slug} mayWorkspace={ws.role === "owner" || !!ws.org_roles?.includes("billing_manager")} />
2123 </span>
2124 )}
2125 {ws && <AskG1tButton slug={ws.slug} />}
2126 <Separator orientation="vertical" className="mx-1 data-[orientation=vertical]:h-5 max-md:hidden" />
2127 {/* On a phone, Notifications is in the bottom bar. */}
2128 <span className="flex max-md:hidden">
2129 <NotificationsBell counts={shell.inbox ? { ...shell.inbox, unread: notificationsUnread } : null} />
2130 </span>
2131 <CreateMenu shell={shell} />
2132 {/* Without a workspace there is no rail: the account is here. */}
2133 {!ws && <AccountMenu user={user} side="bottom" />}
2134 </div>
2135 </header>
2136 {banner}
2137 <main id="content" tabIndex={-1} {...leaving} className={`min-w-0 grow outline-none ${leaving.className}`}>
2138 <InMain.Provider value={true}>{children}</InMain.Provider>
2139 </main>
2140 </div>
2141 </div>
2142 {ws && <BottomBar user={user} workspace={ws} pins={shell.pins ?? []} unread={unread} onReselect={panel ? () => setDrawer(true) : undefined} />}
2143 <CommandPalette open={palette} onOpenChange={setPalette} commands={commands} repo={shell.repo ? `${shell.repo.namespace}/${shell.repo.name}` : null} />
2144 </SidebarProvider>
2145 );
2146}
2147
2148/** Create new: a project, an issue in the one you are in, a workspace or a team. */
2149function CreateMenu({ shell }: { shell: ShellData }) {
2150 return (
2151 <DropdownMenu>
2152 <Hint label="Create new">
2153 <DropdownMenuTrigger asChild>
2154 <Button variant="ghost" size="bar" aria-label="Create new" className="gap-0.5 px-1.5 text-fg/90">
2155 <Plus size={17} className="max-md:size-5" />
2156 <ChevronDown size={12} className="text-faint max-md:hidden" />
2157 </Button>
2158 </DropdownMenuTrigger>
2159 </Hint>
2160 <DropdownMenuContent align="end" className="min-w-52">
2161 {shell.repo && (
2162 <>
2163 <DropdownMenuLabel className="truncate">In {shell.repo.name}</DropdownMenuLabel>
2164 <DropdownMenuItem asChild>
2165 <Link to={`/${shell.repo.namespace}/${shell.repo.name}/issues/new`}>
2166 <CircleDot />
2167 New issue
2168 </Link>
2169 </DropdownMenuItem>
2170 {shell.repo.member && (
2171 <DropdownMenuItem asChild>
2172 <Link to={`/${shell.repo.namespace}/${shell.repo.name}/plans`}>
2173 <ListTree />
2174 Plan work
2175 </Link>
2176 </DropdownMenuItem>
2177 )}
2178 <DropdownMenuSeparator />
2179 </>
2180 )}
2181 <DropdownMenuItem asChild>
2182 <Link to="/new">
2183 <Box />
2184 New project
2185 </Link>
2186 </DropdownMenuItem>
2187 <DropdownMenuItem asChild>
2188 <Link to="/new/github">
2189 <GitBranch />
2190 Import from GitHub
2191 </Link>
2192 </DropdownMenuItem>
2193 {/* A team in the workspace you are in, for whoever it lets create one. A new workspace is made from the workspace switcher in the rail. */}
2194 {shell.workspace && <DropdownMenuSeparator />}
2195 {shell.workspace &&
2196 (mayCreateTeams(shell.workspace.team_creation, shell.workspace.role) ? (
2197 <DropdownMenuItem asChild>
2198 <Link to={`/${shell.workspace.slug}/-/teams/new`}>
2199 <UsersRound />
2200 New team
2201 </Link>
2202 </DropdownMenuItem>
2203 ) : (
2204 <DropdownMenuItem disabled>
2205 <UsersRound />
2206 New team
2207 <span className="ml-auto pl-3 text-xs text-faint">Owners only</span>
2208 </DropdownMenuItem>
2209 ))}
2210 </DropdownMenuContent>
2211 </DropdownMenu>
2212 );
2213}