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