Skip to content

Commit 4778457

Browse files
fix(web): track switch dialog no longer offers a switch that moves nothing (pingdotgg#27484)
Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent 0ceaa9a commit 4778457

3 files changed

Lines changed: 108 additions & 6 deletions

File tree

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

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ import {
1818
type ChannelSwitchRelease,
1919
} from "../sidebar/updateEverything.logic";
2020
import { isHostedByThisApp, useUpdateEverything } from "../sidebar/useUpdateEverything";
21-
import { localUpdaterStaysPut, prepareLocalTrackSwitch } from "./updateTrackSwitch.logic";
21+
import {
22+
localUpdaterStaysPut,
23+
nothingToMove,
24+
prepareLocalTrackSwitch,
25+
} from "./updateTrackSwitch.logic";
2226
import {
2327
AlertDialog,
2428
AlertDialogClose,
@@ -82,6 +86,15 @@ function SwitchPlan({
8286
const [checking, setChecking] = useState(false);
8387
const everything = useUpdateEverything(switchesLocal ? release.version : null, release);
8488
const label = channelSwitchLabel(release.channel);
89+
const idle = nothingToMove({
90+
label,
91+
channel: release.channel,
92+
savedChannel: updateState?.channel ?? null,
93+
switchesLocal,
94+
crossesLocal,
95+
rows: everything.rows,
96+
hasTargets: everything.hasUpdates,
97+
});
8598
// This app's reinstall restarts every server it hosts, so each of their databases must allow it.
8699
const localBlocked = localSwitchBlockReason(
87100
APP_VERSION,
@@ -157,9 +170,7 @@ function SwitchPlan({
157170
providerCount={0}
158171
rows={everything.rows}
159172
notes={[
160-
...(everything.rows.length === 0 && !crossesLocal
161-
? [`Every connected machine is already on ${label}. This only saves the track.`]
162-
: []),
173+
...(idle.note === null ? [] : [idle.note]),
163174
...(crossesLocal && updatesOff
164175
? ["This app's updates are off here, so reinstall it yourself to switch."]
165176
: []),
@@ -171,7 +182,9 @@ function SwitchPlan({
171182
confirmLabel={checking ? "Checking…" : `Switch to ${label}`}
172183
busy={checking}
173184
disabledReason={
174-
!switchesLocal || localBlocked === null ? null : `This app cannot switch: ${localBlocked}.`
185+
switchesLocal && localBlocked !== null
186+
? `This app cannot switch: ${localBlocked}.`
187+
: idle.disabledReason
175188
}
176189
onConfirm={() => void run()}
177190
/>

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

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import type { DesktopUpdateChannel, DesktopUpdateState } from "@t3tools/contracts";
22
import { describe, expect, it } from "vite-plus/test";
33

4-
import { localUpdaterStaysPut, prepareLocalTrackSwitch } from "./updateTrackSwitch.logic";
4+
import {
5+
localUpdaterStaysPut,
6+
nothingToMove,
7+
prepareLocalTrackSwitch,
8+
} from "./updateTrackSwitch.logic";
59

610
const STABLE = "0.1.3";
711

@@ -75,6 +79,67 @@ describe("prepareLocalTrackSwitch", () => {
7579
});
7680
});
7781

82+
describe("nothingToMove", () => {
83+
const skippedRemote = {
84+
skipped: "its server predates database checks; update it on Nightly first",
85+
};
86+
const stableSwitch = {
87+
label: "Stable",
88+
channel: "latest" as const,
89+
savedChannel: "latest" as const,
90+
switchesLocal: false,
91+
crossesLocal: false,
92+
rows: [skippedRemote],
93+
hasTargets: false,
94+
};
95+
96+
it("disables a switch that would neither move a machine nor save a track", () => {
97+
expect(nothingToMove(stableSwitch)).toEqual({
98+
note: null,
99+
disabledReason: "No machine can switch to Stable now.",
100+
});
101+
});
102+
103+
it("says a switch only saves the track when no machine moves", () => {
104+
const onlySaves = { note: "No machine can switch to Stable now. This only saves the track." };
105+
expect(nothingToMove({ ...stableSwitch, savedChannel: "nightly" })).toEqual({
106+
...onlySaves,
107+
disabledReason: null,
108+
});
109+
// Before the desktop reports its saved track, confirming may still need to save it.
110+
expect(nothingToMove({ ...stableSwitch, savedChannel: null })).toEqual({
111+
...onlySaves,
112+
disabledReason: null,
113+
});
114+
// A desktop host already on the track still gets its saved track changed.
115+
expect(nothingToMove({ ...stableSwitch, hasTargets: true })).toEqual({
116+
...onlySaves,
117+
disabledReason: null,
118+
});
119+
// With its updater off, this app stays on the other track.
120+
expect(
121+
nothingToMove({ ...stableSwitch, rows: [], crossesLocal: true, savedChannel: "nightly" }),
122+
).toEqual({
123+
...onlySaves,
124+
disabledReason: null,
125+
});
126+
expect(nothingToMove({ ...stableSwitch, rows: [], savedChannel: "nightly" })).toEqual({
127+
note: "Every connected machine is already on Stable. This only saves the track.",
128+
disabledReason: null,
129+
});
130+
});
131+
132+
it("stays out of a switch that moves a machine", () => {
133+
const none = { note: null, disabledReason: null };
134+
expect(nothingToMove({ ...stableSwitch, switchesLocal: true, crossesLocal: true })).toEqual(
135+
none,
136+
);
137+
expect(nothingToMove({ ...stableSwitch, rows: [skippedRemote, { skipped: null }] })).toEqual(
138+
none,
139+
);
140+
});
141+
});
142+
78143
describe("localUpdaterStaysPut", () => {
79144
it("moves an app whose updater is off only because its policy rules out nightly", () => {
80145
const blocked = { enabled: false, channelBlockedByPolicy: true as const };

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,30 @@ export async function prepareLocalTrackSwitch(
4949
};
5050
}
5151

52+
/** When no machine moves, confirming only saves the track; when that track is already saved too,
53+
* confirming would do nothing. Track-only hosts are not rows but still get a request. */
54+
export function nothingToMove(input: {
55+
readonly label: string;
56+
readonly channel: DesktopUpdateChannel;
57+
// Null until the desktop reports it; an unknown track may still need saving.
58+
readonly savedChannel: DesktopUpdateChannel | null;
59+
readonly switchesLocal: boolean;
60+
readonly crossesLocal: boolean;
61+
readonly rows: ReadonlyArray<{ readonly skipped: string | null }>;
62+
readonly hasTargets: boolean;
63+
}): { readonly note: string | null; readonly disabledReason: string | null } {
64+
if (input.switchesLocal || input.rows.some((row) => row.skipped === null)) {
65+
return { note: null, disabledReason: null };
66+
}
67+
const reason =
68+
input.rows.length === 0 && !input.crossesLocal
69+
? `Every connected machine is already on ${input.label}.`
70+
: `No machine can switch to ${input.label} now.`;
71+
return !input.hasTargets && input.savedChannel === input.channel
72+
? { note: null, disabledReason: reason }
73+
: { note: `${reason} This only saves the track.`, disabledReason: null };
74+
}
75+
5276
/**
5377
* Whether this app stays put while connected machines move: its updater is off, as for a .deb
5478
* install or without a feed. Off only because a policy rules out its nightly channel, it moves.

0 commit comments

Comments
 (0)