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