Skip to content

Commit 0f70a56

Browse files
t3dotggclaude
andcommitted
feat(web): switch saved environments off instead of removing them
Disconnect and Remove both deleted the saved environment, so there was no way to silence an errored machine without re-pairing it. Each saved row now has a switch as its main action. Off drops the connection, stops retrying, hides the error, and pulls the machine's projects and threads out of the sidebar. The flag persists across restarts. Remove moves into an overflow menu behind a destructive confirm, and an Update all button appears when connected machines are behind the client version. Mobile picks up the same enabled flag through client-runtime. Co-Authored-By: Claude Fable 5.1 <[email protected]>
1 parent af2bacc commit 0f70a56

40 files changed

Lines changed: 655 additions & 168 deletions

‎apps/desktop/src/app/DesktopConnectionCatalogStore.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,7 @@ const migrateSavedEnvironmentRecords = Effect.fn(
372372
profiles,
373373
credentials,
374374
remoteDpopTokens: [],
375+
disabledEnvironmentIds: [],
375376
};
376377
});
377378

‎apps/mobile/src/connection/storage.ts‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
putRemoteDpopTokenInCatalog,
66
registerConnectionInCatalog,
77
removeConnectionFromCatalog,
8+
setConnectionEnabledInCatalog,
89
removeCatalogValue,
910
replaceCatalogValue,
1011
} from "@t3tools/client-runtime/platform";
@@ -21,7 +22,12 @@ import * as Option from "effect/Option";
2122
import * as CatalogStore from "./catalog-store";
2223

2324
function targetPersistenceError(
24-
operation: "list-targets" | "register-connection" | "remove-connection",
25+
operation:
26+
| "list-targets"
27+
| "list-disabled-targets"
28+
| "register-connection"
29+
| "remove-connection"
30+
| "set-connection-enabled",
2531
error: ConnectionTransientError,
2632
) {
2733
return new ConnectionPersistenceError({
@@ -39,6 +45,10 @@ export const connectionStorageLayer = Layer.effectContext(
3945
Effect.map((document) => document.targets),
4046
Effect.mapError((error) => targetPersistenceError("list-targets", error)),
4147
),
48+
listDisabled: catalog.read.pipe(
49+
Effect.map((document) => document.disabledEnvironmentIds),
50+
Effect.mapError((error) => targetPersistenceError("list-disabled-targets", error)),
51+
),
4252
});
4353
const registrationStore = ConnectionRegistrationStore.of({
4454
register: (registration) =>
@@ -49,6 +59,12 @@ export const connectionStorageLayer = Layer.effectContext(
4959
catalog
5060
.update((document) => removeConnectionFromCatalog(document, target))
5161
.pipe(Effect.mapError((error) => targetPersistenceError("remove-connection", error))),
62+
setEnabled: (environmentId, enabled) =>
63+
catalog
64+
.update((document) => setConnectionEnabledInCatalog(document, environmentId, enabled))
65+
.pipe(
66+
Effect.mapError((error) => targetPersistenceError("set-connection-enabled", error)),
67+
),
5268
});
5369
const profileStore = ProfileStore.make({
5470
get: (connectionId) =>

‎apps/mobile/src/features/cloud/ConnectOnboardingRouteScreen.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ function ConfiguredConnectOnboardingRouteScreen() {
4545
const navigation = useNavigation();
4646
const insets = useSafeAreaInsets();
4747
const { isSignedIn, userId } = useAuth({ treatPendingAsSignedOut: false });
48-
const { connectedEnvironments, onReconnectEnvironment } = useRemoteConnections();
48+
const { connectedEnvironments, onSetEnvironmentEnabled } = useRemoteConnections();
4949
const { refreshRelayEnvironments } = useConnectionController();
5050
const { connectedCloudEnvironments } = splitEnvironmentSections({
5151
connectedEnvironments,
@@ -110,7 +110,7 @@ function ConfiguredConnectOnboardingRouteScreen() {
110110
{isSignedIn ? (
111111
<CloudEnvironmentRows
112112
connectedCloudEnvironments={connectedCloudEnvironments}
113-
onReconnectEnvironment={onReconnectEnvironment}
113+
onSetEnvironmentEnabled={onSetEnvironmentEnabled}
114114
showHeader={false}
115115
/>
116116
) : (

‎apps/mobile/src/features/connection/CloudEnvironmentRows.tsx‎

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import { type RelayEnvironmentView, useConnectionController } from "./useConnect
3333

3434
interface CloudEnvironmentRowsProps {
3535
readonly connectedCloudEnvironments: ReadonlyArray<ConnectedEnvironmentSummary>;
36-
readonly onReconnectEnvironment: (environmentId: EnvironmentId) => void;
36+
readonly onSetEnvironmentEnabled: (environmentId: EnvironmentId, enabled: boolean) => void;
3737
readonly showcaseAvailableEnvironments?: ReadonlyArray<RelayEnvironmentView>;
3838
readonly showcaseSignedIn?: boolean;
3939
/**
@@ -97,11 +97,6 @@ function CloudEnvironmentRowsContent(
9797
[controller],
9898
);
9999

100-
const handleDisconnectCloudEnvironment = useCallback(
101-
(environmentId: EnvironmentId) => controller.removeEnvironment(environmentId),
102-
[controller],
103-
);
104-
105100
const handleToggleCloudError = useCallback((environmentId: string) => {
106101
setExpandedErrorId((current) => (current === environmentId ? null : environmentId));
107102
}, []);
@@ -144,8 +139,9 @@ function CloudEnvironmentRowsContent(
144139
key={environment.environmentId}
145140
environment={environment}
146141
borderTop={index !== 0}
147-
onConnect={() => props.onReconnectEnvironment(environment.environmentId)}
148-
onDisconnect={() => handleDisconnectCloudEnvironment(environment.environmentId)}
142+
onSetEnabled={(enabled) =>
143+
props.onSetEnvironmentEnabled(environment.environmentId, enabled)
144+
}
149145
errorExpanded={expandedErrorId === environment.environmentId}
150146
onToggleError={() => handleToggleCloudError(environment.environmentId)}
151147
/>
@@ -204,36 +200,36 @@ function CloudEnvironmentRowsContent(
204200
);
205201
}
206202

203+
/**
204+
* A saved T3 Connect environment. The switch turns it on or off; off keeps the
205+
* registration and cache but drops the connection and hides its errors.
206+
* Removal lives on the Settings environments screen.
207+
*/
207208
function ConnectedCloudEnvironmentRow(props: {
208209
readonly environment: ConnectedEnvironmentSummary;
209210
readonly borderTop: boolean;
210211
readonly errorExpanded: boolean;
211-
readonly onConnect: () => void;
212-
readonly onDisconnect: () => void;
212+
readonly onSetEnabled: (enabled: boolean) => void;
213213
readonly onToggleError: () => void;
214214
}) {
215215
const serverConfig = useAtomValue(
216216
serverEnvironment.configValueAtom(props.environment.environmentId),
217217
);
218+
const enabled = props.environment.isEnabled;
218219
return (
219220
<View>
220221
<CloudEnvironmentRowShell
221222
borderTop={props.borderTop}
222-
connectionError={props.environment.connectionError}
223-
connectionErrorTraceId={props.environment.connectionErrorTraceId}
224-
connectionState={props.environment.connectionState}
223+
connectionError={enabled ? props.environment.connectionError : null}
224+
connectionErrorTraceId={enabled ? props.environment.connectionErrorTraceId : null}
225+
connectionState={enabled ? props.environment.connectionState : "available"}
225226
errorExpanded={props.errorExpanded}
226227
label={props.environment.environmentLabel}
227228
machine={resolveEnvironmentMachineKind(serverConfig)}
228-
onValueChange={(enabled) => {
229-
if (enabled) {
230-
props.onConnect();
231-
return;
232-
}
233-
props.onDisconnect();
234-
}}
229+
onValueChange={props.onSetEnabled}
235230
onToggleError={props.onToggleError}
236-
value={props.environment.connectionState !== "available"}
231+
{...(enabled ? {} : { statusText: "Off" })}
232+
value={enabled}
237233
/>
238234
</View>
239235
);

‎apps/mobile/src/features/connection/ConnectionEnvironmentRow.tsx‎

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,17 @@ import Animated, { FadeIn, FadeOut, LinearTransition } from "react-native-reanim
1111

1212
import { AppText as Text, AppTextInput as TextInput } from "../../components/AppText";
1313
import { EnvironmentMachineSymbol } from "../../components/EnvironmentMachineSymbol";
14+
import { ThemedSwitch } from "../../components/ThemedSwitch";
1415
import { cn } from "../../lib/cn";
1516
import { copyTextWithHaptic } from "../../lib/copyTextWithHaptic";
1617
import type { ConnectedEnvironmentSummary } from "../../state/remote-runtime-types";
1718
import { serverEnvironment } from "../../state/server";
1819
import { ConnectionStatusDot } from "./ConnectionStatusDot";
1920

2021
function connectionStatusLabel(environment: ConnectedEnvironmentSummary): string | null {
22+
if (!environment.isEnabled) {
23+
return "Off";
24+
}
2125
return connectionStatusText({
2226
phase: environment.connectionState,
2327
error: environment.connectionError,
@@ -31,6 +35,7 @@ export function ConnectionEnvironmentRow(props: {
3135
readonly onToggle: () => void;
3236
readonly onReconnect: (environmentId: EnvironmentId) => void;
3337
readonly onRemove: (environmentId: EnvironmentId) => void;
38+
readonly onSetEnabled: (environmentId: EnvironmentId, enabled: boolean) => void;
3439
readonly onUpdate: (
3540
environmentId: EnvironmentId,
3641
updates: { readonly label: string; readonly displayUrl: string },
@@ -41,12 +46,14 @@ export function ConnectionEnvironmentRow(props: {
4146
const serverConfig = useAtomValue(
4247
serverEnvironment.configValueAtom(props.environment.environmentId),
4348
);
49+
const enabled = props.environment.isEnabled;
4450
const statusLabel = connectionStatusLabel(props.environment);
45-
const statusTraceId = props.environment.connectionErrorTraceId;
46-
const hasConnectionFailure = props.environment.connectionError !== null;
51+
const statusTraceId = enabled ? props.environment.connectionErrorTraceId : null;
52+
const hasConnectionFailure = enabled && props.environment.connectionError !== null;
4753
const isRetrying =
48-
props.environment.connectionState === "connecting" ||
49-
props.environment.connectionState === "reconnecting";
54+
enabled &&
55+
(props.environment.connectionState === "connecting" ||
56+
props.environment.connectionState === "reconnecting");
5057
const handleSave = useCallback(async () => {
5158
const result = await props.onUpdate(props.environment.environmentId, {
5259
label: label.trim(),
@@ -70,7 +77,7 @@ export function ConnectionEnvironmentRow(props: {
7077
onPress={props.onToggle}
7178
>
7279
<ConnectionStatusDot
73-
state={props.environment.connectionState}
80+
state={enabled ? props.environment.connectionState : "available"}
7481
pulse={isRetrying}
7582
size={8}
7683
/>
@@ -125,6 +132,10 @@ export function ConnectionEnvironmentRow(props: {
125132
) : null}
126133
</View>
127134

135+
<ThemedSwitch
136+
onValueChange={(next) => props.onSetEnabled(props.environment.environmentId, next)}
137+
value={enabled}
138+
/>
128139
<SymbolView
129140
name="chevron.down"
130141
size={12}

‎apps/mobile/src/features/connection/ConnectionsRouteScreen.tsx‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export function ConnectionsRouteScreen() {
1717
connectedEnvironments,
1818
onReconnectEnvironment,
1919
onRemoveEnvironmentPress,
20+
onSetEnvironmentEnabled,
2021
onUpdateEnvironment,
2122
} = useRemoteConnections();
2223
const navigation = useNavigation();
@@ -74,6 +75,7 @@ export function ConnectionsRouteScreen() {
7475
onToggle={() => handleToggle(environment.environmentId)}
7576
onReconnect={onReconnectEnvironment}
7677
onRemove={onRemoveEnvironmentPress}
78+
onSetEnabled={onSetEnvironmentEnabled}
7779
onUpdate={onUpdateEnvironment}
7880
/>
7981
</View>

‎apps/mobile/src/features/connection/environmentSections.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ function connectedEnvironment(
1515
environmentLabel: input.environmentLabel ?? input.environmentId,
1616
displayUrl: input.displayUrl ?? `https://${input.environmentId}.example.test/`,
1717
isRelayManaged: input.isRelayManaged,
18+
isEnabled: input.isEnabled ?? true,
1819
connectionState: input.connectionState ?? "connected",
1920
connectionError: input.connectionError ?? null,
2021
connectionErrorTraceId: input.connectionErrorTraceId ?? null,

‎apps/mobile/src/features/connection/useConnectionController.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ export function useConnectionController() {
4040
const registerEnvironment = useAtomCommand(environmentCatalog.register, "environment register");
4141
const removeEnvironmentMutation = useAtomCommand(environmentCatalog.remove, "environment remove");
4242
const retryEnvironmentMutation = useAtomCommand(environmentCatalog.retryNow, "environment retry");
43+
const setEnvironmentEnabledMutation = useAtomCommand(
44+
environmentCatalog.setEnabled,
45+
"environment toggle",
46+
);
4347
const refreshRelayEnvironments = useAtomCommand(
4448
relayEnvironmentDiscovery.refresh,
4549
"relay environment refresh",
@@ -93,6 +97,11 @@ export function useConnectionController() {
9397
(environmentId: EnvironmentId) => retryEnvironmentMutation(environmentId),
9498
[retryEnvironmentMutation],
9599
);
100+
const setEnvironmentEnabled = useCallback(
101+
(environmentId: EnvironmentId, enabled: boolean) =>
102+
setEnvironmentEnabledMutation({ environmentId, enabled }),
103+
[setEnvironmentEnabledMutation],
104+
);
96105
const updateEnvironment = useCallback(
97106
(
98107
environmentId: EnvironmentId,
@@ -120,6 +129,7 @@ export function useConnectionController() {
120129
connectRelayEnvironment,
121130
removeEnvironment,
122131
retryEnvironment,
132+
setEnvironmentEnabled,
123133
updateEnvironment,
124134
refreshRelayEnvironments,
125135
};

‎apps/mobile/src/features/home/workspace-connection-status.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ describe("workspace connection status", () => {
4545
environmentLabel: "Julius’s Mac mini",
4646
displayUrl: "",
4747
isRelayManaged: false,
48+
isEnabled: true,
4849
connectionState: "reconnecting",
4950
connectionError: null,
5051
connectionErrorTraceId: null,

‎apps/mobile/src/features/settings/SettingsEnvironmentsRouteScreen.tsx‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export function SettingsEnvironmentsRouteScreen() {
2828
connectedEnvironments,
2929
onReconnectEnvironment,
3030
onRemoveEnvironmentPress,
31+
onSetEnvironmentEnabled,
3132
onUpdateEnvironment,
3233
} = useRemoteConnections();
3334
const navigation = useNavigation();
@@ -136,6 +137,7 @@ export function SettingsEnvironmentsRouteScreen() {
136137
onToggle={() => handleToggle(environment.environmentId)}
137138
onReconnect={onReconnectEnvironment}
138139
onRemove={onRemoveEnvironmentPress}
140+
onSetEnabled={onSetEnvironmentEnabled}
139141
onUpdate={handleUpdateEnvironment}
140142
/>
141143
</View>
@@ -163,7 +165,7 @@ export function SettingsEnvironmentsRouteScreen() {
163165
user is signed out — the component gates discovery itself. */}
164166
<CloudEnvironmentRows
165167
connectedCloudEnvironments={connectedCloudEnvironments}
166-
onReconnectEnvironment={onReconnectEnvironment}
168+
onSetEnvironmentEnabled={onSetEnvironmentEnabled}
167169
{...(SHOWCASE_ENABLED
168170
? {
169171
showcaseAvailableEnvironments: SHOWCASE_AVAILABLE_CLOUD_ENVIRONMENTS,

0 commit comments

Comments
 (0)