π OpenHands: AI-Driven Development
fix(conversation): open the Usage panel page at phone width (#18537)
Engel Nystd4c5d39227da
diff --git a/.pr/phone-usage-panel/after-desktop-display-usage.png b/.pr/phone-usage-panel/after-desktop-display-usage.pngnew file mode 100644index 0000000000..7f53db7f03Binary files /dev/null and b/.pr/phone-usage-panel/after-desktop-display-usage.png differdiff --git a/.pr/phone-usage-panel/after-phone-context-ring-usage.png b/.pr/phone-usage-panel/after-phone-context-ring-usage.pngnew file mode 100644index 0000000000..a21264c6a8Binary files /dev/null and b/.pr/phone-usage-panel/after-phone-context-ring-usage.png differdiff --git a/.pr/phone-usage-panel/after-phone-display-usage.png b/.pr/phone-usage-panel/after-phone-display-usage.pngnew file mode 100644index 0000000000..a21264c6a8Binary files /dev/null and b/.pr/phone-usage-panel/after-phone-display-usage.png differdiff --git a/.pr/phone-usage-panel/before-phone-display-usage.png b/.pr/phone-usage-panel/before-phone-display-usage.pngnew file mode 100644index 0000000000..66461eb71fBinary files /dev/null and b/.pr/phone-usage-panel/before-phone-display-usage.png differdiff --git a/__tests__/hooks/use-conversation-panel-route.test.tsx b/__tests__/hooks/use-conversation-panel-route.test.tsxindex cd09d5b5fe..c9158f22e4 100644--- a/__tests__/hooks/use-conversation-panel-route.test.tsx+++ b/__tests__/hooks/use-conversation-panel-route.test.tsx@@ -2,6 +2,7 @@ import { act, render, screen } from "@testing-library/react";import { afterEach, beforeEach, describe, expect, it } from "vitest";import { MemoryRouter, Route, Routes, useLocation } from "react-router";import { useConversationPanelRoute } from "#/hooks/use-conversation-panel-route";+import { useSelectConversationTab } from "#/hooks/use-select-conversation-tab";import { handleCanvasUIAction } from "#/services/canvas-ui";import { useConversationStore } from "#/stores/conversation-store";import type { CanvasUIAction } from "#/types/agent-server/core";@@ -23,9 +24,15 @@ function setWindowWidth(width: number) {function Probe() {const showsMobilePanelPage = useConversationPanelRoute(CONVERSATION_ID);+ const { navigateToTab } = useSelectConversationTab();const location = useLocation();return (<div>+ <button+ type="button"+ data-testid="navigate-to-usage"+ onClick={() => navigateToTab("usage")}+ /><span data-testid="path">{location.pathname}</span><span data-testid="mobile-panel-page">{String(showsMobilePanelPage)}@@ -77,6 +84,33 @@ describe("useConversationPanelRoute", () => {setWindowWidth(originalInnerWidth);});+ it("opens the panel page at phone width when an app control navigates to a tab", () => {+ setWindowWidth(PHONE_WIDTH);+ renderAt(CHAT_PATH);++ act(() => {+ screen.getByTestId("navigate-to-usage").click();+ });++ expect(screen.getByTestId("path")).toHaveTextContent(PANEL_PATH);+ expect(screen.getByTestId("mobile-panel-page")).toHaveTextContent("true");+ expect(useConversationStore.getState().selectedTab).toBe("usage");+ });++ it("keeps the chat route on desktop when an app control navigates to a tab", () => {+ setWindowWidth(DESKTOP_WIDTH);+ renderAt(CHAT_PATH);++ act(() => {+ screen.getByTestId("navigate-to-usage").click();+ });++ expect(screen.getByTestId("path")).toHaveTextContent(CHAT_PATH);+ expect(screen.getByTestId("path")).not.toHaveTextContent(PANEL_PATH);+ expect(useConversationStore.getState().isRightPanelShown).toBe(true);+ expect(useConversationStore.getState().selectedTab).toBe("usage");+ });+it("opens the panel page at phone width when the agent reveals a tab", () => {setWindowWidth(PHONE_WIDTH);renderAt(CHAT_PATH);diff --git a/src/hooks/use-select-conversation-tab.ts b/src/hooks/use-select-conversation-tab.tsindex 161ca66c7f..f5f2099194 100644--- a/src/hooks/use-select-conversation-tab.ts+++ b/src/hooks/use-select-conversation-tab.ts@@ -4,6 +4,7 @@ import {type ConversationTab,} from "#/stores/conversation-store";import { useOptionalConversationId } from "#/hooks/use-conversation-id";+import { requestPanelReveal } from "#/services/canvas-ui";/*** Custom hook for selecting conversation tabs with consistent behavior.@@ -60,11 +61,13 @@ export function useSelectConversationTab() {* Navigates to a tab without toggle behavior.* Always shows the panel and selects the tab, even if already selected.* Use this for "View" or "Read More" buttons that should always navigate.+ * At phone width the drawer is its own page, so this also opens it there.*/const navigateToTab = (tab: ConversationTab) => {onTabChange(tab);setPanelOpen(true);setIsOverviewPanelShown(false);+ requestPanelReveal();};const navigateToChanges = () => {diff --git a/src/services/canvas-ui.ts b/src/services/canvas-ui.tsindex ae9c17e184..e9bb3efdf0 100644--- a/src/services/canvas-ui.ts+++ b/src/services/canvas-ui.ts@@ -35,6 +35,15 @@ export function subscribeToPanelReveal(};}+/**+ * Ask whoever shows the conversation drawer to reveal it. Desktop already+ * shows the drawer from the store flags; at phone width the conversation+ * route answers by opening `/conversations/:id/panel`.+ */+export function requestPanelReveal(): void {+ panelRevealListeners.forEach((listener) => listener());+}+// Mirrors src/hooks/use-select-conversation-tab.ts so a non-React caller (the// WebSocket dispatch) gets the same "persist the tab and reveal the right// panel if collapsed" behavior as in-app tab switches.@@ -48,7 +57,7 @@ function navigateToTab(tab: ConversationTab, conversationId: string | null) {store.setHasRightPanelToggled(true);store.setIsRightPanelShown(true);}- panelRevealListeners.forEach((listener) => listener());+ requestPanelReveal();}function isValidTab(value: string): value is ConversationTab {