Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

SavedEnvironmentRows.tsx

711 lines25.4 KB

1import { SessionPermissions } from "./SessionPermissions";
2import {
3 ChevronRightIcon,
4 ChevronsLeftRightEllipsisIcon,
5 EllipsisIcon,
6 RouteIcon,
7} from "lucide-react";
8import { useAtomValue } from "@effect/atom-react";
9import { useEffect, useEffectEvent, useState } from "react";
10import {
11 AuthRelayWriteScope,
12 type EnvironmentId,
13 connectReachabilityHelpUrl,
14 formatConnectReachable,
15 resolveEnvironmentMachineKind,
16} from "@t3tools/contracts";
17import {
18 connectionRoutes,
19 hasSavedBearerRoute,
20 connectionStatusText,
21 environmentMcpUrl,
22} from "@t3tools/client-runtime/connection";
23import * as Option from "effect/Option";
24​
25import { useCopyToClipboard } from "../../hooks/useCopyToClipboard";
26import { cn } from "../../lib/utils";
27import { SettingsRow } from "./settingsLayout";
28import { searchableSetting } from "./settingsSearch";
29import { EnvironmentIconMenu } from "./EnvironmentIconPicker";
30import { EnvironmentRoutesList } from "./EnvironmentRoutesList";
31import {
32 ConnectionDiagnosisPanel,
33 ConnectionDiagnosisSummary,
34 useConnectionDiagnosis,
35} from "./ConnectionDiagnosisDetails";
36import { usePreparedConnection } from "~/state/session";
37import { EnvironmentRow, environmentTransportLabel } from "./EnvironmentRow";
38import { Menu, MenuItem, MenuPopup, MenuSeparator, MenuTrigger } from "../ui/menu";
39import { Switch } from "../ui/switch";
40import { stackedThreadToast, toastManager } from "../ui/toast";
41import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";
42import { Button } from "../ui/button";
43import { Empty, EmptyDescription, EmptyHeader, EmptyMedia, EmptyTitle } from "../ui/empty";
44import {
45 resolveServerConfigVersionMismatch,
46 resolveServerSelfUpdateCapability,
47 supportsDesktopAppUpdate,
48 supportsServerUpdateThreadContinuation,
49} from "~/versionSkew";
50import { hasCloudPublicConfig } from "~/cloud/publicConfig";
51import { useCloudLinkController } from "~/cloud/useCloudLinkController";
52import { environmentCatalog } from "~/connection/catalog";
53import { readEnvironmentScope } from "~/state/session";
54import {
55 type EnvironmentPresentation,
56 useRelayEnvironmentDiscovery,
57 usePrimaryEnvironmentId,
58} from "~/state/environments";
59import { APP_VERSION } from "~/branding";
60import { useAtomCommand } from "../../state/use-atom-command";
61import { serverEnvironment } from "~/state/server";
62import {
63 OutdatedServerUpdateAction,
64 ServerUpdateAction,
65 ServerUpdateProgress,
66} from "../ServerUpdateAction";
67import { CloudEnvironmentConnectRows } from "../cloud/CloudEnvironmentConnectList";
68​
69type SavedBackendListRowProps = {
70 environment: EnvironmentPresentation;
71 removingEnvironmentId: EnvironmentId | null;
72 onSetEnabled: (environmentId: EnvironmentId, enabled: boolean) => void;
73 onRemove: (environment: EnvironmentPresentation) => void;
74 onAddRoute: (environment: EnvironmentPresentation) => void;
75};
76​
77function savedBackendStatus(environment: EnvironmentPresentation): {
78 readonly text: string;
79 readonly tone: "muted" | "error";
80} {
81 if (!environment.entry.enabled && environment.connection.phase !== "unsupported")
82 return { text: "Off", tone: "muted" };
83 const { connection } = environment;
84 switch (connection.phase) {
85 case "connected":
86 return { text: "Connected", tone: "muted" };
87 case "connecting":
88 return { text: "Connecting", tone: "muted" };
89 case "reconnecting":
90 return {
91 text: connection.error ? `Reconnecting: ${connection.error}` : "Reconnecting",
92 tone: "error",
93 };
94 case "unsupported":
95 return { text: "Client not supported", tone: "muted" };
96 case "error":
97 return {
98 text: connection.error ? `Connection failed: ${connection.error}` : "Connection failed",
99 tone: "error",
100 };
101 case "offline":
102 return { text: "Offline", tone: "muted" };
103 case "available":
104 return { text: "Not connected", tone: "muted" };
105 }
107​
108export function SavedBackendListRow({
109 environment,
110 removingEnvironmentId,
111 onSetEnabled,
112 onRemove,
113 onAddRoute,
114}: SavedBackendListRowProps) {
115 const [routesOpen, setRoutesOpen] = useState(false);
116 const [permissionsOpen, setPermissionsOpen] = useState(false);
117 const [diagnosisOpen, setDiagnosisOpen] = useState(false);
118 const environmentId = environment.environmentId;
119 const unsupported = environment.connection.phase === "unsupported";
120 const blocked = unsupported && !hasSavedBearerRoute(environment.entry);
121 const enabled = environment.entry.enabled && !unsupported;
122 const isConnected = environment.connection.phase === "connected";
123 const isRemoving = removingEnvironmentId === environmentId;
124 const errorTraceId = environment.connection.traceId;
125 const { copyToClipboard: copyTraceIdToClipboard } = useCopyToClipboard<{ traceId: string }>({
126 target: "trace ID",
127 onCopy: ({ traceId }) => {
128 toastManager.add({
129 type: "success",
130 title: "Trace ID copied",
131 description: traceId,
132 });
133 },
134 onError: (error) => {
135 toastManager.add(
136 stackedThreadToast({
137 type: "error",
138 title: "Could not copy trace ID",
139 description: error.message,
140 }),
141 );
142 },
143 });
144 const copyTraceId = (traceId: string) => {
145 copyTraceIdToClipboard(traceId, { traceId });
146 };
147 const { copyToClipboard: copyMcpUrl } = useCopyToClipboard<{ url: string }>({
148 target: "MCP URL",
149 onCopy: ({ url }) => {
150 toastManager.add({
151 type: "success",
152 title: "MCP URL copied",
153 description: `Add it to an agent, e.g. claude mcp add --transport http t3 ${url}`,
154 });
155 },
156 onError: (error) => {
157 toastManager.add(
158 stackedThreadToast({
159 type: "error",
160 title: "Could not copy MCP URL",
161 description: error.message,
162 }),
163 );
164 },
165 });
166 const versionMismatch = resolveServerConfigVersionMismatch(environment.serverConfig);
167 const serverUpdateState = useAtomValue(serverEnvironment.updateStateAtom(environmentId));
168 const resumingServerUpdate =
169 serverUpdateState.status === "running" && serverUpdateState.stage === "resuming";
170 const status = savedBackendStatus(environment);
171 const serverVersion = environment.serverConfig?.environment.serverVersion ?? null;
172 // Discovery empties its map on every refresh, so hold the last descriptor
173 // seen or the glyph would blink back to the generic one each time.
174 const relayDiscovery = useRelayEnvironmentDiscovery();
175 const discoveredDescriptor = Option.getOrNull(
176 relayDiscovery.environments.get(environmentId)?.status ?? Option.none(),
177 )?.descriptor;
178 const [lastDescriptor, setLastDescriptor] = useState(discoveredDescriptor);
179 if (discoveredDescriptor !== undefined && discoveredDescriptor !== lastDescriptor) {
180 setLastDescriptor(discoveredDescriptor);
181 }
182 const discoveredRelayHttpBaseUrl =
183 relayDiscovery.environments.get(environmentId)?.environment.endpoint.httpBaseUrl;
184 const [lastRelayHttpBaseUrl, setLastRelayHttpBaseUrl] = useState(discoveredRelayHttpBaseUrl);
185 if (
186 discoveredRelayHttpBaseUrl !== undefined &&
187 discoveredRelayHttpBaseUrl !== lastRelayHttpBaseUrl
188 ) {
189 setLastRelayHttpBaseUrl(discoveredRelayHttpBaseUrl);
190 }
191 const retryNow = useAtomCommand(environmentCatalog.retryNow);
192 const {
193 diagnosis: currentDiagnosis,
194 state: connectionState,
195 relayOnly,
196 } = useConnectionDiagnosis(environment);
197 const diagnosis = resumingServerUpdate ? null : currentDiagnosis;
198 const prepared = usePreparedConnection(environmentId);
199 const connectedTarget = isConnected && prepared._tag === "Some" ? prepared.value.target : null;
200 const mcpUrl = environmentMcpUrl({
201 entry: environment.entry,
202 relayHttpBaseUrl: discoveredRelayHttpBaseUrl ?? lastRelayHttpBaseUrl,
203 connectedTarget,
204 });
205 const machineKind = resolveEnvironmentMachineKind(
206 environment.serverConfig ??
207 (lastDescriptor === undefined ? null : { environment: lastDescriptor }),
208 );
209 const routeCount = connectionRoutes(environment.entry).length;
210 const subtitleText = [
211 environmentTransportLabel(environment, connectedTarget),
212 // The headline below names the failure in full.
213 diagnosis ? null : resumingServerUpdate ? "Restarting" : status.text,
214 enabled && versionMismatch ? serverVersion : null,
215 ]
216 .filter((value): value is string => value !== null)
217 .join(" · ");
218​
219 const showUpdateAction =
220 enabled &&
221 isConnected &&
222 versionMismatch !== null &&
223 (serverUpdateState.status === "idle" || serverUpdateState.status === "failed");
224​
225 const statusTooltip = `${
226 unsupported
227 ? (environment.connection.error ?? connectionStatusText(environment.connection))
228 : enabled
229 ? connectionStatusText(environment.connection)
230 : "Switched off"
231 }${
232 versionMismatch
233 ? `\nUpdate available: ${versionMismatch.serverVersion} → ${versionMismatch.clientVersion}`
234 : ""
235 }`;
236​
237 return (
238 <EnvironmentRow
239 kind={machineKind}
240 label={environment.label}
241 dimmed={!enabled}
242 subtitle={
243 <span className="flex min-w-0 items-center gap-1">
244 <Tooltip>
245 {/* The status can change while the tooltip is open, and base-ui only
246 re-measures the popup when the trigger's payload changes. */}
247 <TooltipTrigger
248 payload={statusTooltip}
249 render={
250 <span
251 className={cn(
252 "min-w-0 truncate",
253 enabled &&
254 status.tone === "error" &&
255 !resumingServerUpdate &&
256 !diagnosis &&
257 "text-destructive",
258 )}
259 />
260 }
261 >
262 {subtitleText}
263 </TooltipTrigger>
264 <TooltipPopup side="top" className="whitespace-pre-wrap">
265 {statusTooltip}
266 </TooltipPopup>
267 </Tooltip>
268 <span aria-hidden className="shrink-0">
269 ·
270 </span>
271 <button
272 type="button"
273 aria-expanded={routesOpen}
274 onClick={() => setRoutesOpen((open) => !open)}
275 className="inline-flex shrink-0 items-center gap-0.5 rounded-sm text-muted-foreground outline-none hover:text-foreground focus-visible:ring-1 focus-visible:ring-inset focus-visible:ring-ring"
276 >
277 {routeCount === 1 ? "Routes" : `${routeCount} routes`}
278 <ChevronRightIcon
279 aria-hidden
280 className={cn(
281 "size-3 shrink-0 transition-transform duration-150 motion-reduce:transition-none",
282 routesOpen && "rotate-90",
283 )}
284 />
285 </button>
286 <span aria-hidden className="shrink-0">
287 ·
288 </span>
289 <button
290 type="button"
291 aria-expanded={permissionsOpen}
292 aria-controls={`remote-permissions-${environmentId}`}
293 onClick={() => setPermissionsOpen((open) => !open)}
294 className="inline-flex shrink-0 items-center gap-0.5 rounded-sm text-muted-foreground outline-none hover:text-foreground focus-visible:ring-1 focus-visible:ring-inset focus-visible:ring-ring"
295 >
296 Permissions
297 <ChevronRightIcon
298 aria-hidden
299 className={cn(
300 "size-3 shrink-0 transition-transform duration-150 motion-reduce:transition-none",
301 permissionsOpen && "rotate-90",
302 )}
303 />
304 </button>
305 </span>
306 }
307 below={
308 <>
309 {diagnosis ? (
310 <ConnectionDiagnosisSummary
311 diagnosis={diagnosis}
312 retryAt={connectionState.phase === "backoff" ? connectionState.retryAt : null}
313 attempt={connectionState.attempt}
314 expanded={diagnosisOpen}
315 onToggle={() => setDiagnosisOpen((open) => !open)}
316 />
317 ) : null}
318 {serverUpdateState.status !== "idle" ? (
319 <div className="mt-1 max-w-md">
320 <ServerUpdateProgress state={serverUpdateState} />
321 </div>
322 ) : null}
323 </>
324 }
325 detail={
326 <>
327 {diagnosis && diagnosisOpen ? (
328 <ConnectionDiagnosisPanel
329 hostLabel={environment.label}
330 diagnosis={diagnosis}
331 onRetry={() => void retryNow(environmentId)}
332 onAddRoute={relayOnly ? () => onAddRoute(environment) : null}
333 />
334 ) : null}
335 {routesOpen && (
336 <EnvironmentRoutesList
337 environment={environment}
338 onAddRoute={() => onAddRoute(environment)}
339 />
340 )}
341 {permissionsOpen && (
342 <div
343 id={`remote-permissions-${environmentId}`}
344 className="mt-2 border-t border-border/50"
345 >
346 <SessionPermissions
347 environmentId={environmentId}
348 connected={isConnected}
349 routeContext
350 />
351 </div>
352 )}
353 </>
354 }
355 >
356 {unsupported &&
357 environment.entry.serverUpdateRequired === true &&
358 serverUpdateState.status !== "running" ? (
359 <OutdatedServerUpdateAction
360 environmentId={environmentId}
361 serverLabel={`${environment.label} server`}
362 fromVersion={lastDescriptor?.serverVersion}
363 targetVersion={APP_VERSION}
364 label={serverUpdateState.status === "failed" ? "Retry update" : "Update"}
365 />
366 ) : null}
367 {showUpdateAction ? (
368 <ServerUpdateAction
369 environmentId={environmentId}
370 serverLabel={`${environment.label} server`}
371 selfUpdate={resolveServerSelfUpdateCapability(environment.serverConfig)}
372 installation={environment.serverConfig?.environment.capabilities.serverInstallation}
373 desktopAppUpdate={supportsDesktopAppUpdate(environment.serverConfig)}
374 threadContinuation={supportsServerUpdateThreadContinuation(environment.serverConfig)}
375 targetVersion={versionMismatch.clientVersion}
376 label={serverUpdateState.status === "failed" ? "Retry update" : "Update"}
377 appearance="icon"
378 />
379 ) : null}
380 <Tooltip>
381 <TooltipTrigger
382 render={
383 <Switch
384 size="sm"
385 checked={enabled}
386 disabled={isRemoving || blocked}
387 aria-label={`${enabled ? "Switch off" : "Switch on"} ${environment.label}`}
388 onCheckedChange={(checked) => onSetEnabled(environmentId, checked)}
389 />
390 }
391 />
392 <TooltipPopup side="top">
393 {blocked ? "Client not supported" : enabled ? "Switch off" : "Switch on"}
394 </TooltipPopup>
395 </Tooltip>
396 <Menu>
397 <MenuTrigger
398 render={
399 <Button
400 type="button"
401 variant="ghost-muted"
402 size="icon-xs"
403 disabled={isRemoving}
404 aria-label={`More actions for ${environment.label}`}
405 />
406 }
407 >
408 <EllipsisIcon className="size-3.5" />
409 </MenuTrigger>
410 <MenuPopup align="end">
411 <EnvironmentIconMenu
412 environmentId={environmentId}
413 serverConfig={environment.serverConfig}
414 />
415 <MenuItem onClick={() => setRoutesOpen((open) => !open)}>
416 <RouteIcon />
417 {routesOpen ? "Hide routes" : "Routes"}
418 </MenuItem>
419 {mcpUrl ? (
420 <MenuItem onClick={() => copyMcpUrl(mcpUrl, { url: mcpUrl })}>Copy MCP URL</MenuItem>
421 ) : null}
422 {errorTraceId ? (
423 <MenuItem onClick={() => copyTraceId(errorTraceId)}>Copy trace ID</MenuItem>
424 ) : null}
425 <MenuSeparator />
426 <MenuItem variant="destructive" onClick={() => onRemove(environment)}>
427 {isRemoving ? "Removing…" : "Remove from this device…"}
428 </MenuItem>
429 </MenuPopup>
430 </Menu>
431 </EnvironmentRow>
432 );
434​
435function CloudLinkSwitch({
436 checked,
437 disabled,
438 disabledReason,
439 onCheckedChange,
440 ariaLabel = "Enable T3 Connect",
441}: {
442 readonly checked: boolean;
443 readonly disabled: boolean;
444 readonly disabledReason: string | null;
445 readonly onCheckedChange?: (enabled: boolean) => void;
446 readonly ariaLabel?: string;
447}) {
448 const control = (
449 <Switch
450 aria-label={ariaLabel}
451 checked={checked}
452 disabled={disabled}
453 {...(onCheckedChange ? { onCheckedChange } : {})}
454 />
455 );
456 return disabledReason ? (
457 <Tooltip>
458 <TooltipTrigger render={<span className="inline-flex">{control}</span>} />
459 <TooltipPopup side="top">{disabledReason}</TooltipPopup>
460 </Tooltip>
461 ) : (
462 control
463 );
465​
466function ConfiguredCloudLinkRow({ canManageRelay }: { readonly canManageRelay: boolean }) {
467 const primaryEnvironmentId = usePrimaryEnvironmentId();
468 const {
469 isSignedIn,
470 linkState: primaryCloudLinkState,
471 linkRevoked,
472 managedTunnelActive,
473 managedTunnelOutOfSync,
474 publishAgentActivity,
475 holdWebhooksWhileOffline,
476 operationError,
477 reconcileCloudState,
478 } = useCloudLinkController();
479 const [isUpdating, setIsUpdating] = useState(false);
480 const [isUpdatingPreference, setIsUpdatingPreference] = useState(false);
481​
482 const disabledReason = !isSignedIn
483 ? "Sign in to T3 Connect to manage this environment."
484 : !canManageRelay
485 ? "Your session does not have permission to manage T3 Connect access."
486 : null;
487 const isBusy = isUpdating || isUpdatingPreference;
488 const refreshLinkState = useEffectEvent(primaryCloudLinkState.refresh);
489 // The server rechecks reachability when the tunnel's 30 s readiness poll changes.
490 // Poll while mounted, so a failed read does not stop later ones.
491 useEffect(() => {
492 const interval = window.setInterval(() => refreshLinkState(), 30_000);
493 return () => window.clearInterval(interval);
494 }, []);
495 const reachability = managedTunnelActive ? primaryCloudLinkState.data?.reachability : undefined;
496 const reachabilityStatus =
497 reachability?.status === "reachable" ? (
498 formatConnectReachable(reachability)
499 ) : reachability?.status === "unreachable" ? (
500 <span className="block text-destructive">
501 {[reachability.reason, reachability.hint, `Fix: ${reachability.fix}`]
502 .filter(Boolean)
503 .join(" ")}{" "}
504 <a
505 href={connectReachabilityHelpUrl(reachability.cause)}
506 target="_blank"
507 rel="noreferrer"
508 className="underline underline-offset-2"
509 >
510 More info
511 </a>
512 </span>
513 ) : null;
514​
515 const updateManagedTunnel = async (enabled: boolean) => {
516 if (
517 primaryEnvironmentId === null ||
518 !readEnvironmentScope(primaryEnvironmentId, AuthRelayWriteScope)
519 )
520 return;
521 setIsUpdating(true);
522 const ok = await reconcileCloudState({ managedTunnel: enabled, publish: publishAgentActivity });
523 if (ok) {
524 toastManager.add({
525 type: "success",
526 title: enabled
527 ? "T3 Connect linked"
528 : publishAgentActivity
529 ? "T3 Connect tunnel disabled"
530 : "T3 Connect unlinked",
531 description: enabled
532 ? "This environment is available through T3 Connect."
533 : publishAgentActivity
534 ? "The managed tunnel was removed. Agent activity publishing stays on."
535 : "This environment is no longer available through T3 Connect.",
536 });
537 }
538 setIsUpdating(false);
539 };
540​
541 const updatePublishAgentActivity = async (enabled: boolean) => {
542 if (
543 primaryEnvironmentId === null ||
544 !readEnvironmentScope(primaryEnvironmentId, AuthRelayWriteScope)
545 )
546 return;
547 setIsUpdatingPreference(true);
548 const ok = await reconcileCloudState({ managedTunnel: managedTunnelActive, publish: enabled });
549 if (ok) {
550 toastManager.add({
551 type: "success",
552 title: enabled ? "Agent activity enabled" : "Agent activity disabled",
553 description: enabled
554 ? "This environment publishes agent activity to your mobile clients."
555 : "This environment will stop publishing agent activity.",
556 });
557 }
558 setIsUpdatingPreference(false);
559 };
560​
561 const updateHoldWebhooks = async (enabled: boolean) => {
562 setIsUpdatingPreference(true);
563 const ok = await reconcileCloudState({
564 managedTunnel: managedTunnelActive,
565 publish: publishAgentActivity,
566 holdWebhooksWhileOffline: enabled,
567 });
568 if (ok) {
569 toastManager.add({
570 type: "success",
571 title: enabled ? "Webhooks held while offline" : "Webhooks no longer held",
572 description: enabled
573 ? "T3 Connect keeps webhook requests for up to 24 hours while this environment is offline."
574 : "Requests to an offline environment now fail. Anything already held is still delivered.",
575 });
576 }
577 setIsUpdatingPreference(false);
578 };
579​
580 return (
581 <>
582 {window.desktopBridge ? (
583 <SettingsRow
584 title={searchableSetting("t3-connect").title}
585 description={
586 linkRevoked
587 ? "This environment was removed from T3 Connect. Turn it on to link it again."
588 : managedTunnelActive
589 ? reachability?.status === "unreachable"
590 ? "T3 Connect is on, but other devices cannot reach this environment."
591 : reachability?.status === "reachable"
592 ? "This environment is available to your other devices through T3 Connect."
593 : "T3 Connect is on. Reachability has not been checked yet."
594 : managedTunnelOutOfSync
595 ? "T3 Connect is out of sync. This environment is linked only to publish agent activity, so other devices cannot connect. Turn T3 Connect on to repair it."
596 : "Make this environment available to your other devices through T3 Connect."
597 }
598 status={operationError ?? primaryCloudLinkState.error ?? reachabilityStatus}
599 control={
600 <CloudLinkSwitch
601 checked={managedTunnelActive}
602 disabled={
603 !canManageRelay ||
604 !isSignedIn ||
605 primaryCloudLinkState.data === null ||
606 primaryCloudLinkState.isPending ||
607 isBusy
608 }
609 disabledReason={disabledReason}
610 onCheckedChange={(enabled) => void updateManagedTunnel(enabled)}
611 />
612 }
613 />
614 ) : linkRevoked ? (
615 <SettingsRow
616 title={searchableSetting("t3-connect").title}
617 description="This environment was removed from T3 Connect. Run `t3 connect link` on the host to link it again."
618 />
619 ) : null}
620 <SettingsRow
621 title={searchableSetting("publish-agent-activity").title}
622 description="Send activity to mobile notifications and Live Activities without T3 Connect."
623 control={
624 <CloudLinkSwitch
625 ariaLabel="Publish agent activity to mobile clients"
626 checked={publishAgentActivity}
627 disabled={
628 !canManageRelay ||
629 !isSignedIn ||
630 primaryCloudLinkState.data === null ||
631 primaryCloudLinkState.isPending ||
632 isBusy
633 }
634 disabledReason={disabledReason}
635 onCheckedChange={(enabled) => void updatePublishAgentActivity(enabled)}
636 />
637 }
638 />
639 {managedTunnelActive ? (
640 <SettingsRow
641 title={searchableSetting("hold-webhooks-while-offline").title}
642 description="Keep webhook requests for up to 24 hours while this environment is offline, then deliver them. Off: T3 Connect only forwards requests and stores nothing."
643 control={
644 <CloudLinkSwitch
645 ariaLabel="Hold webhook requests while this environment is offline"
646 checked={holdWebhooksWhileOffline}
647 disabled={!canManageRelay || !isSignedIn || primaryCloudLinkState.isPending || isBusy}
648 disabledReason={disabledReason}
649 onCheckedChange={(enabled) => void updateHoldWebhooks(enabled)}
650 />
651 }
652 />
653 ) : null}
654 </>
655 );
657​
658export function CloudLinkRow({
659 canReadRelay,
660 canManageRelay,
661}: {
662 readonly canReadRelay: boolean;
663 readonly canManageRelay: boolean;
664}) {
665 if (!hasCloudPublicConfig()) return null;
666 if (!canReadRelay) {
667 return (
668 <SettingsRow
669 title="T3 Connect"
670 description="To edit these settings, pair this connection with both View relay and Manage relay permissions."
671 />
672 );
673 }
674 return <ConfiguredCloudLinkRow canManageRelay={canManageRelay} />;
676​
677function EmptyRemoteEnvironments({ cloudEnabled = true }: { readonly cloudEnabled?: boolean }) {
678 return (
679 <Empty className="min-h-52">
680 <EmptyMedia variant="icon">
681 <ChevronsLeftRightEllipsisIcon />
682 </EmptyMedia>
683 <EmptyHeader>
684 <EmptyTitle>No saved remote environments</EmptyTitle>
685 <EmptyDescription>
686 {cloudEnabled
687 ? "Click “Add environment” to pair another environment, or connect one from T3 Connect."
688 : "Click “Add environment” to pair another environment."}
689 </EmptyDescription>
690 </EmptyHeader>
691 </Empty>
692 );
694​
695export function CloudRemoteEnvironmentRows({
696 primaryEnvironmentId,
697 savedEnvironments,
698}: {
699 readonly primaryEnvironmentId: EnvironmentId | null;
700 readonly savedEnvironments: ReadonlyArray<EnvironmentPresentation>;
701}) {
702 return hasCloudPublicConfig() ? (
703 <CloudEnvironmentConnectRows
704 primaryEnvironmentId={primaryEnvironmentId}
705 savedEnvironments={savedEnvironments}
706 empty={<EmptyRemoteEnvironments />}
707 />
708 ) : savedEnvironments.length === 0 ? (
709 <EmptyRemoteEnvironments cloudEnabled={false} />
710 ) : null;