Skip to content

Commit 0d36552

Browse files
fix(web): preserve host identity and show mixed device switches
1 parent 6290f6a commit 0d36552

3 files changed

Lines changed: 32 additions & 6 deletions

File tree

‎apps/web/src/components/settings/IntegrationsSettings.tsx‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { useScopedSettings, useUpdateScopedSettings } from "./useScopedSettings";
2+
import { ScopedSwitch } from "./ScopedSwitch";
23
import { DeviceHostsSettings } from "./DeviceHostsSettings";
34
/**
45
* Integrations settings - preferences for surfaces T3 Code embeds rather than
@@ -654,7 +655,8 @@ function DeviceIntegrationControls({
654655
control={
655656
<>
656657
{pending === "hub" ? <DeviceHubSetupStatus state={state} pending compact /> : null}
657-
<Switch
658+
<ScopedSwitch
659+
settingKeys={["enableDeviceSupport"]}
658660
checked={enabled}
659661
disabled={projectScope || !loaded || !environmentId || busy || pending !== null}
660662
aria-label="Device hub"
@@ -712,7 +714,8 @@ function DeviceIntegrationControls({
712714
control={
713715
<>
714716
{pending === "agent" ? <AgentDeviceSetupStatus state={state} pending compact /> : null}
715-
<Switch
717+
<ScopedSwitch
718+
settingKeys={["enableAgentDeviceAccess"]}
716719
checked={agentAccessEnabled}
717720
disabled={
718721
connectedEnvironments.length === 0 ||

‎apps/web/src/components/settings/deviceHostsSettings.logic.test.ts‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,18 @@ describe("device host changes across environments", () => {
4040
shared,
4141
]);
4242
});
43+
44+
it("prefers the selected ID over a sibling with the same destination", () => {
45+
const sibling = { ...shared, id: "sibling", label: "Another entry" };
46+
const edited = { ...shared, label: "Renamed" };
47+
expect(updateDeviceHosts([sibling, shared], edited, false, shared)).toEqual([sibling, edited]);
48+
expect(updateDeviceHosts([sibling, shared], shared, true)).toEqual([sibling]);
49+
});
50+
51+
it("refuses an ambiguous destination on another environment instead of changing a sibling", () => {
52+
const remote = { ...shared, id: "remote" };
53+
const sibling = { ...shared, id: "sibling" };
54+
expect(() => updateDeviceHosts([remote, sibling], shared, true)).toThrow("Multiple hosts");
55+
expect(() => updateDeviceHosts([remote, sibling], shared, false)).toThrow("Multiple hosts");
56+
});
4357
});

‎apps/web/src/components/settings/deviceHostsSettings.logic.ts‎

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,22 @@ export function updateDeviceHosts(
1111
candidate.target === other.target &&
1212
candidate.port === other.port &&
1313
candidate.identityFile === other.identityFile;
14-
const matches = (candidate: SshDeviceHostConfig) =>
15-
candidate.id === original.id || sameDestination(candidate, original);
16-
if (remove) return hosts.filter((candidate) => !matches(candidate));
14+
const findDestination = (destination: SshDeviceHostConfig) => {
15+
const matches = hosts.filter((candidate) => sameDestination(candidate, destination));
16+
if (matches.length > 1) {
17+
throw new Error(
18+
"Multiple hosts match this SSH destination. Select the environment to edit its hosts.",
19+
);
20+
}
21+
return matches[0];
22+
};
1723
// A retry can encounter the updated destination on an environment that
1824
// already saved, including one with a different environment-local host ID.
1925
const existing =
20-
hosts.find(matches) ?? hosts.find((candidate) => sameDestination(candidate, host));
26+
hosts.find((candidate) => candidate.id === original.id) ??
27+
findDestination(original) ??
28+
(remove ? undefined : findDestination(host));
29+
if (remove) return hosts.filter((candidate) => candidate.id !== existing?.id);
2130
return existing
2231
? hosts.map((candidate) =>
2332
candidate.id === existing.id ? { ...host, id: existing.id } : candidate,

0 commit comments

Comments
 (0)