diff --git a/docs/guides/remote-instances.md b/docs/guides/remote-instances.md index 703d7c20d..1e4d5fb81 100644 --- a/docs/guides/remote-instances.md +++ b/docs/guides/remote-instances.md @@ -255,11 +255,12 @@ opens upward and shows the computer name, recent hosts, and **Manage connections 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 +distinct progress/error indicators. **Manage connections…** opens a full page in +the main content area beside the existing sidebar, 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 +**Back** returns to the same view and draft. The page 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 +Selecting a host on the page 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 48701b228..7ef310c24 100644 --- a/webui/src/App.tsx +++ b/webui/src/App.tsx @@ -1114,6 +1114,8 @@ function Shell({ const remoteConnections = useRemoteConnections(); const localActive = remoteConnections?.localActive !== false; const managingConnections = remoteConnections?.managing === true; + const remoteConnectionsRef = useRef(remoteConnections); + remoteConnectionsRef.current = remoteConnections; const { client, getToken } = useClient(); const { theme, toggle } = useTheme(); const { @@ -1275,6 +1277,9 @@ function Shell({ const navigate = useCallback( (route: ShellRoute, options?: { replace?: boolean }) => { const leave = () => { + // Navigating the local sidebar is an explicit choice of a local view. + // Merely opening global connection management does not switch hosts. + if (remoteConnectionsRef.current?.managing) remoteConnectionsRef.current.selectLocal(); setActiveKey(route.activeKey); setView(route.view); setSettingsInitialSection(route.settingsSection); @@ -2707,11 +2712,11 @@ function Shell({ const sidebarProps = { sessions: sidebarTopicSessions, temporarySessions: temporarySessionList, - activeKey: view === "chat" + activeKey: !managingConnections && view === "chat" ? (temporaryChatActive ? activeKey : activeSidebarKey) : null, loading, - newChatActive: view === "chat" && activeKey === null, + newChatActive: !managingConnections && view === "chat" && activeKey === null, onNewChat, onSelect: onSelectSidebarItem, onCloseTemporaryChat, @@ -2737,7 +2742,7 @@ function Shell({ onOpenSkills, onSettingsIntent, onOpenSearch: onOpenSessionSearch, - activeUtility: view === "apps" || view === "automations" || view === "skills" || view === "channels" ? view : null, + activeUtility: !managingConnections && (view === "apps" || view === "automations" || view === "skills" || view === "channels") ? view : null, onToggleArchived, pinnedKeys: sidebarPinnedTabKeys, archivedKeys: sidebarArchivedTabKeys, @@ -2766,7 +2771,7 @@ function Shell({ return ( - +
+
{(view === "chat" || chatVisited) &&
- + }> }
)} +
+ {managingConnections &&
+ remoteConnections?.closeManagement()} + /> +
}
diff --git a/webui/src/components/remote/RemoteConnectionsPage.tsx b/webui/src/components/remote/RemoteConnectionsPage.tsx index 6f8d2b04a..ecfde0272 100644 --- a/webui/src/components/remote/RemoteConnectionsPage.tsx +++ b/webui/src/components/remote/RemoteConnectionsPage.tsx @@ -24,10 +24,9 @@ const emptyProfile = (): Omit => ({ }); /** The page is a server directory. Add/edit/first-use verification share one dialog. */ -export function RemoteConnectionsPage({ mainNavigationExpanded = false, hostChromeInset = false, inPanel = false, onBackToChat }: { +export function RemoteConnectionsPage({ mainNavigationExpanded = false, hostChromeInset = false, onBackToChat }: { mainNavigationExpanded?: boolean; hostChromeInset?: boolean; - inPanel?: boolean; onBackToChat: () => void; }) { const { t } = useTranslation(); @@ -60,6 +59,8 @@ export function RemoteConnectionsPage({ mainNavigationExpanded = false, hostChro const optionsId = useId(); const statusId = useId(); const refresh = connections?.refresh; + const page = useRef(null); + useEffect(() => { if (connections?.managing) page.current?.focus({ preventScroll: true }); }, [connections?.managing]); // Keep confirmation content intact during Radix's exit animation. useEffect(() => { if (removing) lastRemoval.current = removing; }, [removing]); @@ -247,18 +248,17 @@ export function RemoteConnectionsPage({ mainNavigationExpanded = false, hostChro setError(""); setErrorCode(""); setSSHOptions(true); }; - return
+ return
- {!inPanel &&
-

{t("remote.title")}

-
} +

{t("remote.description")}

{directory?.available && <> diff --git a/webui/src/components/remote/RemoteInstances.tsx b/webui/src/components/remote/RemoteInstances.tsx index 9a81f1cf0..26bac669f 100644 --- a/webui/src/components/remote/RemoteInstances.tsx +++ b/webui/src/components/remote/RemoteInstances.tsx @@ -2,13 +2,11 @@ import { createContext, useContext, useEffect, useLayoutEffect, useRef, useState import { Loader2, PlugZap } from "lucide-react"; import { useTranslation } from "react-i18next"; import { Button } from "@/components/ui/button"; -import { Sheet, SheetContent, SheetTitle } from "@/components/ui/sheet"; import { needsRemoteSetup, type RemoteDirectory } from "@/lib/remote-instances"; import { useHostSessions } from "./useHostSessions"; import { HostNavigationContext, HostSwitcher, RemoteHostMenu, type HostPicker } from "./HostSwitcher"; import { useSidebarHostBridge } from "./useSidebarHostBridge"; import { readPairReturn, subscribePairReturn } from "@/lib/remote-pair-return"; -import { RemoteConnectionsPage } from "./RemoteConnectionsPage"; import type { HostConnectionState } from "./HostConnectionStatus"; const RemoteContext = createContext<{ @@ -17,6 +15,7 @@ const RemoteContext = createContext<{ activeHostId: string | null; hostStates: Record; managing: boolean; + closeManagement: () => void; selectLocal: () => void; openHostIds: string[]; directory: RemoteDirectory | null; @@ -35,7 +34,6 @@ export function RemoteInstances({ children }: { children: ReactNode }) { const [managing, setManaging] = useState(false); const managementOpen = useRef(false); const managementConnect = useRef(false); - const managementPanel = useRef(null); const legacyFooter = useRef(null); const returnedPair = useSyncExternalStore(subscribePairReturn, readPairReturn); const returnLocal = hosts.local; @@ -59,7 +57,10 @@ export function RemoteInstances({ children }: { children: ReactNode }) { const restoreFocus = () => { const fallback = legacyFooter.current?.querySelector("[data-host-switcher]"); if (activeHostId.current && fallback) fallback.focus({ preventScroll: true }); - else if (activeHostId.current) bridge.focus(activeHostId.current); + else if (activeHostId.current) { + frameNodes.current.get(activeHostId.current)?.focus({ preventScroll: true }); + bridge.focus(activeHostId.current); + } else restoreLocalFocus(); }; const available = directory?.available === true || hosts.directoryError; @@ -101,23 +102,30 @@ export function RemoteInstances({ children }: { children: ReactNode }) { kind: "shell", name: selected?.name || t("remote.localShort"), hostname: selected?.hostname || directory?.machine_name || "nanobot", localName: directory?.machine_name || "nanobot", currentId: selected?.id || null, recentIds: hosts.recentIds, profiles: (directory?.profiles || []).map(({ id, name, host }) => ({ id, name, host, state: hostStates[id] })), - pending, error: message, offline: !!offline, select: (id) => { if (id) switchHost(id); else hosts.local(); }, + pending, error: message, offline: !!offline, + select: (id) => { + if (!id) selectLocal(); + else if (managing) void connect(id).catch(() => {}); + else switchHost(id); + }, manage, cancel: hosts.cancel, clearError: hosts.clearError, restoreFocus: () => { if (!managing) restoreFocus(); }, }; useEffect(() => { if (selected) document.title = `${selected.name} · nanobot`; }, [selected]); useEffect(() => { const rememberFocus = (event: FocusEvent) => { - if (event.target instanceof HTMLElement && localPanel.current?.contains(event.target) + if (!managementOpen.current && event.target instanceof HTMLElement && localPanel.current?.contains(event.target) && !event.target.closest("[data-host-switcher]")) lastLocalFocus.current = event.target; }; document.addEventListener("focusin", rememberFocus); return () => document.removeEventListener("focusin", rememberFocus); }, []); useLayoutEffect(() => { - if (selected) frameNodes.current.get(selected.id)?.focus({ preventScroll: true }); + if (managing) return; + if (selected) restoreFocus(); else restoreLocalFocus(); - }, [selected]); + // Focus only on view changes, not on directory refreshes. + }, [selected, managing]); useEffect(() => { if (!selected) return; const stop = (event: KeyboardEvent) => event.stopPropagation(); @@ -127,19 +135,19 @@ export function RemoteInstances({ children }: { children: ReactNode }) { }, [selected]); return changeManagement(false), selectLocal, openHostIds: frames.map((frame) => frame.connection.id), directoryError: hosts.directoryError, refresh: hosts.refresh, connect, disconnect: hosts.disconnect, cancel: hosts.cancel }}>
-
+
{children}
{frames.map((frame) => { - const active = selected?.id === frame.connection.id; + const active = !managing && selected?.id === frame.connection.id; return
@@ -150,7 +158,7 @@ export function RemoteInstances({ children }: { children: ReactNode }) { onLoad={() => { bridge.initialize(frame.connection.id); hosts.loaded(frame.connection.id); }} />
; })} - {selected && (offline || !activeFrame?.loaded) &&
+ {!managing && selected && (offline || !activeFrame?.loaded) &&
{offline ? : }

{selected.name} · {selected.hostname}

{t(offline ? "remote.offline" : "remote.opening")}

@@ -165,18 +173,10 @@ export function RemoteInstances({ children }: { children: ReactNode }) {
{/* Older remote bundles cannot host the control. Keep an explicit exit in a compact bottom strip, never cover their sidebar controls. */} - {selected && (!bridge.readyIds.includes(selected.id) || offline) &&
+ {!managing && selected && (!bridge.readyIds.includes(selected.id) || offline) &&
} - - { event.preventDefault(); managementPanel.current?.focus(); }} - onCloseAutoFocus={(event) => { event.preventDefault(); restoreFocus(); }}> -
{t("remote.title")}
- changeManagement(false)} /> -
-
; diff --git a/webui/src/tests/app-layout.test.tsx b/webui/src/tests/app-layout.test.tsx index e357d986a..b2dbe8ce2 100644 --- a/webui/src/tests/app-layout.test.tsx +++ b/webui/src/tests/app-layout.test.tsx @@ -683,7 +683,7 @@ describe("App layout", () => { expect(window.location.hash).toBe("#/channels"); }); - it("opens management over the current view while keeping the standalone deep link", async () => { + it("opens management in the main content area while keeping the standalone deep link", async () => { requestMutationSpy.mockResolvedValue({ hosts: [], files: [], incomplete: false }); mockFetchRoutes({ "/api/settings": baseSettingsPayload(), @@ -698,6 +698,8 @@ describe("App layout", () => { fireEvent.pointerDown(await within(sidebar).findByRole("button", { name: "Switch host" }), { button: 0, ctrlKey: false }); fireEvent.click(await screen.findByRole("menuitem", { name: "Manage connections…" })); expect(await screen.findByRole("heading", { name: "Remote connections" })).toBeVisible(); + expect(screen.getByRole("main")).toContainElement(screen.getByRole("region", { name: "Remote connections" })); + expect(screen.queryByRole("dialog")).not.toBeInTheDocument(); expect(sidebar).toBeVisible(); fireEvent.click(await screen.findByRole("button", { name: "Connect to remote nanobot" })); fireEvent.pointerDown(screen.getByRole("button", { name: "Other ways" }), { button: 0, ctrlKey: false }); @@ -707,7 +709,7 @@ describe("App layout", () => { expect(window.location.hash).toBe(originalHash); expect(document.title).toBe(originalTitle); fireEvent.click(screen.getByRole("button", { name: "Cancel" })); - fireEvent.click(within(screen.getByRole("dialog", { name: "Remote connections" })).getByRole("button", { name: "Close" })); + fireEvent.click(screen.getByRole("button", { name: "Back", exact: true })); fireEvent.click(within(sidebar).getByRole("button", { name: "New topic" })); expect(window.location.hash).toBe("#/new"); expect(screen.queryByRole("textbox", { name: "SSH address" })).not.toBeInTheDocument(); @@ -720,6 +722,22 @@ describe("App layout", () => { expect(within(sidebar).queryByRole("button", { name: "Remote connections" })).not.toBeInTheDocument(); }); + it("lets sidebar navigation leave the management page without a second dismissal", async () => { + mockFetchRoutes({ + "/api/settings": baseSettingsPayload(), + "/api/remote-instances": { available: true, profiles: [] }, + }); + render(); + const sidebar = await screen.findByRole("navigation", { name: "Sidebar navigation" }); + fireEvent.pointerDown(await within(sidebar).findByRole("button", { name: "Switch host" }), { button: 0, ctrlKey: false }); + fireEvent.click(await screen.findByRole("menuitem", { name: "Manage connections…" })); + expect(await screen.findByRole("region", { name: "Remote connections" })).toBeVisible(); + fireEvent.click(within(sidebar).getByRole("button", { name: "Apps" })); + expect(await screen.findByRole("heading", { name: "Apps" })).toBeVisible(); + expect(screen.queryByRole("region", { name: "Remote connections" })).not.toBeInTheDocument(); + expect(window.location.hash).toBe("#/apps"); + }); + it("closes the mobile sidebar when managing connections from its host menu", async () => { const user = userEvent.setup(); requestMutationSpy.mockResolvedValue({ hosts: [], files: [], incomplete: false }); @@ -739,7 +757,8 @@ describe("App layout", () => { fireEvent.pointerDown(await within(sheet).findByRole("button", { name: "Switch host" }), { button: 0, ctrlKey: false }); fireEvent.click(await screen.findByRole("menuitem", { name: "Manage connections…" })); await waitFor(() => expect(sheet).not.toBeInTheDocument()); - expect(screen.getByRole("dialog", { name: "Remote connections" })).toBeVisible(); + expect(screen.getByRole("main")).toContainElement(screen.getByRole("region", { name: "Remote connections" })); + expect(screen.queryByRole("dialog")).not.toBeInTheDocument(); expect(await screen.findByRole("heading", { name: "Remote connections" })).toBeVisible(); expect(window.location.hash).not.toBe("#/remote"); expect(screen.queryByRole("button", { name: "Remote connections" })).not.toBeInTheDocument(); diff --git a/webui/src/tests/remote-instances.test.tsx b/webui/src/tests/remote-instances.test.tsx index 387a40017..5a00c734c 100644 --- a/webui/src/tests/remote-instances.test.tsx +++ b/webui/src/tests/remote-instances.test.tsx @@ -1,7 +1,7 @@ import { act, cleanup, fireEvent, render, screen, waitFor, within } from "@testing-library/react"; import { useEffect, useState } from "react"; import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; -import { RemoteInstances } from "@/components/remote/RemoteInstances"; +import { RemoteInstances, useRemoteConnections } from "@/components/remote/RemoteInstances"; import { RemoteConnectionsPage } from "@/components/remote/RemoteConnectionsPage"; import { Sidebar } from "@/components/Sidebar"; import { HOST_BRIDGE } from "@/components/remote/host-bridge"; @@ -34,6 +34,7 @@ const profile = { id: "3b968d52-081d-4898-9970-ff0a1fc93817", name: "Team server const connection: RemoteConnection = { ...profile, hostname: "team-host", gateway_id: "gateway-1", url: "http://127.0.0.1:23456/#/?bootstrapSecret=private-secret" }; const noop = () => {}; function LocalShell({ collapsed = false, initialRemote = false }) { + const connections = useRemoteConnections(); const [remotePage, setRemotePage] = useState(initialRemote); useEffect(() => { const route = () => setRemotePage(window.location.hash === "#/remote"); @@ -42,12 +43,14 @@ function LocalShell({ collapsed = false, initialRemote = false }) { }, []); return <> { window.location.hash = "/new"; setRemotePage(false); }} onSelect={noop} onRequestDelete={noop} onTogglePin={noop} + onNewChat={() => { if (connections?.managing) connections.selectLocal(); window.location.hash = "/new"; setRemotePage(false); }} onSelect={noop} onRequestDelete={noop} onTogglePin={noop} onRequestRename={noop} onToggleArchive={noop} onToggleGroup={noop} onRequestRenameProject={noop} onNewChatInProject={noop} onOpenSettings={noop} onOpenApps={noop} onOpenSkills={noop} onOpenAutomations={noop} onOpenChannels={noop} onOpenSearch={noop} onToggleArchived={noop} /> -
{remotePage ? setRemotePage(false)} /> : <>

Local conversations