feat(environments): draw each environment as the machine it runs on (#9299)
Co-authored-by: Julius Marminge <[email protected]> Co-authored-by: Claude Fable 5 <[email protected]>
This commit is contained in:
32 files changed
+1222
-84
No files matched your search
@@ -1,4 +1,4 @@
|
||||
import type { EnvironmentId, VcsRef, ProjectId } from "@t3tools/contracts";
|
||||
import type { EnvironmentId, EnvironmentMachineKind, VcsRef, ProjectId } from "@t3tools/contracts";
|
||||
import * as Schema from "effect/Schema";
|
||||
import { toSortableTimestamp } from "../lib/threadSort";
|
||||
export {
|
||||
@@ -11,6 +11,7 @@ export interface EnvironmentOption {
|
||||
projectId: ProjectId;
|
||||
label: string;
|
||||
isPrimary: boolean;
|
||||
machine: EnvironmentMachineKind;
|
||||
}
|
||||
|
||||
export const EnvMode = Schema.Literals(["local", "worktree"]);
|
||||
|
||||
@@ -2,16 +2,15 @@ import { scopeProjectRef, scopeThreadRef } from "@t3tools/client-runtime/environ
|
||||
import type { EnvironmentId, ThreadId } from "@t3tools/contracts";
|
||||
import {
|
||||
ChevronDownIcon,
|
||||
CloudIcon,
|
||||
FolderGit2Icon,
|
||||
FolderGitIcon,
|
||||
FolderIcon,
|
||||
HistoryIcon,
|
||||
MonitorIcon,
|
||||
} from "lucide-react";
|
||||
import { memo, useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
|
||||
|
||||
import { useComposerDraftStore, type DraftId } from "../composerDraftStore";
|
||||
import { EnvironmentMachineIcon } from "./EnvironmentMachineIcon";
|
||||
import { useProject, useThread, useThreadShellsForProjectRefs } from "../state/entities";
|
||||
import { useIsMobile } from "../hooks/useMediaQuery";
|
||||
import {
|
||||
@@ -105,12 +104,14 @@ const MobileRunContextSelector = memo(function MobileRunContextSelector({
|
||||
? resolveEnvModeLabel("worktree")
|
||||
: resolveCurrentWorkspaceLabel(activeWorktreePath);
|
||||
const isLocked = envLocked || envModeLocked;
|
||||
const EnvironmentIcon = activeEnvironment?.isPrimary ? MonitorIcon : CloudIcon;
|
||||
const icon = showEnvironmentIndicator ? (
|
||||
// Button's base styles apply `-mx-0.5` to descendant SVGs, which eats 4px
|
||||
// out of whatever gap we set. mx-0! cancels that so gap-0.5 reads as 2px.
|
||||
<span className="inline-flex shrink-0 items-center gap-0.5">
|
||||
<EnvironmentIcon className="size-3 shrink-0 mx-0!" />
|
||||
<EnvironmentMachineIcon
|
||||
kind={activeEnvironment?.machine ?? "server"}
|
||||
className="size-3 shrink-0 mx-0!"
|
||||
/>
|
||||
<WorkspaceIcon className="size-3 shrink-0 mx-0!" />
|
||||
</span>
|
||||
) : (
|
||||
@@ -151,21 +152,18 @@ const MobileRunContextSelector = memo(function MobileRunContextSelector({
|
||||
value={environmentId}
|
||||
onValueChange={(value) => onEnvironmentChange(value as EnvironmentId)}
|
||||
>
|
||||
{availableEnvironments.map((env) => {
|
||||
const Icon = env.isPrimary ? MonitorIcon : CloudIcon;
|
||||
return (
|
||||
<MenuRadioItem
|
||||
key={env.environmentId}
|
||||
disabled={envLocked}
|
||||
value={env.environmentId}
|
||||
>
|
||||
<span className="flex min-w-0 items-center gap-1.5">
|
||||
<Icon className="size-3" />
|
||||
<span className="min-w-0 truncate">{env.label}</span>
|
||||
</span>
|
||||
</MenuRadioItem>
|
||||
);
|
||||
})}
|
||||
{availableEnvironments.map((env) => (
|
||||
<MenuRadioItem
|
||||
key={env.environmentId}
|
||||
disabled={envLocked}
|
||||
value={env.environmentId}
|
||||
>
|
||||
<span className="flex min-w-0 items-center gap-1.5">
|
||||
<EnvironmentMachineIcon kind={env.machine} className="size-3" />
|
||||
<span className="min-w-0 truncate">{env.label}</span>
|
||||
</span>
|
||||
</MenuRadioItem>
|
||||
))}
|
||||
</MenuRadioGroup>
|
||||
</MenuGroup>
|
||||
<MenuSeparator />
|
||||
|
||||
@@ -22,6 +22,7 @@ import {
|
||||
PROVIDER_SEND_TURN_MAX_ATTACHMENTS,
|
||||
ProviderInteractionMode,
|
||||
ProviderDriverKind,
|
||||
resolveEnvironmentMachineKind,
|
||||
RuntimeMode,
|
||||
TerminalOpenInput,
|
||||
} from "@t3tools/contracts";
|
||||
@@ -303,6 +304,7 @@ import { type ExpandedImagePreview } from "./chat/ExpandedImagePreview";
|
||||
import { NoActiveThreadState } from "./NoActiveThreadState";
|
||||
import { WorkspacePageHeader } from "./WorkspacePageHeader";
|
||||
import {
|
||||
type EnvironmentOption,
|
||||
resolveEffectiveEnvMode,
|
||||
resolveLocalCheckoutBranchMismatch,
|
||||
shouldShowComposerContextStrip,
|
||||
@@ -2061,22 +2063,18 @@ function ChatViewContent(props: ChatViewProps) {
|
||||
(p) => deriveLogicalProjectKeyFromSettings(p, projectGroupingSettings) === logicalKey,
|
||||
);
|
||||
const seen = new Set<string>();
|
||||
const envs: Array<{
|
||||
environmentId: EnvironmentId;
|
||||
projectId: ProjectId;
|
||||
label: string;
|
||||
isPrimary: boolean;
|
||||
}> = [];
|
||||
const envs: EnvironmentOption[] = [];
|
||||
for (const p of memberProjects) {
|
||||
if (seen.has(p.environmentId)) continue;
|
||||
seen.add(p.environmentId);
|
||||
const isPrimary = p.environmentId === primaryEnvironmentId;
|
||||
const label = environmentById.get(p.environmentId)?.label ?? p.environmentId;
|
||||
const environment = environmentById.get(p.environmentId) ?? null;
|
||||
envs.push({
|
||||
environmentId: p.environmentId,
|
||||
projectId: p.id,
|
||||
label,
|
||||
label: environment?.label ?? p.environmentId,
|
||||
isPrimary,
|
||||
machine: resolveEnvironmentMachineKind(environment?.serverConfig ?? null),
|
||||
});
|
||||
}
|
||||
// Sort: primary first, then alphabetical
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
import type { EnvironmentMachineKind } from "@t3tools/contracts";
|
||||
import { CloudIcon, LaptopIcon, MonitorIcon, ServerIcon, type LucideProps } from "lucide-react";
|
||||
import type { FunctionComponent, SVGProps } from "react";
|
||||
|
||||
// Lucide has no Apple desktops, so these two are drawn to its grammar (24
|
||||
// unit grid, 2 unit stroke, round joins) and share its prop surface so callers
|
||||
// can swap freely.
|
||||
function LucideLike(props: SVGProps<SVGSVGElement>) {
|
||||
return (
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
width="24"
|
||||
height="24"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeWidth="2"
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
/** A Mac mini: squat rounded slab with a front-edge LED. */
|
||||
export function MacMiniIcon(props: SVGProps<SVGSVGElement>) {
|
||||
return (
|
||||
<LucideLike {...props}>
|
||||
<rect width="20" height="8" x="2" y="8" rx="2" />
|
||||
<path d="M6 12h.01" />
|
||||
</LucideLike>
|
||||
);
|
||||
}
|
||||
|
||||
/** A Mac Studio: the same slab twice as tall, ports along the front foot. */
|
||||
export function MacStudioIcon(props: SVGProps<SVGSVGElement>) {
|
||||
return (
|
||||
<LucideLike {...props}>
|
||||
<rect width="18" height="14" x="3" y="5" rx="2" />
|
||||
<path d="M7 15h.01M11 15h.01M15 15h.01" />
|
||||
</LucideLike>
|
||||
);
|
||||
}
|
||||
|
||||
const ICON_BY_KIND: Record<EnvironmentMachineKind, FunctionComponent<LucideProps>> = {
|
||||
server: ServerIcon,
|
||||
cloud: CloudIcon,
|
||||
desktop: MonitorIcon,
|
||||
laptop: LaptopIcon,
|
||||
"mac-mini": MacMiniIcon,
|
||||
"mac-studio": MacStudioIcon,
|
||||
};
|
||||
|
||||
export const ENVIRONMENT_MACHINE_KIND_LABELS: Record<EnvironmentMachineKind, string> = {
|
||||
server: "Server",
|
||||
cloud: "Cloud VM",
|
||||
desktop: "Desktop",
|
||||
laptop: "Laptop",
|
||||
"mac-mini": "Mac mini",
|
||||
"mac-studio": "Mac Studio",
|
||||
};
|
||||
|
||||
export function environmentMachineIcon(
|
||||
kind: EnvironmentMachineKind,
|
||||
): FunctionComponent<LucideProps> {
|
||||
return ICON_BY_KIND[kind];
|
||||
}
|
||||
|
||||
export function EnvironmentMachineIcon({
|
||||
kind,
|
||||
...props
|
||||
}: LucideProps & { readonly kind: EnvironmentMachineKind }) {
|
||||
const Icon = ICON_BY_KIND[kind];
|
||||
return <Icon {...props} />;
|
||||
}
|
||||
@@ -22,6 +22,7 @@ import {
|
||||
ThreadWorktreeIndicator,
|
||||
useLinkedThreadPullRequest,
|
||||
} from "./ThreadStatusIndicators";
|
||||
import { EnvironmentMachineIcon } from "./EnvironmentMachineIcon";
|
||||
import { ProjectFavicon } from "./ProjectFavicon";
|
||||
import { useAtomValue } from "@effect/atom-react";
|
||||
import { autoAnimate } from "@formkit/auto-animate";
|
||||
@@ -48,6 +49,7 @@ import {
|
||||
type ScopedThreadRef,
|
||||
type ResolvedKeybindingsConfig,
|
||||
type SidebarProjectGroupingMode,
|
||||
resolveEnvironmentMachineKind,
|
||||
ThreadId,
|
||||
} from "@t3tools/contracts";
|
||||
import {
|
||||
@@ -395,9 +397,11 @@ export const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThr
|
||||
});
|
||||
const environment = useEnvironment(thread.environmentId);
|
||||
const primaryEnvironmentId = usePrimaryEnvironmentId();
|
||||
const isRemoteThread =
|
||||
primaryEnvironmentId !== null && thread.environmentId !== primaryEnvironmentId;
|
||||
// No primary (the hosted app) means every thread is remote, and the machine
|
||||
// glyph is what tells the environments apart.
|
||||
const isRemoteThread = thread.environmentId !== primaryEnvironmentId;
|
||||
const remoteEnvLabel = environment?.label ?? null;
|
||||
const remoteMachine = resolveEnvironmentMachineKind(environment?.serverConfig ?? null);
|
||||
// A desktop-local secondary backend (e.g. the WSL backend) shows up as a
|
||||
// bearer environment whose connection id is prefixed "local:". It runs on the
|
||||
// user's own machine, so the cloud icon is misleading — label it "Local" and
|
||||
@@ -876,7 +880,10 @@ export const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThr
|
||||
/>
|
||||
}
|
||||
>
|
||||
<CloudIcon className="size-3 text-muted-foreground/40" />
|
||||
<EnvironmentMachineIcon
|
||||
kind={remoteMachine}
|
||||
className="size-3 text-muted-foreground/40"
|
||||
/>
|
||||
</TooltipTrigger>
|
||||
<TooltipPopup side="top">{threadEnvironmentLabel}</TooltipPopup>
|
||||
</Tooltip>
|
||||
|
||||
@@ -29,7 +29,12 @@ import {
|
||||
scopeThreadRef,
|
||||
scopedThreadKey,
|
||||
} from "@t3tools/client-runtime/environment";
|
||||
import type { ScopedThreadRef, ThreadId } from "@t3tools/contracts";
|
||||
import {
|
||||
resolveEnvironmentMachineKind,
|
||||
type EnvironmentMachineKind,
|
||||
type ScopedThreadRef,
|
||||
type ThreadId,
|
||||
} from "@t3tools/contracts";
|
||||
import type { TimestampFormat } from "@t3tools/contracts/settings";
|
||||
import {
|
||||
AlarmClockIcon,
|
||||
@@ -47,7 +52,6 @@ import {
|
||||
PinIcon,
|
||||
PlusIcon,
|
||||
SearchIcon,
|
||||
ServerIcon,
|
||||
SettingsIcon,
|
||||
SquarePenIcon,
|
||||
TerminalIcon,
|
||||
@@ -121,6 +125,7 @@ import {
|
||||
import { formatRelativeTimeLabel, parseTimestampDate } from "../timestampFormat";
|
||||
import type { SidebarThreadSummary } from "../types";
|
||||
import { cn } from "~/lib/utils";
|
||||
import { EnvironmentMachineIcon } from "./EnvironmentMachineIcon";
|
||||
import { buildThreadActionMenuItems } from "./threadActionMenu.logic";
|
||||
import {
|
||||
animatePinnedLayoutChanges,
|
||||
@@ -274,6 +279,7 @@ function SidebarThreadTooltip({
|
||||
projectCwd,
|
||||
projectFaviconPath,
|
||||
environmentLabel,
|
||||
environmentMachine,
|
||||
providerEntry,
|
||||
showInstanceBadge,
|
||||
modelInstanceId,
|
||||
@@ -287,6 +293,7 @@ function SidebarThreadTooltip({
|
||||
projectCwd: string | null;
|
||||
projectFaviconPath: string | null;
|
||||
environmentLabel: string | null;
|
||||
environmentMachine: EnvironmentMachineKind;
|
||||
providerEntry: ProviderInstanceEntry | null;
|
||||
showInstanceBadge: boolean;
|
||||
modelInstanceId: string;
|
||||
@@ -325,7 +332,10 @@ function SidebarThreadTooltip({
|
||||
) : null}
|
||||
{environmentLabel ? (
|
||||
<div className="flex min-w-0 items-center gap-2">
|
||||
<ServerIcon className="size-3 shrink-0 stroke-muted-foreground" />
|
||||
<EnvironmentMachineIcon
|
||||
kind={environmentMachine}
|
||||
className="size-3 shrink-0 stroke-muted-foreground"
|
||||
/>
|
||||
<div className="min-w-0 truncate text-foreground/75">{environmentLabel}</div>
|
||||
</div>
|
||||
) : null}
|
||||
@@ -735,6 +745,7 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: {
|
||||
jumpLabel: string | null;
|
||||
currentEnvironmentId: string | null;
|
||||
environmentLabel: string | null;
|
||||
environmentMachine: EnvironmentMachineKind;
|
||||
projectCwd: string | null;
|
||||
projectFaviconPath: string | null;
|
||||
projectTitle: string | null;
|
||||
@@ -963,8 +974,11 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: {
|
||||
? getTriggerDisplayModelLabel(selectedModel)
|
||||
: thread.modelSelection.model;
|
||||
|
||||
const isRemote =
|
||||
props.currentEnvironmentId !== null && thread.environmentId !== props.currentEnvironmentId;
|
||||
// The local environment is "this machine" and needs no marker; every other
|
||||
// one gets its machine glyph. With no local environment (the hosted app)
|
||||
// that is every thread, which is the point: the glyph is what tells rows on
|
||||
// different machines apart.
|
||||
const isRemote = thread.environmentId !== props.currentEnvironmentId;
|
||||
|
||||
const detailsTooltip = (
|
||||
<SidebarThreadTooltip
|
||||
@@ -973,6 +987,7 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: {
|
||||
projectCwd={props.projectCwd}
|
||||
projectFaviconPath={props.projectFaviconPath}
|
||||
environmentLabel={props.environmentLabel}
|
||||
environmentMachine={props.environmentMachine}
|
||||
providerEntry={providerEntry}
|
||||
showInstanceBadge={showInstanceBadge}
|
||||
modelInstanceId={modelInstanceId}
|
||||
@@ -1590,7 +1605,11 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: {
|
||||
>
|
||||
{isRemote ? (
|
||||
<span className="inline-flex shrink-0 items-center text-sidebar-muted-foreground/70">
|
||||
<ServerIcon aria-hidden className="size-3.5" />
|
||||
<EnvironmentMachineIcon
|
||||
aria-hidden
|
||||
kind={props.environmentMachine}
|
||||
className="size-3.5"
|
||||
/>
|
||||
</span>
|
||||
) : null}
|
||||
{driverKind ? (
|
||||
@@ -1636,6 +1655,7 @@ const SidebarSearchResultRow = memo(function SidebarSearchResultRow(props: {
|
||||
projectFaviconPath: string | null;
|
||||
projectTitle: string | null;
|
||||
environmentLabel: string | null;
|
||||
environmentMachine: EnvironmentMachineKind;
|
||||
providerEntryByInstanceId: ReadonlyMap<string, ProviderInstanceEntry>;
|
||||
isHighlighted: boolean;
|
||||
isRouteActive: boolean;
|
||||
@@ -1731,6 +1751,7 @@ const SidebarSearchResultRow = memo(function SidebarSearchResultRow(props: {
|
||||
projectCwd={props.projectCwd}
|
||||
projectFaviconPath={props.projectFaviconPath}
|
||||
environmentLabel={props.environmentLabel}
|
||||
environmentMachine={props.environmentMachine}
|
||||
providerEntry={providerEntry}
|
||||
showInstanceBadge={showInstanceBadge}
|
||||
modelInstanceId={modelInstanceId}
|
||||
@@ -1871,6 +1892,19 @@ export default function Sidebar() {
|
||||
),
|
||||
[environments],
|
||||
);
|
||||
const environmentMachineById = useMemo(
|
||||
() =>
|
||||
new Map(
|
||||
environments.map(
|
||||
(environment) =>
|
||||
[
|
||||
environment.environmentId,
|
||||
resolveEnvironmentMachineKind(environment.serverConfig),
|
||||
] as const,
|
||||
),
|
||||
),
|
||||
[environments],
|
||||
);
|
||||
const orderedProjects = useMemo(
|
||||
() =>
|
||||
orderItemsByPreferredIds({
|
||||
@@ -3717,6 +3751,9 @@ export default function Sidebar() {
|
||||
) ?? null
|
||||
}
|
||||
environmentLabel={environmentLabelById.get(thread.environmentId) ?? null}
|
||||
environmentMachine={
|
||||
environmentMachineById.get(thread.environmentId) ?? "server"
|
||||
}
|
||||
providerEntryByInstanceId={
|
||||
providerEntriesByEnvironment.get(thread.environmentId) ??
|
||||
EMPTY_PROVIDER_ENTRIES
|
||||
@@ -3815,6 +3852,9 @@ export default function Sidebar() {
|
||||
}
|
||||
currentEnvironmentId={primaryEnvironmentId}
|
||||
environmentLabel={environmentLabelById.get(thread.environmentId) ?? null}
|
||||
environmentMachine={
|
||||
environmentMachineById.get(thread.environmentId) ?? "server"
|
||||
}
|
||||
projectCwd={
|
||||
projectCwdByKey.get(`${thread.environmentId}:${thread.projectId}`) ?? null
|
||||
}
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
import { scopedThreadKey, scopeProjectRef } from "@t3tools/client-runtime/environment";
|
||||
import { squashAtomCommandFailure } from "@t3tools/client-runtime/state/runtime";
|
||||
import type {
|
||||
EnvironmentId,
|
||||
PullRequestAction,
|
||||
PullRequestMergeMethod,
|
||||
PullRequestUpdateMethod,
|
||||
PullRequestRef,
|
||||
PullRequestState,
|
||||
ScopedThreadRef,
|
||||
import {
|
||||
type EnvironmentId,
|
||||
type PullRequestAction,
|
||||
type PullRequestMergeMethod,
|
||||
type PullRequestUpdateMethod,
|
||||
type PullRequestRef,
|
||||
type PullRequestState,
|
||||
resolveEnvironmentMachineKind,
|
||||
type ScopedThreadRef,
|
||||
} from "@t3tools/contracts";
|
||||
import {
|
||||
ArrowDownUpIcon,
|
||||
@@ -36,7 +37,6 @@ import {
|
||||
PlayIcon,
|
||||
RefreshCwIcon,
|
||||
RotateCcwIcon,
|
||||
ServerIcon,
|
||||
TriangleAlertIcon,
|
||||
} from "lucide-react";
|
||||
import {
|
||||
@@ -77,6 +77,7 @@ import {
|
||||
AlertDialogPopup,
|
||||
AlertDialogTitle,
|
||||
} from "../ui/alert-dialog";
|
||||
import { EnvironmentMachineIcon } from "../EnvironmentMachineIcon";
|
||||
import { Badge } from "../ui/badge";
|
||||
import { Button } from "../ui/button";
|
||||
import { Input } from "../ui/input";
|
||||
@@ -272,7 +273,10 @@ function ActOnEnvironmentPicker({
|
||||
{/* The radio item lays its children out as one block, so the icon and the label
|
||||
need their own row to share a line. */}
|
||||
<span className="flex min-w-0 items-center gap-2">
|
||||
<ServerIcon className="size-3.5 shrink-0" />
|
||||
<EnvironmentMachineIcon
|
||||
kind={environment.machine ?? "server"}
|
||||
className="size-3.5 shrink-0"
|
||||
/>
|
||||
<span className="truncate">{environment.label}</span>
|
||||
</span>
|
||||
</MenuRadioItem>
|
||||
@@ -729,7 +733,11 @@ export function PullRequestDetailPanel({
|
||||
? resolvePickableEnvironments(
|
||||
{ environmentId, projectId: reference.projectId },
|
||||
projects,
|
||||
environments,
|
||||
environments.map((environment) => ({
|
||||
environmentId: environment.environmentId,
|
||||
label: environment.label,
|
||||
machine: resolveEnvironmentMachineKind(environment.serverConfig),
|
||||
})),
|
||||
)
|
||||
: [],
|
||||
[context, environmentId, environments, projects, reference.projectId],
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { EnvironmentId, ProjectId } from "@t3tools/contracts";
|
||||
import type { EnvironmentId, EnvironmentMachineKind, ProjectId } from "@t3tools/contracts";
|
||||
|
||||
/** The little of a project this needs: who holds it, and which repository it is a copy of. */
|
||||
export interface AssignableProject {
|
||||
@@ -69,6 +69,7 @@ export interface PickableEnvironment {
|
||||
readonly projectId: ProjectId;
|
||||
readonly workspaceRoot: string;
|
||||
readonly label: string;
|
||||
readonly machine?: EnvironmentMachineKind;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -85,17 +86,21 @@ export interface PickableEnvironment {
|
||||
export function resolvePickableEnvironments(
|
||||
current: { readonly environmentId: EnvironmentId; readonly projectId: ProjectId },
|
||||
projects: ReadonlyArray<AssignableProject & { readonly workspaceRoot: string }>,
|
||||
environments: ReadonlyArray<{ readonly environmentId: EnvironmentId; readonly label: string }>,
|
||||
environments: ReadonlyArray<{
|
||||
readonly environmentId: EnvironmentId;
|
||||
readonly label: string;
|
||||
readonly machine?: EnvironmentMachineKind;
|
||||
}>,
|
||||
): ReadonlyArray<PickableEnvironment> {
|
||||
const own = projects.find(
|
||||
(project) =>
|
||||
project.environmentId === current.environmentId && project.id === current.projectId,
|
||||
);
|
||||
const key = own === undefined ? undefined : repositoryKey(own);
|
||||
const ownLabel = environments.find(
|
||||
const ownEnvironment = environments.find(
|
||||
(environment) => environment.environmentId === current.environmentId,
|
||||
)?.label;
|
||||
if (own === undefined || !key || ownLabel === undefined) return [];
|
||||
);
|
||||
if (own === undefined || !key || ownEnvironment === undefined) return [];
|
||||
const others = environments.flatMap((environment) => {
|
||||
if (environment.environmentId === current.environmentId) return [];
|
||||
// One entry per server, whichever copy comes first: a server holding two worktrees of the
|
||||
@@ -112,6 +117,7 @@ export function resolvePickableEnvironments(
|
||||
projectId: copy.id,
|
||||
workspaceRoot: copy.workspaceRoot,
|
||||
label: environment.label,
|
||||
...(environment.machine === undefined ? {} : { machine: environment.machine }),
|
||||
},
|
||||
];
|
||||
});
|
||||
@@ -123,7 +129,8 @@ export function resolvePickableEnvironments(
|
||||
environmentId: current.environmentId,
|
||||
projectId: own.id,
|
||||
workspaceRoot: own.workspaceRoot,
|
||||
label: ownLabel,
|
||||
label: ownEnvironment.label,
|
||||
...(ownEnvironment.machine === undefined ? {} : { machine: ownEnvironment.machine }),
|
||||
},
|
||||
...others,
|
||||
];
|
||||
|
||||
@@ -27,6 +27,7 @@ import {
|
||||
type DesktopServerExposureState,
|
||||
type DesktopWslState,
|
||||
type EnvironmentId,
|
||||
resolveEnvironmentMachineKind,
|
||||
} from "@t3tools/contracts";
|
||||
import { connectionStatusText } from "@t3tools/client-runtime/connection";
|
||||
import {
|
||||
@@ -53,6 +54,7 @@ import {
|
||||
useRelativeTimeTick,
|
||||
} from "./settingsLayout";
|
||||
import { searchableSetting } from "./settingsSearch";
|
||||
import { EnvironmentIconPicker } from "./EnvironmentIconPicker";
|
||||
import { Input } from "../ui/input";
|
||||
import { Checkbox } from "../ui/checkbox";
|
||||
import {
|
||||
@@ -86,6 +88,7 @@ import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";
|
||||
import { Button } from "../ui/button";
|
||||
import { Empty, EmptyDescription, EmptyHeader, EmptyMedia, EmptyTitle } from "../ui/empty";
|
||||
import { AnimatedHeight } from "../AnimatedHeight";
|
||||
import { EnvironmentMachineIcon } from "../EnvironmentMachineIcon";
|
||||
import { Textarea } from "../ui/textarea";
|
||||
import { getPairingTokenFromUrl, setPairingTokenOnUrl } from "../../pairingUrl";
|
||||
import { readHostedPairingRequest } from "../../hostedPairing";
|
||||
@@ -1438,6 +1441,11 @@ function SavedBackendListRow({
|
||||
: null
|
||||
}
|
||||
/>
|
||||
<EnvironmentMachineIcon
|
||||
aria-hidden
|
||||
kind={resolveEnvironmentMachineKind(environment.serverConfig)}
|
||||
className="size-3.5 shrink-0 text-muted-foreground"
|
||||
/>
|
||||
<h3 className="min-w-0 truncate text-sm font-medium text-foreground">
|
||||
{environment.label}
|
||||
</h3>
|
||||
@@ -1445,6 +1453,15 @@ function SavedBackendListRow({
|
||||
{metadataBits.length > 0 ? (
|
||||
<p className="truncate text-xs text-muted-foreground">{metadataBits.join(" · ")}</p>
|
||||
) : null}
|
||||
{isConnected ? (
|
||||
<div className="pt-1">
|
||||
<EnvironmentIconPicker
|
||||
environmentId={environmentId}
|
||||
serverConfig={environment.serverConfig}
|
||||
size="xs"
|
||||
/>
|
||||
</div>
|
||||
) : null}
|
||||
{serverUpdateState.status !== "idle" ? (
|
||||
<div className="max-w-md">
|
||||
<ServerUpdateProgress state={serverUpdateState} />
|
||||
@@ -3081,6 +3098,18 @@ export function ConnectionsSettings() {
|
||||
}
|
||||
/>
|
||||
) : null}
|
||||
{primaryEnvironmentId !== null ? (
|
||||
<SettingsRow
|
||||
{...searchableSetting("environment-icon")}
|
||||
description="The machine other devices see this environment as. Automatic uses what the server detected."
|
||||
control={
|
||||
<EnvironmentIconPicker
|
||||
environmentId={primaryEnvironmentId}
|
||||
serverConfig={primaryServerConfig}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
) : null}
|
||||
{desktopBridge ? (
|
||||
<>
|
||||
{renderNetworkAccessRow()}
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
import type { ServerConfig } from "@t3tools/contracts";
|
||||
import { describe, expect, it } from "vite-plus/test";
|
||||
|
||||
import { resolveEnvironmentIconPickerLock } from "./EnvironmentIconPicker";
|
||||
|
||||
const config = (environmentIcon: boolean | undefined) =>
|
||||
({
|
||||
environment: { capabilities: environmentIcon === undefined ? {} : { environmentIcon } },
|
||||
}) as unknown as ServerConfig;
|
||||
|
||||
describe("resolveEnvironmentIconPickerLock", () => {
|
||||
it("locks until the environment is connected", () => {
|
||||
expect(
|
||||
resolveEnvironmentIconPickerLock({ serverConfig: null, operateAccess: "granted" }),
|
||||
).toMatch(/Connect/);
|
||||
});
|
||||
|
||||
it("locks on servers that predate the setting, before looking at permissions", () => {
|
||||
expect(
|
||||
resolveEnvironmentIconPickerLock({
|
||||
serverConfig: config(undefined),
|
||||
operateAccess: "denied",
|
||||
}),
|
||||
).toMatch(/too old/);
|
||||
});
|
||||
|
||||
it("locks when the session cannot operate the environment", () => {
|
||||
expect(
|
||||
resolveEnvironmentIconPickerLock({ serverConfig: config(true), operateAccess: "denied" }),
|
||||
).toMatch(/cannot change/);
|
||||
});
|
||||
|
||||
it("stays open while access is still resolving so a slow session does not flicker", () => {
|
||||
expect(
|
||||
resolveEnvironmentIconPickerLock({ serverConfig: config(true), operateAccess: "pending" }),
|
||||
).toBeNull();
|
||||
expect(
|
||||
resolveEnvironmentIconPickerLock({ serverConfig: config(true), operateAccess: "granted" }),
|
||||
).toBeNull();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,161 @@
|
||||
import {
|
||||
ENVIRONMENT_MACHINE_KINDS,
|
||||
isEnvironmentMachineKind,
|
||||
resolveEnvironmentMachineKind,
|
||||
type EnvironmentId,
|
||||
type ServerConfig,
|
||||
} from "@t3tools/contracts";
|
||||
import { useCallback } from "react";
|
||||
|
||||
import { isElectron } from "../../env";
|
||||
import { usePrimarySessionState } from "../../environments/primary";
|
||||
import { useUpdateEnvironmentSettings } from "../../hooks/useSettings";
|
||||
import { usePrimaryEnvironmentId } from "../../state/environments";
|
||||
import { useEnvironmentSessionState } from "../../state/session";
|
||||
import { ENVIRONMENT_MACHINE_KIND_LABELS, EnvironmentMachineIcon } from "../EnvironmentMachineIcon";
|
||||
import { Select, SelectItem, SelectPopup, SelectTrigger, SelectValue } from "../ui/select";
|
||||
import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";
|
||||
import {
|
||||
resolvePrimaryOperateAccess,
|
||||
resolveRemoteOperateAccess,
|
||||
} from "./ProviderSettingsPanel.logic";
|
||||
|
||||
const AUTOMATIC_VALUE = "automatic";
|
||||
|
||||
/**
|
||||
* Why the picker is inert, in the order the user can do something about it.
|
||||
* Null means it can be changed.
|
||||
*/
|
||||
export function resolveEnvironmentIconPickerLock(input: {
|
||||
readonly serverConfig: ServerConfig | null;
|
||||
readonly operateAccess: "granted" | "denied" | "pending";
|
||||
}): string | null {
|
||||
if (input.serverConfig === null) {
|
||||
return "Connect to this environment to change its icon.";
|
||||
}
|
||||
if (input.serverConfig.environment.capabilities.environmentIcon !== true) {
|
||||
return "This environment's server is too old to keep an icon. Update it to choose one.";
|
||||
}
|
||||
if (input.operateAccess === "denied") {
|
||||
return "Your session on this environment cannot change its settings.";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// Same split the provider settings use: the desktop app owns its primary
|
||||
// server outright, a browser session on the primary checks its cookie
|
||||
// session's scopes, and a remote checks the scopes its own server reports.
|
||||
function useEnvironmentOperateAccess(environmentId: EnvironmentId) {
|
||||
const isPrimary = usePrimaryEnvironmentId() === environmentId;
|
||||
const primarySession = usePrimarySessionState();
|
||||
const remoteSession = useEnvironmentSessionState(environmentId);
|
||||
if (isPrimary) {
|
||||
return isElectron
|
||||
? "granted"
|
||||
: resolvePrimaryOperateAccess({
|
||||
isPrimary: true,
|
||||
hasDesktopBridge: false,
|
||||
session: primarySession.data,
|
||||
isPending: primarySession.isPending,
|
||||
hasError: primarySession.error !== null,
|
||||
});
|
||||
}
|
||||
return resolveRemoteOperateAccess({
|
||||
session: remoteSession.data,
|
||||
isPending: remoteSession.isPending,
|
||||
hasError: remoteSession.hasError,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Picks the machine glyph an environment wears everywhere it is listed.
|
||||
* "Automatic" clears the override so the server's own detection shows
|
||||
* through; the label says what that currently resolves to so the user can
|
||||
* tell whether detection got it right before overriding. The control stays
|
||||
* visible while locked so the current icon still reads, the same way
|
||||
* server-scoped rows go inert instead of disappearing.
|
||||
*/
|
||||
export function EnvironmentIconPicker({
|
||||
environmentId,
|
||||
serverConfig,
|
||||
size = "sm",
|
||||
}: {
|
||||
readonly environmentId: EnvironmentId;
|
||||
readonly serverConfig: ServerConfig | null;
|
||||
readonly size?: "xs" | "sm";
|
||||
}) {
|
||||
const updateSettings = useUpdateEnvironmentSettings(environmentId);
|
||||
const operateAccess = useEnvironmentOperateAccess(environmentId);
|
||||
const lock = resolveEnvironmentIconPickerLock({ serverConfig, operateAccess });
|
||||
const override = serverConfig?.settings.environmentIcon ?? null;
|
||||
const detected = serverConfig?.environment.platform.machine ?? null;
|
||||
const resolved = resolveEnvironmentMachineKind(serverConfig);
|
||||
const value = override ?? AUTOMATIC_VALUE;
|
||||
const automaticLabel =
|
||||
detected === null ? "Automatic" : `Automatic (${ENVIRONMENT_MACHINE_KIND_LABELS[detected]})`;
|
||||
|
||||
const handleValueChange = useCallback(
|
||||
(next: string | null) => {
|
||||
if (next === null) return;
|
||||
if (next === AUTOMATIC_VALUE) {
|
||||
updateSettings({ environmentIcon: null });
|
||||
} else if (isEnvironmentMachineKind(next)) {
|
||||
updateSettings({ environmentIcon: next });
|
||||
}
|
||||
},
|
||||
[updateSettings],
|
||||
);
|
||||
|
||||
const select = (
|
||||
<Select value={value} onValueChange={handleValueChange} disabled={lock !== null}>
|
||||
<SelectTrigger size={size} className="w-full sm:w-52" aria-label="Environment icon">
|
||||
<SelectValue>
|
||||
<span className="flex min-w-0 items-center gap-2">
|
||||
<EnvironmentMachineIcon kind={resolved} className="size-3.5 shrink-0" />
|
||||
<span className="truncate">
|
||||
{override === null ? automaticLabel : ENVIRONMENT_MACHINE_KIND_LABELS[override]}
|
||||
</span>
|
||||
</span>
|
||||
</SelectValue>
|
||||
</SelectTrigger>
|
||||
<SelectPopup align="end" alignItemWithTrigger={false}>
|
||||
<SelectItem hideIndicator value={AUTOMATIC_VALUE}>
|
||||
<span className="flex min-w-0 items-center gap-2">
|
||||
<EnvironmentMachineIcon kind={detected ?? "server"} className="size-3.5 shrink-0" />
|
||||
<span className="truncate">{automaticLabel}</span>
|
||||
</span>
|
||||
</SelectItem>
|
||||
{ENVIRONMENT_MACHINE_KINDS.map((kind) => (
|
||||
<SelectItem hideIndicator key={kind} value={kind}>
|
||||
<span className="flex min-w-0 items-center gap-2">
|
||||
<EnvironmentMachineIcon kind={kind} className="size-3.5 shrink-0" />
|
||||
<span className="truncate">{ENVIRONMENT_MACHINE_KIND_LABELS[kind]}</span>
|
||||
</span>
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectPopup>
|
||||
</Select>
|
||||
);
|
||||
|
||||
if (lock === null) {
|
||||
return select;
|
||||
}
|
||||
return (
|
||||
<Tooltip>
|
||||
<TooltipTrigger
|
||||
render={
|
||||
// Focusable so keyboard users can still reach the explanation.
|
||||
<span
|
||||
tabIndex={0}
|
||||
className="flex w-full items-center rounded-md outline-none focus-visible:ring-2 focus-visible:ring-ring sm:w-auto"
|
||||
/>
|
||||
}
|
||||
>
|
||||
<span className="flex w-full items-center sm:w-auto">{select}</span>
|
||||
</TooltipTrigger>
|
||||
<TooltipPopup side="top" className="max-w-72">
|
||||
{lock}
|
||||
</TooltipPopup>
|
||||
</Tooltip>
|
||||
);
|
||||
}
|
||||
@@ -406,6 +406,14 @@ export const SETTINGS_SEARCH_ITEMS = [
|
||||
],
|
||||
primaryOnly: true,
|
||||
},
|
||||
{
|
||||
id: "environment-icon",
|
||||
title: "Environment icon",
|
||||
to: "/settings/connections",
|
||||
targetId: "connections-environment",
|
||||
searchTerms: ["machine glyph sidebar mac mini studio laptop desktop server cloud vm"],
|
||||
localBackendManagementOnly: true,
|
||||
},
|
||||
{
|
||||
id: "network-access",
|
||||
title: "Network access",
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { scopeThreadRef } from "@t3tools/client-runtime/environment";
|
||||
import { pullRequestHostOf, ThreadId } from "@t3tools/contracts";
|
||||
import { pullRequestHostOf, resolveEnvironmentMachineKind, ThreadId } from "@t3tools/contracts";
|
||||
import type {
|
||||
EnvironmentId,
|
||||
ProjectId,
|
||||
@@ -19,8 +19,6 @@ import {
|
||||
ChevronDownIcon,
|
||||
ClockIcon,
|
||||
EyeIcon,
|
||||
MonitorIcon,
|
||||
ServerIcon,
|
||||
GitMergeIcon,
|
||||
GitPullRequestClosedIcon,
|
||||
GitPullRequestIcon,
|
||||
@@ -86,6 +84,7 @@ import {
|
||||
writePullRequestListPreferences,
|
||||
} from "../components/pullRequest/pullRequestListPreferences";
|
||||
import { assignProjectsToEnvironments } from "../components/pullRequest/pullRequestProjectAssignment.logic";
|
||||
import { environmentMachineIcon } from "../components/EnvironmentMachineIcon";
|
||||
import { PullRequestDetailPanel } from "../components/pullRequest/PullRequestDetailPanel";
|
||||
import {
|
||||
PullRequestFiltersMenu,
|
||||
@@ -1736,14 +1735,14 @@ function PullRequestsRouteView() {
|
||||
};
|
||||
}),
|
||||
];
|
||||
// The same shape the host pills take, so the two groups read as one control. A local
|
||||
// connection wears the screen it is on; every other server wears a server.
|
||||
// The same shape the host pills take, so the two groups read as one control. Each server
|
||||
// wears the machine it runs on.
|
||||
const serverMenuOptions: ReadonlyArray<PullRequestFilterOption<string>> = [
|
||||
{ value: "", label: "All servers", Icon: LayersIcon },
|
||||
...capableEnvironments.map((environment) => ({
|
||||
value: environment.environmentId,
|
||||
label: environment.label,
|
||||
Icon: environment.displayUrl === null ? MonitorIcon : ServerIcon,
|
||||
Icon: environmentMachineIcon(resolveEnvironmentMachineKind(environment.serverConfig)),
|
||||
})),
|
||||
];
|
||||
const sortMenu = (
|
||||
|
||||
Reference in new issue
Block a user