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