TypeScript
fix(web): update dialog shows one row per machine (#26210)
Theo Browne91992bd5d464
diff --git a/apps/web/src/components/sidebar/SidebarUpdatePill.browser.test.tsx b/apps/web/src/components/sidebar/SidebarUpdatePill.browser.test.tsxindex c7b1ca44877..714d1564bac 100644--- a/apps/web/src/components/sidebar/SidebarUpdatePill.browser.test.tsx+++ b/apps/web/src/components/sidebar/SidebarUpdatePill.browser.test.tsx@@ -37,9 +37,10 @@ vi.mock("./useUpdateEverything", () => ({useUpdateEverything: () => ({hasUpdates: mocks.hasUpdates,summary: "Update everything",- lines: [],+ version: null,+ providerCount: 0,+ rows: [],restarts: [],- skipped: [],}),}));diff --git a/apps/web/src/components/sidebar/SidebarUpdatePill.tsx b/apps/web/src/components/sidebar/SidebarUpdatePill.tsxindex 89c992f8cc9..ecfeb4d664a 100644--- a/apps/web/src/components/sidebar/SidebarUpdatePill.tsx+++ b/apps/web/src/components/sidebar/SidebarUpdatePill.tsx@@ -396,10 +396,10 @@ function SidebarUpdateControl() {<UpdateEverythingDialogopen={isConfirmingEverything}onOpenChange={setIsConfirmingEverything}- summary={everything.summary}- lines={everything.lines}+ version={everything.version}+ providerCount={everything.providerCount}+ rows={everything.rows}restarts={everything.restarts}- skipped={everything.skipped}onConfirm={() => void runEverything()}/>);diff --git a/apps/web/src/components/sidebar/UpdateEverythingDialog.tsx b/apps/web/src/components/sidebar/UpdateEverythingDialog.tsxindex e235047d36e..8cd5c5ca777 100644--- a/apps/web/src/components/sidebar/UpdateEverythingDialog.tsx+++ b/apps/web/src/components/sidebar/UpdateEverythingDialog.tsx@@ -1,6 +1,8 @@import { useAtomValue } from "@effect/atom-react";import { EnvironmentId } from "@t3tools/contracts";import { Atom } from "effect/reactivity";+import { ChevronRightIcon } from "lucide-react";+import { Fragment, type RefObject, useRef } from "react";import { environmentThreadShells } from "~/state/threads";import {@@ -13,7 +15,10 @@ import {AlertDialogTitle,} from "../ui/alert-dialog";import { Button } from "../ui/button";-import type { RestartingMachine, SkippedMachine } from "./updateEverything.logic";+import { Collapsible, CollapsiblePanel, CollapsibleTrigger } from "../ui/collapsible";+import { MiddleTruncate } from "../ui/middle-truncate";+import { ScrollArea } from "../ui/scroll-area";+import type { RestartingMachine, UpdateEverythingRow } from "./updateEverything.logic";const isRunning = (status: string) =>status === "preparing" || status === "starting" || status === "running";@@ -37,35 +42,54 @@ const runningThreadCountAtom = Atom.family((environmentIds: string) =>interface UpdateEverythingDialogProps {readonly open: boolean;readonly onOpenChange: (open: boolean) => void;- readonly summary: string;- readonly lines: ReadonlyArray<string>;+ readonly version: string | null;+ readonly providerCount: number;+ readonly rows: ReadonlyArray<UpdateEverythingRow>;readonly restarts: ReadonlyArray<RestartingMachine>;- readonly skipped: ReadonlyArray<SkippedMachine>;readonly onConfirm: () => void;}+type UpdateEverythingDialogContentProps = Omit<+ UpdateEverythingDialogProps,+ "open" | "onOpenChange"+> & {+ readonly cancelRef: RefObject<HTMLButtonElement | null>;+};+export function UpdateEverythingDialog({open,onOpenChange,...content}: UpdateEverythingDialogProps) {+ const cancelRef = useRef<HTMLButtonElement>(null);return (<AlertDialog open={open} onOpenChange={onOpenChange}>{/* Refocusing the trigger after a pointer close shows its focus ring and opens its tooltip. */}- <AlertDialogPopup finalFocus={(closeType) => closeType === "keyboard"}>- <UpdateEverythingDialogContent {...content} />+ <AlertDialogPopup+ className="sm:max-w-xl"+ initialFocus={cancelRef}+ finalFocus={(closeType) => closeType === "keyboard"}+ >+ <UpdateEverythingDialogContent {...content} cancelRef={cancelRef} /></AlertDialogPopup></AlertDialog>);}+const APP_LABELS = {+ "this-app": "This app",+ server: "Server",+ "desktop-app": "Desktop app",+} as const;+function UpdateEverythingDialogContent({- summary,- lines,+ version,+ providerCount,+ rows,restarts,- skipped,onConfirm,-}: Omit<UpdateEverythingDialogProps, "open" | "onOpenChange">) {+ cancelRef,+}: UpdateEverythingDialogContentProps) {const stopped = useAtomValue(runningThreadCountAtom(restarts@@ -84,16 +108,96 @@ function UpdateEverythingDialogContent({);const running = stopped + continuing;const threads = `${running} running ${running === 1 ? "thread" : "threads"}`;+ const restarting = new Set(restarts.map((machine) => machine.environmentId));+ const updating = rows.filter((row) => row.app !== null || row.providers.length > 0);+ const skipped = rows.filter((row) => row.skipped !== null);return (<>- <AlertDialogHeader>- <AlertDialogTitle>{summary}?</AlertDialogTitle>- <AlertDialogDescription className="whitespace-pre-line">- {lines.join("\n")}+ <AlertDialogHeader className="shrink-0">+ <AlertDialogTitle>+ Update {updating.length} {updating.length === 1 ? "machine" : "machines"}?+ </AlertDialogTitle>+ <AlertDialogDescription>+ {version !== null ? (+ <>+ T3 Code <span className="font-mono text-xs">{version}</span>+ </>+ ) : null}+ {version !== null && providerCount > 0 ? " · " : null}+ {providerCount > 0+ ? `${providerCount} provider ${providerCount === 1 ? "update" : "updates"}`+ : null}</AlertDialogDescription>+ </AlertDialogHeader>+ <ScrollArea scrollFade>+ <div className="flex flex-col gap-3 px-6 pb-4">+ {/* Machine names truncate first. Provider lists wrap between names, never inside one. */}+ <div className="grid grid-cols-[minmax(4rem,max-content)_max-content_minmax(min-content,1fr)_max-content] gap-x-4 text-sm">+ <div className="col-span-full grid grid-cols-subgrid border-b pb-1.5 text-muted-foreground text-xs">+ <span>Machine</span>+ <span>T3 Code</span>+ <span>Providers</span>+ <span />+ </div>+ {updating.map((row) => (+ <div+ key={row.environmentId ?? "this-app"}+ className="col-span-full grid grid-cols-subgrid border-b border-border/50 py-1.5 last:border-b-0"+ >+ <span className="max-w-32 min-w-0">+ <MiddleTruncate value={row.label} />+ </span>+ <span>+ {row.app !== null ? APP_LABELS[row.app] : null}+ {row.app === null && row.skipped !== null ? (+ <span className="text-muted-foreground">Skipped</span>+ ) : null}+ {row.app === "this-app" ? (+ <span className="block text-muted-foreground text-xs">restarts last</span>+ ) : null}+ </span>+ <span>+ {row.providers.map((provider, index) => (+ <Fragment key={provider}>+ <span className="whitespace-nowrap">{provider}</span>+ {index < row.providers.length - 1 ? ", " : null}+ </Fragment>+ ))}+ </span>+ <span className="text-right">+ {row.environmentId !== null && restarting.has(row.environmentId) ? (+ <RunningThreads environmentId={row.environmentId} />+ ) : null}+ </span>+ </div>+ ))}+ </div>+ {skipped.length > 0 ? (+ <Collapsible>+ <CollapsibleTrigger className="flex items-center gap-1 text-muted-foreground text-xs hover:text-foreground data-panel-open:[&_svg]:rotate-90">+ <ChevronRightIcon className="size-3.5 transition-transform" aria-hidden />+ {skipped.length} skipped+ </CollapsibleTrigger>+ <CollapsiblePanel>+ <div className="grid grid-cols-[minmax(0,max-content)_1fr] gap-x-3 gap-y-0.5 pt-1.5 ps-4.5 text-muted-foreground text-xs">+ {skipped.map((row) => (+ <Fragment key={row.environmentId ?? "this-app"}>+ <span className="max-w-32 min-w-0">+ <MiddleTruncate value={row.label} />+ </span>+ <span className="wrap-anywhere">{row.skipped}</span>+ </Fragment>+ ))}+ </div>+ </CollapsiblePanel>+ </Collapsible>+ ) : null}+ </div>+ </ScrollArea>+ <AlertDialogFooter>{running > 0 ? (- <p className="pt-2 text-sm">+ <p className="self-center text-muted-foreground text-sm max-sm:order-1 max-sm:text-center sm:mr-auto">{stopped === 0? `${threads} will be interrupted and can resume after the restart.`: continuing === 0@@ -101,16 +205,16 @@ function UpdateEverythingDialogContent({: `${threads} will be interrupted. ${continuing} can resume after the restart.`}</p>) : null}- {skipped.length > 0 ? (- <p className="whitespace-pre-line pt-2 text-sm">- {skipped.map((machine) => `Skips ${machine.label}: ${machine.reason}`).join("\n")}- </p>- ) : null}- </AlertDialogHeader>- <AlertDialogFooter>- <AlertDialogClose render={<Button variant="outline" />}>Cancel</AlertDialogClose>+ <AlertDialogClose ref={cancelRef} render={<Button variant="outline" />}>+ Cancel+ </AlertDialogClose><Button onClick={onConfirm}>Update</Button></AlertDialogFooter></>);}++function RunningThreads({ environmentId }: { readonly environmentId: EnvironmentId }) {+ const count = useAtomValue(runningThreadCountAtom(environmentId));+ return count > 0 ? <span className="whitespace-nowrap text-warning">{count} running</span> : null;+}diff --git a/apps/web/src/components/sidebar/updateEverything.logic.test.ts b/apps/web/src/components/sidebar/updateEverything.logic.test.tsindex 3b13cd30df8..3739308f7b1 100644--- a/apps/web/src/components/sidebar/updateEverything.logic.test.ts+++ b/apps/web/src/components/sidebar/updateEverything.logic.test.ts@@ -4,6 +4,7 @@ import { describe, expect, it } from "vite-plus/test";import {collectRestartingMachines,collectServerUpdateTargets,+ describeUpdateEverything,runUpdateEverything,type UpdateEverythingMachine,} from "./updateEverything.logic";@@ -136,3 +137,43 @@ describe("runUpdateEverything", () => {expect(result.localReady).toBe(false);});});++describe("describeUpdateEverything", () => {+ it("gives each machine one row with its T3 Code and provider updates", () => {+ const id = EnvironmentId.make;+ const { rows } = describeUpdateEverything({+ localVersion: "1.1.0",+ localMachines: [+ { environmentId: id("local"), label: "Mainbook" },+ { environmentId: id("wsl"), label: "Mainbook WSL" },+ ],+ servers: [+ {+ environmentId: id("npm"),+ serverLabel: "bb-1",+ selfUpdate: "respawn",+ targetVersion: "1.1.0",+ },+ ],+ providerMachines: [+ { environmentId: id("npm"), label: "bb-1", providers: ["Codex", "Claude"] },+ { environmentId: id("local"), label: "Mainbook", providers: ["Codex"] },+ { environmentId: id("manual"), label: "alvin", providers: ["Claude"] },+ ],+ skipped: [+ { environmentId: id("manual"), label: "alvin", reason: "needs a manual update" },+ { environmentId: id("offline"), label: "TheoRoom", reason: "not connected" },+ ],+ });++ expect(+ rows.map(({ label, app, skipped, providers }) => [label, app, skipped, providers]),+ ).toEqual([+ ["Mainbook", "this-app", null, ["Codex"]],+ ["Mainbook WSL", "this-app", null, []],+ ["bb-1", "server", null, ["Codex", "Claude"]],+ ["alvin", null, "needs a manual update", ["Claude"]],+ ["TheoRoom", null, "not connected", []],+ ]);+ });+});diff --git a/apps/web/src/components/sidebar/updateEverything.logic.ts b/apps/web/src/components/sidebar/updateEverything.logic.tsindex ad103ff936f..469e5a0faf6 100644--- a/apps/web/src/components/sidebar/updateEverything.logic.ts+++ b/apps/web/src/components/sidebar/updateEverything.logic.ts@@ -351,6 +351,11 @@ export function getUpdateEverythingToastView(export interface UpdateEverythingPlan {readonly localVersion: string | null;+ /** Machines whose servers this app hosts; this app's update restarts them. */+ readonly localMachines: ReadonlyArray<{+ readonly environmentId: EnvironmentId;+ readonly label: string;+ }>;readonly servers: ReadonlyArray<Pick<ServerUpdateTarget, "environmentId" | "serverLabel" | "selfUpdate" | "targetVersion">>;@@ -359,6 +364,15 @@ export interface UpdateEverythingPlan {readonly label: string;readonly providers: ReadonlyArray<string>;}>;+ readonly skipped: ReadonlyArray<SkippedMachine>;+}++export interface UpdateEverythingRow {+ readonly environmentId: EnvironmentId | null;+ readonly label: string;+ readonly app: "this-app" | "server" | "desktop-app" | null;+ readonly skipped: string | null;+ readonly providers: ReadonlyArray<string>;}function countLabel(count: number, noun: string): string | null {@@ -370,9 +384,12 @@ function joinList(parts: ReadonlyArray<string>): string {return `${parts.slice(0, -1).join(", ")}, and ${parts.at(-1)}`;}+/** One row per machine: this app's machines first, then servers, provider-only, and skipped. */export function describeUpdateEverything(plan: UpdateEverythingPlan): {readonly summary: string;- readonly lines: ReadonlyArray<string>;+ readonly version: string | null;+ readonly providerCount: number;+ readonly rows: ReadonlyArray<UpdateEverythingRow>;} {const providerCount = plan.providerMachines.reduce((count, machine) => count + machine.providers.length,@@ -386,30 +403,46 @@ export function describeUpdateEverything(plan: UpdateEverythingPlan): {].filter((part) => part !== null),)}`;- const machines = new Map<EnvironmentId, { label: string; items: string[] }>();- const itemsFor = (environmentId: EnvironmentId, label: string) => {- const existing = machines.get(environmentId);- if (existing) return existing.items;- const items: string[] = [];- machines.set(environmentId, { label, items });- return items;+ const rows = new Map<EnvironmentId | null, UpdateEverythingRow>();+ const update = (+ environmentId: EnvironmentId | null,+ label: string,+ change: Partial<UpdateEverythingRow>,+ ) => {+ const row = rows.get(environmentId) ?? {+ environmentId,+ label,+ app: null,+ skipped: null,+ providers: [],+ };+ rows.set(environmentId, { ...row, ...change });};+ if (plan.localVersion) {+ if (plan.localMachines.length === 0) update(null, "This app", { app: "this-app" });+ for (const machine of plan.localMachines) {+ update(machine.environmentId, machine.label, { app: "this-app" });+ }+ }for (const server of plan.servers) {- itemsFor(server.environmentId, server.serverLabel).push(- server.selfUpdate === "desktop-managed"- ? "desktop app update"- : `server to ${server.targetVersion}`,- );+ update(server.environmentId, server.serverLabel, {+ app: server.selfUpdate === "desktop-managed" ? "desktop-app" : "server",+ });}for (const machine of plan.providerMachines) {- itemsFor(machine.environmentId, machine.label).push(...machine.providers);+ update(machine.environmentId, machine.label, { providers: machine.providers });+ }+ for (const machine of plan.skipped) {+ update(machine.environmentId, machine.label, { skipped: machine.reason });}return {summary,- lines: [- ...(plan.localVersion ? [`This app: ${plan.localVersion}, restarts last`] : []),- ...Array.from(machines.values(), ({ label, items }) => `${label}: ${items.join(", ")}`),- ],+ version:+ plan.localVersion ??+ plan.servers.find((server) => server.selfUpdate !== "desktop-managed")?.targetVersion ??+ null,+ providerCount,+ rows: Array.from(rows.values()),};}diff --git a/apps/web/src/components/sidebar/useUpdateEverything.ts b/apps/web/src/components/sidebar/useUpdateEverything.tsindex e9e5a9b78ef..af38bbf5d4b 100644--- a/apps/web/src/components/sidebar/useUpdateEverything.ts+++ b/apps/web/src/components/sidebar/useUpdateEverything.ts@@ -78,9 +78,11 @@ export function useUpdateEverything(localUpdateVersion: string | null) {const providers = useProviderUpdates();const updateServer = useServerUpdate();- const { summary, lines } = describeUpdateEverything({+ const view = describeUpdateEverything({localVersion: localUpdateVersion,+ localMachines: machines.filter((machine) => machine.hostedByThisApp),servers,+ skipped,providerMachines: providers.machines.map((machine) => ({environmentId: machine.environmentId,label: machine.label,@@ -92,10 +94,8 @@ export function useUpdateEverything(localUpdateVersion: string | null) {return {hasUpdates: servers.length > 0 || providers.machines.length > 0,- summary,- lines,+ ...view,restarts,- skipped,run: async ({downloadLocal,installLocal,