Open History to see the last commit
1import type { DesktopSshEnvironmentTarget, EnvironmentMachineKind } from "@t3tools/contracts";
2import * as Option from "effect/Option";
3import type { ReactNode } from "react";
4
5import { cn } from "~/lib/utils";
6import type { EnvironmentPresentation } from "~/state/environments";
7import { isDesktopLocalConnectionTarget } from "~/connection/desktopLocal";
8import { EnvironmentMachineIcon } from "../EnvironmentMachineIcon";
9
10export function formatDesktopSshTarget(target: DesktopSshEnvironmentTarget): string {
11 const authority = target.username ? `${target.username}@${target.hostname}` : target.hostname;
12 return target.port ? `${authority}:${target.port}` : authority;
13}
14
15/**
16 * How this client reaches a machine, printed first in every environment row so
17 * T3 Connect, SSH, WSL, and plain remote links are told apart without a legend.
18 */
19export function environmentTransportLabel(environment: EnvironmentPresentation): string {
20 const { entry } = environment;
21 if (entry.target._tag === "PrimaryConnectionTarget") return "This machine";
22 if (environment.relayManaged) return "T3 Connect";
23 if (isDesktopLocalConnectionTarget(entry.target)) return "WSL";
24 if (
25 entry.target._tag === "SshConnectionTarget" &&
26 Option.isSome(entry.profile) &&
27 entry.profile.value._tag === "SshConnectionProfile"
28 ) {
29 return `SSH ${formatDesktopSshTarget(entry.profile.value.target)}`;
30 }
31 return environment.displayUrl ?? "Remote link";
32}
33
34/**
35 * One machine in a grouped settings list: icon, name, a single subtitle line,
36 * and controls on the right. Every environment list on the Connections page
37 * uses this so the lists share one rhythm.
38 */
39export function EnvironmentRow({
40 kind,
41 label,
42 subtitle,
43 below,
44 dimmed = false,
45 className,
46 children,
47}: {
48 readonly kind: EnvironmentMachineKind;
49 readonly label: string;
50 readonly subtitle: ReactNode;
51 /** Extra content under the subtitle, such as update progress. */
52 readonly below?: ReactNode;
53 readonly dimmed?: boolean;
54 readonly className?: string;
55 readonly children?: ReactNode;
56}) {
57 return (
58 <div
59 className={cn(
60 "grid grid-cols-[auto_minmax(0,1fr)_auto] items-center gap-x-3 px-3 py-2.5 sm:px-4",
61 dimmed && "opacity-60",
62 className,
63 )}
64 >
65 <EnvironmentMachineIcon aria-hidden kind={kind} className="size-4 text-muted-foreground" />
66 <div className="min-w-0">
67 <p className="truncate text-sm font-medium text-foreground">{label}</p>
68 <div className="truncate text-xs text-muted-foreground">{subtitle}</div>
69 {below}
70 </div>
71 <div className="flex shrink-0 items-center gap-1">{children}</div>
72 </div>
73 );
74}