π OpenHands: AI-Driven Development
fix: open Cloud settings in the same tab when locked to a Cloud host (#17253)
Hiep Le725f5584b941
diff --git a/__tests__/components/backends/backend-selector.test.tsx b/__tests__/components/backends/backend-selector.test.tsxindex aaf0bfc140..b09794b794 100644--- a/__tests__/components/backends/backend-selector.test.tsx+++ b/__tests__/components/backends/backend-selector.test.tsx@@ -851,6 +851,33 @@ describe("BackendSelector", () => {`${SEED_CLOUD_PRODUCTION.host}/settings?org=org-2`,);});++ it("renders the cloud settings link as a same-tab anchor when locked to Cloud", async () => {+ // Arrange: an OHE/SaaS-hosted canvas locked to the active cloud host+ vi.stubEnv("VITE_LOCK_TO_CLOUD", SEED_CLOUD_PRODUCTION.host);+ let cloudId = "";++ // Act+ renderWithProviders(+ <TestSeed+ onMount={(ctx) => {+ cloudId = ctx.addBackend(SEED_CLOUD_PRODUCTION).id;+ ctx.setActive(cloudId, null);+ }}+ >+ <BackendSelector />+ </TestSeed>,+ );++ // Assert: same tab, so browser Back returns to the canvas+ const link = screen.getByTestId("backend-selector-settings-link");+ expect(link).toHaveAttribute(+ "href",+ `${SEED_CLOUD_PRODUCTION.host}/settings`,+ );+ expect(link).not.toHaveAttribute("target");+ expect(link).not.toHaveAttribute("rel");+ });});describe("connection indicator", () => {diff --git a/__tests__/components/features/settings/cloud-settings-link.test.tsx b/__tests__/components/features/settings/cloud-settings-link.test.tsxindex 2aa98ee34c..365fba59b9 100644--- a/__tests__/components/features/settings/cloud-settings-link.test.tsx+++ b/__tests__/components/features/settings/cloud-settings-link.test.tsx@@ -1,4 +1,4 @@-import { describe, it, expect, beforeEach, afterEach } from "vitest";+import { describe, it, expect, beforeEach, afterEach, vi } from "vitest";import { render, screen } from "@testing-library/react";import { QueryClient, QueryClientProvider } from "@tanstack/react-query";import {@@ -47,6 +47,7 @@ beforeEach(() => {afterEach(() => {window.localStorage.clear();__resetActiveStoreForTests();+ vi.unstubAllEnvs();});describe("CloudSettingsLink", () => {@@ -79,6 +80,23 @@ describe("CloudSettingsLink", () => {);});+ it("opens in the same tab without the external-link icon when locked to Cloud", () => {+ // Arrange: an OHE/SaaS-hosted canvas locked to the active cloud host+ vi.stubEnv("VITE_LOCK_TO_CLOUD", "https://app.all-hands.dev");+ setRegisteredBackends([cloudBackend]);+ setActiveSelection({ backendId: cloudBackend.id });++ // Act+ renderWithProviders();++ // Assert: same tab (Back returns to the canvas) and no "new tab" hint+ const link = screen.getByTestId("settings-cloud-link");+ expect(link).toHaveAttribute("href", "https://app.all-hands.dev/settings");+ expect(link).not.toHaveAttribute("target");+ expect(link).not.toHaveAttribute("rel");+ expect(link.querySelector("svg.lucide-external-link")).toBeNull();+ });+it("appends the active org so cloud settings open on the same organization", () => {setRegisteredBackends([cloudBackend]);setActiveSelection({ backendId: cloudBackend.id, orgId: "org-123" });diff --git a/__tests__/components/features/sidebar/sidebar-cloud-settings.test.tsx b/__tests__/components/features/sidebar/sidebar-cloud-settings.test.tsxindex 9fe55553c4..199e4153ce 100644--- a/__tests__/components/features/sidebar/sidebar-cloud-settings.test.tsx+++ b/__tests__/components/features/sidebar/sidebar-cloud-settings.test.tsx@@ -1,8 +1,4 @@-import {- render,- screen,- fireEvent,-} from "@testing-library/react";+import { render, screen, fireEvent } from "@testing-library/react";import { QueryClient, QueryClientProvider } from "@tanstack/react-query";import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";import { Sidebar } from "#/components/features/sidebar/sidebar";@@ -231,6 +227,7 @@ describe("Sidebar with Cloud Backend", () => {window.localStorage.clear();useSidebarStore.setState({ collapsed: false });cloudBackendMock.orgId = "org-1";+ vi.unstubAllEnvs();});it("opens cloud settings in new tab when connected to cloud backend", () => {@@ -264,4 +261,22 @@ describe("Sidebar with Cloud Backend", () => {const settingsLink = screen.getByTestId("collapsed-settings-link");expect(settingsLink).toHaveAttribute("rel", "noopener noreferrer");});++ it("opens cloud settings in the same tab when locked to Cloud", () => {+ // Arrange: an OHE/SaaS-hosted canvas locked to the active cloud host+ vi.stubEnv("VITE_LOCK_TO_CLOUD", "https://cloud.example.com");+ useSidebarStore.setState({ collapsed: true });++ // Act+ renderSidebar("/conversations");++ // Assert: same tab, so browser Back returns to the canvas+ const settingsLink = screen.getByTestId("collapsed-settings-link");+ expect(settingsLink).toHaveAttribute(+ "href",+ "https://cloud.example.com/settings?org=org-1",+ );+ expect(settingsLink).not.toHaveAttribute("target");+ expect(settingsLink).not.toHaveAttribute("rel");+ });});diff --git a/src/components/features/backends/backend-selector.tsx b/src/components/features/backends/backend-selector.tsxindex 677ab8b479..c83be59bad 100644--- a/src/components/features/backends/backend-selector.tsx+++ b/src/components/features/backends/backend-selector.tsx@@ -426,8 +426,8 @@ export function BackendSelector({{active.backend.kind === "cloud" ? (<ahref={`${active.backend.host.replace(/\/+$/, "")}/settings${cloudSettingsOrgQuery}`}- target="_blank"- rel="noopener noreferrer"+ target={isLockedToCloud ? undefined : "_blank"}+ rel={isLockedToCloud ? undefined : "noopener noreferrer"}data-testid="backend-selector-settings-link"aria-label={settingsLabel}className={cn(diff --git a/src/components/features/settings/cloud-settings-link.tsx b/src/components/features/settings/cloud-settings-link.tsxindex 10cf6b6d94..2e089a1ec6 100644--- a/src/components/features/settings/cloud-settings-link.tsx+++ b/src/components/features/settings/cloud-settings-link.tsx@@ -3,6 +3,7 @@ import { Cloud, ExternalLink } from "lucide-react";import { I18nKey } from "#/i18n/declaration";import { useActiveBackendContext } from "#/contexts/active-backend-context";import { isNoBackend } from "#/api/backend-registry/active-store";+import { getLockedCloudHost } from "#/api/agent-server-config";import { cn } from "#/utils/utils";import {SIDEBAR_ICON_SLOT_CLASS,@@ -13,7 +14,9 @@ import {/*** Renders only for cloud backends β local backends have no equivalent- * hosted settings page.+ * hosted settings page. Opens in the same tab when the canvas is locked to a+ * Cloud host (SaaS / self-hosted OHE): the settings page shares that host+ * with the canvas, so Back should return here (OHE-3242).*/export function CloudSettingsLink() {const { t } = useTranslation("openhands");@@ -22,6 +25,8 @@ export function CloudSettingsLink() {if (isNoBackend(backend) || backend.kind !== "cloud") return null;+ const isLockedToCloud = getLockedCloudHost() !== null;+// `org` is consumed by the cloud settings loader so the page opens on the// org that is active here instead of the cloud's last-used org.const orgQuery = orgId ? `?org=${encodeURIComponent(orgId)}` : "";@@ -31,8 +36,8 @@ export function CloudSettingsLink() {<adata-testid="settings-cloud-link"href={cloudSettingsUrl}- target="_blank"- rel="noopener noreferrer"+ target={isLockedToCloud ? undefined : "_blank"}+ rel={isLockedToCloud ? undefined : "noopener noreferrer"}className={cn(sidebarNavRowClassName({ collapsed: false }),SIDEBAR_ROW_INTERACTIVE_CLASS.idle,@@ -44,10 +49,12 @@ export function CloudSettingsLink() {<span className={cn(sidebarNavLabelClassName(false), "flex-1")}>{t(I18nKey.SETTINGS$CLOUD_SETTINGS_LINK)}</span>- <ExternalLink- className="size-4 shrink-0 text-[var(--oh-muted)]"- aria-hidden- />+ {!isLockedToCloud && (+ <ExternalLink+ className="size-4 shrink-0 text-[var(--oh-muted)]"+ aria-hidden+ />+ )}</a>);}diff --git a/src/components/features/sidebar/sidebar-rail-body.tsx b/src/components/features/sidebar/sidebar-rail-body.tsxindex bba1054236..47398791ca 100644--- a/src/components/features/sidebar/sidebar-rail-body.tsx+++ b/src/components/features/sidebar/sidebar-rail-body.tsx@@ -10,6 +10,7 @@ import {} from "lucide-react";import { OpenHandsLogoButton } from "#/components/shared/buttons/openhands-logo-button";import { NavigationLink } from "#/components/shared/navigation-link";+import { getLockedCloudHost } from "#/api/agent-server-config";import {automationListPath,getInterfaceCopy,@@ -119,6 +120,10 @@ export function SidebarRailBody({const cloudSettingsUrl = isCloudBackend? `${activeBackend.host.replace(/\/+$/, "")}/settings${cloudSettingsOrgQuery}`: null;+ // Locked-to-Cloud (SaaS / self-hosted OHE) serves the canvas at /canvas on+ // the cloud host itself, so cloud settings open in this tab and Back+ // returns here (OHE-3242). Standalone / Electron keep the new tab.+ const isLockedToCloud = getLockedCloudHost() !== null;return (<div className="flex min-h-0 flex-1 flex-col">@@ -287,8 +292,8 @@ export function SidebarRailBody({{isCloudBackend && cloudSettingsUrl ? (<ahref={cloudSettingsUrl}- target="_blank"- rel="noopener noreferrer"+ target={isLockedToCloud ? undefined : "_blank"}+ rel={isLockedToCloud ? undefined : "noopener noreferrer"}data-testid="collapsed-settings-link"aria-label={t(I18nKey.SIDEBAR$SETTINGS)}className={sidebarNavRowClassName({ collapsed: true })}