Skip to content

Commit d1554f5

Browse files
refactor(web): open the Files side panel through the panel host
The Files explorer and single-file surfaces now render through the panel registry, like Diff, Preview, Terminal, Device and the pull request panels. The body moves to panels/files/FilesSidePanel and reads the thread, composer draft target and workspace mutation id from the panel host, keybindings from the server atom, and opens files through the right panel store for the host's thread. The launcher entry, tab title and tab icon read the one definition; ChatView keeps the surface inputs, editors and the pending-file pair as props. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
1 parent df78494 commit d1554f5

11 files changed

Lines changed: 366 additions & 119 deletions

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

Lines changed: 31 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,7 @@ import { useAtomValue } from "@effect/atom-react";
149149
import { Atom } from "effect/reactivity";
150150
import {
151151
Fragment,
152-
lazy,
153152
type SetStateAction,
154-
Suspense,
155153
useCallback,
156154
useEffect,
157155
useEffectEvent,
@@ -702,7 +700,6 @@ function useDraftHeroLayoutTransition(
702700

703701
const selectAutoShowFloatingPreview = (settings: { browserAutoShowFloatingPreview: boolean }) =>
704702
settings.browserAutoShowFloatingPreview;
705-
const FilePreviewPanel = lazy(() => import("./files/FilePreviewPanel"));
706703
const EMPTY_PENDING_FILE_SURFACE_IDS: ReadonlySet<string> = new Set();
707704
const TYPE_TO_FOCUS_EDITABLE_SELECTOR = [
708705
"input",
@@ -4955,13 +4952,6 @@ export default function ChatView(props: ChatViewProps) {
49554952
);
49564953
if (!sessionStillExists) usePreviewMiniPlayerStore.getState().close(activeThreadRef);
49574954
}, [activePreviewMiniPlayer, activeThreadRef, deviceState.sessions, deviceStateLoaded]);
4958-
const openFileSurface = useCallback(
4959-
(relativePath: string) => {
4960-
if (!activeThreadRef || !activeProject) return;
4961-
useRightPanelStore.getState().openFile(activeThreadRef, relativePath);
4962-
},
4963-
[activeProject, activeThreadRef],
4964-
);
49654955
// The thread's own change request, placed against the project it belongs to. Without a
49664956
// project there is nothing to resolve it against, so the caller falls back to the browser.
49674957
const persistedLinkedThreadPullRequest = isServerThread
@@ -10495,47 +10485,36 @@ export default function ChatView(props: ChatViewProps) {
1049510485
renderedRightPanelSurface?.kind === "file") &&
1049610486
((activeProject && activeWorkspaceRoot) ||
1049710487
(renderedRightPanelSurface.kind === "file" && renderedRightPanelSurface.attachment)) ? (
10498-
<Suspense fallback={null}>
10499-
<FilePreviewPanel
10500-
key={`${activeThread.environmentId}:${
10501-
renderedRightPanelSurface.kind === "file" && renderedRightPanelSurface.attachment
10502-
? `attachment:${renderedRightPanelSurface.attachment.id}`
10503-
: activeWorkspaceRoot
10504-
}`}
10505-
environmentId={activeThread.environmentId}
10506-
cwd={activeWorkspaceRoot ?? ""}
10507-
projectName={activeProject?.title ?? ""}
10508-
threadRef={activeThreadRef}
10509-
composerDraftTarget={composerDraftTarget}
10510-
keybindings={keybindings}
10511-
availableEditors={availableEditors}
10512-
relativePath={
10513-
renderedRightPanelSurface.kind === "file"
10514-
? renderedRightPanelSurface.relativePath
10515-
: null
10516-
}
10517-
{...(renderedRightPanelSurface.kind === "file" && renderedRightPanelSurface.attachment
10518-
? { attachment: renderedRightPanelSurface.attachment }
10519-
: {})}
10520-
revealLine={
10521-
renderedRightPanelSurface.kind === "file"
10522-
? (renderedRightPanelSurface.revealLine ?? null)
10523-
: null
10524-
}
10525-
revealRequestId={
10526-
renderedRightPanelSurface.kind === "file"
10527-
? renderedRightPanelSurface.revealRequestId
10528-
: 0
10529-
}
10530-
onOpenFile={openFileSurface}
10531-
onPendingChange={handleFilePendingChange}
10532-
selectedFilePending={
10533-
renderedRightPanelSurface.kind === "file" &&
10534-
pendingFileSurfaceIds.has(renderedRightPanelSurface.id)
10535-
}
10536-
workspaceMutationId={workspaceMutationId}
10537-
/>
10538-
</Suspense>
10488+
<RegisteredSidePanel
10489+
key={`${activeThread.environmentId}:${
10490+
renderedRightPanelSurface.kind === "file" && renderedRightPanelSurface.attachment
10491+
? `attachment:${renderedRightPanelSurface.attachment.id}`
10492+
: activeWorkspaceRoot
10493+
}`}
10494+
id="files"
10495+
cwd={activeWorkspaceRoot ?? ""}
10496+
projectName={activeProject?.title ?? ""}
10497+
availableEditors={availableEditors}
10498+
relativePath={
10499+
renderedRightPanelSurface.kind === "file" ? renderedRightPanelSurface.relativePath : null
10500+
}
10501+
{...(renderedRightPanelSurface.kind === "file" && renderedRightPanelSurface.attachment
10502+
? { attachment: renderedRightPanelSurface.attachment }
10503+
: {})}
10504+
revealLine={
10505+
renderedRightPanelSurface.kind === "file"
10506+
? (renderedRightPanelSurface.revealLine ?? null)
10507+
: null
10508+
}
10509+
revealRequestId={
10510+
renderedRightPanelSurface.kind === "file" ? renderedRightPanelSurface.revealRequestId : 0
10511+
}
10512+
onPendingChange={handleFilePendingChange}
10513+
selectedFilePending={
10514+
renderedRightPanelSurface.kind === "file" &&
10515+
pendingFileSurfaceIds.has(renderedRightPanelSurface.id)
10516+
}
10517+
/>
1053910518
) : null
1054010519
) : null;
1054110520
const rightPanelContent = (
@@ -10548,6 +10527,7 @@ export default function ChatView(props: ChatViewProps) {
1054810527
available: activeProject !== null && canOperateTerminal,
1054910528
onOpen: addTerminalSurface,
1055010529
},
10530+
files: { available: activeProject !== null, onOpen: addFilesSurface },
1055110531
device: { available: activeThreadRef !== null, onOpen: addDeviceSurface },
1055210532
"pull-request": { available: pullRequestSurfaceAvailable, onOpen: addPullRequestSurface },
1055310533
"pull-requests": { available: pullRequestsSurfaceAvailable, onOpen: addPullRequestsSurface },
@@ -11388,8 +11368,6 @@ export default function ChatView(props: ChatViewProps) {
1138811368
onCopyFilePath={copyRightPanelFilePath}
1138911369
panels={sidePanelLaunchers}
1139011370
onAddBrowserInProfile={createBrowserSurface}
11391-
onAddFiles={addFilesSurface}
11392-
filesAvailable={activeProject !== null}
1139311371
>
1139411372
{rightPanelContent}
1139511373
</RightPanelTabs>
@@ -11436,8 +11414,6 @@ export default function ChatView(props: ChatViewProps) {
1143611414
onCopyFilePath={copyRightPanelFilePath}
1143711415
panels={sidePanelLaunchers}
1143811416
onAddBrowserInProfile={createBrowserSurface}
11439-
onAddFiles={addFilesSurface}
11440-
filesAvailable={activeProject !== null}
1144111417
>
1144211418
{rightPanelContent}
1144311419
</RightPanelTabs>

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,9 @@ function Harness() {
8787
device: { available: false, onOpen: () => undefined },
8888
"pull-request": { available: false, onOpen: () => undefined },
8989
"pull-requests": { available: false, onOpen: () => undefined },
90+
files: { available: false, onOpen: () => undefined },
9091
}}
9192
onAddBrowserInProfile={openBrowser}
92-
onAddFiles={() => undefined}
93-
filesAvailable={false}
9493
>
9594
{null}
9695
</RightPanelTabs>

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,9 @@ async function renderPanel(overrides: Partial<ComponentProps<typeof RightPanelTa
8383
device: { available: false, onOpen: noop },
8484
"pull-request": { available: false, onOpen: noop },
8585
"pull-requests": { available: false, onOpen: noop },
86+
files: { available: true, onOpen: addFiles },
8687
}}
8788
onAddBrowserInProfile={noop}
88-
onAddFiles={addFiles}
89-
filesAvailable
9089
{...overrides}
9190
>
9291
content

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,9 @@ function Harness({ terminalAvailable }: { terminalAvailable: boolean }) {
8383
device: { available: false, onOpen: () => undefined },
8484
"pull-request": { available: false, onOpen: () => undefined },
8585
"pull-requests": { available: false, onOpen: () => undefined },
86+
files: { available: false, onOpen: () => undefined },
8687
}}
8788
onAddBrowserInProfile={() => undefined}
88-
onAddFiles={() => undefined}
89-
filesAvailable={false}
9089
>
9190
{null}
9291
</RightPanelTabs>

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,8 @@ describe("right panel surface actions", () => {
3535
device: { available: true, onOpen: () => undefined },
3636
"pull-request": { available: true, onOpen: () => undefined },
3737
"pull-requests": { available: true, onOpen: () => undefined },
38+
files: { available: true, onOpen: () => undefined },
3839
},
39-
onAddFiles: () => undefined,
40-
filesAvailable: true,
4140
});
4241

4342
it("keeps launcher order, letters and copy for registered and local surfaces", () => {
@@ -169,10 +168,9 @@ function renderTabs(
169168
device: { available: false, onOpen: () => undefined },
170169
"pull-request": { available: false, onOpen: () => undefined },
171170
"pull-requests": { available: false, onOpen: () => undefined },
171+
files: { available: false, onOpen: () => undefined },
172172
}}
173173
onAddBrowserInProfile={() => undefined}
174-
onAddFiles={() => undefined}
175-
filesAvailable={false}
176174
>
177175
<div>content</div>
178176
</RightPanelTabs>,

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

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import {
2525
import { restrictToFirstScrollableAncestor, restrictToHorizontalAxis } from "@dnd-kit/modifiers";
2626
import { horizontalListSortingStrategy, SortableContext, useSortable } from "@dnd-kit/sortable";
2727
import { CSS } from "@dnd-kit/utilities";
28-
import { ChevronDown, ChevronLeft, ChevronRight, Files, Plus } from "lucide-react";
28+
import { ChevronDown, ChevronLeft, ChevronRight, Plus } from "lucide-react";
2929
import { Volume2, VolumeOff } from "lucide";
3030
import {
3131
type ComponentProps,
@@ -125,8 +125,6 @@ interface RightPanelTabsProps {
125125
/** Whether each registered panel can open here, and how; titles and icons come from its definition. */
126126
panels: Readonly<Record<SidePanelId, SidePanelLauncher>>;
127127
onAddBrowserInProfile: (profileId: string) => void;
128-
onAddFiles: () => void;
129-
filesAvailable: boolean;
130128
pullRequestStatusSeeds?: Readonly<Record<string, PullRequestTabStatusSeed>>;
131129
children: ReactNode;
132130
}
@@ -177,7 +175,7 @@ interface SurfaceAction {
177175
onClick: () => void;
178176
}
179177

180-
type SurfaceActionInputs = Pick<RightPanelTabsProps, "panels" | "onAddFiles" | "filesAvailable">;
178+
type SurfaceActionInputs = Pick<RightPanelTabsProps, "panels">;
181179

182180
/**
183181
* The surfaces the empty launcher and the add menu offer, in launcher order.
@@ -203,16 +201,7 @@ export function rightPanelSurfaceActions(props: SurfaceActionInputs): SurfaceAct
203201
return [
204202
registered("preview"),
205203
registered("terminal"),
206-
{
207-
id: "files",
208-
label: "Files",
209-
icon: Files,
210-
shortcut: "F",
211-
available: props.filesAvailable,
212-
unavailableHint: "Available when a project is open.",
213-
unavailableReason: "Files are only available when a project is open.",
214-
onClick: props.onAddFiles,
215-
},
204+
registered("files"),
216205
registered("diff"),
217206
registered("pull-request"),
218207
registered("pull-requests"),
@@ -547,7 +536,7 @@ function surfaceTitle(
547536
case "diff":
548537
return getSidePanelMetadata("diff").title;
549538
case "files":
550-
return "Files";
539+
return getSidePanelMetadata("files").title;
551540
case "file":
552541
return surface.relativePath.slice(
553542
Math.max(surface.relativePath.lastIndexOf("/"), surface.relativePath.lastIndexOf("\\")) + 1,
@@ -625,8 +614,10 @@ function SurfaceIcon({
625614
const Icon = getSidePanelMetadata("diff").icon;
626615
return <Icon className="size-3 shrink-0" />;
627616
}
628-
case "files":
629-
return <Files className="size-3 shrink-0" />;
617+
case "files": {
618+
const Icon = getSidePanelMetadata("files").icon;
619+
return <Icon className="size-3 shrink-0" />;
620+
}
630621
case "file":
631622
return (
632623
<PierreEntryIcon

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const loaded = vi.hoisted(() => ({
1010
device: 0,
1111
pullRequest: 0,
1212
pullRequests: 0,
13+
files: 0,
1314
previewRenders: [] as unknown[],
1415
}));
1516
vi.mock("./diff/DiffSidePanel", () => {
@@ -24,6 +25,10 @@ vi.mock("./device/DeviceSidePanel", () => {
2425
loaded.device += 1;
2526
return { default: () => null };
2627
});
28+
vi.mock("./files/FilesSidePanel", () => {
29+
loaded.files += 1;
30+
return { default: () => null };
31+
});
2732
vi.mock("./preview/PreviewSidePanel", () => {
2833
loaded.preview += 1;
2934
return {
@@ -69,6 +74,7 @@ describe("bundled side panels", () => {
6974
device: 0,
7075
pullRequest: 0,
7176
pullRequests: 0,
77+
files: 0,
7278
});
7379
await act(async () => {
7480
create(
@@ -86,6 +92,7 @@ describe("bundled side panels", () => {
8692
device: 0,
8793
pullRequest: 0,
8894
pullRequests: 0,
95+
files: 0,
8996
});
9097
expect(loaded.previewRenders).toEqual([{ props: { tabId: "tab-1" }, host }]);
9198
});
@@ -122,6 +129,17 @@ describe("bundled side panels", () => {
122129
});
123130
});
124131

132+
const filesProps = {
133+
cwd: "/repo",
134+
projectName: "repo",
135+
relativePath: null,
136+
availableEditors: [],
137+
revealLine: null,
138+
revealRequestId: 0,
139+
onPendingChange: () => undefined,
140+
selectedFilePending: false,
141+
};
142+
125143
// Never called. The project typecheck compiles these pairings, and each
126144
// expect-error directive fails it if a wrong pairing starts to compile.
127145
export function typeFixtures(
@@ -177,6 +195,13 @@ export function typeFixtures(
177195
<RegisteredSidePanel id="preview" shortcutsEnabled />
178196
{/* @ts-expect-error The host owns the composer draft target. */}
179197
<RegisteredSidePanel id="pull-request" {...pullRequest} composerDraftTarget={threadRef} />
198+
<RegisteredSidePanel id="files" {...filesProps} />
199+
{/* @ts-expect-error Files props on Preview. */}
200+
<RegisteredSidePanel id="preview" cwd="/repo" />
201+
{/* @ts-expect-error Files needs its surface inputs. */}
202+
<RegisteredSidePanel id="files" cwd="/repo" />
203+
{/* @ts-expect-error The host owns the composer draft target. */}
204+
<RegisteredSidePanel id="files" {...filesProps} composerDraftTarget={threadRef} />
180205
{/* @ts-expect-error Preview props on Diff. */}
181206
<RegisteredSidePanel id="diff" tabId="tab-1" />
182207
{/* @ts-expect-error Device props on Preview. */}

‎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, Smartphone, TerminalSquare } from "lucide-react";
1+
import { FileDiff, Files, Globe2, Smartphone, TerminalSquare } from "lucide-react";
22
import { Suspense, type ComponentType } from "react";
33

44
import { PullRequestGlyph } from "~/components/pullRequest/pullRequestIcons";
@@ -64,6 +64,15 @@ const bundledPanels = createPanelRegistry([
6464
fallback: <PullRequestPanelPending label="Loading pull requests" />,
6565
load: () => import("./pullRequest/PullRequestsSidePanel"),
6666
},
67+
{
68+
id: "files",
69+
title: "Files",
70+
icon: Files,
71+
launcherKey: "F",
72+
unavailableHint: "Available when a project is open.",
73+
unavailableReason: "Files are only available when a project is open.",
74+
load: () => import("./files/FilesSidePanel"),
75+
},
6776
]);
6877

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

0 commit comments

Comments
 (0)