Skip to content

Commit ebb72ea

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 1ee9e51 commit ebb72ea

10 files changed

Lines changed: 352 additions & 117 deletions

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

Lines changed: 31 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,7 @@ import { useAtomValue } from "@effect/atom-react";
141141
import { Atom } from "effect/unstable/reactivity";
142142
import {
143143
Fragment,
144-
lazy,
145144
type SetStateAction,
146-
Suspense,
147145
useCallback,
148146
useEffect,
149147
useEffectEvent,
@@ -676,7 +674,6 @@ function useDraftHeroLayoutTransition(
676674

677675
const selectAutoShowFloatingPreview = (settings: { browserAutoShowFloatingPreview: boolean }) =>
678676
settings.browserAutoShowFloatingPreview;
679-
const FilePreviewPanel = lazy(() => import("./files/FilePreviewPanel"));
680677
const EMPTY_PENDING_FILE_SURFACE_IDS: ReadonlySet<string> = new Set();
681678
const TYPE_TO_FOCUS_EDITABLE_SELECTOR = [
682679
"input",
@@ -4751,13 +4748,6 @@ export default function ChatView(props: ChatViewProps) {
47514748
);
47524749
if (!sessionStillExists) usePreviewMiniPlayerStore.getState().close(activeThreadRef);
47534750
}, [activePreviewMiniPlayer, activeThreadRef, deviceState.sessions, deviceStateLoaded]);
4754-
const openFileSurface = useCallback(
4755-
(relativePath: string) => {
4756-
if (!activeThreadRef || !activeProject) return;
4757-
useRightPanelStore.getState().openFile(activeThreadRef, relativePath);
4758-
},
4759-
[activeProject, activeThreadRef],
4760-
);
47614751
// The thread's own change request, placed against the project it belongs to. Without a
47624752
// project there is nothing to resolve it against, so the caller falls back to the browser.
47634753
const persistedLinkedThreadPullRequest = isServerThread
@@ -9987,47 +9977,36 @@ export default function ChatView(props: ChatViewProps) {
99879977
renderedRightPanelSurface?.kind === "file") &&
99889978
((activeProject && activeWorkspaceRoot) ||
99899979
(renderedRightPanelSurface.kind === "file" && renderedRightPanelSurface.attachment)) ? (
9990-
<Suspense fallback={null}>
9991-
<FilePreviewPanel
9992-
key={`${activeThread.environmentId}:${
9993-
renderedRightPanelSurface.kind === "file" && renderedRightPanelSurface.attachment
9994-
? `attachment:${renderedRightPanelSurface.attachment.id}`
9995-
: activeWorkspaceRoot
9996-
}`}
9997-
environmentId={activeThread.environmentId}
9998-
cwd={activeWorkspaceRoot ?? ""}
9999-
projectName={activeProject?.title ?? ""}
10000-
threadRef={activeThreadRef}
10001-
composerDraftTarget={composerDraftTarget}
10002-
keybindings={keybindings}
10003-
availableEditors={availableEditors}
10004-
relativePath={
10005-
renderedRightPanelSurface.kind === "file"
10006-
? renderedRightPanelSurface.relativePath
10007-
: null
10008-
}
10009-
{...(renderedRightPanelSurface.kind === "file" && renderedRightPanelSurface.attachment
10010-
? { attachment: renderedRightPanelSurface.attachment }
10011-
: {})}
10012-
revealLine={
10013-
renderedRightPanelSurface.kind === "file"
10014-
? (renderedRightPanelSurface.revealLine ?? null)
10015-
: null
10016-
}
10017-
revealRequestId={
10018-
renderedRightPanelSurface.kind === "file"
10019-
? renderedRightPanelSurface.revealRequestId
10020-
: 0
10021-
}
10022-
onOpenFile={openFileSurface}
10023-
onPendingChange={handleFilePendingChange}
10024-
selectedFilePending={
10025-
renderedRightPanelSurface.kind === "file" &&
10026-
pendingFileSurfaceIds.has(renderedRightPanelSurface.id)
10027-
}
10028-
workspaceMutationId={workspaceMutationId}
10029-
/>
10030-
</Suspense>
9980+
<RegisteredSidePanel
9981+
key={`${activeThread.environmentId}:${
9982+
renderedRightPanelSurface.kind === "file" && renderedRightPanelSurface.attachment
9983+
? `attachment:${renderedRightPanelSurface.attachment.id}`
9984+
: activeWorkspaceRoot
9985+
}`}
9986+
id="files"
9987+
cwd={activeWorkspaceRoot ?? ""}
9988+
projectName={activeProject?.title ?? ""}
9989+
availableEditors={availableEditors}
9990+
relativePath={
9991+
renderedRightPanelSurface.kind === "file" ? renderedRightPanelSurface.relativePath : null
9992+
}
9993+
{...(renderedRightPanelSurface.kind === "file" && renderedRightPanelSurface.attachment
9994+
? { attachment: renderedRightPanelSurface.attachment }
9995+
: {})}
9996+
revealLine={
9997+
renderedRightPanelSurface.kind === "file"
9998+
? (renderedRightPanelSurface.revealLine ?? null)
9999+
: null
10000+
}
10001+
revealRequestId={
10002+
renderedRightPanelSurface.kind === "file" ? renderedRightPanelSurface.revealRequestId : 0
10003+
}
10004+
onPendingChange={handleFilePendingChange}
10005+
selectedFilePending={
10006+
renderedRightPanelSurface.kind === "file" &&
10007+
pendingFileSurfaceIds.has(renderedRightPanelSurface.id)
10008+
}
10009+
/>
1003110010
) : null
1003210011
) : null;
1003310012
const panelHost: PanelHost | null = activeThreadRef
@@ -10049,6 +10028,7 @@ export default function ChatView(props: ChatViewProps) {
1004910028
preview: { available: true, onOpen: createBrowserSurface },
1005010029
diff: { available: isServerThread && isGitRepo, onOpen: addDiffSurface },
1005110030
terminal: { available: activeProject !== null, onOpen: addTerminalSurface },
10031+
files: { available: activeProject !== null, onOpen: addFilesSurface },
1005210032
device: { available: activeThreadRef !== null, onOpen: addDeviceSurface },
1005310033
"pull-request": { available: pullRequestSurfaceAvailable, onOpen: addPullRequestSurface },
1005410034
"pull-requests": { available: pullRequestsSurfaceAvailable, onOpen: addPullRequestsSurface },
@@ -10866,8 +10846,6 @@ export default function ChatView(props: ChatViewProps) {
1086610846
onCopyFilePath={copyRightPanelFilePath}
1086710847
panels={sidePanelLaunchers}
1086810848
onAddBrowserInProfile={createBrowserSurface}
10869-
onAddFiles={addFilesSurface}
10870-
filesAvailable={activeProject !== null}
1087110849
>
1087210850
{rightPanelContent}
1087310851
</RightPanelTabs>
@@ -10910,8 +10888,6 @@ export default function ChatView(props: ChatViewProps) {
1091010888
onCopyFilePath={copyRightPanelFilePath}
1091110889
panels={sidePanelLaunchers}
1091210890
onAddBrowserInProfile={createBrowserSurface}
10913-
onAddFiles={addFilesSurface}
10914-
filesAvailable={activeProject !== null}
1091510891
>
1091610892
{rightPanelContent}
1091710893
</RightPanelTabs>

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,9 @@ function Harness() {
7676
device: { available: false, onOpen: () => undefined },
7777
"pull-request": { available: false, onOpen: () => undefined },
7878
"pull-requests": { available: false, onOpen: () => undefined },
79+
files: { available: false, onOpen: () => undefined },
7980
}}
8081
onAddBrowserInProfile={openBrowser}
81-
onAddFiles={() => undefined}
82-
filesAvailable={false}
8382
>
8483
{null}
8584
</RightPanelTabs>

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,9 @@ function Harness({ terminalAvailable }: { terminalAvailable: boolean }) {
7272
device: { available: false, onOpen: () => undefined },
7373
"pull-request": { available: false, onOpen: () => undefined },
7474
"pull-requests": { available: false, onOpen: () => undefined },
75+
files: { available: false, onOpen: () => undefined },
7576
}}
7677
onAddBrowserInProfile={() => undefined}
77-
onAddFiles={() => undefined}
78-
filesAvailable={false}
7978
>
8079
{null}
8180
</RightPanelTabs>

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

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

4241
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
@@ -13,7 +13,7 @@ import type {
1313
PullRequestState,
1414
} from "@t3tools/contracts";
1515
import { getTerminalLabel } from "@t3tools/shared/terminalLabels";
16-
import { ChevronDown, ChevronLeft, ChevronRight, Files, Plus } from "lucide-react";
16+
import { ChevronDown, ChevronLeft, ChevronRight, Plus } from "lucide-react";
1717
import { Volume2, VolumeOff } from "lucide";
1818
import {
1919
type ComponentType,
@@ -105,8 +105,6 @@ interface RightPanelTabsProps {
105105
/** Whether each registered panel can open here, and how; titles and icons come from its definition. */
106106
panels: Readonly<Record<SidePanelId, SidePanelLauncher>>;
107107
onAddBrowserInProfile: (profileId: string) => void;
108-
onAddFiles: () => void;
109-
filesAvailable: boolean;
110108
pullRequestStatusSeeds?: Readonly<Record<string, PullRequestTabStatusSeed>>;
111109
children: ReactNode;
112110
}
@@ -157,7 +155,7 @@ interface SurfaceAction {
157155
onClick: () => void;
158156
}
159157

160-
type SurfaceActionInputs = Pick<RightPanelTabsProps, "panels" | "onAddFiles" | "filesAvailable">;
158+
type SurfaceActionInputs = Pick<RightPanelTabsProps, "panels">;
161159

162160
/**
163161
* The surfaces the empty launcher and the add menu offer, in launcher order.
@@ -183,16 +181,7 @@ export function rightPanelSurfaceActions(props: SurfaceActionInputs): SurfaceAct
183181
return [
184182
registered("preview"),
185183
registered("terminal"),
186-
{
187-
id: "files",
188-
label: "Files",
189-
icon: Files,
190-
shortcut: "F",
191-
available: props.filesAvailable,
192-
unavailableHint: "Available when a project is open.",
193-
unavailableReason: "Files are only available when a project is open.",
194-
onClick: props.onAddFiles,
195-
},
184+
registered("files"),
196185
registered("diff"),
197186
registered("pull-request"),
198187
registered("pull-requests"),
@@ -525,7 +514,7 @@ function surfaceTitle(
525514
case "diff":
526515
return getSidePanelMetadata("diff").title;
527516
case "files":
528-
return "Files";
517+
return getSidePanelMetadata("files").title;
529518
case "file":
530519
return surface.relativePath.slice(
531520
Math.max(surface.relativePath.lastIndexOf("/"), surface.relativePath.lastIndexOf("\\")) + 1,
@@ -603,8 +592,10 @@ function SurfaceIcon({
603592
const Icon = getSidePanelMetadata("diff").icon;
604593
return <Icon className="size-3 shrink-0" />;
605594
}
606-
case "files":
607-
return <Files className="size-3 shrink-0" />;
595+
case "files": {
596+
const Icon = getSidePanelMetadata("files").icon;
597+
return <Icon className="size-3 shrink-0" />;
598+
}
608599
case "file":
609600
return (
610601
<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";
@@ -66,6 +66,15 @@ const bundledPanels = createPanelRegistry([
6666
fallback: <PullRequestPanelPending label="Loading pull requests" />,
6767
load: () => import("./pullRequest/PullRequestsSidePanel"),
6868
},
69+
{
70+
id: "files",
71+
title: "Files",
72+
icon: Files,
73+
launcherKey: "F",
74+
unavailableHint: "Available when a project is open.",
75+
unavailableReason: "Files are only available when a project is open.",
76+
load: () => import("./files/FilesSidePanel"),
77+
},
6978
]);
7079

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

0 commit comments

Comments
 (0)