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