The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 23, 09:15 UTC
fix(web): settings stay compact with many connected machines (#19744)
maria committed
Oct 15, 2026 at 23:42 UTC
6d73370ef1c54c2a3bdb187cb72cf6f7b88b44c3
13 files changed
+1414
-403
apps/web/src/components/settings/DeviceHostEditor.tsx
+48
-16
@@ -1,8 +1,9 @@
1
import { useState } from "react";
2
import * as Option from "effect/Option";
3
import type { SshDeviceHostConfig } from "@t3tools/contracts";
4
-import { CheckIcon, MonitorIcon, XIcon } from "lucide-react";
5
-import { Button } from "../ui/button";
4
+import { CheckIcon, ChevronDownIcon, MonitorIcon, XIcon } from "lucide-react";
5
+import { Button, InlineButton } from "../ui/button";
6
+import { Collapsible, CollapsiblePanel, CollapsibleTrigger } from "../ui/collapsible";
7
import { Input } from "../ui/input";
8
import { Spinner } from "../ui/spinner";
9
import {
@@ -38,12 +39,24 @@ export function DeviceHostEditor({
39
onClose: () => void;
40
}) {
41
const [draft, setDraft] = useState(host);
42
+ const [expandedChecks, setExpandedChecks] = useState<{ key: string; open: boolean } | null>(null);
43
const { checks, testConnection } = useHostConnectionChecks(targets);
42
- const results = checks[deviceHostConnectionKey(draft)];
44
+ const connectionKey = deviceHostConnectionKey(draft);
45
+ const results = checks[connectionKey];
46
const checking = Object.values(results ?? {}).some((check) => check.status === "pending");
47
const input = parseDeviceHostDraft({ ...draft, label: draft.label.trim() || draft.target });
48
const valid = Option.isSome(input);
49
const failed = Object.values(results ?? {}).filter((check) => check.status === "failed").length;
50
+ const checksOpen =
51
+ targets.length === 1 ||
52
+ (expandedChecks?.key === connectionKey ? expandedChecks.open : failed > 0);
53
+ const checkSummary = checking
54
+ ? "Checking environments…"
55
+ : results
56
+ ? failed
57
+ ? `${failed} of ${targets.length} failed`
58
+ : "Connection checks passed"
59
+ : "Check access before saving";
60
return (
61
<Dialog
62
open
@@ -136,17 +149,34 @@ export function DeviceHostEditor({
149
Optional. Resolved separately on each environment.
150
</p>
151
</details>
139
- <div className="rounded-lg border border-border/60">
152
+ <Collapsible
153
+ open={checksOpen}
154
+ onOpenChange={(open) => setExpandedChecks({ key: connectionKey, open })}
155
+ render={<div className="rounded-lg border border-border/60" />}
156
+ >
157
<div className="flex items-center justify-between gap-3 px-3 py-2.5">
141
- <p role="status" className="text-xs text-muted-foreground">
142
- {checking
143
- ? "Checking environments…"
144
- : results
145
- ? failed
146
- ? `${failed} of ${targets.length} failed`
147
- : "Connection checks passed"
148
- : "Check access before saving"}
149
- </p>
158
+ {targets.length === 1 ? (
159
+ <p role="status" className="text-xs text-muted-foreground">
160
+ {checkSummary}
161
+ </p>
162
+ ) : (
163
+ <div className="min-w-0 text-xs [--inline-button-white-space:normal]">
164
+ <CollapsibleTrigger
165
+ disabled={!results}
166
+ aria-label={`${checkSummary}. Per-machine results`}
167
+ render={<InlineButton tone="muted" />}
168
+ >
169
+ <span role="status" className="text-left">
170
+ {checkSummary}
171
+ </span>
172
+ {results ? (
173
+ <ChevronDownIcon
174
+ className={`size-3 shrink-0 ${checksOpen ? "rotate-180" : ""}`}
175
+ />
176
+ ) : null}
177
+ </CollapsibleTrigger>
178
+ </div>
179
+ )}
180
<Button
181
type="button"
182
size="sm"
@@ -160,7 +190,9 @@ export function DeviceHostEditor({
190
</Button>
191
</div>
192
{results ? (
163
- <ul className="border-t border-border/60 divide-y divide-border/40">
193
+ <CollapsiblePanel
194
+ render={<ul className="border-t border-border/60 divide-y divide-border/40" />}
195
+ >
196
{targets.map((target) => {
197
const result = results[target.environmentId];
198
if (!result) return null;
@@ -206,9 +238,9 @@ export function DeviceHostEditor({
238
</li>
239
);
240
})}
209
- </ul>
241
+ </CollapsiblePanel>
242
) : null}
211
- </div>
243
+ </Collapsible>
244
</DialogPanel>
245
<DialogFooter>
246
<Button type="button" variant="ghost" disabled={busy} onClick={onClose}>
apps/web/src/components/settings/DeviceHostsSettings.tsx
+368
-137
@@ -1,4 +1,8 @@
1
import { DeviceToolVersions } from "../device/DeviceToolVersions";
2
+import { DeviceHostAvailability } from "../device/DeviceHostAvailability";
3
+import { useAtomValue } from "@effect/atom-react";
4
+import * as Option from "effect/Option";
5
+import { AsyncResult, Atom } from "effect/reactivity";
6
import { AuthSettingsWriteScope } from "@t3tools/contracts";
7
import { readEnvironmentScope, useEnvironmentScope } from "../../state/session";
8
import { Tooltip, TooltipTrigger, TooltipPopup } from "../ui/tooltip";
@@ -6,21 +10,36 @@ import { AppleIcon, AndroidIcon } from "../Icons";
10
import { Spinner } from "../ui/spinner";
11
import type { EnvironmentId, SshDeviceHostConfig } from "@t3tools/contracts";
12
import { randomUUID } from "../../lib/utils";
9
-import { useState } from "react";
10
-import { deviceEnvironment, useDeviceState } from "../../state/device";
13
+import { useMemo, useState } from "react";
14
+import { deviceEnvironment } from "../../state/device";
15
import { serverEnvironment } from "../../state/server";
16
import { useAtomCommand } from "../../state/use-atom-command";
13
-import { Button } from "../ui/button";
14
-import { MoreVertical, PlusIcon } from "lucide-react";
17
+import { Button, InlineButton } from "../ui/button";
18
+import {
19
+ CheckIcon,
20
+ ChevronDownIcon,
21
+ CircleIcon,
22
+ MoreVertical,
23
+ PlusIcon,
24
+ TriangleAlertIcon,
25
+} from "lucide-react";
26
+import { Collapsible, CollapsiblePanel, CollapsibleTrigger } from "../ui/collapsible";
27
import { Menu, MenuTrigger, MenuPopup, MenuItem } from "../ui/menu";
28
import { SettingsRow } from "./settingsLayout";
29
30
import { useSettingsScope } from "./SettingsScopeContext";
31
import { toastManager } from "../ui/toast";
20
-import { updateDeviceHosts } from "./deviceHostsSettings.logic";
32
+import {
33
+ groupDeviceHosts,
34
+ updateDeviceHosts,
35
+ type DeviceHostEnvironment,
36
+ type DeviceHostGroup,
37
+} from "./deviceHostsSettings.logic";
38
+import { FoldedSettingsSection } from "./FoldedSettingsSection";
39
import { DeviceHostEditor } from "./DeviceHostEditor";
40
import { useHostConnectionChecks } from "./useHostConnectionChecks";
41
import { deviceHostConnectionKey } from "./deviceHostConnectionChecks";
42
+import { settingsScopeEnvironmentLabel, settingsScopeEnvironmentLabels } from "./settingsScopeAxis";
43
44
export function DeviceHostsSettings(props: { environmentId: EnvironmentId | null }) {
45
const { scope, environments, connectedEnvironments } = useSettingsScope();
@@ -32,10 +51,21 @@ export function DeviceHostsSettings(props: { environmentId: EnvironmentId | null
51
const [busy, setBusy] = useState(false);
52
const targets = environments.map((environment) => ({
53
environmentId: environment.environmentId,
35
- label: environment.label,
54
+ label: settingsScopeEnvironmentLabel(environment, environments),
55
connected: environment.connection.phase === "connected",
56
}));
57
const { checks, testConnection } = useHostConnectionChecks(targets);
58
+ const hostEnvironments = useMemo(
59
+ () =>
60
+ connectedEnvironments.map((environment) => ({
61
+ environmentId: environment.environmentId,
62
+ label: environment.label,
63
+ labels: settingsScopeEnvironmentLabels(environment, connectedEnvironments),
64
+ hosts: environment.serverConfig?.settings.deviceHosts ?? [],
65
+ })),
66
+ [connectedEnvironments],
67
+ );
68
+ const groupedHosts = useMemo(() => groupDeviceHosts(hostEnvironments), [hostEnvironments]);
69
const save = async (host: SshDeviceHostConfig, remove = false, original = host) => {
70
if (!props.environmentId || projectScope) return;
71
setBusy(true);
@@ -80,6 +110,30 @@ export function DeviceHostsSettings(props: { environmentId: EnvironmentId | null
110
setBusy(false);
111
}
112
};
113
+ const listActions = {
114
+ busy: !canConfigure || projectScope || busy,
115
+ checks,
116
+ testConnection: async (host: SshDeviceHostConfig) => {
117
+ const results = await testConnection(host);
118
+ if (!results) return;
119
+ const failed = targets.filter((target) => results[target.environmentId]?.status === "failed");
120
+ toastManager.add({
121
+ type: failed.length ? "error" : "success",
122
+ title: failed.length
123
+ ? `${host.label}: ${failed.length} of ${targets.length} environments failed`
124
+ : `${host.label}: connection checks passed`,
125
+ description: failed.length
126
+ ? `Could not connect from ${failed.map((target) => target.label).join(", ")}.`
127
+ : "Connected or already available locally on each selected environment.",
128
+ });
129
+ return results;
130
+ },
131
+ onEdit: (host: SshDeviceHostConfig) => {
132
+ setOriginalHost(host);
133
+ setEditing(host);
134
+ },
135
+ onRemove: (host: SshDeviceHostConfig) => void save(host, true),
136
+ };
137
return (
138
<SettingsRow
139
id="device-hosts"
@@ -110,44 +164,43 @@ export function DeviceHostsSettings(props: { environmentId: EnvironmentId | null
164
</p>
165
) : (
166
<>
113
- {connectedEnvironments.map((environment) => (
114
- <div key={environment.environmentId}>
115
- {connectedEnvironments.length > 1 ? (
116
- <p className="pt-3 pb-1 text-xs font-medium text-muted-foreground">
117
- {environment.label}
118
- </p>
119
- ) : null}
120
- <DeviceHostList
121
- environmentLabel={environment.label}
122
- environmentId={environment.environmentId}
123
- hosts={environment.serverConfig?.settings.deviceHosts ?? []}
124
- busy={!canConfigure || projectScope || busy}
125
- checks={checks}
126
- testConnection={async (host) => {
127
- const results = await testConnection(host);
128
- if (!results) return;
129
- const failed = targets.filter(
130
- (target) => results[target.environmentId]?.status === "failed",
131
- );
132
- toastManager.add({
133
- type: failed.length ? "error" : "success",
134
- title: failed.length
135
- ? `${host.label}: ${failed.length} of ${targets.length} environments failed`
136
- : `${host.label}: connection checks passed`,
137
- description: failed.length
138
- ? `Could not connect from ${failed.map((target) => target.label).join(", ")}.`
139
- : "Connected or already available locally on each selected environment.",
140
- });
141
- return results;
142
- }}
143
- onEdit={(host) => {
144
- setOriginalHost(host);
145
- setEditing(host);
146
- }}
147
- onRemove={(host) => void save(host, true)}
148
- />
167
+ {hostEnvironments.length > 1 && groupedHosts === null ? (
168
+ <div className="space-y-2">
169
+ {hostEnvironments.map((environment) => (
170
+ <FoldedSettingsSection
171
+ key={environment.environmentId}
172
+ id={`device-hosts-${environment.environmentId}`}
173
+ title={
174
+ <>
175
+ <span className="block max-w-64 truncate">
176
+ {environment.labels.primary}
177
+ </span>
178
+ {environment.labels.secondary ? (
179
+ <span className="block max-w-64 truncate text-xs font-normal text-muted-foreground">
180
+ {environment.labels.secondary}
181
+ </span>
182
+ ) : null}
183
+ </>
184
+ }
185
+ summary={
186
+ summarizeLabels(environment.hosts.map((host) => host.label)) ||
187
+ "No device hosts"
188
+ }
189
+ >
190
+ <div className="px-3 sm:px-4 [&>div:first-child]:border-t-0">
191
+ <DeviceHostList environments={[environment]} {...listActions} />
192
+ </div>
193
+ </FoldedSettingsSection>
194
+ ))}
195
</div>
150
- ))}
196
+ ) : (
197
+ <DeviceHostList
198
+ environments={hostEnvironments}
199
+ groups={groupedHosts ?? undefined}
200
+ compact={hostEnvironments.length > 1}
201
+ {...listActions}
202
+ />
203
+ )}
204
{editing ? (
205
<DeviceHostEditor
206
key={editing.id}
@@ -167,39 +220,112 @@ export function DeviceHostsSettings(props: { environmentId: EnvironmentId | null
220
}
221
222
function DeviceHostList({
170
- environmentLabel,
171
- environmentId,
172
- hosts,
223
+ environments,
224
+ groups,
225
+ compact = false,
226
busy,
227
onEdit,
228
onRemove,
229
checks,
230
testConnection,
231
}: {
179
- environmentLabel: string;
180
- environmentId: EnvironmentId;
181
- hosts: ReadonlyArray<SshDeviceHostConfig>;
232
+ environments: ReadonlyArray<DeviceHostEnvironment>;
233
+ groups?: ReadonlyArray<DeviceHostGroup> | undefined;
234
+ compact?: boolean;
235
busy: boolean;
236
onEdit: (host: SshDeviceHostConfig) => void;
237
onRemove: (host: SshDeviceHostConfig) => void;
238
checks: ReturnType<typeof useHostConnectionChecks>["checks"];
239
testConnection: ReturnType<typeof useHostConnectionChecks>["testConnection"];
240
}) {
188
- const { state } = useDeviceState(environmentId);
241
+ const { environments: scopeEnvironments } = useSettingsScope();
242
+ const environmentLabels = new Map(
243
+ scopeEnvironments.map((environment) => [
244
+ environment.environmentId,
245
+ settingsScopeEnvironmentLabels(environment, scopeEnvironments),
246
+ ]),
247
+ );
248
+ const states = useAtomValue(
249
+ useMemo(
250
+ () =>
251
+ Atom.make(
252
+ (get) =>
253
+ new Map(
254
+ environments.map(({ environmentId }) => {
255
+ const result = get(deviceEnvironment.state({ environmentId, input: {} }));
256
+ return [environmentId, Option.getOrUndefined(AsyncResult.value(result))] as const;
257
+ }),
258
+ ),
259
+ ),
260
+ [environments],
261
+ ),
262
+ );
263
const retry = useAtomCommand(deviceEnvironment.list);
264
const [retrying, setRetrying] = useState<string | null>(null);
265
+ const retryHost = (environmentId: EnvironmentId, hostId: string, key = hostId) => {
266
+ setRetrying(key);
267
+ void retry({ environmentId, input: { retryHostId: hostId } }).finally(() => setRetrying(null));
268
+ };
269
+ const rows =
270
+ groups ??
271
+ environments.flatMap((environment) =>
272
+ environment.hosts.map((host) => ({
273
+ host,
274
+ members: [{ environmentId: environment.environmentId, label: environment.label, host }],
275
+ })),
276
+ );
277
return (
278
<>
193
- {hosts.length === 0 ? (
279
+ {rows.length === 0 ? (
280
<p className="py-2 text-sm text-muted-foreground">No device hosts.</p>
281
) : null}
196
- {hosts.map((host) => {
197
- const status = state.hostStatuses[host.id];
198
- const check = checks[deviceHostConnectionKey(host)]?.[environmentId];
282
+ {rows.map(({ host, members }) => {
283
+ const hostChecks = checks[deviceHostConnectionKey(host)];
284
+ const checkedMembers = scopeEnvironments.flatMap((environment) =>
285
+ hostChecks?.[environment.environmentId] &&
286
+ !members.some((member) => member.environmentId === environment.environmentId)
287
+ ? [{ environmentId: environment.environmentId, label: environment.label, host }]
288
+ : [],
289
+ );
290
+ const results = [...members, ...checkedMembers].map((member) => {
291
+ const state = states.get(member.environmentId);
292
+ const status = state?.hostStatuses[member.host.id];
293
+ const check = hostChecks?.[member.environmentId];
294
+ const summary = state?.hosts.find((value) => value.id === member.host.id);
295
+ const label = environmentLabels.get(member.environmentId)?.primary ?? member.label;
296
+ const address = environmentLabels.get(member.environmentId)?.secondary;
297
+ const error =
298
+ check?.status === "failed"
299
+ ? check.error
300
+ : check?.status === "local"
301
+ ? undefined
302
+ : status?.status === "failed"
303
+ ? status.detail
304
+ : undefined;
305
+ return {
306
+ ...member,
307
+ label,
308
+ address,
309
+ name: [label, address].filter(Boolean).join(" · "),
310
+ state,
311
+ status,
312
+ check,
313
+ summary,
314
+ error,
315
+ versions: (
316
+ <DeviceToolVersions
317
+ owner={label}
318
+ error={summary?.toolInspectionError}
319
+ tools={summary?.tools ?? (check?.status === "connected" ? check.tools : undefined)}
320
+ />
321
+ ),
322
+ };
323
+ });
324
+ const first = results[0];
325
+ if (!first) return null;
326
+ const { environmentId, status, check, summary, error } = first;
327
const platforms =
200
- (check?.status === "connected" ? check.platforms : undefined) ??
201
- state.hosts.find((value) => value.id === host.id)?.platforms ??
202
- [];
328
+ (check?.status === "connected" ? check.platforms : undefined) ?? summary?.platforms ?? [];
329
const progress =
330
check?.status === "pending"
331
? "Checking connection…"
@@ -208,61 +334,166 @@ function DeviceHostList({
334
: status?.status === "starting"
335
? "Connecting…"
336
: null;
211
- const error =
212
- check?.status === "failed"
213
- ? check.error
214
- : check?.status === "local"
215
- ? undefined
216
- : status?.status === "failed"
217
- ? status.detail
218
- : undefined;
337
+ const failed = results.filter(
338
+ (result) =>
339
+ result.check?.status === "failed" ||
340
+ (result.check?.status !== "local" && result.status?.status === "failed"),
341
+ );
342
+ const pending = results.some(
343
+ (result) =>
344
+ result.check?.status === "pending" ||
345
+ result.status?.status === "installing" ||
346
+ result.status?.status === "starting",
347
+ );
348
+ const ready = results.every(
349
+ (result) =>
350
+ result.check?.status === "connected" ||
351
+ result.check?.status === "local" ||
352
+ result.status?.status === "ready",
353
+ );
354
+ const retryable = results.filter(
355
+ (result) =>
356
+ result.status?.status === "failed" &&
357
+ result.state?.supportsHostRetry &&
358
+ result.state.hostStatus !== "disabled",
359
+ );
360
+ const canRetry = !compact && retryable.includes(first);
361
+ const indicators = compact
362
+ ? [
363
+ {
364
+ key: "connection",
365
+ label: failed.length
366
+ ? "Connection failed"
367
+ : pending
368
+ ? "Checking connections"
369
+ : ready
370
+ ? "Connected"
371
+ : "Connection not checked",
372
+ warning: failed.length > 0,
373
+ icon: failed.length ? (
374
+ <TriangleAlertIcon className="size-3.5" />
375
+ ) : pending ? (
376
+ <Spinner size="xs" />
377
+ ) : ready ? (
378
+ <CheckIcon className="size-3.5" />
379
+ ) : (
380
+ <CircleIcon className="size-3.5" />
381
+ ),
382
+ detail: failed.length ? (
383
+ <div className="space-y-1">
384
+ {failed.map((result) => (
385
+ <p key={result.environmentId}>
386
+ {result.name}: {result.error || "Connection failed"}
387
+ </p>
388
+ ))}
389
+ </div>
390
+ ) : pending ? (
391
+ "Checking connections…"
392
+ ) : ready ? (
393
+ "Connected or available locally on each listed machine"
394
+ ) : (
395
+ "Test the connection to check access from each machine"
396
+ ),
397
+ },
398
+ ]
399
+ : platforms
400
+ .filter((platform) => platform.available)
401
+ .map((platform) => ({
402
+ key: platform.platform,
403
+ label: platform.platform === "ios" ? "iOS available" : "Android available",
404
+ warning: false,
405
+ icon:
406
+ platform.platform === "ios" ? (
407
+ // The Apple mark is bottom-heavy; lift it so it does not dip under the label.
408
+ <AppleIcon className="size-3.5 -translate-y-px" />
409
+ ) : (
410
+ <AndroidIcon className="size-3.5" />
411
+ ),
412
+ }));
413
return (
414
<div key={host.id} className="flex items-center gap-2 border-t border-border/50 py-2.5">
415
<div className="min-w-0 flex-1">
416
<div className="flex min-w-0 items-center gap-2">
417
<p className="truncate text-sm font-medium">{host.label}</p>
224
- {platforms
225
- .filter((platform) => platform.available)
226
- .map((platform) => (
227
- <Tooltip key={platform.platform}>
228
- <TooltipTrigger
229
- render={
230
- <span
231
- tabIndex={0}
232
- role="img"
233
- aria-label={
234
- platform.platform === "ios" ? "iOS available" : "Android available"
235
- }
236
- className="shrink-0 text-muted-foreground"
237
- />
238
- }
239
- >
240
- {platform.platform === "ios" ? (
241
- // The Apple mark is bottom-heavy; lift it so it does not dip under the label.
242
- <AppleIcon className="size-3.5 -translate-y-px" />
243
- ) : (
244
- <AndroidIcon className="size-3.5" />
245
- )}
246
- </TooltipTrigger>
247
- <TooltipPopup>
248
- {platform.platform === "ios" ? "iOS available" : "Android available"}
249
- </TooltipPopup>
250
- </Tooltip>
251
- ))}
418
+ {indicators.map((indicator) => (
419
+ <Tooltip key={indicator.key}>
420
+ <TooltipTrigger
421
+ render={
422
+ <span
423
+ tabIndex={0}
424
+ role="img"
425
+ aria-label={indicator.label}
426
+ className={
427
+ indicator.warning
428
+ ? "shrink-0 text-warning"
429
+ : "shrink-0 text-muted-foreground"
430
+ }
431
+ />
432
+ }
433
+ >
434
+ {indicator.icon}
435
+ </TooltipTrigger>
436
+ <TooltipPopup>
437
+ {"detail" in indicator ? indicator.detail : indicator.label}
438
+ </TooltipPopup>
439
+ </Tooltip>
440
+ ))}
441
</div>
442
<p className="truncate text-xs text-muted-foreground">{host.target}</p>
254
- <DeviceToolVersions
255
- owner={environmentLabel}
256
- error={state.hosts.find((value) => value.id === host.id)?.toolInspectionError}
257
- tools={
258
- state.hosts.find((value) => value.id === host.id)?.tools ??
259
- (check?.status === "connected" ? check.tools : undefined)
260
- }
261
- />
262
- {check?.status === "local" ? (
443
+ {compact ? (
444
+ <Collapsible>
445
+ <div className="min-w-0 text-xs [--inline-button-white-space:normal]">
446
+ <CollapsibleTrigger
447
+ aria-label={`${host.label} machine details`}
448
+ render={<InlineButton tone="muted" />}
449
+ >
450
+ <span className="line-clamp-1 break-all text-left">
451
+ {summarizeLabels(results.map((result) => result.name))}
452
+ </span>
453
+ <ChevronDownIcon className="size-3 shrink-0" />
454
+ </CollapsibleTrigger>
455
+ </div>
456
+ <CollapsiblePanel>
457
+ <div className="mt-2 space-y-2">
458
+ {results.map((result) => (
459
+ <div key={result.environmentId}>
460
+ <p className="text-xs text-muted-foreground">{result.label}</p>
461
+ {result.address ? (
462
+ <p className="truncate text-xs text-muted-foreground">
463
+ {result.address}
464
+ </p>
465
+ ) : null}
466
+ {result.error ? (
467
+ <p role="status" className="text-xs text-destructive">
468
+ {result.error}
469
+ </p>
470
+ ) : null}
471
+ {result.versions}
472
+ {result.check?.status === "local" ? (
473
+ <p className="text-xs text-muted-foreground">
474
+ Already available locally
475
+ </p>
476
+ ) : (
477
+ <DeviceHostAvailability
478
+ platforms={
479
+ (result.check?.status === "connected"
480
+ ? result.check.platforms
481
+ : result.summary?.platforms) ?? []
482
+ }
483
+ />
484
+ )}
485
+ </div>
486
+ ))}
487
+ </div>
488
+ </CollapsiblePanel>
489
+ </Collapsible>
490
+ ) : (
491
+ first.versions
492
+ )}
493
+ {!compact && check?.status === "local" ? (
494
<p className="mt-1 text-xs text-muted-foreground">Already available locally</p>
495
) : null}
265
- {error ? (
496
+ {!compact && error ? (
497
<div className="mt-1" role="status">
498
<details className="text-xs text-destructive">
499
<summary>Connection failed</summary>
@@ -271,7 +502,7 @@ function DeviceHostList({
502
</div>
503
) : null}
504
</div>
274
- {progress ? (
505
+ {!compact && progress ? (
506
<span
507
role="status"
508
className="inline-flex items-center gap-1.5 text-xs text-muted-foreground"
@@ -294,47 +525,47 @@ function DeviceHostList({
525
<MoreVertical />
526
</MenuTrigger>
527
<MenuPopup align="end">
297
- <MenuItem
298
- onClick={() => {
299
- onEdit(host);
300
- }}
301
- >
302
- Edit
303
- </MenuItem>
528
+ <MenuItem onClick={() => onEdit(host)}>Edit</MenuItem>
529
<MenuItem variant="destructive" onClick={() => onRemove(host)}>
530
Remove
531
</MenuItem>
532
+ {compact
533
+ ? retryable.map((result) => (
534
+ <MenuItem
535
+ key={result.environmentId}
536
+ disabled={retrying !== null}
537
+ onClick={() =>
538
+ retryHost(result.environmentId, result.host.id, result.environmentId)
539
+ }
540
+ >
541
+ {retrying === result.environmentId ? "Retrying" : "Retry"} from{" "}
542
+ {result.label}
543
+ {result.address ? ` (${result.address})` : null}
544
+ </MenuItem>
545
+ ))
546
+ : null}
547
</MenuPopup>
548
</Menu>
309
- {status?.status === "failed" &&
310
- state.supportsHostRetry &&
311
- state.hostStatus !== "disabled" ? (
312
- <Button
313
- size="sm"
314
- variant="outline"
315
- disabled={busy || retrying !== null}
316
- onClick={() => {
317
- setRetrying(host.id);
318
- void retry({ environmentId, input: { retryHostId: host.id } }).finally(() =>
319
- setRetrying(null),
320
- );
321
- }}
322
- >
323
- {retrying === host.id ? "Retrying…" : "Retry"}
324
- </Button>
325
- ) : (
326
- <Button
327
- size="sm"
328
- variant="outline"
329
- disabled={busy || progress !== null}
330
- onClick={() => void testConnection(host)}
331
- >
332
- Test connection
333
- </Button>
334
- )}
549
+ <Button
550
+ size="sm"
551
+ variant="outline"
552
+ disabled={
553
+ busy || (canRetry ? retrying !== null : compact ? pending : progress !== null)
554
+ }
555
+ onClick={() => {
556
+ if (canRetry) retryHost(environmentId, host.id);
557
+ else void testConnection(host);
558
+ }}
559
+ >
560
+ {canRetry ? (retrying === host.id ? "Retrying…" : "Retry") : "Test connection"}
561
+ </Button>
562
</div>
563
);
564
})}
565
</>
566
);
567
}
568
+
569
+function summarizeLabels(labels: ReadonlyArray<string>) {
570
+ return `${labels.slice(0, 2).join(", ")}${labels.length > 2 ? ` +${labels.length - 2}` : ""}`;
571
+}
apps/web/src/components/settings/FoldedSettingsSection.tsx
+1
-1
@@ -20,7 +20,7 @@ export function FoldedSettingsSection({
20
children,
21
}: {
22
readonly id: string;
23
- readonly title: string;
23
+ readonly title: ReactNode;
24
readonly summary?: string | null;
25
readonly control?: ReactNode;
26
readonly headerPlacement?: "inside" | "outside";
apps/web/src/components/settings/ProjectSettingsPanel.tsx
+82
-18
@@ -32,6 +32,7 @@ import { Alert, AlertDescription } from "../ui/alert";
32
import { Button } from "../ui/button";
33
import { Input } from "../ui/input";
34
import { stackedThreadToast, toastManager } from "../ui/toast";
35
+import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";
36
import {
37
SettingResetButton,
38
SettingsPageContainer,
@@ -46,6 +47,7 @@ import { ProjectActionsSettings } from "./ProjectActionsSettings";
47
import { ProjectDefaultsSettings } from "./ProjectDefaultsSettings";
48
import { projectGroupTitleNeedsUpdate } from "./ProjectSettingsPanel.logic";
49
import { useSettingsProjectGroups } from "./useSettingsProjectGroups";
50
+import { settingsScopeEnvironmentLabels } from "./settingsScopeAxis";
51
52
const ProjectIconPickerDialog = lazy(() =>
53
import("./ProjectIconPickerDialog").then((module) => ({
@@ -423,26 +425,88 @@ function ProjectDetail({
425
],
426
);
427
428
+ const checkoutsByEnvironment = new Map<EnvironmentId, SidebarProjectGroupMember[]>();
429
+ for (const member of group.memberProjects) {
430
+ const members = checkoutsByEnvironment.get(member.environmentId);
431
+ if (members) members.push(member);
432
+ else checkoutsByEnvironment.set(member.environmentId, [member]);
433
+ }
434
+ const checkoutRemoveButton = (member: SidebarProjectGroupMember) => (
435
+ <Button
436
+ size="sm"
437
+ variant="outline"
438
+ disabled={!editableIds.has(member.environmentId)}
439
+ onClick={() => void removeMembers([member])}
440
+ aria-label={`Remove checkout ${member.workspaceRoot}`}
441
+ >
442
+ Remove
443
+ </Button>
444
+ );
445
const checkoutChoices = (
446
<SettingsSection title="Checkouts">
428
- {group.memberProjects.map((member) => (
429
- <SettingsRow
430
- key={member.physicalProjectKey}
431
- title={member.environmentLabel ?? "Environment"}
432
- description={member.workspaceRoot}
433
- control={
434
- <Button
435
- size="sm"
436
- variant="outline"
437
- disabled={!editableIds.has(member.environmentId)}
438
- onClick={() => void removeMembers([member])}
439
- aria-label={`Remove checkout ${member.workspaceRoot}`}
440
- >
441
- Remove
442
- </Button>
443
- }
444
- />
445
- ))}
447
+ {Array.from(checkoutsByEnvironment, ([environmentId, members]) => {
448
+ if (checkoutsByEnvironment.size === 1) {
449
+ return members.map((member) => (
450
+ <SettingsRow
451
+ key={member.physicalProjectKey}
452
+ title={member.environmentLabel ?? "Environment"}
453
+ description={member.workspaceRoot}
454
+ control={checkoutRemoveButton(member)}
455
+ />
456
+ ));
457
+ }
458
+ const firstMember = members[0]!;
459
+ const hasMultiple = members.length > 1;
460
+ const environment = environmentById.get(environmentId);
461
+ const labels = environment
462
+ ? settingsScopeEnvironmentLabels(environment, environments)
463
+ : { primary: firstMember.environmentLabel ?? "Environment", secondary: environmentId };
464
+ return (
465
+ <SettingsRow
466
+ key={environmentId}
467
+ title={labels.primary}
468
+ description={
469
+ <>
470
+ {labels.secondary ? (
471
+ <span className="block truncate">{labels.secondary}</span>
472
+ ) : null}
473
+ {!hasMultiple ? (
474
+ <Tooltip>
475
+ <TooltipTrigger render={<span className="block truncate" />}>
476
+ {firstMember.workspaceRoot}
477
+ </TooltipTrigger>
478
+ <TooltipPopup>{firstMember.workspaceRoot}</TooltipPopup>
479
+ </Tooltip>
480
+ ) : null}
481
+ </>
482
+ }
483
+ control={hasMultiple ? undefined : checkoutRemoveButton(firstMember)}
484
+ >
485
+ {hasMultiple ? (
486
+ <div className="space-y-3 pb-2 pt-1">
487
+ {members.map((member) => (
488
+ <div
489
+ key={member.physicalProjectKey}
490
+ className="flex min-w-0 items-center justify-between gap-3"
491
+ >
492
+ <Tooltip>
493
+ <TooltipTrigger
494
+ render={
495
+ <span className="min-w-0 truncate text-xs text-muted-foreground/80" />
496
+ }
497
+ >
498
+ {member.workspaceRoot}
499
+ </TooltipTrigger>
500
+ <TooltipPopup>{member.workspaceRoot}</TooltipPopup>
501
+ </Tooltip>
502
+ <div className="shrink-0">{checkoutRemoveButton(member)}</div>
503
+ </div>
504
+ ))}
505
+ </div>
506
+ ) : null}
507
+ </SettingsRow>
508
+ );
509
+ })}
510
</SettingsSection>
511
);
512
apps/web/src/components/settings/ScheduledTasksSettings.tsx
+203
-12
@@ -1,4 +1,7 @@
1
import { useAtomValue } from "@effect/atom-react";
2
+import { connectionStatusTitle } from "@t3tools/client-runtime/connection";
3
+import * as Option from "effect/Option";
4
+import { AsyncResult, Atom } from "effect/reactivity";
5
import {
6
Clock3Icon,
7
CopyIcon,
@@ -54,14 +57,18 @@ import {
57
type EnvironmentPresentation,
58
} from "../../state/environments";
59
import { useProjects } from "../../state/entities";
57
-import { useEnvironmentQuery } from "../../state/query";
60
+import { formatEnvironmentQueryError, useEnvironmentQuery } from "../../state/query";
61
import { EMPTY_SERVER_PROVIDERS, serverEnvironment } from "../../state/server";
62
import { useAtomCommand } from "../../state/use-atom-command";
63
import { WorktreeBaseBranchPicker } from "../WorktreeBaseBranchPicker";
64
import { EnvironmentMachineIcon } from "../EnvironmentMachineIcon";
65
+import { ConnectionStatusDot, connectionPhaseDotClassName } from "../ConnectionStatusDot";
66
import { AuthOrchestrationOperateScope } from "@t3tools/contracts";
67
import { readEnvironmentScope } from "~/state/session";
68
import { useSettingsScope } from "./SettingsScopeContext";
69
+import { EnvironmentRow, environmentTransportLabel } from "./EnvironmentRow";
70
+import { SettingsGroup } from "./SettingsGroup";
71
+import { settingsScopeEnvironmentLabel, settingsScopeEnvironmentLabels } from "./settingsScopeAxis";
72
import {
73
WEBHOOK_SIGNATURE_DEFAULTS,
74
matchesScheduledTaskScope,
@@ -94,6 +101,7 @@ import { Select, SelectItem, SelectPopup, SelectTrigger, SelectValue } from "../
101
import { Switch } from "../ui/switch";
102
import { Textarea } from "../ui/textarea";
103
import { stackedThreadToast, toastManager } from "../ui/toast";
104
+import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";
105
import {
106
SettingsPageContainer,
107
SettingsRow,
@@ -285,6 +293,13 @@ export function ScheduledTasksSettings(target: {
293
<EmptyDescription>Connect an environment to manage scheduled tasks.</EmptyDescription>
294
</EmptyHeader>
295
</Empty>
296
+ ) : environments.length > 1 ? (
297
+ <ScheduledTaskEnvironmentList
298
+ key={`${target.environmentId ?? defaultEnvironment?.environmentId}:${target.taskId ?? ""}`}
299
+ environmentId={target.environmentId ?? defaultEnvironment?.environmentId}
300
+ taskId={target.taskId}
301
+ onEdit={openForEdit}
302
+ />
303
) : (
304
<div className="space-y-8">
305
{environments.map((entry) => (
@@ -316,6 +331,153 @@ export function ScheduledTasksSettings(target: {
331
);
332
}
333
334
+function ScheduledTaskEnvironmentList({
335
+ environmentId,
336
+ taskId,
337
+ onEdit,
338
+}: {
339
+ readonly environmentId: EnvironmentId | undefined;
340
+ readonly taskId: ScheduledTaskId | undefined;
341
+ readonly onEdit: (environmentId: EnvironmentId, task: ScheduledTask) => void;
342
+}) {
343
+ const { scope, environments } = useSettingsScope();
344
+ const states = useAtomValue(
345
+ useMemo(
346
+ () =>
347
+ Atom.make((get) =>
348
+ environments.map((environment) => {
349
+ const connected =
350
+ environment.connection.phase === "connected" && environment.serverConfig !== null;
351
+ const query = connected
352
+ ? get(
353
+ serverEnvironment.scheduledTasksLive({
354
+ environmentId: environment.environmentId,
355
+ input: {},
356
+ }),
357
+ )
358
+ : null;
359
+ const data = query === null ? null : Option.getOrNull(AsyncResult.value(query));
360
+ return {
361
+ environment,
362
+ connected,
363
+ tasks: data?.tasks.filter((task) =>
364
+ matchesScheduledTaskScope(scope, environment.environmentId, task.projectId),
365
+ ),
366
+ error: query?._tag === "Failure" ? formatEnvironmentQueryError(query.cause) : null,
367
+ };
368
+ }),
369
+ ),
370
+ [environments, scope],
371
+ ),
372
+ );
373
+ const linkedState = states.find((state) => state.environment.environmentId === environmentId);
374
+ const linkedTask = linkedState?.tasks?.find((task) => task.id === taskId);
375
+ const openedLink = useRef(false);
376
+ useEffect(() => {
377
+ if (!openedLink.current && environmentId && linkedTask) {
378
+ openedLink.current = true;
379
+ onEdit(environmentId, linkedTask);
380
+ }
381
+ }, [environmentId, linkedTask, onEdit]);
382
+ useRelativeTimeTick(60_000);
383
+
384
+ const loaded = states.filter((state) => state.connected && state.error === null && state.tasks);
385
+ const populated = loaded.filter((state) => state.tasks && state.tasks.length > 0);
386
+ const summaries: Record<string, string[]> = {
387
+ "Not connected:": [],
388
+ "Loading scheduled tasks on": [],
389
+ "Could not load scheduled tasks:": [],
390
+ "No tasks on": [],
391
+ };
392
+ for (const { environment, connected, tasks, error } of states) {
393
+ const label = settingsScopeEnvironmentLabel(environment, environments);
394
+ if (!connected) {
395
+ summaries["Not connected:"]!.push(
396
+ `${label} (${connectionStatusTitle(environment.connection)})`,
397
+ );
398
+ } else if (error !== null) {
399
+ summaries["Could not load scheduled tasks:"]!.push(`${label}: ${error}`);
400
+ } else if (!tasks) {
401
+ summaries["Loading scheduled tasks on"]!.push(label);
402
+ } else if (tasks.length === 0 && populated.length > 0) {
403
+ summaries["No tasks on"]!.push(label);
404
+ }
405
+ }
406
+
407
+ return (
408
+ <SettingsGroup>
409
+ {populated.map(({ environment, tasks }) => {
410
+ const { primary, secondary } = settingsScopeEnvironmentLabels(environment, environments);
411
+ const transport = environmentTransportLabel(environment);
412
+ return (
413
+ <div key={environment.environmentId} className="divide-y divide-border/50">
414
+ <EnvironmentRow
415
+ kind={resolveEnvironmentMachineKind(environment.serverConfig)}
416
+ label={primary}
417
+ subtitle={
418
+ <>
419
+ {secondary && secondary !== transport ? (
420
+ <span className="block truncate">{secondary}</span>
421
+ ) : null}
422
+ <span className="block truncate">{transport}</span>
423
+ </>
424
+ }
425
+ >
426
+ <ConnectionStatusDot
427
+ dotClassName={connectionPhaseDotClassName(environment.connection.phase)}
428
+ tooltipText={connectionStatusTitle(environment.connection)}
429
+ />
430
+ <span className="text-xs text-muted-foreground">
431
+ {connectionStatusTitle(environment.connection)}
432
+ </span>
433
+ </EnvironmentRow>
434
+ {tasks?.map((task) => (
435
+ <ScheduledTaskRow
436
+ key={task.id}
437
+ environmentId={environment.environmentId}
438
+ task={task}
439
+ onEdit={() => onEdit(environment.environmentId, task)}
440
+ />
441
+ ))}
442
+ </div>
443
+ );
444
+ })}
445
+ {taskId && linkedState?.tasks && linkedState.error === null && !linkedTask ? (
446
+ <SettingsRow
447
+ title="Task unavailable"
448
+ description="This task no longer exists or is outside the selected project scope."
449
+ role="status"
450
+ />
451
+ ) : null}
452
+ {populated.length === 0 && loaded.length > 0 ? (
453
+ <SettingsRow
454
+ title="No scheduled tasks"
455
+ description="No tasks match this environment and project selection."
456
+ />
457
+ ) : null}
458
+ {Object.entries(summaries).map(([label, entries]) => {
459
+ if (entries.length === 0) return null;
460
+ const summary = `${label} ${entries.join(", ")}`;
461
+ return (
462
+ <Tooltip key={label}>
463
+ <TooltipTrigger
464
+ render={
465
+ <p
466
+ className="truncate px-3 py-2.5 text-xs text-muted-foreground sm:px-4"
467
+ role="status"
468
+ />
469
+ }
470
+ >
471
+ {summary}
472
+ </TooltipTrigger>
473
+ <TooltipPopup>{summary}</TooltipPopup>
474
+ </Tooltip>
475
+ );
476
+ })}
477
+ </SettingsGroup>
478
+ );
479
+}
480
+
481
function ScheduledTaskEnvironmentSection({
482
environment,
483
showEnvironmentHeading,
@@ -1009,15 +1171,34 @@ function ScheduledTaskEditorDialog({
1171
</SelectValue>
1172
</SelectTrigger>
1173
<SelectPopup>
1012
- {connectedEnvironments.map((entry) => (
1013
- <SelectItem key={entry.environmentId} value={entry.environmentId}>
1014
- <EnvironmentMachineIcon
1015
- kind={resolveEnvironmentMachineKind(entry.serverConfig)}
1016
- className="size-4"
1017
- />
1018
- {entry.label}
1019
- </SelectItem>
1020
- ))}
1174
+ {connectedEnvironments.map((entry) => {
1175
+ const { secondary } = settingsScopeEnvironmentLabels(
1176
+ entry,
1177
+ connectedEnvironments,
1178
+ );
1179
+ return (
1180
+ <SelectItem
1181
+ key={entry.environmentId}
1182
+ value={entry.environmentId}
1183
+ label={entry.label}
1184
+ >
1185
+ <span className="flex min-w-0 items-center gap-2">
1186
+ <EnvironmentMachineIcon
1187
+ kind={resolveEnvironmentMachineKind(entry.serverConfig)}
1188
+ className="size-4"
1189
+ />
1190
+ <span className="min-w-0">
1191
+ <span className="block truncate">{entry.label}</span>
1192
+ {secondary ? (
1193
+ <span className="block max-w-72 truncate text-xs text-muted-foreground">
1194
+ {secondary}
1195
+ </span>
1196
+ ) : null}
1197
+ </span>
1198
+ </span>
1199
+ </SelectItem>
1200
+ );
1201
+ })}
1202
</SelectPopup>
1203
</Select>
1204
</Field>
@@ -1057,8 +1238,18 @@ function ScheduledTaskEditorDialog({
1238
</SelectTrigger>
1239
<SelectPopup>
1240
{projects.map((project) => (
1060
- <SelectItem key={project.id} value={project.id}>
1061
- {project.title}
1241
+ <SelectItem key={project.id} value={project.id} label={project.title}>
1242
+ <span className="block truncate">{project.title}</span>
1243
+ {allProjects.some(
1244
+ (other) =>
1245
+ other.title === project.title &&
1246
+ (other.environmentId !== project.environmentId ||
1247
+ other.id !== project.id),
1248
+ ) ? (
1249
+ <span className="block max-w-72 truncate text-xs text-muted-foreground">
1250
+ {project.workspaceRoot}
1251
+ </span>
1252
+ ) : null}
1253
</SelectItem>
1254
))}
1255
</SelectPopup>
apps/web/src/components/settings/SettingInheritance.tsx
+188
-33
@@ -6,7 +6,7 @@ import {
6
type ServerSettings,
7
type WorktreeSubmodules,
8
} from "@t3tools/contracts";
9
-import { CheckIcon, LayersIcon } from "lucide-react";
9
+import { CheckIcon, ChevronRightIcon, LayersIcon } from "lucide-react";
10
import * as Equal from "effect/Equal";
11
12
import { cn } from "../../lib/utils";
@@ -15,10 +15,13 @@ import { EnvironmentMachineIcon } from "../EnvironmentMachineIcon";
15
import { resolveEnvModeLabel, WORKTREE_SUBMODULES_LABELS } from "../BranchToolbar.logic";
16
import { PULL_REQUEST_MERGE_METHOD_LABELS } from "../pullRequest/pullRequestDetail.logic";
17
import { Button, InlineButton } from "../ui/button";
18
+import { Collapsible, CollapsiblePanel, CollapsibleTrigger } from "../ui/collapsible";
19
import { Popover, PopoverPopup, PopoverTrigger } from "../ui/popover";
20
import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";
21
+import { useOptionalSettingsScope } from "./SettingsScopeContext";
22
import type { ProjectOverrideEntry, ScopedSettingsTarget } from "./scopedSettings";
23
import { isProjectScopedSettingKey } from "./scopedSettings";
24
+import { settingsScopeEnvironmentLabels } from "./settingsScopeAxis";
25
26
interface InheritanceLayer {
27
readonly key: "project" | "environment" | "t3.json" | "built-in";
@@ -173,14 +176,19 @@ export function SettingInheritance({
176
state: SettingInheritanceState;
177
summary: string;
178
targets: readonly ScopedSettingsTarget[];
176
- environments: readonly Pick<EnvironmentPresentation, "environmentId" | "serverConfig">[];
179
+ environments: readonly Pick<
180
+ EnvironmentPresentation,
181
+ "environmentId" | "label" | "displayUrl" | "serverConfig"
182
+ >[];
183
keys: readonly (keyof ServerSettings)[];
184
/** At environment scope: projects whose own value hides the environment's. */
185
overridingProjects?: readonly SettingOverridingProject[];
186
onClearOverrides?: (entries: readonly ProjectOverrideEntry[]) => void;
187
}) {
188
+ const scopeContext = useOptionalSettingsScope();
189
const key = keys[0];
190
if (!key || targets.length === 0) return null;
191
+ const hasMultipleEnvironments = new Set(targets.map((target) => target.environmentId)).size > 1;
192
const overrideSummary =
193
overridingProjects.length > 0
194
? `${summary} · ${overridingProjects.length} project ${overridingProjects.length === 1 ? "override" : "overrides"}`
@@ -190,15 +198,51 @@ export function SettingInheritance({
198
(candidate) => candidate.environmentId === target.environmentId,
199
);
200
if (!environment?.serverConfig) return [];
201
+ const labels = settingsScopeEnvironmentLabels(environment, environments);
202
+ const path = scopeContext?.scope.members.find(
203
+ (member) => member.environmentId === target.environmentId && member.id === target.projectId,
204
+ )?.workspaceRoot;
205
+ const secondary = [labels.secondary, path?.split(/[\\/]/).filter(Boolean).slice(-2).join("/")]
206
+ .filter(Boolean)
207
+ .join(" · ");
208
+ const layers = settingInheritanceLayers(target, environment.serverConfig.settings, key);
209
+ const winningLayer = layers.find((layer) => layer.effective);
210
return [
211
{
212
+ id: `${target.environmentId}:${target.projectId ?? ""}`,
213
target,
196
- environment: { ...environment, serverConfig: environment.serverConfig },
214
+ label: [labels.primary, secondary].filter(Boolean).join(" · "),
215
+ machineLabel: [labels.primary, labels.secondary].filter(Boolean).join(" · "),
216
+ overrides: environment.serverConfig.settings.projectSettingsOverrides,
217
machine: resolveEnvironmentMachineKind(environment.serverConfig),
198
- layers: settingInheritanceLayers(target, environment.serverConfig.settings, key),
218
+ layers,
219
+ winningLayer,
220
+ resolution: {
221
+ winner: winningLayer?.key,
222
+ layers: layers.map(({ key, value }) => [key, value]),
223
+ settings: keys.map((settingKey) => target.settings[settingKey]),
224
+ },
225
},
226
];
227
});
228
+ const primary =
229
+ chains.find(
230
+ ({ target }) =>
231
+ target.environmentId === scopeContext?.target?.environmentId &&
232
+ target.projectId === scopeContext?.target?.projectId,
233
+ ) ?? chains[0];
234
+ const machineLabelFor = (environmentId: string) =>
235
+ chains.find((entry) => entry.target.environmentId === environmentId)?.machineLabel ?? "";
236
+ const groups: (typeof chains)[] = [];
237
+ for (const chain of hasMultipleEnvironments && primary
238
+ ? [primary, ...chains.filter((entry) => entry !== primary)]
239
+ : chains) {
240
+ const group =
241
+ hasMultipleEnvironments &&
242
+ groups.find(([first]) => first && Equal.equals(first.resolution, chain.resolution));
243
+ if (group) group.push(chain);
244
+ else groups.push([chain]);
245
+ }
246
return (
247
<Popover>
248
<Tooltip>
@@ -227,15 +271,11 @@ export function SettingInheritance({
271
</Tooltip>
272
<PopoverPopup align="start" width="md" padding="none">
273
<div className="divide-y divide-border/60">
230
- {chains.map(({ target, environment, machine, layers }) => (
231
- <section
232
- key={`${target.environmentId}:${target.projectId ?? ""}`}
233
- className="px-3 py-2.5"
234
- >
235
- <h4 className="flex items-center gap-1.5 pb-1.5 text-xs font-medium text-muted-foreground">
236
- <EnvironmentMachineIcon aria-hidden kind={machine} className="size-3.5 shrink-0" />
237
- <span className="min-w-0 truncate">{target.label}</span>
238
- </h4>
274
+ {groups.map((members) => {
275
+ const first = members[0];
276
+ if (!first) return null;
277
+ const { id, target, machine, layers, winningLayer } = first;
278
+ const chain = (
279
<ol role="list" className="text-sm">
280
{layers.map((layer) => (
281
<li
@@ -273,44 +313,159 @@ export function SettingInheritance({
313
</li>
314
))}
315
</ol>
276
- {(() => {
277
- const overriding = overridingProjects.filter(
278
- (project) => project.environmentId === target.environmentId,
279
- );
280
- if (overriding.length === 0) return null;
281
- const overrides = environment.serverConfig.settings.projectSettingsOverrides;
282
- return (
283
- <div className="mt-2 border-t border-border/60 pt-2">
316
+ );
317
+ return (
318
+ <section key={id} className="px-3 py-2.5">
319
+ {!hasMultipleEnvironments ? (
320
+ <h4 className="flex items-center gap-1.5 pb-1.5 text-xs font-medium text-muted-foreground">
321
+ <EnvironmentMachineIcon
322
+ aria-hidden
323
+ kind={machine}
324
+ className="size-3.5 shrink-0"
325
+ />
326
+ <span className="min-w-0 truncate">{target.label}</span>
327
+ </h4>
328
+ ) : null}
329
+ {hasMultipleEnvironments && groups.length > 1 ? (
330
+ <Collapsible>
331
+ <CollapsibleTrigger
332
+ render={
333
+ <Button
334
+ variant="ghost"
335
+ size="sm-multiline"
336
+ className="w-full justify-start text-left"
337
+ />
338
+ }
339
+ >
340
+ <span className="flex w-full min-w-0 flex-col">
341
+ <span className="flex min-w-0 items-center gap-2">
342
+ <span className="min-w-0 flex-1 truncate text-sm text-foreground tabular-nums">
343
+ {winningLayer?.value}
344
+ </span>
345
+ <span className="text-xs text-muted-foreground">
346
+ {winningLayer?.key === "environment"
347
+ ? "Environment"
348
+ : winningLayer?.label}
349
+ </span>
350
+ <ChevronRightIcon
351
+ aria-hidden
352
+ className="size-3 shrink-0 text-muted-foreground [[data-panel-open]_&]:rotate-90"
353
+ />
354
+ </span>
355
+ <span className="flex min-w-0 flex-col gap-0.5 text-xs text-muted-foreground">
356
+ {members.map((member) => (
357
+ <span
358
+ key={member.id}
359
+ className="flex min-w-0 max-w-full items-center gap-1"
360
+ >
361
+ <EnvironmentMachineIcon
362
+ aria-hidden
363
+ kind={member.machine}
364
+ className="size-3 shrink-0"
365
+ />
366
+ <span className="truncate">{member.label}</span>
367
+ </span>
368
+ ))}
369
+ </span>
370
+ </span>
371
+ </CollapsibleTrigger>
372
+ <CollapsiblePanel>
373
+ <div className="pt-1.5">{chain}</div>
374
+ </CollapsiblePanel>
375
+ </Collapsible>
376
+ ) : (
377
+ <>
378
+ {chain}
379
+ {hasMultipleEnvironments ? (
380
+ <p className="px-2 pt-1.5 text-xs text-muted-foreground">
381
+ Same on all machines
382
+ </p>
383
+ ) : null}
384
+ </>
385
+ )}
386
+ {(() => {
387
+ const overriding = overridingProjects.filter((project) =>
388
+ members.some((member) => member.target.environmentId === project.environmentId),
389
+ );
390
+ if (overriding.length === 0) return null;
391
+ const foldOverrides = hasMultipleEnvironments && overriding.length > 3;
392
+ const header = (
393
<div className="flex items-center justify-between gap-3 px-2 text-xs text-muted-foreground">
285
- <span>Overridden by</span>
394
+ {foldOverrides ? (
395
+ <CollapsibleTrigger render={<InlineButton tone="muted" />}>
396
+ <ChevronRightIcon
397
+ aria-hidden
398
+ className="size-3 [[data-panel-open]_&]:rotate-90"
399
+ />
400
+ Overridden by
401
+ </CollapsibleTrigger>
402
+ ) : (
403
+ <span>Overridden by</span>
404
+ )}
405
{onClearOverrides ? (
406
<InlineButton onClick={() => onClearOverrides(overriding)}>
407
Reset {overriding.length === 1 ? "it" : "all"}
408
</InlineButton>
409
) : null}
410
</div>
292
- <ul role="list" className="mt-0.5 text-sm">
411
+ );
412
+ const projects = (
413
+ <ul
414
+ role="list"
415
+ className={cn("mt-0.5 text-sm", foldOverrides && "max-h-48 overflow-y-auto")}
416
+ >
417
{overriding.map((project) => (
418
<li
295
- key={project.projectId}
419
+ key={`${project.environmentId}:${project.projectId}`}
420
className="grid grid-cols-[minmax(0,1fr)_auto] items-center gap-x-3 px-2 py-1"
421
>
298
- <InlineButton className="min-w-0 justify-start" onClick={project.open}>
299
- <span className="truncate">{project.label}</span>
300
- </InlineButton>
422
+ <span className="flex min-w-0 flex-col items-start">
423
+ <InlineButton
424
+ className="min-w-0 max-w-full justify-start"
425
+ onClick={project.open}
426
+ >
427
+ <span className="truncate">{project.label}</span>
428
+ </InlineButton>
429
+ {hasMultipleEnvironments ? (
430
+ <span className="max-w-full truncate text-xs text-muted-foreground">
431
+ {machineLabelFor(project.environmentId)}
432
+ </span>
433
+ ) : null}
434
+ </span>
435
<span className="max-w-32 truncate text-muted-foreground tabular-nums">
436
{isProjectScopedSettingKey(key)
303
- ? formatValue(key, overrides[project.projectId]?.[key])
437
+ ? formatValue(
438
+ key,
439
+ members.find(
440
+ (member) =>
441
+ member.target.environmentId === project.environmentId,
442
+ )?.overrides[project.projectId]?.[key],
443
+ )
444
: null}
445
</span>
446
</li>
447
))}
448
</ul>
309
- </div>
310
- );
311
- })()}
312
- </section>
313
- ))}
449
+ );
450
+ return (
451
+ <div className="mt-2 border-t border-border/60 pt-2">
452
+ {foldOverrides ? (
453
+ <Collapsible>
454
+ {header}
455
+ <CollapsiblePanel>{projects}</CollapsiblePanel>
456
+ </Collapsible>
457
+ ) : (
458
+ <>
459
+ {header}
460
+ {projects}
461
+ </>
462
+ )}
463
+ </div>
464
+ );
465
+ })()}
466
+ </section>
467
+ );
468
+ })}
469
</div>
470
</PopoverPopup>
471
</Popover>
apps/web/src/components/settings/SettingsPanels.tsx
+69
-23
@@ -1,4 +1,5 @@
1
import { SettingsGroup } from "./SettingsGroup";
2
+import { settingsScopeEnvironmentLabels } from "./settingsScopeAxis";
3
import { useScopedSettingsWriteAllowed } from "./useScopedSettings";
4
import { Spinner } from "~/components/ui/spinner";
5
import { NotificationSettings } from "./NotificationSettings";
@@ -3443,7 +3444,7 @@ export function GeneralSettingsPanel() {
3444
}
3445
3446
export function ArchivedThreadsPanel() {
3446
- const { scope } = useSettingsScope();
3447
+ const { scope, groups: projectGroups, environments } = useSettingsScope();
3448
const { unarchiveThread, confirmAndDeleteThread } = useThreadActions();
3449
const {
3450
snapshots: archivedSnapshots,
@@ -3452,7 +3453,7 @@ export function ArchivedThreadsPanel() {
3453
refresh: refreshArchivedThreads,
3454
} = useArchivedThreadSnapshots(scope.environmentIds);
3455
3455
- const archivedGroups = useMemo(() => {
3456
+ const { groups: archivedGroups, hasMultipleEnvironments } = useMemo(() => {
3457
const selectedProjectKeys =
3458
scope.kind === "project" || scope.kind === "checkout"
3459
? new Set(scope.members.map((member) => `${member.environmentId}:${member.id}`))
@@ -3470,15 +3471,43 @@ export function ArchivedThreadsPanel() {
3471
),
3472
),
3473
);
3474
+ const environmentLabels = new Map(
3475
+ environments.map((environment) => {
3476
+ const { primary, secondary } = settingsScopeEnvironmentLabels(environment, environments);
3477
+ return [environment.environmentId, secondary ? `${primary} (${secondary})` : primary];
3478
+ }),
3479
+ );
3480
const threads = archivedSnapshots.flatMap(({ environmentId, snapshot }) =>
3474
- snapshot.threads.map((thread) => presentThreadShell(environmentId, thread)),
3481
+ snapshot.threads.map((thread) => ({
3482
+ ...presentThreadShell(environmentId, thread),
3483
+ environmentLabel: environmentLabels.get(environmentId) ?? environmentId,
3484
+ })),
3485
+ );
3486
+ const hasMultipleEnvironments =
3487
+ new Set(
3488
+ threads
3489
+ .filter((thread) =>
3490
+ projectsByEnvironmentAndId.has(`${thread.environmentId}:${thread.projectId}`),
3491
+ )
3492
+ .map((thread) => thread.environmentId),
3493
+ ).size > 1;
3494
+ const logicalGroupsByProjectKey = new Map(
3495
+ projectGroups.flatMap((group) =>
3496
+ group.memberProjectRefs.map(
3497
+ (member) => [`${member.environmentId}:${member.projectId}`, group] as const,
3498
+ ),
3499
+ ),
3500
);
3501
3502
const archivedProjects = Array.from(projectsByEnvironmentAndId.values());
3478
- const groups: Array<{
3479
- readonly project: (typeof archivedProjects)[number];
3480
- readonly threads: Array<(typeof threads)[number]>;
3481
- }> = [];
3503
+ const groups = new Map<
3504
+ string,
3505
+ {
3506
+ readonly project: (typeof archivedProjects)[number];
3507
+ readonly title: string;
3508
+ readonly threads: Array<(typeof threads)[number]>;
3509
+ }
3510
+ >();
3511
for (const project of archivedProjects) {
3512
const projectThreads: Array<(typeof threads)[number]> = [];
3513
for (const thread of threads) {
@@ -3487,18 +3516,34 @@ export function ArchivedThreadsPanel() {
3516
}
3517
}
3518
if (projectThreads.length > 0) {
3490
- groups.push({
3491
- project,
3492
- threads: projectThreads.toSorted((left, right) => {
3493
- const leftKey = left.archivedAt ?? left.createdAt;
3494
- const rightKey = right.archivedAt ?? right.createdAt;
3495
- return rightKey.localeCompare(leftKey) || right.id.localeCompare(left.id);
3496
- }),
3497
- });
3519
+ const physicalProjectKey = `${project.environmentId}:${project.id}` as const;
3520
+ const logicalGroup = hasMultipleEnvironments
3521
+ ? logicalGroupsByProjectKey.get(physicalProjectKey)
3522
+ : undefined;
3523
+ const groupKey = logicalGroup?.projectKey ?? physicalProjectKey;
3524
+ const group = groups.get(groupKey);
3525
+ if (group) {
3526
+ group.threads.push(...projectThreads);
3527
+ } else {
3528
+ groups.set(groupKey, {
3529
+ project,
3530
+ title: logicalGroup?.displayName ?? project.title,
3531
+ threads: projectThreads,
3532
+ });
3533
+ }
3534
}
3535
}
3500
- return groups;
3501
- }, [archivedSnapshots, scope]);
3536
+ const sortedGroups = Array.from(groups, ([key, group]) => ({
3537
+ ...group,
3538
+ key,
3539
+ threads: group.threads.toSorted((left, right) => {
3540
+ const leftKey = left.archivedAt ?? left.createdAt;
3541
+ const rightKey = right.archivedAt ?? right.createdAt;
3542
+ return rightKey.localeCompare(leftKey) || right.id.localeCompare(left.id);
3543
+ }),
3544
+ }));
3545
+ return { groups: sortedGroups, hasMultipleEnvironments };
3546
+ }, [archivedSnapshots, environments, projectGroups, scope]);
3547
3548
const handleArchivedThreadContextMenu = useCallback(
3549
async (threadRef: ScopedThreadRef, position: { x: number; y: number }) => {
@@ -3578,16 +3623,16 @@ export function ArchivedThreadsPanel() {
3623
/>
3624
</SettingsSection>
3625
) : (
3581
- archivedGroups.map(({ project, threads: projectThreads }, index) => (
3626
+ archivedGroups.map(({ key, project, title, threads: projectThreads }, index) => (
3627
<SettingsSection
3583
- key={`${project.environmentId}:${project.id}`}
3628
+ key={key}
3629
id={index === 0 ? searchableSetting("archive").id : undefined}
3585
- title={project.title}
3630
+ title={title}
3631
icon={<ProjectFavicon project={project} />}
3632
>
3633
{projectThreads.map((thread) => (
3634
<SettingsRow
3590
- key={thread.id}
3635
+ key={`${thread.environmentId}:${thread.id}`}
3636
onContextMenu={(event) => {
3637
event.preventDefault();
3638
void (async () => {
@@ -3615,11 +3660,12 @@ export function ArchivedThreadsPanel() {
3660
}}
3661
title={thread.title}
3662
description={
3618
- <>
3663
+ <span className={hasMultipleEnvironments ? "block truncate" : undefined}>
3664
+ {hasMultipleEnvironments ? `${thread.environmentLabel} · ` : null}
3665
Archived {formatRelativeTimeLabel(thread.archivedAt ?? thread.createdAt)}
3666
{" \u00b7 Created "}
3667
{formatRelativeTimeLabel(thread.createdAt)}
3622
- </>
3668
+ </span>
3669
}
3670
control={
3671
<Button
apps/web/src/components/settings/SettingsScopeNotice.tsx
+137
-54
@@ -1,12 +1,31 @@
1
-import { Button } from "../ui/button";
2
-import { Alert, AlertAction, AlertDescription } from "../ui/alert";
3
-import { SettingsPageContainer } from "./settingsLayout";
1
+import { resolveEnvironmentMachineKind, type EnvironmentId } from "@t3tools/contracts";
2
+import { useLocation, useNavigate } from "@tanstack/react-router";
3
+import { ChevronRightIcon, LayersIcon } from "lucide-react";
4
+import type { ReactNode } from "react";
5
+
6
+import { cn } from "../../lib/utils";
7
+import type { SidebarProjectSnapshot } from "../../sidebarProjectGrouping";
8
+import { useEnvironments, type EnvironmentPresentation } from "../../state/environments";
9
+import { EnvironmentMachineIcon } from "../EnvironmentMachineIcon";
10
+import { ProjectFavicon } from "../ProjectFavicon";
11
+import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";
12
+import { ITEM_ROW_CLASSNAME } from "./itemRows";
13
+import { SettingsGroup } from "./SettingsGroup";
14
+import { SettingsPageContainer, SettingsSection } from "./settingsLayout";
15
import { useSettingsScope } from "./SettingsScopeContext";
5
-import { useEnvironments } from "../../state/environments";
16
import type { SettingsScopeSearch } from "./settingsScope";
7
-import { useSettingsProjectGroups } from "./useSettingsProjectGroups";
8
-import { useLocation, useNavigate } from "@tanstack/react-router";
9
-import type { EnvironmentId } from "@t3tools/contracts";
17
+import {
18
+ settingsScopeEnvironmentAddress,
19
+ settingsScopeEnvironmentLabels,
20
+ settingsScopeProjectMachines,
21
+} from "./settingsScopeAxis";
22
+
23
+interface ScopeChoice {
24
+ label: string;
25
+ secondary?: string;
26
+ icon: ReactNode;
27
+ search: SettingsScopeSearch;
28
+}
29
30
/** Offer an explicit target change when a category has no settings at this scope. */
31
export function SettingsScopeNotice({
@@ -20,28 +39,58 @@ export function SettingsScopeNotice({
39
targetId?: string;
40
eligibleEnvironmentIds?: readonly EnvironmentId[];
41
}) {
23
- const { selectScope, search } = useSettingsScope();
42
+ const { selectScope, search, groups } = useSettingsScope();
43
const navigate = useNavigate({ from: "/settings" });
44
const pathname = useLocation({ select: (location) => location.pathname });
45
const { environments } = useEnvironments();
27
- const groups = useSettingsProjectGroups();
28
- const choices: { label: string; search: SettingsScopeSearch }[] =
46
+ const environmentIcon = (environment: EnvironmentPresentation | undefined) =>
47
+ environment ? (
48
+ <EnvironmentMachineIcon
49
+ aria-hidden
50
+ kind={resolveEnvironmentMachineKind(environment.serverConfig)}
51
+ className="size-4 shrink-0 text-muted-foreground"
52
+ />
53
+ ) : null;
54
+ const choiceGroups =
55
target === "checkout"
30
- ? groups
31
- .filter((group) => !search.project || group.projectKey === search.project)
32
- .flatMap((group) =>
33
- group.memberProjects.map((member) => ({
34
- label: `${group.displayName} · ${member.environmentLabel ?? "Environment"} · ${member.workspaceRoot}`,
35
- search: {
36
- project: group.projectKey,
37
- machine: member.environmentId,
38
- checkout: member.physicalProjectKey,
39
- },
40
- })),
41
- )
56
+ ? groups.filter((group) => !search.project || group.projectKey === search.project)
57
+ : [null];
58
+ const renderChoices = (group: SidebarProjectSnapshot | null) => {
59
+ const choices: ScopeChoice[] = group
60
+ ? group.memberProjects.map((member) => {
61
+ const environment = environments.find(
62
+ (entry) => entry.environmentId === member.environmentId,
63
+ );
64
+ const { primary, secondary } = environment
65
+ ? settingsScopeEnvironmentLabels(environment, environments)
66
+ : {
67
+ primary: member.environmentLabel ?? "Environment",
68
+ secondary: member.environmentId,
69
+ };
70
+ return {
71
+ label: primary,
72
+ secondary: [secondary, member.workspaceRoot].filter(Boolean).join(" · "),
73
+ icon: environmentIcon(environment),
74
+ search: {
75
+ project: group.projectKey,
76
+ machine: member.environmentId,
77
+ checkout: member.physicalProjectKey,
78
+ },
79
+ };
80
+ })
81
: target === "project"
82
? groups.map((group) => ({
83
label: group.displayName,
84
+ secondary: [
85
+ ...(groups.some(
86
+ (other) =>
87
+ other.projectKey !== group.projectKey && other.displayName === group.displayName,
88
+ )
89
+ ? settingsScopeProjectMachines(group, environments)
90
+ : []),
91
+ group.workspaceRoot,
92
+ ].join(" · "),
93
+ icon: <ProjectFavicon project={group} className="size-4 shrink-0" />,
94
search: { project: group.projectKey },
95
}))
96
: target === "environment"
@@ -51,40 +100,74 @@ export function SettingsScopeNotice({
100
eligibleEnvironmentIds === undefined ||
101
eligibleEnvironmentIds.includes(entry.environmentId),
102
)
54
- .map((entry) => ({
55
- label: environments.some(
56
- (other) =>
57
- other.environmentId !== entry.environmentId && other.label === entry.label,
58
- )
59
- ? `${entry.label} · ${entry.displayUrl || entry.environmentId}`
60
- : entry.label,
61
- search: { machine: entry.environmentId },
62
- }))
63
- : [{ label: "Open all environments", search: {} }];
103
+ .map((entry) => {
104
+ const { primary, secondary } = settingsScopeEnvironmentLabels(entry, environments);
105
+ return {
106
+ label: primary,
107
+ secondary: secondary || settingsScopeEnvironmentAddress(entry),
108
+ icon: environmentIcon(entry),
109
+ search: { machine: entry.environmentId },
110
+ };
111
+ })
112
+ : [
113
+ {
114
+ label: "Open all environments",
115
+ icon: <LayersIcon aria-hidden className="size-4 shrink-0 text-muted-foreground" />,
116
+ search: {},
117
+ },
118
+ ];
119
+ return choices.map((choice) => (
120
+ <button
121
+ key={JSON.stringify(choice.search)}
122
+ type="button"
123
+ className={cn(
124
+ ITEM_ROW_CLASSNAME,
125
+ "flex w-full min-w-0 cursor-pointer items-center gap-3 text-left outline-none hover:bg-accent/50 focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring",
126
+ )}
127
+ onClick={() => {
128
+ if (targetId)
129
+ void navigate({ to: pathname, search: () => choice.search, hash: targetId });
130
+ else selectScope(choice.search);
131
+ }}
132
+ >
133
+ {choice.icon}
134
+ <span className="min-w-0 flex-1">
135
+ <span className="block truncate text-sm font-medium">{choice.label}</span>
136
+ {choice.secondary ? (
137
+ <Tooltip>
138
+ <TooltipTrigger
139
+ render={<span className="block truncate text-xs text-muted-foreground" />}
140
+ >
141
+ {choice.secondary}
142
+ </TooltipTrigger>
143
+ <TooltipPopup>{choice.secondary}</TooltipPopup>
144
+ </Tooltip>
145
+ ) : null}
146
+ </span>
147
+ <ChevronRightIcon aria-hidden className="size-4 shrink-0 text-muted-foreground" />
148
+ </button>
149
+ ));
150
+ };
151
return (
152
<SettingsPageContainer>
66
- <Alert role="status">
67
- <AlertDescription>
68
- <p>{children}</p>
69
- <AlertAction className="flex-wrap">
70
- {choices.map((choice) => (
71
- <Button
72
- key={JSON.stringify(choice.search)}
73
- size="sm-multiline"
74
- variant="outline"
75
- className="max-w-full break-all text-left"
76
- onClick={() => {
77
- if (targetId)
78
- void navigate({ to: pathname, search: () => choice.search, hash: targetId });
79
- else selectScope(choice.search);
80
- }}
81
- >
82
- {choice.label}
83
- </Button>
84
- ))}
85
- </AlertAction>
86
- </AlertDescription>
87
- </Alert>
153
+ <div className="space-y-3">
154
+ <p role="status" className="px-3 text-sm text-muted-foreground sm:px-4">
155
+ {children}
156
+ </p>
157
+ <div className="space-y-4">
158
+ {choiceGroups.map((group) =>
159
+ group?.displayName ? (
160
+ <SettingsSection key={group.projectKey} title={group.displayName}>
161
+ {renderChoices(group)}
162
+ </SettingsSection>
163
+ ) : (
164
+ <SettingsGroup key={group?.projectKey ?? target}>
165
+ {renderChoices(group)}
166
+ </SettingsGroup>
167
+ ),
168
+ )}
169
+ </div>
170
+ </div>
171
</SettingsPageContainer>
172
);
173
}
apps/web/src/components/settings/SettingsScopeSentence.tsx
+192
-83
@@ -1,13 +1,22 @@
1
import { resolveEnvironmentMachineKind } from "@t3tools/contracts";
2
import { useLocation } from "@tanstack/react-router";
3
-import { ChevronDownIcon, LayersIcon } from "lucide-react";
4
-import type { ReactNode } from "react";
3
+import { CheckIcon, ChevronDownIcon, LayersIcon } from "lucide-react";
4
+import { Fragment, useState, type ReactNode } from "react";
5
6
import type { SidebarProjectSnapshot } from "../../sidebarProjectGrouping";
7
import { useEnvironments, type EnvironmentPresentation } from "../../state/environments";
8
import { EnvironmentMachineIcon } from "../EnvironmentMachineIcon";
9
import { ProjectFavicon } from "../ProjectFavicon";
10
import { InlineButton } from "../ui/button";
11
+import {
12
+ Combobox,
13
+ ComboboxEmpty,
14
+ ComboboxItem,
15
+ ComboboxList,
16
+ ComboboxPopup,
17
+ ComboboxSearchInput,
18
+ ComboboxTrigger,
19
+} from "../ui/combobox";
20
import {
21
Menu,
22
MenuPopup,
@@ -26,7 +35,10 @@ import {
35
projectAxisValue,
36
selectEnvironmentAxis,
37
selectProjectAxis,
38
+ settingsScopeEnvironmentAddress,
39
settingsScopeEnvironmentLabel,
40
+ settingsScopeEnvironmentLabels,
41
+ settingsScopeProjectMachines,
42
} from "./settingsScopeAxis";
43
44
/** Pages whose every row is saved on this client; they have no scope to pick. */
@@ -80,29 +92,133 @@ export function SettingsScopeSentence() {
92
);
93
}
94
95
+interface ScopeOption {
96
+ value: string;
97
+ label: string;
98
+ secondary?: string;
99
+ icon?: ReactNode;
100
+ offline?: boolean;
101
+}
102
+
103
+function ScopeOptionLabel({ option }: { option: ScopeOption }) {
104
+ return (
105
+ <>
106
+ {option.icon}
107
+ <span className="min-w-0 flex-1">
108
+ <span className="block truncate">{option.label}</span>
109
+ {option.secondary ? (
110
+ <span className="block truncate text-xs text-muted-foreground">{option.secondary}</span>
111
+ ) : null}
112
+ </span>
113
+ {option.offline ? (
114
+ <span className="shrink-0 text-xs text-muted-foreground">Offline</span>
115
+ ) : null}
116
+ </>
117
+ );
118
+}
119
+
120
function ScopeMenu({
121
ariaLabel,
122
icon,
123
label,
87
- children,
124
+ value,
125
+ options,
126
+ allOption,
127
+ searchLabel,
128
+ onChange,
129
}: {
130
ariaLabel: string;
131
icon: ReactNode;
132
label: string;
92
- children: ReactNode;
133
+ value: string;
134
+ options: ScopeOption[];
135
+ allOption: ScopeOption | null;
136
+ searchLabel: string;
137
+ onChange: (next: string) => void;
138
}) {
139
+ const [query, setQuery] = useState("");
140
+ const Trigger = options.length > 6 ? ComboboxTrigger : MenuTrigger;
141
+ const trigger = (
142
+ <Trigger
143
+ aria-label={`${ariaLabel}: ${label}`}
144
+ render={<InlineButton tone="picker" />}
145
+ className="min-w-0 max-w-72"
146
+ >
147
+ {icon}
148
+ <span className="min-w-0 truncate">{label}</span>
149
+ <ChevronDownIcon aria-hidden className="size-3.5 shrink-0 text-muted-foreground" />
150
+ </Trigger>
151
+ );
152
+ const choices = allOption ? [allOption, ...options] : options;
153
+ if (options.length > 6) {
154
+ const needle = query.trim().toLowerCase();
155
+ const filteredItems = choices.filter((option) =>
156
+ `${option.label} ${option.secondary ?? ""} ${option.value}`.toLowerCase().includes(needle),
157
+ );
158
+ return (
159
+ <Combobox
160
+ items={choices}
161
+ filteredItems={filteredItems}
162
+ filter={null}
163
+ autoHighlight
164
+ itemToStringLabel={(option) => option.label}
165
+ isItemEqualToValue={(a, b) => a.value === b.value}
166
+ value={choices.find((option) => option.value === value) ?? null}
167
+ onOpenChange={(open) => {
168
+ if (!open) setQuery("");
169
+ }}
170
+ onValueChange={(option) => {
171
+ if (option) onChange(option.value);
172
+ }}
173
+ >
174
+ {trigger}
175
+ <ComboboxPopup align="start" className="w-80">
176
+ <ComboboxSearchInput
177
+ aria-label={searchLabel}
178
+ placeholder={searchLabel}
179
+ value={query}
180
+ onChange={(event) => setQuery(event.target.value)}
181
+ />
182
+ <ComboboxEmpty>No matches found.</ComboboxEmpty>
183
+ <ComboboxList>
184
+ {(option: ScopeOption) => (
185
+ <ComboboxItem key={option.value} value={option}>
186
+ <ScopeOptionLabel option={option} />
187
+ {option.value === value ? (
188
+ <CheckIcon aria-hidden className="size-3.5 shrink-0" />
189
+ ) : null}
190
+ </ComboboxItem>
191
+ )}
192
+ </ComboboxList>
193
+ </ComboboxPopup>
194
+ </Combobox>
195
+ );
196
+ }
197
return (
198
<Menu>
96
- <MenuTrigger
97
- aria-label={`${ariaLabel}: ${label}`}
98
- render={<InlineButton tone="picker" />}
99
- className="min-w-0 max-w-72"
100
- >
101
- {icon}
102
- <span className="min-w-0 truncate">{label}</span>
103
- <ChevronDownIcon aria-hidden className="size-3.5 shrink-0 text-muted-foreground" />
104
- </MenuTrigger>
105
- <MenuPopup align="start">{children}</MenuPopup>
199
+ {trigger}
200
+ <MenuPopup align="start">
201
+ <div className="w-72 max-w-full">
202
+ <MenuRadioGroup
203
+ value={value}
204
+ onValueChange={(next) => {
205
+ if (typeof next === "string") onChange(next);
206
+ }}
207
+ >
208
+ {choices.map((option, index) => (
209
+ <Fragment key={option.value}>
210
+ <MenuRadioItem value={option.value} closeOnClick>
211
+ <span className="flex min-w-0 items-center gap-2">
212
+ <ScopeOptionLabel option={option} />
213
+ <MenuRadioItemIndicator />
214
+ </span>
215
+ </MenuRadioItem>
216
+ {index === 0 && allOption ? <MenuSeparator /> : null}
217
+ </Fragment>
218
+ ))}
219
+ </MenuRadioGroup>
220
+ </div>
221
+ </MenuPopup>
222
</Menu>
223
);
224
}
@@ -143,83 +259,76 @@ function EnvironmentScopeMenu({
259
? "No environments"
260
: "All environments"
261
}
146
- >
147
- <MenuRadioGroup
148
- value={environmentValue}
149
- onValueChange={(next) => {
150
- if (typeof next === "string") onChange(selectEnvironmentAxis(value, next));
151
- }}
152
- >
153
- {!singleEnvironment ? (
154
- <>
155
- <MenuRadioItem value={ALL_ENVIRONMENTS_VALUE} closeOnClick>
156
- <span className="flex min-w-0 items-center gap-2">
157
- <LayersIcon aria-hidden className="size-3.5" />
158
- <span className="min-w-0 flex-1 truncate">All environments</span>
159
- <MenuRadioItemIndicator />
160
- </span>
161
- </MenuRadioItem>
162
- <MenuSeparator />
163
- </>
164
- ) : null}
165
- {environments.map((environment) => (
166
- <MenuRadioItem
167
- key={environment.environmentId}
168
- value={environment.environmentId}
169
- closeOnClick
170
- >
171
- <span className="flex min-w-0 items-center gap-2">
172
- <EnvironmentMachineIcon
173
- aria-hidden
174
- kind={resolveEnvironmentMachineKind(environment.serverConfig)}
175
- className="size-3.5"
176
- />
177
- <span className="min-w-0 flex-1 truncate">
178
- {settingsScopeEnvironmentLabel(environment, environments)}
179
- </span>
180
- {environment.connection.phase === "connected" ? null : (
181
- <span className="shrink-0 text-xs text-muted-foreground">Offline</span>
182
- )}
183
- <MenuRadioItemIndicator />
184
- </span>
185
- </MenuRadioItem>
186
- ))}
187
- </MenuRadioGroup>
188
- </ScopeMenu>
262
+ value={environmentValue}
263
+ onChange={(next) => onChange(selectEnvironmentAxis(value, next))}
264
+ searchLabel="Search environments"
265
+ allOption={
266
+ singleEnvironment
267
+ ? null
268
+ : {
269
+ value: ALL_ENVIRONMENTS_VALUE,
270
+ label: "All environments",
271
+ icon: <LayersIcon aria-hidden className="size-3.5 shrink-0" />,
272
+ }
273
+ }
274
+ options={environments.map((environment) => {
275
+ const { primary, secondary } = settingsScopeEnvironmentLabels(environment, environments);
276
+ return {
277
+ value: environment.environmentId,
278
+ label: primary,
279
+ secondary:
280
+ environments.length <= 1
281
+ ? ""
282
+ : secondary || settingsScopeEnvironmentAddress(environment),
283
+ icon: (
284
+ <EnvironmentMachineIcon
285
+ aria-hidden
286
+ kind={resolveEnvironmentMachineKind(environment.serverConfig)}
287
+ className="size-3.5 shrink-0"
288
+ />
289
+ ),
290
+ offline: environment.connection.phase !== "connected",
291
+ };
292
+ })}
293
+ />
294
);
295
}
296
192
-function ProjectScopeMenu({ value, groups, onChange }: SettingsScopeMenuProps) {
297
+function ProjectScopeMenu({ value, groups, environments, onChange }: SettingsScopeMenuProps) {
298
const selected = groups.find((group) => group.projectKey === value.project);
299
+ const projects = groups.map((group) => ({
300
+ group,
301
+ machines: settingsScopeProjectMachines(group, environments, true).join(", "),
302
+ }));
303
return (
304
<ScopeMenu
305
ariaLabel="Project scope"
306
icon={selected ? <ProjectFavicon project={selected} className="size-3.5 shrink-0" /> : null}
307
label={selected?.displayName ?? (value.project ? "Unavailable project" : "All projects")}
199
- >
200
- <MenuRadioGroup
201
- value={projectAxisValue(value)}
202
- onValueChange={(next) => {
203
- if (typeof next === "string") onChange(selectProjectAxis(value, next));
204
- }}
205
- >
206
- <MenuRadioItem value={ALL_PROJECTS_VALUE} closeOnClick>
207
- <span className="flex min-w-0 items-center gap-2">
208
- <span className="min-w-0 flex-1 truncate">All projects</span>
209
- <MenuRadioItemIndicator />
210
- </span>
211
- </MenuRadioItem>
212
- <MenuSeparator />
213
- {groups.map((group) => (
214
- <MenuRadioItem key={group.projectKey} value={group.projectKey} closeOnClick>
215
- <span className="flex min-w-0 items-center gap-2">
216
- <ProjectFavicon project={group} className="size-3.5" />
217
- <span className="min-w-0 flex-1 truncate">{group.displayName}</span>
218
- <MenuRadioItemIndicator />
219
- </span>
220
- </MenuRadioItem>
221
- ))}
222
- </MenuRadioGroup>
223
- </ScopeMenu>
308
+ value={projectAxisValue(value)}
309
+ onChange={(next) => onChange(selectProjectAxis(value, next))}
310
+ searchLabel="Search projects"
311
+ allOption={{ value: ALL_PROJECTS_VALUE, label: "All projects" }}
312
+ options={projects.map(({ group, machines }) => {
313
+ const sameName = projects.filter(
314
+ (other) =>
315
+ other.group.projectKey !== group.projectKey &&
316
+ other.group.displayName === group.displayName,
317
+ );
318
+ return {
319
+ value: group.projectKey,
320
+ label: group.displayName,
321
+ secondary:
322
+ sameName.length === 0
323
+ ? environments.length > 1
324
+ ? group.workspaceRoot
325
+ : ""
326
+ : sameName.some((other) => other.machines === machines)
327
+ ? `${machines} · ${group.workspaceRoot}`
328
+ : machines,
329
+ icon: <ProjectFavicon project={group} className="size-3.5 shrink-0" />,
330
+ };
331
+ })}
332
+ />
333
);
334
}
apps/web/src/components/settings/StorageSettings.tsx
+27
-15
@@ -47,6 +47,7 @@ import {
47
useScopedSettingsMixed,
48
useUpdateScopedSettings,
49
} from "./useScopedSettings";
50
+import { settingsScopeEnvironmentLabel } from "./settingsScopeAxis";
51
52
function WorktreesDirectoryRow() {
53
const { connectedEnvironments, targets } = useSettingsScope();
@@ -171,6 +172,20 @@ const KEEP_WHEN_LABELS = {
172
"tracked-changes": "Edited tracked files",
173
} as const;
174
175
+/** One line for the last-run fold; identical results across machines collapse into one. */
176
+function lastRunSummary(
177
+ entries: readonly { readonly label: string; readonly counts: string }[],
178
+ machineCount: number,
179
+) {
180
+ const first = entries[0];
181
+ if (!first) return "";
182
+ if (machineCount <= 1) return first.counts;
183
+ if (entries.length === machineCount && entries.every((entry) => entry.counts === first.counts)) {
184
+ return `${first.counts} on every machine`;
185
+ }
186
+ return entries.map((entry) => `${entry.label}: ${entry.counts}`).join(" · ");
187
+}
188
+
189
function CleanupResults({
190
report,
191
environmentLabel,
@@ -294,6 +309,10 @@ function CleanupSection() {
309
return {
310
environment,
311
report,
312
+ label: settingsScopeEnvironmentLabel(environment, connectedEnvironments),
313
+ counts: report
314
+ ? `${report.counts.removed} removed, ${report.counts.kept} kept${report.counts.failed > 0 ? `, ${report.counts.failed} failed` : ""}`
315
+ : "",
316
description: report
317
? `Last run ${formatRelativeTimeLabel(report.finishedAt)}. ${formatBytes(report.bytesFreed)} recovered.${report.counts.failed > 0 ? ` ${report.counts.failed} ${report.counts.failed === 1 ? "item" : "items"} couldn't be removed.` : ""}`
318
: query?.failed
@@ -346,9 +365,9 @@ function CleanupSection() {
365
<span>
366
{!hasRules
367
? "Turn on a cleanup rule to use this."
349
- : summaries.map(({ environment, description }) => (
368
+ : summaries.map(({ environment, label, description }) => (
369
<span key={environment.environmentId} className="block">
351
- {supported.length > 1 ? `${environment.label}: ` : ""}
370
+ {supported.length > 1 ? `${label}: ` : ""}
371
{description}
372
</span>
373
))}
@@ -371,25 +390,18 @@ function CleanupSection() {
390
id="storage-cleanup-last-run"
391
title="Last run"
392
headerPlacement="inside"
374
- summary={summaries
375
- .flatMap(({ environment, report }) =>
376
- report
377
- ? [
378
- `${connectedEnvironments.length > 1 ? `${environment.label}: ` : ""}${report.counts.removed} removed, ${report.counts.kept} kept${report.counts.failed > 0 ? `, ${report.counts.failed} failed` : ""}`,
379
- ]
380
- : [],
381
- )
382
- .join(" · ")}
393
+ summary={lastRunSummary(
394
+ summaries.filter(({ report }) => report !== null),
395
+ connectedEnvironments.length,
396
+ )}
397
>
398
{summaries.map(
385
- ({ environment, report }) =>
399
+ ({ environment, label, report }) =>
400
report && (
401
<CleanupResults
402
key={environment.environmentId}
403
report={report}
390
- environmentLabel={
391
- connectedEnvironments.length > 1 ? environment.label : undefined
392
- }
404
+ environmentLabel={connectedEnvironments.length > 1 ? label : undefined}
405
/>
406
),
407
)}
apps/web/src/components/settings/deviceHostsSettings.logic.ts
+53
-1
@@ -1,4 +1,56 @@
1
-import type { SshDeviceHostConfig } from "@t3tools/contracts";
1
+import type { EnvironmentId, SshDeviceHostConfig } from "@t3tools/contracts";
2
+
3
+export interface DeviceHostEnvironment {
4
+ readonly environmentId: EnvironmentId;
5
+ readonly label: string;
6
+ readonly hosts: ReadonlyArray<SshDeviceHostConfig>;
7
+}
8
+
9
+export interface DeviceHostGroup {
10
+ readonly host: SshDeviceHostConfig;
11
+ readonly members: Array<{
12
+ readonly environmentId: EnvironmentId;
13
+ readonly label: string;
14
+ readonly host: SshDeviceHostConfig;
15
+ }>;
16
+}
17
+
18
+/** Only combine matching configurations; ambiguous identities keep their machine's list. */
19
+export function groupDeviceHosts(
20
+ environments: ReadonlyArray<DeviceHostEnvironment>,
21
+): ReadonlyArray<DeviceHostGroup> | null {
22
+ const groups = new Map<string, DeviceHostGroup>();
23
+ const identities = new Map<string, string>();
24
+ const configurations = new Map<string, string>();
25
+ for (const environment of environments) {
26
+ const destinations = new Set<string>();
27
+ for (const host of environment.hosts) {
28
+ const destination = JSON.stringify([host.target, host.port, host.identityFile]);
29
+ const configuration = JSON.stringify([host.label, host.target, host.port, host.identityFile]);
30
+ const previousConfiguration = identities.get(host.id);
31
+ const targetConfiguration = configurations.get(host.target);
32
+ const group = groups.get(destination);
33
+ if (
34
+ destinations.has(destination) ||
35
+ (previousConfiguration !== undefined && previousConfiguration !== configuration) ||
36
+ (targetConfiguration !== undefined && targetConfiguration !== configuration)
37
+ ) {
38
+ return null;
39
+ }
40
+ destinations.add(destination);
41
+ identities.set(host.id, configuration);
42
+ configurations.set(host.target, configuration);
43
+ const member = {
44
+ environmentId: environment.environmentId,
45
+ label: environment.label,
46
+ host,
47
+ };
48
+ if (group) group.members.push(member);
49
+ else groups.set(destination, { host, members: [member] });
50
+ }
51
+ }
52
+ return [...groups.values()];
53
+}
54
55
/** Apply one host change without replacing another environment's host list. */
56
export function updateDeviceHosts(
apps/web/src/components/settings/settingsScopeAxis.test.ts
+1
-4
@@ -25,10 +25,7 @@ describe("settings scope environment labels", () => {
25
const environments = [first, second];
26
expect(
27
environments.map((environment) => settingsScopeEnvironmentLabel(environment, environments)),
28
- ).toEqual([
29
- "Development · https://first.example.com",
30
- "Development · https://second.example.com",
31
- ]);
28
+ ).toEqual(["Development · first.example.com", "Development · second.example.com"]);
29
});
30
31
it("falls back to environment IDs when duplicate names have no display URL", () => {
apps/web/src/components/settings/settingsScopeAxis.ts
+45
-6
@@ -1,19 +1,58 @@
1
+import type { SidebarProjectSnapshot } from "../../sidebarProjectGrouping";
2
import type { EnvironmentPresentation } from "../../state/environments";
3
import type { ResolvedSettingsScope, SettingsScopeSearch } from "./settingsScope";
4
5
type ScopeEnvironment = Pick<EnvironmentPresentation, "environmentId" | "label" | "displayUrl">;
6
6
-export function settingsScopeEnvironmentLabel(
7
+export function settingsScopeEnvironmentAddress(environment: ScopeEnvironment) {
8
+ if (!environment.displayUrl) return environment.environmentId;
9
+ try {
10
+ return new URL(environment.displayUrl).host || environment.displayUrl;
11
+ } catch {
12
+ return environment.displayUrl;
13
+ }
14
+}
15
+
16
+export function settingsScopeEnvironmentLabels(
17
environment: ScopeEnvironment,
8
- environments: readonly ScopeEnvironment[],
18
+ environments?: readonly ScopeEnvironment[],
19
) {
10
- const duplicate = environments.some(
20
+ const duplicates = environments?.filter(
21
(other) =>
22
other.environmentId !== environment.environmentId && other.label === environment.label,
23
);
14
- return duplicate
15
- ? `${environment.label} · ${environment.displayUrl ?? environment.environmentId}`
16
- : environment.label;
24
+ const address = settingsScopeEnvironmentAddress(environment);
25
+ const secondary = duplicates?.some((other) => settingsScopeEnvironmentAddress(other) === address)
26
+ ? environment.displayUrl || environment.environmentId
27
+ : address;
28
+ return {
29
+ primary: environment.label,
30
+ secondary: environments === undefined || duplicates?.length ? secondary : "",
31
+ };
32
+}
33
+
34
+export function settingsScopeEnvironmentLabel(
35
+ environment: ScopeEnvironment,
36
+ environments: readonly ScopeEnvironment[],
37
+) {
38
+ const { primary, secondary } = settingsScopeEnvironmentLabels(environment, environments);
39
+ return secondary ? `${primary} · ${secondary}` : primary;
40
+}
41
+
42
+export function settingsScopeProjectMachines(
43
+ group: SidebarProjectSnapshot,
44
+ environments: readonly ScopeEnvironment[],
45
+ includeAddresses = false,
46
+) {
47
+ const machines = group.memberProjects.map((member) => {
48
+ const environment = environments.find((entry) => entry.environmentId === member.environmentId);
49
+ if (!environment) return member.environmentLabel ?? member.environmentId;
50
+ const { primary, secondary } = settingsScopeEnvironmentLabels(environment, environments);
51
+ const address =
52
+ secondary || (includeAddresses ? settingsScopeEnvironmentAddress(environment) : "");
53
+ return includeAddresses || address ? `${primary} · ${address}` : primary;
54
+ });
55
+ return Array.from(new Set(machines));
56
}
57
58
export const ALL_ENVIRONMENTS_VALUE = "all";