Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

RightPanelTabs.tsx

755 lines27.2 KB

1import type { ContextMenuItem, PreviewSessionSnapshot, PullRequestState } from "@t3tools/contracts";
2import { getTerminalLabel } from "@t3tools/shared/terminalLabels";
3import {
4 Bot,
5 FileDiff,
6 Files,
7 GitPullRequest,
8 Globe2,
9 Plus,
10 TerminalSquare,
11 X,
12} from "lucide-react";
13import {
14 type KeyboardEvent as ReactKeyboardEvent,
15 type MouseEvent as ReactMouseEvent,
16 type ReactElement,
17 type ReactNode,
18 useCallback,
19 useEffect,
20 useRef,
21 useState,
22} from "react";
23​
24import { isElectron } from "~/env";
25import type { RightPanelSurface } from "~/rightPanelStore";
26import { cn } from "~/lib/utils";
27import { readLocalApi } from "~/localApi";
28import { Tooltip, TooltipPopup, TooltipTrigger } from "~/components/ui/tooltip";
29import { Kbd } from "~/components/ui/kbd";
30import { Menu, MenuItem, MenuPopup, MenuTrigger } from "~/components/ui/menu";
31import { ScrollArea } from "~/components/ui/scroll-area";
32import { faviconUrlForOrigin } from "~/lib/favicon";
33import { useTheme } from "~/hooks/useTheme";
34import { COLLAPSED_SIDEBAR_TITLEBAR_INSET_CLASS } from "~/workspaceTitlebar";
35​
36import { PreviewPanelShell, type PreviewPanelMode } from "./preview/PreviewPanelShell";
37import { PierreEntryIcon } from "./chat/PierreEntryIcon";
38​
39interface RightPanelTabsProps {
40 mode: PreviewPanelMode;
41 maximized?: boolean;
42 /** Forwarded to PreviewPanelShell so this surface persists its own width. */
43 widthStorageKey?: string;
44 /** Forwarded to PreviewPanelShell as the initial width before a user resize. */
45 defaultWidth?: number;
46 layoutControls?: ReactNode;
47 surfaces: readonly RightPanelSurface[];
48 activeSurfaceId: string | null;
49 pendingSurfaceIds: ReadonlySet<string>;
50 previewSessions: Readonly<Record<string, PreviewSessionSnapshot>>;
51 terminalLabelsById: ReadonlyMap<string, string>;
52 onActivate: (surface: RightPanelSurface) => void;
53 onCloseSurface: (surface: RightPanelSurface) => void;
54 onCloseOtherSurfaces: (surface: RightPanelSurface) => void;
55 onCloseSurfacesToRight: (surface: RightPanelSurface) => void;
56 onCloseAllSurfaces: () => void;
57 onCopyFilePath: (relativePath: string) => void;
58 onAddBrowser: () => void;
59 onAddTerminal: () => void;
60 onAddDiff: () => void;
61 onAddFiles: () => void;
62 onAddPullRequest: () => void;
63 onAddAgents: () => void;
64 browserAvailable: boolean;
65 terminalAvailable: boolean;
66 diffAvailable: boolean;
67 filesAvailable: boolean;
68 pullRequestAvailable: boolean;
69 agentsAvailable: boolean;
70 pullRequestStatuses?: Readonly<Record<string, PullRequestTabStatus>>;
71 /** Running + waiting subagents; badges the Agents card in the empty state. */
72 liveAgentCount: number;
73 children: ReactNode;
75​
76export interface PullRequestTabStatus {
77 projectId: string;
78 repository: string;
79 number: number;
80 state: PullRequestState;
81 isDraft: boolean;
83​
84const SURFACE_DISABLED_REASONS = {
85 browser: "Browser previews are only available in the T3 Code desktop app.",
86 terminal: "Terminal surfaces are only available from a project thread.",
87 files: "Files are only available when a project is open.",
88 diff: "Diff is only available for server threads in Git repositories.",
89 pullRequest: "This thread's branch has no pull request yet.",
90 agents: "Agents are only available from a thread.",
91} as const;
92​
93/** Overlays that must win over the launcher's letter shortcuts. */
94const LAUNCHER_SHORTCUT_BLOCKING_LAYERS = [
95 '[data-slot="dialog-popup"]',
96 '[data-slot="alert-dialog-popup"]',
97 '[data-slot="command-dialog-popup"]',
98 '[data-slot="menu-popup"]',
99 '[data-slot="select-popup"]',
100 '[data-slot="popover-popup"]',
101 '[data-slot="combobox-popup"]',
102 '[data-slot="autocomplete-popup"]',
103].join(",");
104​
105/** One-line unavailability hints for the empty-state cards. */
106const SURFACE_UNAVAILABLE_HINTS = {
107 browser: "Only available in the desktop app.",
108 terminal: "Available when a project is open.",
109 files: "Available when a project is open.",
110 diff: "Available for Git repositories.",
111 pullRequest: "No pull request on this branch yet.",
112 agents: "Available from a thread.",
113} as const;
114​
115type TabContextMenuAction = "copy-path" | "close" | "close-others" | "close-to-right" | "close-all";
116​
117function DisabledReasonTooltip(props: { reason: string; trigger: ReactElement }) {
118 return (
119 <Tooltip>
120 <TooltipTrigger render={props.trigger} />
121 <TooltipPopup side="top">{props.reason}</TooltipPopup>
122 </Tooltip>
123 );
125​
126function SurfaceMenuItem(props: {
127 available: boolean;
128 disabledReason?: string;
129 onClick: () => void;
130 children: ReactNode;
131}) {
132 const item = (
133 <MenuItem
134 className={!props.available ? "data-disabled:pointer-events-auto" : undefined}
135 onClick={props.onClick}
136 disabled={!props.available}
137 >
138 {props.children}
139 </MenuItem>
140 );
141 if (props.available || !props.disabledReason) return item;
142 return <DisabledReasonTooltip reason={props.disabledReason} trigger={item} />;
144​
145/**
146 * Card launcher shown when the right panel has no surfaces. Keyboard-first
147 * without palette chrome: a surface's letter opens it directly from anywhere
148 * outside a typing context, and arrows plus Enter work while the launcher is
149 * focused. The highlight only appears on hover or arrow use. Unavailable
150 * surfaces stay visible with a one-line reason.
151 */
152function RightPanelEmptyState(props: {
153 onAddBrowser: () => void;
154 onAddTerminal: () => void;
155 onAddDiff: () => void;
156 onAddFiles: () => void;
157 onAddPullRequest: () => void;
158 onAddAgents: () => void;
159 browserAvailable: boolean;
160 terminalAvailable: boolean;
161 diffAvailable: boolean;
162 filesAvailable: boolean;
163 pullRequestAvailable: boolean;
164 agentsAvailable: boolean;
165 liveAgentCount: number;
166}) {
167 // -1 means no highlight: it only appears on hover or arrow use.
168 const [highlight, setHighlight] = useState(-1);
169​
170 const actions = [
171 {
172 label: "Browser",
173 description: "Open a local app or URL.",
174 icon: Globe2,
175 shortcut: "B",
176 available: props.browserAvailable,
177 disabledReason: SURFACE_UNAVAILABLE_HINTS.browser,
178 onClick: props.onAddBrowser,
179 badgeCount: 0,
180 },
181 {
182 label: "Terminal",
183 description: "Start a shell in this workspace.",
184 icon: TerminalSquare,
185 shortcut: "T",
186 available: props.terminalAvailable,
187 disabledReason: SURFACE_UNAVAILABLE_HINTS.terminal,
188 onClick: props.onAddTerminal,
189 badgeCount: 0,
190 },
191 {
192 label: "Files",
193 description: "Browse and read workspace files.",
194 icon: Files,
195 shortcut: "F",
196 available: props.filesAvailable,
197 disabledReason: SURFACE_UNAVAILABLE_HINTS.files,
198 onClick: props.onAddFiles,
199 badgeCount: 0,
200 },
201 {
202 label: "Diff",
203 description: "Review changes in this thread.",
204 icon: FileDiff,
205 shortcut: "D",
206 available: props.diffAvailable,
207 disabledReason: SURFACE_UNAVAILABLE_HINTS.diff,
208 onClick: props.onAddDiff,
209 badgeCount: 0,
210 },
211 {
212 label: "Pull request",
213 description: "Open this branch's pull request.",
214 icon: GitPullRequest,
215 shortcut: "P",
216 available: props.pullRequestAvailable,
217 disabledReason: SURFACE_UNAVAILABLE_HINTS.pullRequest,
218 onClick: props.onAddPullRequest,
219 badgeCount: 0,
220 },
221 {
222 label: "Agents",
223 description: "Follow subagents and workflows.",
224 icon: Bot,
225 shortcut: "A",
226 available: props.agentsAvailable,
227 disabledReason: SURFACE_UNAVAILABLE_HINTS.agents,
228 onClick: props.onAddAgents,
229 badgeCount: props.liveAgentCount,
230 },
231 ] as const;
232​
233 type SurfaceAction = (typeof actions)[number];
234​
235 const availableActions = actions.filter((action) => action.available);
236 const highlightIndex =
237 availableActions.length === 0 ? -1 : Math.min(highlight, availableActions.length - 1);
238​
239 // Letter shortcuts work while the launcher is visible, not only while it
240 // is focused; focus moves around too easily (stray clicks) to carry them.
241 // Capture phase so app-level key handlers cannot swallow the event first;
242 // typing contexts and already-handled events are left alone.
243 const shortcutActionsRef = useRef(availableActions);
244 useEffect(() => {
245 shortcutActionsRef.current = availableActions;
246 });
247 useEffect(() => {
248 const handler = (event: KeyboardEvent) => {
249 if (event.defaultPrevented || event.isComposing) return;
250 if (event.metaKey || event.ctrlKey || event.altKey) return;
251 if (document.querySelector(LAUNCHER_SHORTCUT_BLOCKING_LAYERS)) return;
252 const target = event.target;
253 if (target instanceof HTMLElement) {
254 if (target.closest("input, textarea, select")) return;
255 // An empty contenteditable (the chat composer at rest) does not
256 // count as typing; letters only become text once a draft exists.
257 const editable = target.isContentEditable ? target : target.closest("[contenteditable]");
258 if (editable && (editable.textContent ?? "").trim().length > 0) return;
259 }
260 const action = shortcutActionsRef.current.find(
261 (candidate) => candidate.shortcut.toLowerCase() === event.key.toLowerCase(),
262 );
263 if (!action) return;
264 event.preventDefault();
265 event.stopPropagation();
266 action.onClick();
267 };
268 window.addEventListener("keydown", handler, true);
269 return () => window.removeEventListener("keydown", handler, true);
270 }, []);
271​
272 const handleKeyDown = (event: ReactKeyboardEvent<HTMLDivElement>) => {
273 if (event.defaultPrevented || event.metaKey || event.ctrlKey || event.altKey) return;
274 if (availableActions.length === 0) return;
275 if (event.key === "ArrowDown" || event.key === "ArrowRight") {
276 event.preventDefault();
277 setHighlight((highlightIndex + 1) % availableActions.length);
278 return;
279 }
280 if (event.key === "ArrowUp" || event.key === "ArrowLeft") {
281 event.preventDefault();
282 setHighlight(
283 highlightIndex === -1
284 ? availableActions.length - 1
285 : (highlightIndex - 1 + availableActions.length) % availableActions.length,
286 );
287 return;
288 }
289 if (event.key === "Enter") {
290 // A focused card button owns its own activation; only open from the
291 // highlight when the container itself has focus.
292 if (event.target instanceof HTMLElement && event.target.closest("button")) return;
293 const action = availableActions[highlightIndex];
294 if (!action) return;
295 event.preventDefault();
296 action.onClick();
297 }
298 };
299​
300 // Stable identity so React only runs this callback ref on mount/unmount;
301 // an inline arrow would re-attach and re-focus on every render.
302 const focusOnMount = useCallback((node: HTMLDivElement | null) => {
303 node?.focus();
304 }, []);
305​
306 const isHighlighted = (action: SurfaceAction) =>
307 highlightIndex !== -1 && availableActions[highlightIndex] === action;
308​
309 const actionIcon = (action: SurfaceAction, iconClassName = "size-4") => {
310 const Icon = action.icon;
311 return (
312 <span className="relative inline-flex shrink-0">
313 <Icon className={iconClassName} />
314 {action.badgeCount > 0 ? (
315 <span
316 aria-hidden
317 className="absolute -top-1.5 -right-2 flex h-3.5 min-w-3.5 items-center justify-center rounded-full bg-info px-1 text-[9px] font-semibold tabular-nums text-white"
318 >
319 {action.badgeCount}
320 </span>
321 ) : null}
322 </span>
323 );
324 };
325​
326 const cardShellClass =
327 "rounded-lg border border-border/80 bg-card dark:border-transparent dark:shadow-none dark:inset-ring-1 dark:inset-ring-white/5";
328 const highlightedCardClass = "bg-accent/60 dark:inset-ring-white/20";
329​
330 return (
331 <div
332 ref={focusOnMount}
333 tabIndex={0}
334 onKeyDown={handleKeyDown}
335 aria-label="Open a surface"
336 data-surface-launcher-keys={availableActions.map((action) => action.shortcut).join("")}
337 className={cn(
338 "flex min-h-0 flex-1 items-center justify-center overflow-y-auto px-6 pt-6 outline-none",
339 // The panel topbar sits above this container; matching bottom padding
340 // keeps the cards centered against the full panel, not the leftover.
341 "pb-[calc(var(--workspace-topbar-height)+--spacing(6))]",
342 )}
343 >
344 <div className="relative w-full max-w-lg">
345 <div className="absolute inset-x-0 bottom-full mb-5 text-center">
346 <h3 className="font-medium text-foreground text-sm">Open a surface</h3>
347 <p className="mt-1 text-muted-foreground text-xs">
348 Choose what to show in the right panel.
349 </p>
350 </div>
351 <div className="grid grid-cols-2 gap-2">
352 {actions.map((action) =>
353 action.available ? (
354 <button
355 key={action.label}
356 type="button"
357 onClick={action.onClick}
358 onMouseEnter={() => setHighlight(availableActions.indexOf(action))}
359 onMouseLeave={() =>
360 setHighlight((current) =>
361 current === availableActions.indexOf(action) ? -1 : current,
362 )
363 }
364 className={cn(
365 "relative flex w-full cursor-pointer flex-col items-start p-4 text-left transition hover:border-border hover:bg-accent/60",
366 cardShellClass,
367 isHighlighted(action) && highlightedCardClass,
368 )}
369 >
370 <Kbd className="absolute top-3 right-3">{action.shortcut}</Kbd>
371 <span className="flex items-center gap-2 pe-8">
372 {actionIcon(action)}
373 <span className="font-medium text-sm">{action.label}</span>
374 </span>
375 <span className="mt-1.5 text-muted-foreground text-xs leading-relaxed">
376 {action.description}
377 </span>
378 </button>
379 ) : (
380 <div
381 key={action.label}
382 className={cn(
383 "relative flex w-full flex-col items-start p-4 opacity-40",
384 cardShellClass,
385 )}
386 >
387 <Kbd className="absolute top-3 right-3">{action.shortcut}</Kbd>
388 <span className="flex items-center gap-2 pe-8">
389 {actionIcon(action)}
390 <span className="font-medium text-sm">{action.label}</span>
391 </span>
392 <span className="mt-1.5 text-muted-foreground text-xs leading-relaxed">
393 {action.disabledReason}
394 </span>
395 </div>
396 ),
397 )}
398 </div>
399 </div>
400 </div>
401 );
403​
404function surfaceTitle(
405 surface: RightPanelSurface,
406 sessions: Readonly<Record<string, PreviewSessionSnapshot>>,
407 terminalLabelsById: ReadonlyMap<string, string>,
408): string {
409 switch (surface.kind) {
410 case "diff":
411 return "Diff";
412 case "files":
413 return "Files";
414 case "file":
415 return surface.relativePath.slice(surface.relativePath.lastIndexOf("/") + 1);
416 case "terminal":
417 return (
418 terminalLabelsById.get(surface.activeTerminalId) ??
419 getTerminalLabel(surface.activeTerminalId)
420 );
421 case "pull-request":
422 return `#${surface.number}`;
423 case "agents":
424 return "Agents";
425 case "preview": {
426 const snapshot = surface.resourceId ? sessions[surface.resourceId] : null;
427 if (!snapshot || snapshot.navStatus._tag === "Idle") return "Browser";
428 if (snapshot.navStatus.title.trim().length > 0) return snapshot.navStatus.title;
429 try {
430 return new URL(snapshot.navStatus.url).host || "Browser";
431 } catch {
432 return "Browser";
433 }
434 }
435 }
437​
438function PreviewFavicon({ url }: { url: string | null }) {
439 const faviconUrl = faviconUrlForOrigin(url, 32);
440 const [failedUrl, setFailedUrl] = useState<string | null>(null);
441 if (!faviconUrl || failedUrl === faviconUrl) return <Globe2 className="size-3 shrink-0" />;
442 return (
443 <img
444 src={faviconUrl}
445 alt=""
446 aria-hidden
447 draggable={false}
448 className="size-3 shrink-0 rounded-sm"
449 onError={() => setFailedUrl(faviconUrl)}
450 />
451 );
453​
454function SurfaceIcon({
455 surface,
456 sessions,
457 theme,
458 pullRequestStatuses,
459}: {
460 surface: RightPanelSurface;
461 sessions: Readonly<Record<string, PreviewSessionSnapshot>>;
462 theme: "light" | "dark";
463 pullRequestStatuses: Readonly<Record<string, PullRequestTabStatus>> | undefined;
464}) {
465 switch (surface.kind) {
466 case "preview": {
467 const snapshot = surface.resourceId ? sessions[surface.resourceId] : null;
468 const url = !snapshot || snapshot.navStatus._tag === "Idle" ? null : snapshot.navStatus.url;
469 return <PreviewFavicon url={url} />;
470 }
471 case "diff":
472 return <FileDiff className="size-3 shrink-0" />;
473 case "files":
474 return <Files className="size-3 shrink-0" />;
475 case "file":
476 return (
477 <PierreEntryIcon
478 pathValue={surface.relativePath}
479 kind="file"
480 theme={theme}
481 className="size-3"
482 />
483 );
484 case "terminal":
485 return <TerminalSquare className="size-3 shrink-0" />;
486 case "pull-request": {
487 const status = pullRequestStatuses?.[surface.id] ?? null;
488 const toneClassName =
489 status?.state === "merged"
490 ? "text-violet-600 dark:text-violet-300/90"
491 : status?.state === "closed"
492 ? "text-red-600 dark:text-red-300/90"
493 : status?.isDraft
494 ? "text-zinc-500 dark:text-zinc-400/80"
495 : status?.state === "open"
496 ? "text-emerald-600 dark:text-emerald-300/90"
497 : "text-muted-foreground";
498 return <GitPullRequest className={cn("size-3 shrink-0", toneClassName)} />;
499 }
500 case "agents":
501 return <Bot className="size-3 shrink-0" />;
502 }
504​
505export function RightPanelTabs(props: RightPanelTabsProps) {
506 const ownsDesktopTitleBar = isElectron && props.mode === "inline";
507 const { resolvedTheme } = useTheme();
508 const tabListRef = useRef<HTMLDivElement>(null);
509​
510 const handleTabContextMenu = useCallback(
511 async (event: ReactMouseEvent, surface: RightPanelSurface) => {
512 event.preventDefault();
513 event.stopPropagation();
514​
515 const api = readLocalApi();
516 if (!api) return;
517​
518 const surfaceIndex = props.surfaces.findIndex((entry) => entry.id === surface.id);
519 if (surfaceIndex < 0) return;
520​
521 const items: ContextMenuItem<TabContextMenuAction>[] = [];
522 if (surface.kind === "file") {
523 items.push({ id: "copy-path", label: "Copy path" });
524 }
525 items.push(
526 { id: "close", label: "Close" },
527 {
528 id: "close-others",
529 label: "Close others",
530 disabled: props.surfaces.length <= 1,
531 },
532 {
533 id: "close-to-right",
534 label: "Close to the right",
535 disabled: surfaceIndex >= props.surfaces.length - 1,
536 },
537 {
538 id: "close-all",
539 label: "Close all",
540 disabled: props.surfaces.length === 0,
541 },
542 );
543​
544 const action = await api.contextMenu.show(items, { x: event.clientX, y: event.clientY });
545 switch (action) {
546 case "copy-path":
547 if (surface.kind === "file") props.onCopyFilePath(surface.relativePath);
548 break;
549 case "close":
550 props.onCloseSurface(surface);
551 break;
552 case "close-others":
553 props.onCloseOtherSurfaces(surface);
554 break;
555 case "close-to-right":
556 props.onCloseSurfacesToRight(surface);
557 break;
558 case "close-all":
559 props.onCloseAllSurfaces();
560 break;
561 case null:
562 break;
563 }
564 },
565 [props],
566 );
567 const handleTabMouseDown = useCallback((event: ReactMouseEvent) => {
568 if (event.button !== 1) return;
569 event.preventDefault();
570 }, []);
571 const handleTabAuxClick = useCallback(
572 (event: ReactMouseEvent, surface: RightPanelSurface) => {
573 if (event.button !== 1) return;
574 event.preventDefault();
575 event.stopPropagation();
576 props.onCloseSurface(surface);
577 },
578 [props],
579 );
580​
581 useEffect(() => {
582 const activeTab = tabListRef.current?.querySelector<HTMLElement>("[data-active-tab='true']");
583 activeTab?.scrollIntoView({ block: "nearest", inline: "nearest" });
584 }, [props.activeSurfaceId]);
585​
586 return (
587 <PreviewPanelShell
588 mode={props.mode}
589 {...(props.maximized !== undefined ? { maximized: props.maximized } : {})}
590 {...(props.widthStorageKey !== undefined ? { widthStorageKey: props.widthStorageKey } : {})}
591 {...(props.defaultWidth !== undefined ? { defaultWidth: props.defaultWidth } : {})}
592 >
593 <div
594 className={cn(
595 "workspace-topbar gap-1 pl-2",
596 props.mode !== "inline" && "[--workspace-topbar-height:--spacing(11)]",
597 props.mode === "inline" && !props.layoutControls ? "pr-28" : "pr-3",
598 ownsDesktopTitleBar && "wco:pr-[calc(var(--workspace-native-controls-inset)+6rem)]",
599 props.mode === "inline" && props.maximized && COLLAPSED_SIDEBAR_TITLEBAR_INSET_CLASS,
600 )}
601 data-right-panel-tabbar
602 >
603 <ScrollArea
604 ref={tabListRef}
605 hideScrollbars
606 scrollFade
607 className={cn("min-w-0 flex-1 rounded-none", ownsDesktopTitleBar && "drag-region")}
608 data-right-panel-tab-list
609 >
610 <div className="flex h-full w-max min-w-full items-center gap-1">
611 {props.surfaces.map((surface) => {
612 const active = surface.id === props.activeSurfaceId;
613 const pending = props.pendingSurfaceIds.has(surface.id);
614 const title = surfaceTitle(surface, props.previewSessions, props.terminalLabelsById);
615 return (
616 <div
617 key={surface.id}
618 data-active-tab={active}
619 onMouseDown={handleTabMouseDown}
620 onAuxClick={(event) => handleTabAuxClick(event, surface)}
621 onContextMenu={(event) => void handleTabContextMenu(event, surface)}
622 className={cn(
623 "cursor-pointer group/tab flex h-6 max-w-36 shrink-0 items-center gap-0.5 rounded-md pr-2 pl-1.5 text-xs",
624 active
625 ? "bg-accent text-foreground"
626 : "text-muted-foreground hover:bg-accent/60 hover:text-foreground",
627 )}
628 >
629 <button
630 type="button"
631 className="cursor-pointer group/close relative flex size-4 shrink-0 items-center justify-center rounded-sm hover:bg-muted"
632 aria-label={`Close ${title}`}
633 onClick={() => props.onCloseSurface(surface)}
634 >
635 <span className="relative flex size-3 items-center justify-center group-hover/tab:hidden group-focus-visible/close:hidden">
636 <SurfaceIcon
637 surface={surface}
638 sessions={props.previewSessions}
639 theme={resolvedTheme}
640 pullRequestStatuses={props.pullRequestStatuses}
641 />
642 {pending ? (
643 <span
644 className="absolute -right-0.5 -bottom-0.5 size-1.5 rounded-full bg-current"
645 aria-hidden
646 />
647 ) : null}
648 </span>
649 <X className="hidden size-3 group-hover/tab:block group-focus-visible/close:block" />
650 </button>
651 <Tooltip>
652 <TooltipTrigger
653 render={
654 <button
655 type="button"
656 className="cursor-pointer flex min-w-0 items-center"
657 onClick={() => props.onActivate(surface)}
658 >
659 <span className="truncate">{title}</span>
660 </button>
661 }
662 />
663 <TooltipPopup>{title}</TooltipPopup>
664 </Tooltip>
665 </div>
666 );
667 })}
668 {props.surfaces.length > 0 ? (
669 <Menu>
670 <MenuTrigger
671 className="cursor-pointer relative inline-flex size-6 shrink-0 items-center justify-center rounded-md text-muted-foreground hover:bg-accent hover:text-foreground"
672 aria-label="Add panel surface"
673 >
674 <Plus className="size-3.5" />
675 </MenuTrigger>
676 <MenuPopup align="start" side="bottom" sideOffset={6} className="min-w-44">
677 <SurfaceMenuItem
678 available={props.browserAvailable}
679 disabledReason={SURFACE_DISABLED_REASONS.browser}
680 onClick={props.onAddBrowser}
681 >
682 <Globe2 />
683 Browser
684 </SurfaceMenuItem>
685 <SurfaceMenuItem
686 available={props.terminalAvailable}
687 disabledReason={SURFACE_DISABLED_REASONS.terminal}
688 onClick={props.onAddTerminal}
689 >
690 <TerminalSquare />
691 Terminal
692 </SurfaceMenuItem>
693 <SurfaceMenuItem
694 available={props.filesAvailable}
695 disabledReason={SURFACE_DISABLED_REASONS.files}
696 onClick={props.onAddFiles}
697 >
698 <Files />
699 Files
700 </SurfaceMenuItem>
701 <SurfaceMenuItem
702 available={props.diffAvailable}
703 disabledReason={SURFACE_DISABLED_REASONS.diff}
704 onClick={props.onAddDiff}
705 >
706 <FileDiff />
707 Diff
708 </SurfaceMenuItem>
709 <SurfaceMenuItem
710 available={props.pullRequestAvailable}
711 disabledReason={SURFACE_DISABLED_REASONS.pullRequest}
712 onClick={props.onAddPullRequest}
713 >
714 <GitPullRequest />
715 Pull request
716 </SurfaceMenuItem>
717 <SurfaceMenuItem
718 available={props.agentsAvailable}
719 disabledReason={SURFACE_DISABLED_REASONS.agents}
720 onClick={props.onAddAgents}
721 >
722 <Bot />
723 Agents
724 </SurfaceMenuItem>
725 </MenuPopup>
726 </Menu>
727 ) : null}
728 </div>
729 </ScrollArea>
730 {props.layoutControls}
731 </div>
732 <div className="flex min-h-0 flex-1 flex-col" data-right-panel-surface-content>
733 {props.activeSurfaceId === null ? (
734 <RightPanelEmptyState
735 onAddBrowser={props.onAddBrowser}
736 onAddTerminal={props.onAddTerminal}
737 onAddDiff={props.onAddDiff}
738 onAddFiles={props.onAddFiles}
739 onAddPullRequest={props.onAddPullRequest}
740 onAddAgents={props.onAddAgents}
741 browserAvailable={props.browserAvailable}
742 terminalAvailable={props.terminalAvailable}
743 diffAvailable={props.diffAvailable}
744 filesAvailable={props.filesAvailable}
745 pullRequestAvailable={props.pullRequestAvailable}
746 agentsAvailable={props.agentsAvailable}
747 liveAgentCount={props.liveAgentCount}
748 />
749 ) : (
750 props.children
751 )}
752 </div>
753 </PreviewPanelShell>
754 );