From 61af9463cd2a94fdf951511653a13a320c5890b8 Mon Sep 17 00:00:00 2001 From: Hydra Date: Thu, 12 Nov 2026 21:16:50 +0200 Subject: [PATCH] fix(dashboard): keep destination selection consistent for one server --- .../migration/PlatformImportServices.tsx | 1 - .../servers/managed-server.test.tsx | 95 ++++++++++++++++++- .../src/components/shared/ServerSelector.tsx | 32 +++---- docs/dashboard-design.md | 3 + 4 files changed, 108 insertions(+), 23 deletions(-) diff --git a/apps/dashboard/src/components/migration/PlatformImportServices.tsx b/apps/dashboard/src/components/migration/PlatformImportServices.tsx index 404c14aca..d119a426d 100644 --- a/apps/dashboard/src/components/migration/PlatformImportServices.tsx +++ b/apps/dashboard/src/components/migration/PlatformImportServices.tsx @@ -136,7 +136,6 @@ export function PlatformImportServices({ onSelect={(server) => onTarget(server?.id ?? "", server?.name ?? "")} onReadyChange={onTargetReady} disabled={busy} - label="Plan or server" useSavedDefault={false} />
diff --git a/apps/dashboard/src/components/servers/managed-server.test.tsx b/apps/dashboard/src/components/servers/managed-server.test.tsx index 0263e9ef8..f9e113a54 100644 --- a/apps/dashboard/src/components/servers/managed-server.test.tsx +++ b/apps/dashboard/src/components/servers/managed-server.test.tsx @@ -8,6 +8,7 @@ import { baseDictionary } from "@/i18n"; import { PlatformProvider } from "@/context/PlatformContext"; import { AppDestinationPicker, type AppDestination } from "@/components/deploy/AppDestinationPicker"; import ServerSelector from "@/components/shared/ServerSelector"; +import { PlatformImportServices } from "@/components/migration/PlatformImportServices"; import { BillingLink, BillingWorkspaceProvider, workspaceBillingHref } from "@/components/billing/BillingWorkspaceContext"; import { ApiError } from "@/lib/api/client"; import { ServerUsage } from "./ServerUsage"; @@ -82,15 +83,105 @@ afterEach(async () => { vi.unstubAllGlobals(); }); -it("selects the only server without provisioning anything on render", async () => { +it("keeps the only selected server in the shared picker with Add server inside its menu", async () => { const change = vi.fn(); await render(); expect(change).toHaveBeenCalledExactlyOnceWith(expect.objectContaining({ id: server.id })); expect(host.textContent).toContain("Production"); - expect(host.querySelector('[role="combobox"]')).toBeNull(); + const trigger = host.querySelector('button[aria-haspopup="listbox"]'); + expect(trigger).not.toBeNull(); + expect(document.body.textContent).not.toContain(copy.newProjectServer); expect(h.ensure).not.toHaveBeenCalled(); expect(h.add).not.toHaveBeenCalled(); + await act(async () => trigger!.click()); + expect(document.querySelector('[role="listbox"]')?.textContent).toContain("Production"); + const add = [...document.querySelectorAll("button")].find( + (node) => node.textContent?.trim() === copy.newProjectServer, + ); + expect(add).toBeDefined(); + await act(async () => add!.click()); + expect(h.add).toHaveBeenCalledOnce(); + expect(document.querySelector('[role="listbox"]')).toBeNull(); + expect(change).toHaveBeenCalledTimes(1); + expect(h.ensure).not.toHaveBeenCalled(); }); + +it.each(["railway", "vercel"] as const)( + "changes the %s import destination through the real shared picker", + async (provider) => { + const connected: ServerDetail = { + ...server, + id: "connected-server", + name: "SSH destination", + managed: undefined, + connection: "ssh", + sshHost: "192.0.2.10", + sshUser: "deploy", + sshPort: 22, + }; + h.list.mockResolvedValue({ servers: [connected, server] }); + const target = vi.fn(), + review = vi.fn(); + function Import() { + const [id, setId] = useState(connected.id); + const [ready, setReady] = useState(false); + return ( + {}} + onChoose={() => {}} + onTargetReady={setReady} + onTarget={(next, name) => { + setId(next); + target(next, name); + }} + onReview={() => review(id)} + /> + ); + } + await render(); + expect(button("Check import").disabled).toBe(false); + const trigger = host.querySelector('button[aria-haspopup="listbox"]')!; + expect(trigger.textContent).toContain(connected.name); + await act(async () => trigger.click()); + const destination = [...document.querySelectorAll('[role="option"]')].find( + (node) => node.textContent?.includes(server.name ?? server.id), + ); + expect(destination).toBeDefined(); + await act(async () => destination!.click()); + expect(target).toHaveBeenCalledExactlyOnceWith(server.id, server.name); + expect(trigger.textContent).toContain(server.name); + expect(document.querySelector('[role="listbox"]')).toBeNull(); + await act(async () => button("Check import").click()); + expect(review).toHaveBeenCalledExactlyOnceWith(server.id); + expect(h.add).not.toHaveBeenCalled(); + expect(h.ensure).not.toHaveBeenCalled(); + }, +); it.each([true, false])("uses an acquired server for catalog apps (self-hosted: %s)", async selfHosted => { const changed = vi.fn(), ready = vi.fn(); function Picker() { diff --git a/apps/dashboard/src/components/shared/ServerSelector.tsx b/apps/dashboard/src/components/shared/ServerSelector.tsx index 5fb3cae6e..45d39a82f 100644 --- a/apps/dashboard/src/components/shared/ServerSelector.tsx +++ b/apps/dashboard/src/components/shared/ServerSelector.tsx @@ -8,7 +8,7 @@ import { useI18n } from "@/components/i18n-provider"; import { systemApi, type ServerInfo } from "@/lib/api/system"; import { useServerDestinations } from "@/hooks/useServerDestinations"; import { useAddServerModal } from "@/components/servers/add-server-modal"; -import { ServerPicker, ServerRowContent } from "@/components/shared/ServerPicker"; +import { ServerPicker } from "@/components/shared/ServerPicker"; import { Button } from "@/components/ui/button"; import { usePlatform } from "@/context/PlatformContext"; import { settingsApi } from "@/lib/api/settings"; @@ -297,24 +297,16 @@ export function ServerSelectorView({ ) : automaticCloud ? ( ) : rows.length > 0 ? ( - <> - {rows.length === 1 && effective === rows[0]!.id ? ( -
- -
- ) : ( - select(server.id)} - onAddServer={canAddServer && !disabled && !disabledReason ? addServer : undefined} - addServerLabel={addLabel} - /> - )} - + select(server.id)} + onAddServer={canAddServer && !disabled && !disabledReason ? addServer : undefined} + addServerLabel={addLabel} + /> ) : (

@@ -342,7 +334,7 @@ export function ServerSelectorView({ {restrictedSource ? t.migration.sources.hint : forDeployment && !automaticCloud ? managedCopy.existingServerHint : managedCopy.subscriptionHint}

)} - {canAddServer && (automaticCloud || rows.length === 1) && ( + {canAddServer && automaticCloud && (