Skip to content

Commit c568d16

Browse files
refactor(web): open the right-panel terminal through the panel host
The right-panel terminal is now a registered side panel. Its body reads the thread and visibility from the panel host and keybindings from the server keybindings atom, then hands them to the unchanged memoized terminal, so ChatView renders that leave its inputs alone still skip it. ChatView passes only the terminal surface, launch context, focus request, callbacks and shortcut labels. Launcher copy, letter, order and availability are unchanged; the bottom drawer stays mounted by ChatView. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
1 parent 42aa28e commit c568d16

12 files changed

Lines changed: 516 additions & 53 deletions

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

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,7 @@ import { isMacPlatform } from "../lib/utils";
159159
import { RegisteredSidePanel } from "~/panels/bundledPanels";
160160
import { PanelHostContext, type PanelHost } from "~/panels/panelHost";
161161
import { PersistentThreadTerminalDrawer } from "~/panels/terminal/PersistentThreadTerminalDrawer";
162-
import {
163-
PersistentThreadTerminalPanel,
164-
type TerminalLaunchContext,
165-
} from "~/panels/terminal/PersistentThreadTerminalPanel";
162+
import type { TerminalLaunchContext } from "~/panels/terminal/TerminalSidePanel";
166163
import type { AssistantCitationSourceAnchor } from "~/lib/assistantTextSelection";
167164
import { useShallow } from "zustand/react/shallow";
168165
import {
@@ -9930,13 +9927,11 @@ export default function ChatView(props: ChatViewProps) {
99309927
configuredUrls={configuredPreviewUrls}
99319928
/>
99329929
) : renderedRightPanelSurface?.kind === "terminal" ? (
9933-
<PersistentThreadTerminalPanel
9934-
visible={rightPanelOpen}
9935-
threadRef={activeThreadRef}
9930+
<RegisteredSidePanel
9931+
id="terminal"
99369932
surface={renderedRightPanelSurface}
99379933
launchContext={activeTerminalLaunchContext ?? null}
99389934
focusRequestId={terminalFocusRequestId}
9939-
keybindings={keybindings}
99409935
onAddTerminalContext={addTerminalContextToDraft}
99419936
onSplitTerminal={splitPanelTerminal}
99429937
onSplitTerminalVertical={splitPanelTerminalVertical}
@@ -10084,6 +10079,7 @@ export default function ChatView(props: ChatViewProps) {
1008410079
const sidePanelLaunchers = {
1008510080
preview: { available: true, onOpen: createBrowserSurface },
1008610081
diff: { available: isServerThread && isGitRepo, onOpen: addDiffSurface },
10082+
terminal: { available: activeProject !== null, onOpen: addTerminalSurface },
1008710083
};
1008810084
const threadDetailsPanelProps: ThreadDetailsPanelProps = {
1008910085
anchor: threadPanelPopoverAnchorRef,
@@ -10898,12 +10894,10 @@ export default function ChatView(props: ChatViewProps) {
1089810894
onCopyFilePath={copyRightPanelFilePath}
1089910895
panels={sidePanelLaunchers}
1090010896
onAddBrowserInProfile={createBrowserSurface}
10901-
onAddTerminal={addTerminalSurface}
1090210897
onAddFiles={addFilesSurface}
1090310898
onAddPullRequest={addPullRequestSurface}
1090410899
onAddPullRequests={addPullRequestsSurface}
1090510900
onAddDevice={addDeviceSurface}
10906-
terminalAvailable={activeProject !== null}
1090710901
filesAvailable={activeProject !== null}
1090810902
pullRequestAvailable={pullRequestSurfaceAvailable}
1090910903
pullRequestsAvailable={pullRequestsSurfaceAvailable}
@@ -10950,12 +10944,10 @@ export default function ChatView(props: ChatViewProps) {
1095010944
onCopyFilePath={copyRightPanelFilePath}
1095110945
panels={sidePanelLaunchers}
1095210946
onAddBrowserInProfile={createBrowserSurface}
10953-
onAddTerminal={addTerminalSurface}
1095410947
onAddFiles={addFilesSurface}
1095510948
onAddPullRequest={addPullRequestSurface}
1095610949
onAddPullRequests={addPullRequestsSurface}
1095710950
onAddDevice={addDeviceSurface}
10958-
terminalAvailable={activeProject !== null}
1095910951
filesAvailable={activeProject !== null}
1096010952
pullRequestAvailable={pullRequestSurfaceAvailable}
1096110953
pullRequestsAvailable={pullRequestsSurfaceAvailable}

‎apps/web/src/components/RightPanelTabs.browserProfile.test.tsx‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,13 @@ function Harness() {
7272
panels={{
7373
preview: { available: true, onOpen: openBrowser },
7474
diff: { available: false, onOpen: () => undefined },
75+
terminal: { available: false, onOpen: () => undefined },
7576
}}
7677
onAddBrowserInProfile={openBrowser}
77-
onAddTerminal={() => undefined}
7878
onAddPullRequest={() => undefined}
7979
onAddPullRequests={() => undefined}
8080
onAddFiles={() => undefined}
8181
onAddDevice={() => undefined}
82-
terminalAvailable={false}
8382
filesAvailable={false}
8483
pullRequestAvailable={false}
8584
pullRequestsAvailable={false}
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
// @vitest-environment jsdom
2+
3+
import { EnvironmentId, ThreadId, type ScopedThreadRef } from "@t3tools/contracts";
4+
import { act } from "react";
5+
import { createRoot, type Root } from "react-dom/client";
6+
import { afterEach, beforeEach, describe, expect, it, vi } from "vite-plus/test";
7+
8+
import { selectThreadRightPanelState, useRightPanelStore } from "~/rightPanelStore";
9+
10+
import { RightPanelTabs } from "./RightPanelTabs";
11+
12+
const threadRef: ScopedThreadRef = {
13+
environmentId: EnvironmentId.make("environment-a"),
14+
threadId: ThreadId.make("thread-a"),
15+
};
16+
17+
let root: Root;
18+
let container: HTMLDivElement;
19+
20+
beforeEach(() => {
21+
vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true);
22+
vi.stubGlobal(
23+
"ResizeObserver",
24+
class {
25+
observe() {}
26+
disconnect() {}
27+
},
28+
);
29+
// jsdom lacks the Web Animations API that the tab bar's scroll area waits on.
30+
Element.prototype.getAnimations ??= () => [];
31+
useRightPanelStore.setState({ byThreadKey: {} });
32+
container = document.createElement("div");
33+
document.body.append(container);
34+
root = createRoot(container);
35+
});
36+
37+
afterEach(async () => {
38+
await act(async () => root.unmount());
39+
container.remove();
40+
vi.unstubAllGlobals();
41+
});
42+
43+
// Shows the thread's surfaces from the real right-panel store and opens the
44+
// terminal into it the way ChatView's addTerminalSurface does.
45+
function Harness({ terminalAvailable }: { terminalAvailable: boolean }) {
46+
const surfaces = useRightPanelStore(
47+
(state) => selectThreadRightPanelState(state.byThreadKey, threadRef).surfaces,
48+
);
49+
return (
50+
<RightPanelTabs
51+
mode="inline"
52+
surfaces={surfaces}
53+
environmentId={threadRef.environmentId}
54+
activeSurfaceId={surfaces[0]?.id ?? null}
55+
pendingSurfaceIds={new Set()}
56+
previewSessions={{}}
57+
desktopByTabId={{}}
58+
terminalLabelsById={new Map()}
59+
onActivate={() => undefined}
60+
onCloseSurface={() => undefined}
61+
onCloseOtherSurfaces={() => undefined}
62+
onCloseSurfacesToRight={() => undefined}
63+
onCloseAllSurfaces={() => undefined}
64+
onCopyFilePath={() => undefined}
65+
panels={{
66+
preview: { available: false, onOpen: () => undefined },
67+
diff: { available: false, onOpen: () => undefined },
68+
terminal: {
69+
available: terminalAvailable,
70+
onOpen: () => useRightPanelStore.getState().openTerminal(threadRef, "term-1"),
71+
},
72+
}}
73+
onAddBrowserInProfile={() => undefined}
74+
onAddPullRequest={() => undefined}
75+
onAddPullRequests={() => undefined}
76+
onAddFiles={() => undefined}
77+
onAddDevice={() => undefined}
78+
filesAvailable={false}
79+
pullRequestAvailable={false}
80+
pullRequestsAvailable={false}
81+
deviceAvailable={false}
82+
>
83+
{null}
84+
</RightPanelTabs>
85+
);
86+
}
87+
88+
function launcherRow(label: string): HTMLElement {
89+
const launcher = container.querySelector('[aria-label="Open a surface"]');
90+
// Unavailable rows render as aria-disabled elements rather than buttons.
91+
const row = [
92+
...(launcher?.querySelectorAll<HTMLElement>('button, [aria-disabled="true"]') ?? []),
93+
].find((element) => element.textContent?.startsWith(label));
94+
if (!row) throw new Error(`No launcher row ${label}`);
95+
return row;
96+
}
97+
98+
async function click(element: Element) {
99+
await act(async () => {
100+
element.dispatchEvent(new MouseEvent("pointerdown", { bubbles: true }));
101+
element.dispatchEvent(new MouseEvent("mousedown", { bubbles: true }));
102+
element.dispatchEvent(new MouseEvent("pointerup", { bubbles: true }));
103+
element.dispatchEvent(new MouseEvent("mouseup", { bubbles: true }));
104+
element.dispatchEvent(new MouseEvent("click", { bubbles: true }));
105+
});
106+
}
107+
108+
const threadSurfaces = () =>
109+
selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, threadRef).surfaces;
110+
111+
describe("opening Terminal from the launcher", () => {
112+
it("opens a terminal surface from the row when a project allows it", async () => {
113+
await act(async () => root.render(<Harness terminalAvailable />));
114+
115+
await click(launcherRow("Terminal"));
116+
expect(threadSurfaces()).toMatchObject([{ kind: "terminal", activeTerminalId: "term-1" }]);
117+
expect(container.querySelector('[aria-label="Open a surface"]')).toBeNull();
118+
expect(container.textContent).toContain("Terminal 1");
119+
});
120+
121+
it("keeps the row disabled and opens nothing without a project", async () => {
122+
await act(async () => root.render(<Harness terminalAvailable={false} />));
123+
124+
const row = launcherRow("Terminal");
125+
expect(row.getAttribute("aria-disabled")).toBe("true");
126+
await click(row);
127+
expect(threadSurfaces()).toEqual([]);
128+
expect(container.querySelector('[aria-label="Open a surface"]')).not.toBeNull();
129+
});
130+
});

‎apps/web/src/components/RightPanelTabs.test.tsx‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,12 @@ describe("right panel surface actions", () => {
3030
panels: {
3131
preview: { available: true, onOpen: () => undefined },
3232
diff: { available: true, onOpen: () => undefined },
33+
terminal: { available: true, onOpen: () => undefined },
3334
},
34-
onAddTerminal: () => undefined,
3535
onAddFiles: () => undefined,
3636
onAddPullRequest: () => undefined,
3737
onAddPullRequests: () => undefined,
3838
onAddDevice: () => undefined,
39-
terminalAvailable: true,
4039
filesAvailable: true,
4140
pullRequestAvailable: true,
4241
pullRequestsAvailable: true,
@@ -169,14 +168,13 @@ function renderTabs(
169168
panels={{
170169
preview: { available: true, onOpen: () => undefined },
171170
diff: { available: false, onOpen: () => undefined },
171+
terminal: { available: false, onOpen: () => undefined },
172172
}}
173173
onAddBrowserInProfile={() => undefined}
174-
onAddTerminal={() => undefined}
175174
onAddPullRequest={() => undefined}
176175
onAddPullRequests={() => undefined}
177176
onAddFiles={() => undefined}
178177
onAddDevice={() => undefined}
179-
terminalAvailable={false}
180178
filesAvailable={false}
181179
pullRequestAvailable={false}
182180
pullRequestsAvailable={false}

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

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,7 @@ import type {
1313
PullRequestState,
1414
} from "@t3tools/contracts";
1515
import { getTerminalLabel } from "@t3tools/shared/terminalLabels";
16-
import {
17-
Smartphone,
18-
ChevronDown,
19-
ChevronLeft,
20-
ChevronRight,
21-
Files,
22-
Plus,
23-
TerminalSquare,
24-
} from "lucide-react";
16+
import { Smartphone, ChevronDown, ChevronLeft, ChevronRight, Files, Plus } from "lucide-react";
2517
import { Volume2, VolumeOff } from "lucide";
2618
import {
2719
type ComponentType,
@@ -113,12 +105,10 @@ interface RightPanelTabsProps {
113105
/** Whether each registered panel can open here, and how; titles and icons come from its definition. */
114106
panels: Readonly<Record<SidePanelId, SidePanelLauncher>>;
115107
onAddBrowserInProfile: (profileId: string) => void;
116-
onAddTerminal: () => void;
117108
onAddFiles: () => void;
118109
onAddPullRequest: () => void;
119110
onAddPullRequests: () => void;
120111
onAddDevice: () => void;
121-
terminalAvailable: boolean;
122112
filesAvailable: boolean;
123113
pullRequestAvailable: boolean;
124114
pullRequestsAvailable: boolean;
@@ -177,12 +167,10 @@ interface SurfaceAction {
177167
type SurfaceActionInputs = Pick<
178168
RightPanelTabsProps,
179169
| "panels"
180-
| "onAddTerminal"
181170
| "onAddFiles"
182171
| "onAddPullRequest"
183172
| "onAddPullRequests"
184173
| "onAddDevice"
185-
| "terminalAvailable"
186174
| "filesAvailable"
187175
| "pullRequestAvailable"
188176
| "pullRequestsAvailable"
@@ -212,16 +200,7 @@ export function rightPanelSurfaceActions(props: SurfaceActionInputs): SurfaceAct
212200
};
213201
return [
214202
registered("preview"),
215-
{
216-
id: "terminal",
217-
label: "Terminal",
218-
icon: TerminalSquare,
219-
shortcut: "T",
220-
available: props.terminalAvailable,
221-
unavailableHint: "Available when a project is open.",
222-
unavailableReason: "Terminal surfaces are only available from a project thread.",
223-
onClick: props.onAddTerminal,
224-
},
203+
registered("terminal"),
225204
{
226205
id: "files",
227206
label: "Files",
@@ -681,8 +660,10 @@ function SurfaceIcon({
681660
className="size-3"
682661
/>
683662
);
684-
case "terminal":
685-
return <TerminalSquare className="size-3 shrink-0" />;
663+
case "terminal": {
664+
const Icon = getSidePanelMetadata("terminal").icon;
665+
return <Icon className="size-3 shrink-0" />;
666+
}
686667
case "pull-request":
687668
return (
688669
<PullRequestSurfaceIcon

0 commit comments

Comments
 (0)