Skip to content

Commit 2587c80

Browse files
t3dotggclaude
andauthored
feat(web): switch saved environments off instead of removing them (pingdotgg#11478)
Co-authored-by: Claude Fable 5.1 <[email protected]>
1 parent 2db675a commit 2587c80

40 files changed

Lines changed: 762 additions & 173 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: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ 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, onRemoveEnvironmentPress } =
49+
useRemoteConnections();
4950
const { refreshRelayEnvironments } = useConnectionController();
5051
const { connectedCloudEnvironments } = splitEnvironmentSections({
5152
connectedEnvironments,
@@ -110,7 +111,8 @@ function ConfiguredConnectOnboardingRouteScreen() {
110111
{isSignedIn ? (
111112
<CloudEnvironmentRows
112113
connectedCloudEnvironments={connectedCloudEnvironments}
113-
onReconnectEnvironment={onReconnectEnvironment}
114+
onSetEnvironmentEnabled={onSetEnvironmentEnabled}
115+
onRemoveEnvironment={onRemoveEnvironmentPress}
114116
showHeader={false}
115117
/>
116118
) : (

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

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ 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;
37+
/** Long-press on a saved row. The callback owns the confirm. */
38+
readonly onRemoveEnvironment: (environmentId: EnvironmentId) => void;
3739
readonly showcaseAvailableEnvironments?: ReadonlyArray<RelayEnvironmentView>;
3840
readonly showcaseSignedIn?: boolean;
3941
/**
@@ -97,11 +99,6 @@ function CloudEnvironmentRowsContent(
9799
[controller],
98100
);
99101

100-
const handleDisconnectCloudEnvironment = useCallback(
101-
(environmentId: EnvironmentId) => controller.removeEnvironment(environmentId),
102-
[controller],
103-
);
104-
105102
const handleToggleCloudError = useCallback((environmentId: string) => {
106103
setExpandedErrorId((current) => (current === environmentId ? null : environmentId));
107104
}, []);
@@ -144,8 +141,10 @@ function CloudEnvironmentRowsContent(
144141
key={environment.environmentId}
145142
environment={environment}
146143
borderTop={index !== 0}
147-
onConnect={() => props.onReconnectEnvironment(environment.environmentId)}
148-
onDisconnect={() => handleDisconnectCloudEnvironment(environment.environmentId)}
144+
onSetEnabled={(enabled) =>
145+
props.onSetEnvironmentEnabled(environment.environmentId, enabled)
146+
}
147+
onRemove={() => props.onRemoveEnvironment(environment.environmentId)}
149148
errorExpanded={expandedErrorId === environment.environmentId}
150149
onToggleError={() => handleToggleCloudError(environment.environmentId)}
151150
/>
@@ -204,38 +203,42 @@ function CloudEnvironmentRowsContent(
204203
);
205204
}
206205

206+
/**
207+
* A saved T3 Connect environment. The switch turns it on or off; off keeps the
208+
* registration and cache but drops the connection and hides its errors.
209+
* Long-press removes it from this device.
210+
*/
207211
function ConnectedCloudEnvironmentRow(props: {
208212
readonly environment: ConnectedEnvironmentSummary;
209213
readonly borderTop: boolean;
210214
readonly errorExpanded: boolean;
211-
readonly onConnect: () => void;
212-
readonly onDisconnect: () => void;
215+
readonly onSetEnabled: (enabled: boolean) => void;
216+
readonly onRemove: () => void;
213217
readonly onToggleError: () => void;
214218
}) {
215219
const serverConfig = useAtomValue(
216220
serverEnvironment.configValueAtom(props.environment.environmentId),
217221
);
222+
const enabled = props.environment.isEnabled;
218223
return (
219-
<View>
224+
<Pressable
225+
accessibilityHint="Long press to remove from this device"
226+
onLongPress={props.onRemove}
227+
>
220228
<CloudEnvironmentRowShell
221229
borderTop={props.borderTop}
222-
connectionError={props.environment.connectionError}
223-
connectionErrorTraceId={props.environment.connectionErrorTraceId}
224-
connectionState={props.environment.connectionState}
230+
connectionError={enabled ? props.environment.connectionError : null}
231+
connectionErrorTraceId={enabled ? props.environment.connectionErrorTraceId : null}
232+
connectionState={enabled ? props.environment.connectionState : "available"}
225233
errorExpanded={props.errorExpanded}
226234
label={props.environment.environmentLabel}
227235
machine={resolveEnvironmentMachineKind(serverConfig)}
228-
onValueChange={(enabled) => {
229-
if (enabled) {
230-
props.onConnect();
231-
return;
232-
}
233-
props.onDisconnect();
234-
}}
236+
onValueChange={props.onSetEnabled}
235237
onToggleError={props.onToggleError}
236-
value={props.environment.connectionState !== "available"}
238+
{...(enabled ? {} : { statusText: "Off" })}
239+
value={enabled}
237240
/>
238-
</View>
241+
</Pressable>
239242
);
240243
}
241244

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

Lines changed: 18 additions & 6 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}
@@ -198,7 +209,8 @@ export function ConnectionEnvironmentRow(props: {
198209
)}
199210

200211
<Pressable
201-
className="h-[42px] w-[42px] items-center justify-center rounded-[14px] border border-input-border bg-input active:opacity-70"
212+
className="h-[42px] w-[42px] items-center justify-center rounded-[14px] border border-input-border bg-input active:opacity-70 disabled:opacity-40"
213+
disabled={!enabled}
202214
onPress={() => props.onReconnect(props.environment.environmentId)}
203215
>
204216
<SymbolView

‎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: 4 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,8 @@ export function SettingsEnvironmentsRouteScreen() {
163165
user is signed out — the component gates discovery itself. */}
164166
<CloudEnvironmentRows
165167
connectedCloudEnvironments={connectedCloudEnvironments}
166-
onReconnectEnvironment={onReconnectEnvironment}
168+
onSetEnvironmentEnabled={onSetEnvironmentEnabled}
169+
onRemoveEnvironment={onRemoveEnvironmentPress}
167170
{...(SHOWCASE_ENABLED
168171
? {
169172
showcaseAvailableEnvironments: SHOWCASE_AVAILABLE_CLOUD_ENVIRONMENTS,

0 commit comments

Comments
 (0)