Skip to content

Commit e18fb8f

Browse files
author
JD
committed
fix(web): keep service editor actions in file previews
Use one environment visibility rule for chat and file previews so a same-home service retains its editor action without a desktop primary. Add a browser regression for opening the selected preview file. Verification: check:changed HEAD passed, including the browser regression and React Compiler checks.
1 parent e100c94 commit e18fb8f

5 files changed

Lines changed: 40 additions & 16 deletions

File tree

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1647,12 +1647,13 @@ export default function ChatView(props: ChatViewProps) {
16471647
serverAvailableEditorsAtom(activeThread?.environmentId ?? environmentId),
16481648
);
16491649
const remoteOpenState = useRemoteOpenState(activeThread?.environmentId ?? environmentId);
1650-
const showOpenInPicker = shouldShowOpenInPicker({
1651-
activeProjectName: activeProject?.title,
1652-
activeThreadEnvironmentId: activeThread?.environmentId ?? environmentId,
1653-
primaryEnvironmentId,
1654-
remoteOpenMode: remoteOpenState.mode,
1655-
});
1650+
const showOpenInPicker =
1651+
Boolean(activeProject?.title) &&
1652+
shouldShowOpenInPicker({
1653+
environmentId: activeThread?.environmentId ?? environmentId,
1654+
primaryEnvironmentId,
1655+
remoteOpenMode: remoteOpenState.mode,
1656+
});
16561657
useOpenFavoriteEditorShortcut({
16571658
enabled: showOpenInPicker && !backgroundThread,
16581659
environmentId: activeThread?.environmentId ?? environmentId,

‎apps/web/src/components/chat/OpenInPicker.logic.test.ts‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ it.each([
1717
expect(
1818
shouldShowOpenInPicker({
1919
...input,
20-
activeProjectName: "Project",
21-
activeThreadEnvironmentId: environmentId,
20+
environmentId,
2221
}),
2322
).toBe(input.expected);
2423
},

‎apps/web/src/components/chat/OpenInPicker.logic.ts‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,12 @@ import type { EnvironmentId } from "@t3tools/contracts";
33
import type { RemoteOpenMode } from "../../remoteOpen";
44

55
export function shouldShowOpenInPicker(input: {
6-
readonly activeProjectName: string | undefined;
7-
readonly activeThreadEnvironmentId: EnvironmentId;
6+
readonly environmentId: EnvironmentId;
87
readonly primaryEnvironmentId: EnvironmentId | null;
98
readonly remoteOpenMode: RemoteOpenMode;
109
}): boolean {
11-
if (!input.activeProjectName) return false;
1210
if (input.primaryEnvironmentId === null) return true;
13-
if (input.activeThreadEnvironmentId === input.primaryEnvironmentId) {
11+
if (input.environmentId === input.primaryEnvironmentId) {
1412
return true;
1513
}
1614
return input.remoteOpenMode !== "local-exec";

‎apps/web/src/components/files/FilePreviewPanel.browser.test.tsx‎

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
import { EnvironmentId, ThreadId, type ProjectReadFileResult } from "@t3tools/contracts";
1+
import {
2+
EnvironmentId,
3+
ThreadId,
4+
type EditorId,
5+
type ProjectReadFileResult,
6+
} from "@t3tools/contracts";
27
import { AsyncResult } from "effect/reactivity";
38
import { describe, expect, it, vi } from "vite-plus/test";
49
import { act, fakeTimers, render } from "../../../test/render";
@@ -19,6 +24,10 @@ vi.mock(import("~/state/session"), async (original) => ({
1924
readEnvironmentScope: () => true,
2025
useEnvironmentScope: () => true,
2126
}));
27+
vi.mock(import("~/state/environments"), async (original) => ({
28+
...(await original()),
29+
usePrimaryEnvironmentId: () => null,
30+
}));
2231
vi.mock(import("~/state/filesystem"), async (original) => ({
2332
...(await original()),
2433
useFilesystemReadAccess: () => ({ canReadFiles: true, isPending: false, error: null }),
@@ -95,7 +104,7 @@ function setup() {
95104
};
96105
}
97106

98-
function markdownPreview(truncated: boolean) {
107+
function markdownPreview(truncated: boolean, availableEditors: ReadonlyArray<EditorId> = []) {
99108
state.file = {
100109
relativePath: "tasks.md",
101110
contents: "- [ ] Keep the rest of this file\n",
@@ -111,7 +120,7 @@ function markdownPreview(truncated: boolean) {
111120
threadRef={threadRef}
112121
composerDraftTarget={threadRef}
113122
keybindings={[]}
114-
availableEditors={[]}
123+
availableEditors={availableEditors}
115124
openInShortcutEnabled={false}
116125
revealLine={null}
117126
revealRequestId={0}
@@ -125,6 +134,18 @@ function markdownPreview(truncated: boolean) {
125134
);
126135
}
127136

137+
it("opens a local service file in the editor without a desktop primary", async () => {
138+
using _settings = setup();
139+
await using screen = await render(markdownPreview(false, ["vscode"]));
140+
const open = screen.getByRole("button", { name: "Open file in preferred editor" });
141+
await expect.element(open).toBeEnabled();
142+
await open.click();
143+
expect(state.writeFile).toHaveBeenCalledExactlyOnceWith({
144+
environmentId,
145+
input: { cwd: "/workspace/tasks.md", editor: "vscode" },
146+
});
147+
});
148+
128149
describe("rendered Markdown task saves", () => {
129150
it("keeps a truncated read read-only without queuing a replacement", async () => {
130151
using _settings = setup();

‎apps/web/src/components/files/FilePreviewPanel.tsx‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ import { lazy, Suspense, useEffect, useRef, useState } from "react";
5353
import { isBrowserPreviewFile, openFileInPreview } from "~/browser/openFileInPreview";
5454
import { useAssetUrlRefresh, useAssetUrlState } from "~/assets/assetUrls";
5555
import { OpenInPicker } from "~/components/chat/OpenInPicker";
56+
import { shouldShowOpenInPicker } from "~/components/chat/OpenInPicker.logic";
5657
import { MediaVideoPlayer } from "~/components/media/MediaVideoPlayer";
5758
import { MediaActions, type MediaActionSource } from "~/components/media/MediaActions";
5859
import { MorphIcon } from "~/components/MorphIcon";
@@ -1283,7 +1284,11 @@ export default function FilePreviewPanel({
12831284
</div>
12841285
</ScrollArea>
12851286
{absolutePath &&
1286-
(environmentId === primaryEnvironmentId || remoteOpenState.mode !== "local-exec") ? (
1287+
shouldShowOpenInPicker({
1288+
environmentId,
1289+
primaryEnvironmentId,
1290+
remoteOpenMode: remoteOpenState.mode,
1291+
}) ? (
12871292
<OpenInPicker
12881293
environmentId={environmentId}
12891294
keybindings={keybindings}

0 commit comments

Comments
 (0)