Skip to content

Commit 98e19e4

Browse files
refactor(web): open the Device side panel through the panel host
Register Device in the bundled panel registry like Browser, Diff and Terminal. The body moves to panels/device and reads its thread and visibility from the panel host; the launcher row, tab title and icon read the definition, so the copy, letter and order are unchanged. The Device tests now mount it through the registered lazy path. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
1 parent 91fb672 commit 98e19e4

10 files changed

Lines changed: 110 additions & 97 deletions

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

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -680,9 +680,6 @@ function useDraftHeroLayoutTransition(
680680

681681
const selectAutoShowFloatingPreview = (settings: { browserAutoShowFloatingPreview: boolean }) =>
682682
settings.browserAutoShowFloatingPreview;
683-
const DevicePanel = lazy(() =>
684-
import("./device/DevicePanel").then((module) => ({ default: module.DevicePanel })),
685-
);
686683
const FilePreviewPanel = lazy(() => import("./files/FilePreviewPanel"));
687684
const EMPTY_PENDING_FILE_SURFACE_IDS: ReadonlySet<string> = new Set();
688685
const TYPE_TO_FOCUS_EDITABLE_SELECTOR = [
@@ -10001,19 +9998,15 @@ export default function ChatView(props: ChatViewProps) {
100019998
) : renderedRightPanelSurface?.kind === "pull-requests" && activeThreadRef ? (
100029999
<ThreadPullRequestsPanel threadRef={activeThreadRef} />
1000310000
) : renderedRightPanelSurface?.kind === "device" ? (
10004-
<Suspense fallback={null}>
10005-
<DevicePanel
10006-
mode="embedded"
10007-
threadRef={activeThreadRef}
10008-
key={renderedRightPanelSurface.id}
10009-
surface={renderedRightPanelSurface}
10010-
visible={rightPanelOpen}
10011-
onDismissSetup={() => {
10012-
closeRightPanelSurface(renderedRightPanelSurface);
10013-
useRightPanelStore.getState().show(activeThreadRef);
10014-
}}
10015-
/>
10016-
</Suspense>
10001+
<RegisteredSidePanel
10002+
id="device"
10003+
key={renderedRightPanelSurface.id}
10004+
surface={renderedRightPanelSurface}
10005+
onDismissSetup={() => {
10006+
closeRightPanelSurface(renderedRightPanelSurface);
10007+
useRightPanelStore.getState().show(activeThreadRef);
10008+
}}
10009+
/>
1001710010
) : (renderedRightPanelSurface?.kind === "files" ||
1001810011
renderedRightPanelSurface?.kind === "file") &&
1001910012
((activeProject && activeWorkspaceRoot) ||
@@ -10080,6 +10073,7 @@ export default function ChatView(props: ChatViewProps) {
1008010073
preview: { available: true, onOpen: createBrowserSurface },
1008110074
diff: { available: isServerThread && isGitRepo, onOpen: addDiffSurface },
1008210075
terminal: { available: activeProject !== null, onOpen: addTerminalSurface },
10076+
device: { available: activeThreadRef !== null, onOpen: addDeviceSurface },
1008310077
};
1008410078
const threadDetailsPanelProps: ThreadDetailsPanelProps = {
1008510079
anchor: threadPanelPopoverAnchorRef,
@@ -10897,11 +10891,9 @@ export default function ChatView(props: ChatViewProps) {
1089710891
onAddFiles={addFilesSurface}
1089810892
onAddPullRequest={addPullRequestSurface}
1089910893
onAddPullRequests={addPullRequestsSurface}
10900-
onAddDevice={addDeviceSurface}
1090110894
filesAvailable={activeProject !== null}
1090210895
pullRequestAvailable={pullRequestSurfaceAvailable}
1090310896
pullRequestsAvailable={pullRequestsSurfaceAvailable}
10904-
deviceAvailable={activeThreadRef !== null}
1090510897
>
1090610898
{rightPanelContent}
1090710899
</RightPanelTabs>
@@ -10947,11 +10939,9 @@ export default function ChatView(props: ChatViewProps) {
1094710939
onAddFiles={addFilesSurface}
1094810940
onAddPullRequest={addPullRequestSurface}
1094910941
onAddPullRequests={addPullRequestsSurface}
10950-
onAddDevice={addDeviceSurface}
1095110942
filesAvailable={activeProject !== null}
1095210943
pullRequestAvailable={pullRequestSurfaceAvailable}
1095310944
pullRequestsAvailable={pullRequestsSurfaceAvailable}
10954-
deviceAvailable={activeThreadRef !== null}
1095510945
>
1095610946
{rightPanelContent}
1095710947
</RightPanelTabs>

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,16 +73,15 @@ function Harness() {
7373
preview: { available: true, onOpen: openBrowser },
7474
diff: { available: false, onOpen: () => undefined },
7575
terminal: { available: false, onOpen: () => undefined },
76+
device: { available: false, onOpen: () => undefined },
7677
}}
7778
onAddBrowserInProfile={openBrowser}
7879
onAddPullRequest={() => undefined}
7980
onAddPullRequests={() => undefined}
8081
onAddFiles={() => undefined}
81-
onAddDevice={() => undefined}
8282
filesAvailable={false}
8383
pullRequestAvailable={false}
8484
pullRequestsAvailable={false}
85-
deviceAvailable={false}
8685
>
8786
{null}
8887
</RightPanelTabs>

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,16 +69,15 @@ function Harness({ terminalAvailable }: { terminalAvailable: boolean }) {
6969
available: terminalAvailable,
7070
onOpen: () => useRightPanelStore.getState().openTerminal(threadRef, "term-1"),
7171
},
72+
device: { available: false, onOpen: () => undefined },
7273
}}
7374
onAddBrowserInProfile={() => undefined}
7475
onAddPullRequest={() => undefined}
7576
onAddPullRequests={() => undefined}
7677
onAddFiles={() => undefined}
77-
onAddDevice={() => undefined}
7878
filesAvailable={false}
7979
pullRequestAvailable={false}
8080
pullRequestsAvailable={false}
81-
deviceAvailable={false}
8281
>
8382
{null}
8483
</RightPanelTabs>

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,14 @@ describe("right panel surface actions", () => {
3131
preview: { available: true, onOpen: () => undefined },
3232
diff: { available: true, onOpen: () => undefined },
3333
terminal: { available: true, onOpen: () => undefined },
34+
device: { available: true, onOpen: () => undefined },
3435
},
3536
onAddFiles: () => undefined,
3637
onAddPullRequest: () => undefined,
3738
onAddPullRequests: () => undefined,
38-
onAddDevice: () => undefined,
3939
filesAvailable: true,
4040
pullRequestAvailable: true,
4141
pullRequestsAvailable: true,
42-
deviceAvailable: true,
4342
});
4443

4544
it("keeps launcher order, letters and copy for registered and local surfaces", () => {
@@ -169,16 +168,15 @@ function renderTabs(
169168
preview: { available: true, onOpen: () => undefined },
170169
diff: { available: false, onOpen: () => undefined },
171170
terminal: { available: false, onOpen: () => undefined },
171+
device: { available: false, onOpen: () => undefined },
172172
}}
173173
onAddBrowserInProfile={() => undefined}
174174
onAddPullRequest={() => undefined}
175175
onAddPullRequests={() => undefined}
176176
onAddFiles={() => undefined}
177-
onAddDevice={() => undefined}
178177
filesAvailable={false}
179178
pullRequestAvailable={false}
180179
pullRequestsAvailable={false}
181-
deviceAvailable={false}
182180
>
183181
<div>content</div>
184182
</RightPanelTabs>,

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

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import type {
1313
PullRequestState,
1414
} from "@t3tools/contracts";
1515
import { getTerminalLabel } from "@t3tools/shared/terminalLabels";
16-
import { Smartphone, ChevronDown, ChevronLeft, ChevronRight, Files, Plus } from "lucide-react";
16+
import { ChevronDown, ChevronLeft, ChevronRight, Files, Plus } from "lucide-react";
1717
import { Volume2, VolumeOff } from "lucide";
1818
import {
1919
type ComponentType,
@@ -108,11 +108,9 @@ interface RightPanelTabsProps {
108108
onAddFiles: () => void;
109109
onAddPullRequest: () => void;
110110
onAddPullRequests: () => void;
111-
onAddDevice: () => void;
112111
filesAvailable: boolean;
113112
pullRequestAvailable: boolean;
114113
pullRequestsAvailable: boolean;
115-
deviceAvailable: boolean;
116114
pullRequestStatusSeeds?: Readonly<Record<string, PullRequestTabStatusSeed>>;
117115
children: ReactNode;
118116
}
@@ -153,7 +151,6 @@ interface SidePanelLauncher {
153151
interface SurfaceAction {
154152
id: string;
155153
label: string;
156-
description?: string;
157154
icon: ComponentType<{ className?: string }>;
158155
shortcut: string;
159156
available: boolean;
@@ -170,11 +167,9 @@ type SurfaceActionInputs = Pick<
170167
| "onAddFiles"
171168
| "onAddPullRequest"
172169
| "onAddPullRequests"
173-
| "onAddDevice"
174170
| "filesAvailable"
175171
| "pullRequestAvailable"
176172
| "pullRequestsAvailable"
177-
| "deviceAvailable"
178173
>;
179174

180175
/**
@@ -232,17 +227,7 @@ export function rightPanelSurfaceActions(props: SurfaceActionInputs): SurfaceAct
232227
unavailableReason: "No linked pull requests are available for this thread.",
233228
onClick: props.onAddPullRequests,
234229
},
235-
{
236-
id: "device",
237-
label: "Device",
238-
description: "Watch an iOS Simulator or Android Emulator.",
239-
icon: Smartphone,
240-
shortcut: "M",
241-
available: props.deviceAvailable,
242-
unavailableHint: "Available from a thread.",
243-
unavailableReason: "Devices are only available from a thread.",
244-
onClick: props.onAddDevice,
245-
},
230+
registered("device"),
246231
];
247232
}
248233

@@ -586,7 +571,7 @@ function surfaceTitle(
586571
case "pull-requests":
587572
return "Pull requests";
588573
case "device":
589-
return surface.title ?? surface.target?.name ?? "Device";
574+
return surface.title ?? surface.target?.name ?? getSidePanelMetadata("device").title;
590575
case "preview": {
591576
const fallback = getSidePanelMetadata("preview").title;
592577
const snapshot = surface.resourceId ? sessions[surface.resourceId] : null;
@@ -674,14 +659,16 @@ function SurfaceIcon({
674659
);
675660
case "pull-requests":
676661
return <PullRequestGlyph.link className="size-3 shrink-0" />;
677-
case "device":
662+
case "device": {
663+
const DeviceIcon = getSidePanelMetadata("device").icon;
678664
return surface.target?.platform === "ios" ? (
679665
<AppleIcon className="size-3 shrink-0" />
680666
) : surface.target?.platform === "android" ? (
681667
<AndroidIcon className="size-3 shrink-0" />
682668
) : (
683-
<Smartphone className="size-3 shrink-0" />
669+
<DeviceIcon className="size-3 shrink-0" />
684670
);
671+
}
685672
}
686673
}
687674

‎apps/web/src/panels/bundledPanels.test.tsx‎

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const loaded = vi.hoisted(() => ({
77
diff: 0,
88
preview: 0,
99
terminal: 0,
10+
device: 0,
1011
previewRenders: [] as unknown[],
1112
}));
1213
vi.mock("./diff/DiffSidePanel", () => {
@@ -17,6 +18,10 @@ vi.mock("./terminal/TerminalSidePanel", () => {
1718
loaded.terminal += 1;
1819
return { default: () => null };
1920
});
21+
vi.mock("./device/DeviceSidePanel", () => {
22+
loaded.device += 1;
23+
return { default: () => null };
24+
});
2025
vi.mock("./preview/PreviewSidePanel", () => {
2126
loaded.preview += 1;
2227
return {
@@ -46,7 +51,7 @@ const host: PanelHost = {
4651

4752
describe("bundled side panels", () => {
4853
it("loads only the selected panel body and lends it the host", async () => {
49-
expect(loaded).toMatchObject({ diff: 0, preview: 0, terminal: 0 });
54+
expect(loaded).toMatchObject({ diff: 0, preview: 0, terminal: 0, device: 0 });
5055
await act(async () => {
5156
create(
5257
<PanelHostContext value={host}>
@@ -56,7 +61,7 @@ describe("bundled side panels", () => {
5661
</PanelHostContext>,
5762
);
5863
});
59-
expect(loaded).toMatchObject({ diff: 0, preview: 1, terminal: 0 });
64+
expect(loaded).toMatchObject({ diff: 0, preview: 1, terminal: 0, device: 0 });
6065
expect(loaded.previewRenders).toEqual([{ props: { tabId: "tab-1" }, host }]);
6166
});
6267

@@ -97,6 +102,8 @@ describe("bundled side panels", () => {
97102
export function typeFixtures(
98103
widenedId: "diff" | "preview",
99104
terminalSurface: Extract<RightPanelSurface, { kind: "terminal" }>,
105+
deviceSurface: Extract<RightPanelSurface, { kind: "device" }>,
106+
dismiss: () => void,
100107
) {
101108
const terminalProps = {
102109
surface: terminalSurface,
@@ -120,8 +127,17 @@ export function typeFixtures(
120127
<RegisteredSidePanel id="terminal" {...terminalProps} visible />
121128
{/* @ts-expect-error Terminal props on Preview. */}
122129
<RegisteredSidePanel id="preview" surface={terminalSurface} />
130+
<RegisteredSidePanel id="device" surface={deviceSurface} onDismissSetup={dismiss} />
123131
{/* @ts-expect-error Preview props on Diff. */}
124132
<RegisteredSidePanel id="diff" tabId="tab-1" />
133+
{/* @ts-expect-error Device props on Preview. */}
134+
<RegisteredSidePanel id="preview" surface={deviceSurface} />
135+
{/* @ts-expect-error Preview props on Device. */}
136+
<RegisteredSidePanel id="device" surface={deviceSurface} onDismissSetup={dismiss} tabId="1" />
137+
{/* @ts-expect-error Device needs its surface and setup dismissal. */}
138+
<RegisteredSidePanel id="device" />
139+
{/* @ts-expect-error The host owns visibility; panels do not take it as a prop. */}
140+
<RegisteredSidePanel id="device" surface={deviceSurface} onDismissSetup={dismiss} visible />
125141
{/* @ts-expect-error The host owns the thread; panels do not take it as a prop. */}
126142
<RegisteredSidePanel id="preview" threadRef={threadRef} />
127143
{/* @ts-expect-error Wrong input shape. */}

‎apps/web/src/panels/bundledPanels.tsx‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { FileDiff, Globe2, TerminalSquare } from "lucide-react";
1+
import { FileDiff, Globe2, Smartphone, TerminalSquare } from "lucide-react";
22
import { Suspense, type ComponentType } from "react";
33

44
import { isPreviewSupportedInRuntime } from "~/previewStateStore";
@@ -34,6 +34,15 @@ const bundledPanels = createPanelRegistry([
3434
unavailableReason: "Terminal surfaces are only available from a project thread.",
3535
load: () => import("./terminal/TerminalSidePanel"),
3636
},
37+
{
38+
id: "device",
39+
title: "Device",
40+
icon: Smartphone,
41+
launcherKey: "M",
42+
unavailableHint: "Available from a thread.",
43+
unavailableReason: "Devices are only available from a thread.",
44+
load: () => import("./device/DeviceSidePanel"),
45+
},
3746
]);
3847

3948
export type SidePanelId = (typeof bundledPanels.definitions)[number]["id"];

0 commit comments

Comments
 (0)