From 715bdf45c8e3c1e532aec30581086c280caa6737 Mon Sep 17 00:00:00 2001 From: Xubin Ren <52506698+Re-bin@users.noreply.github.com> Date: Wed, 30 Sep 2026 23:09:23 +0800 Subject: [PATCH] ui(remote): manage connections without switching hosts --- docs/guides/remote-instances.md | 13 +- webui/src/App.tsx | 8 +- .../remote/HostConnectionStatus.tsx | 20 +++ webui/src/components/remote/HostSwitcher.tsx | 8 +- .../remote/RemoteConnectionsPage.tsx | 26 ++-- .../src/components/remote/RemoteInstances.tsx | 63 +++++++-- webui/src/tests/app-layout.test.tsx | 15 +- webui/src/tests/host-switcher.test.tsx | 6 +- webui/src/tests/remote-instances.test.tsx | 132 ++++++++++++++++-- 9 files changed, 241 insertions(+), 50 deletions(-) create mode 100644 webui/src/components/remote/HostConnectionStatus.tsx diff --git a/docs/guides/remote-instances.md b/docs/guides/remote-instances.md index 84609ec88..703d7c20d 100644 --- a/docs/guides/remote-instances.md +++ b/docs/guides/remote-instances.md @@ -2,7 +2,7 @@ Open your local **nanobot WebUI**, click the current host (initially **Local**) at the bottom of the sidebar, and choose **Manage connections…**. This is the -single entry point for switching and managing hosts. The page lists this computer +single entry point for switching and managing hosts. The panel lists this computer and your saved servers. Choose **Connect to remote nanobot** to copy a prepared pairing command, or choose **Other ways → Use existing SSH settings** to enter an SSH address such as @@ -252,8 +252,15 @@ desktop-host packaging and other platforms still need their own acceptance. The host switcher lives beside **Settings at the bottom of the sidebar**, showing **Local** or your saved server name. It is also available in Settings. Its menu opens upward and shows the computer name, recent hosts, and **Manage connections…**. -With the sidebar collapsed, the icon still opens the same menu. Recent, loaded -hosts show **Ready**. Remote +With the sidebar collapsed, the icon still opens the same menu. A check marks +the host you are viewing; a separate green dot marks an established connection. +Saved but disconnected hosts stay gray, and connecting or failed hosts have +distinct progress/error indicators. **Manage connections…** opens a side panel +without switching to Local, changing the route, or disconnecting the server. +Closing it returns to the same view and draft. The panel uses the same connection +states with text labels, so color is never the only way to distinguish them. +Selecting a host in the panel switches only after its view is ready; a failed +attempt leaves the original host selected. Remote connection setup is hidden inside the embedded remote view, and connecting back to the same gateway is rejected rather than creating a nested local session. diff --git a/webui/src/App.tsx b/webui/src/App.tsx index d356d8d77..48701b228 100644 --- a/webui/src/App.tsx +++ b/webui/src/App.tsx @@ -1111,7 +1111,9 @@ function Shell({ onNativeEngineRestart: () => Promise; }) { const { t, i18n } = useTranslation(); - const localActive = useRemoteConnections()?.localActive !== false; + const remoteConnections = useRemoteConnections(); + const localActive = remoteConnections?.localActive !== false; + const managingConnections = remoteConnections?.managing === true; const { client, getToken } = useClient(); const { theme, toggle } = useTheme(); const { @@ -1156,8 +1158,8 @@ function Shell({ const [mobileSidebarOpen, setMobileSidebarOpen] = useState(false); useEffect(() => { // The drawer portals outside the local host panel; don't leave it over a remote view. - if (!localActive) setMobileSidebarOpen(false); - }, [localActive]); + if (!localActive || managingConnections) setMobileSidebarOpen(false); + }, [localActive, managingConnections]); const mobileSidebarRef = useRef(null); const [sessionSearchOpen, setSessionSearchOpen] = useState(false); const mobileWorkbench = useMediaQuery("(max-width: 767px)"); diff --git a/webui/src/components/remote/HostConnectionStatus.tsx b/webui/src/components/remote/HostConnectionStatus.tsx new file mode 100644 index 000000000..df3da22da --- /dev/null +++ b/webui/src/components/remote/HostConnectionStatus.tsx @@ -0,0 +1,20 @@ +import { CircleAlert, Loader2 } from "lucide-react"; +import { useTranslation } from "react-i18next"; +import { cn } from "@/lib/utils"; + +export type HostConnectionState = "open" | "closed" | "connecting" | "error"; + +/** Connectivity is independent of which host the user is currently viewing. */ +export function HostConnectionStatus({ state, compact = false }: { + state: HostConnectionState; + compact?: boolean; +}) { + const { t } = useTranslation(); + const label = t(`connection.${state}`); + return + {state === "connecting" ? + : state === "error" ? + : } + {label} + ; +} diff --git a/webui/src/components/remote/HostSwitcher.tsx b/webui/src/components/remote/HostSwitcher.tsx index 1aeb113c3..d37c9e954 100644 --- a/webui/src/components/remote/HostSwitcher.tsx +++ b/webui/src/components/remote/HostSwitcher.tsx @@ -8,6 +8,7 @@ import { useClient } from "@/providers/ClientProvider"; import { cn } from "@/lib/utils"; import type { ConnectionStatus } from "@/lib/types"; import type { HostAnchor, EmbeddedHost } from "./host-bridge"; +import { HostConnectionStatus, type HostConnectionState } from "./HostConnectionStatus"; export interface HostPicker { kind: "shell"; @@ -15,7 +16,7 @@ export interface HostPicker { hostname: string; localName: string; currentId: string | null; - profiles: { id: string; name: string; host: string; ready: boolean }[]; + profiles: { id: string; name: string; host: string; state: HostConnectionState }[]; recentIds: string[]; pending: { id: string; name: string } | null; error: string; @@ -100,11 +101,12 @@ function HostMenuItems({ picker }: { picker: HostPicker }) { } {showLocal && !!profiles.length && } {profiles.map((profile) => picker.select(profile.id)} className="gap-2.5" + aria-label={`${profile.name} ${profile.host}`} aria-describedby={`host-state-${profile.id}`} title={`${profile.name} · ${profile.host}`} aria-current={picker.currentId === profile.id || undefined}> {profile.name}{profile.host} - {picker.pending?.id === profile.id ? : picker.currentId === profile.id ? - : profile.ready ? {t("remote.ready")} : null} + + {picker.currentId === profile.id && } )} {!showLocal && !profiles.length &&

{t("remote.noMatchingHosts")}

} diff --git a/webui/src/components/remote/RemoteConnectionsPage.tsx b/webui/src/components/remote/RemoteConnectionsPage.tsx index 3c71a849b..6f8d2b04a 100644 --- a/webui/src/components/remote/RemoteConnectionsPage.tsx +++ b/webui/src/components/remote/RemoteConnectionsPage.tsx @@ -16,6 +16,7 @@ import { useRemoteConnections } from "./RemoteInstances"; import { SSHHostPicker } from "./SSHHostPicker"; import { QuickPairSetup } from "./QuickPairSetup"; import { PairRouteSettings } from "./PairRouteSettings"; +import { HostConnectionStatus } from "./HostConnectionStatus"; const emptyProfile = (): Omit => ({ name: "", host: "", port: null, ssh_config: "", identity_file: "", @@ -23,9 +24,10 @@ const emptyProfile = (): Omit => ({ }); /** The page is a server directory. Add/edit/first-use verification share one dialog. */ -export function RemoteConnectionsPage({ mainNavigationExpanded = false, hostChromeInset = false, onBackToChat }: { +export function RemoteConnectionsPage({ mainNavigationExpanded = false, hostChromeInset = false, inPanel = false, onBackToChat }: { mainNavigationExpanded?: boolean; hostChromeInset?: boolean; + inPanel?: boolean; onBackToChat: () => void; }) { const { t } = useTranslation(); @@ -56,6 +58,7 @@ export function RemoteConnectionsPage({ mainNavigationExpanded = false, hostChro const mounted = useRef(true); const operation = useRef(0); const optionsId = useId(); + const statusId = useId(); const refresh = connections?.refresh; // Keep confirmation content intact during Radix's exit animation. @@ -248,31 +251,36 @@ export function RemoteConnectionsPage({ mainNavigationExpanded = false, hostChro
-
+ hostChromeInset && "pt-[4.25rem] sm:pt-[4.25rem] lg:pt-[4.75rem]", + inPanel && "px-6 py-4 sm:py-4 lg:py-4 [--settings-margin:0px] [--settings-inset:16px]")}> + {!inPanel &&

{t("remote.title")}

-
+
}

{t("remote.description")}

{directory?.available && <> -
+
+ {connections.localActive && {t("remote.current")}} +
{directory.profiles.length > 0 && {directory.profiles.map((profile) =>
-