Skip to content

Commit 641bbe1

Browse files
committed
feat(web): add thread workspace tabs and grid
1 parent 9996038 commit 641bbe1

8 files changed

Lines changed: 1089 additions & 78 deletions

File tree

‎apps/web/src/components/ChatView.tsx‎

Lines changed: 116 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ import {
7171
useRef,
7272
useState,
7373
} from "react";
74-
import { flushSync } from "react-dom";
74+
import { createPortal, flushSync } from "react-dom";
7575
import { useNavigate } from "@tanstack/react-router";
7676
import { useShallow } from "zustand/react/shallow";
7777
import {
@@ -545,13 +545,20 @@ function formatOutgoingPrompt(params: {
545545
const SCRIPT_TERMINAL_COLS = 120;
546546
const SCRIPT_TERMINAL_ROWS = 30;
547547

548+
interface ChatViewWorkspaceContext {
549+
readonly active: boolean;
550+
readonly rightPanelHost: HTMLElement | null;
551+
readonly onRightPanelMaximizedChange: (maximized: boolean) => void;
552+
}
553+
548554
type ChatViewProps =
549555
| {
550556
environmentId: EnvironmentId;
551557
threadId: ThreadId;
552558
onDiffPanelOpen?: () => void;
553559
reserveTitleBarControlInset?: boolean;
554560
forceExpandedMobileComposer?: boolean;
561+
workspace?: ChatViewWorkspaceContext;
555562
threadSyncPhase?: ThreadSyncPhase | null;
556563
routeKind: "server";
557564
draftId?: never;
@@ -562,6 +569,7 @@ type ChatViewProps =
562569
onDiffPanelOpen?: () => void;
563570
reserveTitleBarControlInset?: boolean;
564571
forceExpandedMobileComposer?: boolean;
572+
workspace?: ChatViewWorkspaceContext;
565573
threadSyncPhase?: never;
566574
routeKind: "draft";
567575
draftId: DraftId;
@@ -1252,7 +1260,11 @@ function ChatViewContent(props: ChatViewProps) {
12521260
onDiffPanelOpen,
12531261
reserveTitleBarControlInset = true,
12541262
forceExpandedMobileComposer = false,
1263+
workspace,
12551264
} = props;
1265+
const workspaceActive = workspace?.active ?? true;
1266+
const workspaceRightPanelHost = workspace?.rightPanelHost ?? null;
1267+
const onWorkspaceRightPanelMaximizedChange = workspace?.onRightPanelMaximizedChange;
12561268
const draftId = routeKind === "draft" ? props.draftId : null;
12571269
const threadSyncPhase = routeKind === "server" ? (props.threadSyncPhase ?? null) : null;
12581270
const threadDetailLoading = threadSyncPhase === "loading";
@@ -1731,7 +1743,18 @@ function ChatViewContent(props: ChatViewProps) {
17311743
const canMaximizeRightPanel = rightPanelOpen && !shouldUseRightPanelSheet;
17321744
const rightPanelMaximized =
17331745
canMaximizeRightPanel && maximizedRightPanelThreadKey === routeThreadKey;
1734-
const inlineRightPanelOwnsTitleBar = rightPanelOpen && !shouldUseRightPanelSheet;
1746+
const externalInlineRightPanel =
1747+
workspaceActive && workspaceRightPanelHost && !shouldUseRightPanelSheet
1748+
? workspaceRightPanelHost
1749+
: null;
1750+
const inlineRightPanelOwnsTitleBar =
1751+
workspaceActive && rightPanelOpen && !shouldUseRightPanelSheet;
1752+
1753+
useEffect(() => {
1754+
if (!workspaceActive || !onWorkspaceRightPanelMaximizedChange) return;
1755+
onWorkspaceRightPanelMaximizedChange(rightPanelOpen && rightPanelMaximized);
1756+
return () => onWorkspaceRightPanelMaximizedChange(false);
1757+
}, [onWorkspaceRightPanelMaximizedChange, rightPanelMaximized, rightPanelOpen, workspaceActive]);
17351758

17361759
useEffect(() => {
17371760
if (!activeThreadRef) return;
@@ -4887,6 +4910,7 @@ function ChatViewContent(props: ChatViewProps) {
48874910

48884911
useEffect(() => {
48894912
const handler = (event: globalThis.KeyboardEvent) => {
4913+
if (!workspaceActive) return;
48904914
if (preventRepeatedTerminalCloseShortcut(event, keybindings)) {
48914915
event.stopPropagation();
48924916
return;
@@ -5047,6 +5071,7 @@ function ChatViewContent(props: ChatViewProps) {
50475071
toggleRightPanelMaximized,
50485072
toggleTerminalVisibility,
50495073
composerRef,
5074+
workspaceActive,
50505075
]);
50515076

50525077
const onRevertToTurnCount = useCallback(
@@ -6482,6 +6507,15 @@ function ChatViewContent(props: ChatViewProps) {
64826507
{panelToggleControls}
64836508
</div>
64846509
);
6510+
const hostedPanelLayoutControls = externalInlineRightPanel ? (
6511+
<div className="mr-px flex h-full shrink-0 items-center gap-1">
6512+
<RightPanelMaximizeControl
6513+
maximized={rightPanelMaximized}
6514+
onToggle={toggleRightPanelMaximized}
6515+
/>
6516+
{panelToggleControls}
6517+
</div>
6518+
) : null;
64856519
const rightPanelContent = activeThreadRef ? (
64866520
activeRightPanelSurface?.kind === "preview" ? (
64876521
<Suspense fallback={null}>
@@ -6600,10 +6634,58 @@ function ChatViewContent(props: ChatViewProps) {
66006634
});
66016635
const externalComposerDrawerAttached =
66026636
composerBannerItems.length > 0 || Boolean(threadSyncPhase && !activeEnvironmentUnavailable);
6637+
const terminalThreadRefsToRender = workspace
6638+
? activeThreadRef && activeThreadKey
6639+
? [{ key: activeThreadKey, threadRef: activeThreadRef }]
6640+
: []
6641+
: mountedTerminalThreadRefs;
6642+
const inlineRightPanel =
6643+
workspaceActive &&
6644+
(!workspace || externalInlineRightPanel) &&
6645+
!shouldUseRightPanelSheet &&
6646+
rightPanelOpen &&
6647+
activeThreadRef ? (
6648+
<RightPanelTabs
6649+
mode="inline"
6650+
maximized={rightPanelMaximized}
6651+
{...(hostedPanelLayoutControls ? { layoutControls: hostedPanelLayoutControls } : {})}
6652+
surfaces={rightPanelState.surfaces}
6653+
activeSurfaceId={activeRightPanelSurface?.id ?? null}
6654+
pendingSurfaceIds={pendingFileSurfaceIds}
6655+
previewSessions={activePreviewState.sessions}
6656+
desktopByTabId={activePreviewState.desktopByTabId}
6657+
previewRuntimeTabId={resolvePreviewRuntimeTabId}
6658+
terminalLabelsById={activeTerminalLabelsById}
6659+
onActivate={activateRightPanelSurface}
6660+
onCloseSurface={closeRightPanelSurface}
6661+
onCloseOtherSurfaces={closeOtherRightPanelSurfaces}
6662+
onCloseSurfacesToRight={closeRightPanelSurfacesToRight}
6663+
onCloseAllSurfaces={closeAllRightPanelSurfaces}
6664+
onCopyFilePath={copyRightPanelFilePath}
6665+
onAddBrowser={createBrowserSurface}
6666+
onAddTerminal={addTerminalSurface}
6667+
onAddDiff={addDiffSurface}
6668+
onAddFiles={addFilesSurface}
6669+
onAddPullRequest={addPullRequestSurface}
6670+
onAddAgents={addAgentsSurface}
6671+
browserAvailable={isPreviewSupportedInRuntime()}
6672+
terminalAvailable={activeProject !== null}
6673+
diffAvailable={isServerThread && isGitRepo}
6674+
filesAvailable={activeProject !== null}
6675+
pullRequestAvailable={pullRequestSurfaceAvailable}
6676+
agentsAvailable
6677+
pullRequestStatuses={pullRequestTabStatuses}
6678+
liveAgentCount={agentPanelModel.liveCount}
6679+
>
6680+
{rightPanelContent}
6681+
</RightPanelTabs>
6682+
) : null;
66036683

66046684
return (
66056685
<div className="relative flex min-h-0 min-w-0 flex-1 overflow-hidden bg-background">
6606-
{rightPanelOpen && !shouldUseRightPanelSheet ? panelLayoutControls : null}
6686+
{workspaceActive && rightPanelOpen && !shouldUseRightPanelSheet && !externalInlineRightPanel
6687+
? panelLayoutControls
6688+
: null}
66076689
<div
66086690
className={cn(
66096691
"flex min-h-0 min-w-0 flex-col overflow-x-hidden",
@@ -6614,11 +6696,11 @@ function ChatViewContent(props: ChatViewProps) {
66146696
{/* Top bar */}
66156697
<WorkspacePageHeader
66166698
data-chat-header
6617-
electron={isElectron}
6699+
electron={isElectron && !workspace}
66186700
reserveNativeControls={reserveTitleBarControlInset && !inlineRightPanelOwnsTitleBar}
66196701
className="relative bg-background"
66206702
>
6621-
{!rightPanelOpen ? panelLayoutControls : null}
6703+
{workspaceActive && !rightPanelOpen ? panelLayoutControls : null}
66226704
<ChatHeader
66236705
{...(!supportsPullRequests || threadRepository === null
66246706
? {}
@@ -6997,62 +7079,32 @@ function ChatViewContent(props: ChatViewProps) {
69977079
</div>
69987080
{/* end horizontal flex container */}
69997081

7000-
{mountedTerminalThreadRefs.map(({ key: mountedThreadKey, threadRef: mountedThreadRef }) => (
7001-
<PersistentThreadTerminalDrawer
7002-
key={mountedThreadKey}
7003-
threadRef={mountedThreadRef}
7004-
threadId={mountedThreadRef.threadId}
7005-
visible={mountedThreadKey === activeThreadKey && terminalUiState.terminalOpen}
7006-
launchContext={
7007-
mountedThreadKey === activeThreadKey ? (activeTerminalLaunchContext ?? null) : null
7008-
}
7009-
focusRequestId={mountedThreadKey === activeThreadKey ? terminalFocusRequestId : 0}
7010-
splitShortcutLabel={splitTerminalShortcutLabel ?? undefined}
7011-
splitVerticalShortcutLabel={splitTerminalVerticalShortcutLabel ?? undefined}
7012-
newShortcutLabel={newTerminalShortcutLabel ?? undefined}
7013-
closeShortcutLabel={closeTerminalShortcutLabel ?? undefined}
7014-
keybindings={keybindings}
7015-
onAddTerminalContext={addTerminalContextToDraft}
7016-
/>
7017-
))}
7082+
{terminalThreadRefsToRender.map(
7083+
({ key: mountedThreadKey, threadRef: mountedThreadRef }) => (
7084+
<PersistentThreadTerminalDrawer
7085+
key={mountedThreadKey}
7086+
threadRef={mountedThreadRef}
7087+
threadId={mountedThreadRef.threadId}
7088+
visible={mountedThreadKey === activeThreadKey && terminalUiState.terminalOpen}
7089+
launchContext={
7090+
mountedThreadKey === activeThreadKey ? (activeTerminalLaunchContext ?? null) : null
7091+
}
7092+
focusRequestId={mountedThreadKey === activeThreadKey ? terminalFocusRequestId : 0}
7093+
splitShortcutLabel={splitTerminalShortcutLabel ?? undefined}
7094+
splitVerticalShortcutLabel={splitTerminalVerticalShortcutLabel ?? undefined}
7095+
newShortcutLabel={newTerminalShortcutLabel ?? undefined}
7096+
closeShortcutLabel={closeTerminalShortcutLabel ?? undefined}
7097+
keybindings={keybindings}
7098+
onAddTerminalContext={addTerminalContextToDraft}
7099+
/>
7100+
),
7101+
)}
70187102
</div>
70197103

7020-
{!shouldUseRightPanelSheet && rightPanelOpen && activeThreadRef ? (
7021-
<RightPanelTabs
7022-
mode="inline"
7023-
maximized={rightPanelMaximized}
7024-
surfaces={rightPanelState.surfaces}
7025-
activeSurfaceId={activeRightPanelSurface?.id ?? null}
7026-
pendingSurfaceIds={pendingFileSurfaceIds}
7027-
previewSessions={activePreviewState.sessions}
7028-
desktopByTabId={activePreviewState.desktopByTabId}
7029-
previewRuntimeTabId={resolvePreviewRuntimeTabId}
7030-
terminalLabelsById={activeTerminalLabelsById}
7031-
onActivate={activateRightPanelSurface}
7032-
onCloseSurface={closeRightPanelSurface}
7033-
onCloseOtherSurfaces={closeOtherRightPanelSurfaces}
7034-
onCloseSurfacesToRight={closeRightPanelSurfacesToRight}
7035-
onCloseAllSurfaces={closeAllRightPanelSurfaces}
7036-
onCopyFilePath={copyRightPanelFilePath}
7037-
onAddBrowser={createBrowserSurface}
7038-
onAddTerminal={addTerminalSurface}
7039-
onAddDiff={addDiffSurface}
7040-
onAddFiles={addFilesSurface}
7041-
onAddPullRequest={addPullRequestSurface}
7042-
onAddAgents={addAgentsSurface}
7043-
browserAvailable={isPreviewSupportedInRuntime()}
7044-
terminalAvailable={activeProject !== null}
7045-
diffAvailable={isServerThread && isGitRepo}
7046-
filesAvailable={activeProject !== null}
7047-
pullRequestAvailable={pullRequestSurfaceAvailable}
7048-
agentsAvailable
7049-
pullRequestStatuses={pullRequestTabStatuses}
7050-
liveAgentCount={agentPanelModel.liveCount}
7051-
>
7052-
{rightPanelContent}
7053-
</RightPanelTabs>
7054-
) : null}
7055-
{shouldUseRightPanelSheet && rightPanelOpen && activeThreadRef ? (
7104+
{inlineRightPanel && externalInlineRightPanel
7105+
? createPortal(inlineRightPanel, externalInlineRightPanel)
7106+
: inlineRightPanel}
7107+
{workspaceActive && shouldUseRightPanelSheet && rightPanelOpen && activeThreadRef ? (
70567108
<RightPanelSheet open onClose={closePreviewPanel}>
70577109
<RightPanelTabs
70587110
mode="sheet"
@@ -7112,3 +7164,8 @@ export default function ChatView(props: ChatViewProps) {
71127164
</DiffWorkerPoolProvider>
71137165
);
71147166
}
7167+
7168+
/** Thread workspace panes share one worker pool at their common parent. */
7169+
export function ChatViewWithoutDiffWorkerPool(props: ChatViewProps) {
7170+
return <ChatViewContent {...props} />;
7171+
}

0 commit comments

Comments
 (0)