Skip to content

Commit e100c94

Browse files
author
JD
committed
fix(web): expose service editors without a desktop primary
Keep the editor picker available for a same-home service when the desktop has no primary backend. Read editor availability from the selected environment instead of the missing primary. Verification: check:changed HEAD passed, including picker visibility, scoped editor lists and React compiler checks.
1 parent e2ffe38 commit e100c94

5 files changed

Lines changed: 62 additions & 12 deletions

File tree

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ import { useKnownTerminalSessions, useThreadRunningTerminalIds } from "../state/
233233
import { useEnvironmentQuery } from "../state/query";
234234
import { useEnvironmentScope } from "~/state/session";
235235
import {
236-
primaryServerAvailableEditorsAtom,
236+
serverAvailableEditorsAtom,
237237
primaryServerKeybindingsAtom,
238238
serverEnvironment,
239239
} from "../state/server";
@@ -1643,7 +1643,9 @@ export default function ChatView(props: ChatViewProps) {
16431643
const scriptKeybindings =
16441644
useAtomValue(serverEnvironment.configValueAtom(environmentId))?.keybindings ??
16451645
DEFAULT_RESOLVED_KEYBINDINGS;
1646-
const availableEditors = useAtomValue(primaryServerAvailableEditorsAtom);
1646+
const availableEditors = useAtomValue(
1647+
serverAvailableEditorsAtom(activeThread?.environmentId ?? environmentId),
1648+
);
16471649
const remoteOpenState = useRemoteOpenState(activeThread?.environmentId ?? environmentId);
16481650
const showOpenInPicker = shouldShowOpenInPicker({
16491651
activeProjectName: activeProject?.title,
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { EnvironmentId } from "@t3tools/contracts";
2+
import { expect, it } from "vite-plus/test";
3+
4+
import { shouldShowOpenInPicker } from "./OpenInPicker.logic";
5+
6+
const environmentId = EnvironmentId.make("service");
7+
const primaryEnvironmentId = EnvironmentId.make("desktop");
8+
9+
it.each([
10+
{ primaryEnvironmentId: null, remoteOpenMode: "local-exec", expected: true },
11+
{ primaryEnvironmentId: environmentId, remoteOpenMode: "local-exec", expected: true },
12+
{ primaryEnvironmentId, remoteOpenMode: "local-exec", expected: false },
13+
{ primaryEnvironmentId, remoteOpenMode: "remote-links", expected: true },
14+
] as const)(
15+
"offers editor opening for $remoteOpenMode with primary $primaryEnvironmentId",
16+
(input) => {
17+
expect(
18+
shouldShowOpenInPicker({
19+
...input,
20+
activeProjectName: "Project",
21+
activeThreadEnvironmentId: environmentId,
22+
}),
23+
).toBe(input.expected);
24+
},
25+
);

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,8 @@ export function shouldShowOpenInPicker(input: {
99
readonly remoteOpenMode: RemoteOpenMode;
1010
}): boolean {
1111
if (!input.activeProjectName) return false;
12-
if (
13-
input.primaryEnvironmentId !== null &&
14-
input.activeThreadEnvironmentId === input.primaryEnvironmentId
15-
) {
12+
if (input.primaryEnvironmentId === null) return true;
13+
if (input.activeThreadEnvironmentId === input.primaryEnvironmentId) {
1614
return true;
1715
}
1816
return input.remoteOpenMode !== "local-exec";

‎apps/web/src/state/server.test.ts‎

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,14 @@ import type { EnvironmentConnectionPhase } from "@t3tools/client-runtime/connect
22
import { EnvironmentId, type KeybindingRule, type ServerConfig } from "@t3tools/contracts";
33
import { compileResolvedKeybindingsConfig } from "@t3tools/shared/keybindings";
44
import { Atom, AtomRegistry } from "effect/reactivity";
5-
import { afterEach, describe, expect, it } from "vite-plus/test";
5+
import { afterEach, describe, expect, it, vi } from "vite-plus/test";
66

77
import { resolveShortcutCommand } from "../keybindings";
8-
import { createShortcutKeybindingsAtom } from "./server";
8+
import {
9+
createShortcutKeybindingsAtom,
10+
serverAvailableEditorsAtom,
11+
serverEnvironment,
12+
} from "./server";
913

1014
const PRIMARY = EnvironmentId.make("primary");
1115
const A = EnvironmentId.make("a");
@@ -67,6 +71,24 @@ afterEach(() => {
6771
for (const registry of registries.splice(0)) registry.dispose();
6872
});
6973

74+
it("reads and refreshes the active environment's editors without a desktop primary", () => {
75+
const aConfig = Atom.make<ServerConfig | null>(null);
76+
const bConfig = Atom.make<ServerConfig | null>({ ...config([]), availableEditors: ["zed"] });
77+
using _configs = vi
78+
.spyOn(serverEnvironment, "configValueAtom")
79+
.mockImplementation((environmentId) => (environmentId === A ? aConfig : bConfig));
80+
const registry = AtomRegistry.make();
81+
registries.push(registry);
82+
83+
expect(registry.get(serverAvailableEditorsAtom(A))).toEqual([]);
84+
registry.set(aConfig, { ...config([]), availableEditors: ["vscode"] });
85+
expect(registry.get(serverAvailableEditorsAtom(A))).toEqual(["vscode"]);
86+
expect(registry.get(serverAvailableEditorsAtom(B))).toEqual(["zed"]);
87+
registry.set(aConfig, { ...config([]), availableEditors: ["cursor"] });
88+
expect(registry.get(serverAvailableEditorsAtom(A))).toEqual(["cursor"]);
89+
expect(registry.get(serverAvailableEditorsAtom(B))).toEqual(["zed"]);
90+
});
91+
7092
describe("createShortcutKeybindingsAtom", () => {
7193
it("updates shortcuts from the first connected, configured environment without a primary", () => {
7294
const harness = makeHarness({});

‎apps/web/src/state/server.ts‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,10 +166,13 @@ export const primaryServerKeybindingsAtom = createShortcutKeybindingsAtom({
166166
environmentsAtom: environmentConnectionsAtom,
167167
}).pipe(Atom.withLabel("web-primary-server-keybindings"));
168168

169-
export const primaryServerAvailableEditorsAtom = Atom.make(
170-
(get): ReadonlyArray<EditorId> =>
171-
get(primaryServerConfigAtom)?.availableEditors ?? EMPTY_AVAILABLE_EDITORS,
172-
).pipe(Atom.withLabel("web-primary-server-available-editors"));
169+
export const serverAvailableEditorsAtom = Atom.family((environmentId: EnvironmentId) =>
170+
Atom.make(
171+
(get): ReadonlyArray<EditorId> =>
172+
get(serverEnvironment.configValueAtom(environmentId))?.availableEditors ??
173+
EMPTY_AVAILABLE_EDITORS,
174+
).pipe(Atom.withLabel(`web-server-available-editors:${environmentId}`)),
175+
);
173176

174177
const EMPTY_ENVIRONMENT_THEMES: ReadonlyArray<EnvironmentTheme> = [];
175178

0 commit comments

Comments
 (0)