🙌 OpenHands: AI-Driven Development
fix: improve right panel UX when unpinning active tab (#328)
Rohit Malhotra7d9e6ab6bad5
diff --git a/__tests__/components/features/conversation/conversation-tabs-context-menu.test.tsx b/__tests__/components/features/conversation/conversation-tabs-context-menu.test.tsxindex ba81187f0b..995429f0a2 100644--- a/__tests__/components/features/conversation/conversation-tabs-context-menu.test.tsx+++ b/__tests__/components/features/conversation/conversation-tabs-context-menu.test.tsx@@ -112,20 +112,31 @@ describe("ConversationTabsContextMenu", () => {expect(storedState.unpinnedTabs).not.toContain("terminal");});- it("should close the right panel when unpinning the currently active tab", async () => {+ it("should switch to another pinned tab when unpinning the currently active tab", async () => {const user = userEvent.setup();render(<ConversationTabsContextMenu isOpen={true} onClose={vi.fn()} />);+ // Initially selected tab is "files"+ expect(useConversationStore.getState().selectedTab).toBe("files");++ // Unpin the active "files" tabawait user.click(screen.getByText("COMMON$FILES"));+ // Panel should still be shownconst storeState = useConversationStore.getState();- expect(storeState.hasRightPanelToggled).toBe(false);+ expect(storeState.hasRightPanelToggled).toBe(true);++ // Should have switched to another pinned tab (planner is first in list)+ expect(storeState.selectedTab).toBe("planner");+ // Verify the files tab was unpinnedconst storedState = JSON.parse(localStorage.getItem(`conversation-state-${CONVERSATION_ID}`)!,);- expect(storedState.rightPanelShown).toBe(false);+ expect(storedState.unpinnedTabs).toContain("files");+ // Selected tab should be persisted as the new tab+ expect(storedState.selectedTab).toBe("planner");});it("should not close the right panel when unpinning a non-active tab", async () => {diff --git a/__tests__/components/features/conversation/right-panel-toggle.test.tsx b/__tests__/components/features/conversation/right-panel-toggle.test.tsxnew file mode 100644index 0000000000..da86343ba5--- /dev/null+++ b/__tests__/components/features/conversation/right-panel-toggle.test.tsx@@ -0,0 +1,83 @@+import { render, screen } from "@testing-library/react";+import userEvent from "@testing-library/user-event";+import { describe, it, expect, vi, beforeEach } from "vitest";+import { RightPanelToggle } from "#/components/features/conversation/right-panel-toggle";+import { useConversationStore } from "#/stores/conversation-store";++const CONVERSATION_ID = "conv-abc123";++vi.mock("#/hooks/use-conversation-id", () => ({+ useConversationId: () => ({ conversationId: CONVERSATION_ID }),+}));++describe("RightPanelToggle", () => {+ beforeEach(() => {+ localStorage.clear();+ useConversationStore.setState({+ selectedTab: "files",+ isRightPanelShown: true,+ hasRightPanelToggled: true,+ });+ });++ it("should render the toggle button", () => {+ render(<RightPanelToggle />);+ expect(screen.getByTestId("right-panel-toggle")).toBeInTheDocument();+ });++ it("should hide the panel when clicked while panel is open", async () => {+ const user = userEvent.setup();++ render(<RightPanelToggle />);++ const button = screen.getByTestId("right-panel-toggle");+ await user.click(button);++ const storeState = useConversationStore.getState();+ expect(storeState.hasRightPanelToggled).toBe(false);++ const storedState = JSON.parse(+ localStorage.getItem(`conversation-state-${CONVERSATION_ID}`)!,+ );+ expect(storedState.rightPanelShown).toBe(false);+ });++ it("should show the panel when clicked while panel is hidden", async () => {+ const user = userEvent.setup();++ useConversationStore.setState({+ isRightPanelShown: false,+ hasRightPanelToggled: false,+ });++ render(<RightPanelToggle />);++ const button = screen.getByTestId("right-panel-toggle");+ await user.click(button);++ const storeState = useConversationStore.getState();+ expect(storeState.hasRightPanelToggled).toBe(true);++ const storedState = JSON.parse(+ localStorage.getItem(`conversation-state-${CONVERSATION_ID}`)!,+ );+ expect(storedState.rightPanelShown).toBe(true);+ });++ it("should have aria-pressed attribute reflecting panel state", () => {+ const { unmount } = render(<RightPanelToggle />);+ expect(screen.getByTestId("right-panel-toggle")).toHaveAttribute(+ "aria-pressed",+ "true",+ );++ unmount();++ useConversationStore.setState({ isRightPanelShown: false });+ render(<RightPanelToggle />);+ expect(screen.getByTestId("right-panel-toggle")).toHaveAttribute(+ "aria-pressed",+ "false",+ );+ });+});diff --git a/src/components/features/conversation/conversation-name-with-status.tsx b/src/components/features/conversation/conversation-name-with-status.tsxindex 303fd8372c..f535b5a5db 100644--- a/src/components/features/conversation/conversation-name-with-status.tsx+++ b/src/components/features/conversation/conversation-name-with-status.tsx@@ -11,6 +11,7 @@ import { AgentState } from "#/types/agent-state";import DebugStackframeDot from "#/icons/debug-stackframe-dot.svg?react";import { ServerStatusContextMenu } from "../controls/server-status-context-menu";import { ConversationName } from "./conversation-name";+import { RightPanelToggle } from "./right-panel-toggle";import {isExecutionActive,isExecutionErrored,@@ -57,27 +58,30 @@ export function ConversationNameWithStatus() {};return (- <div className="flex items-center">- <div className="group relative">- <DebugStackframeDot- className="ml-[3.5px] w-6 h-6 cursor-pointer"- color={statusColor}- />- <ServerStatusContextMenu- onClose={() => {}}- onStopServer={- isExecutionActive(executionStatus) ? handleStopServer : undefined- }- onStartServer={- isExecutionPaused(executionStatus) ? handleStartServer : undefined- }- executionStatus={executionStatus}- position="bottom"- className="opacity-0 invisible pointer-events-none group-hover:opacity-100 group-hover:visible group-hover:pointer-events-auto bottom-full left-0 mt-0 min-h-fit"- isPausing={false}- />+ <div className="flex items-center justify-between w-full">+ <div className="flex items-center">+ <div className="group relative">+ <DebugStackframeDot+ className="ml-[3.5px] w-6 h-6 cursor-pointer"+ color={statusColor}+ />+ <ServerStatusContextMenu+ onClose={() => {}}+ onStopServer={+ isExecutionActive(executionStatus) ? handleStopServer : undefined+ }+ onStartServer={+ isExecutionPaused(executionStatus) ? handleStartServer : undefined+ }+ executionStatus={executionStatus}+ position="bottom"+ className="opacity-0 invisible pointer-events-none group-hover:opacity-100 group-hover:visible group-hover:pointer-events-auto bottom-full left-0 mt-0 min-h-fit"+ isPausing={false}+ />+ </div>+ <ConversationName /></div>- <ConversationName />+ <RightPanelToggle className="mr-2" /></div>);}diff --git a/src/components/features/conversation/conversation-tabs/conversation-tabs-context-menu.tsx b/src/components/features/conversation/conversation-tabs/conversation-tabs-context-menu.tsxindex 59b5360c49..7c48d6a72f 100644--- a/src/components/features/conversation/conversation-tabs/conversation-tabs-context-menu.tsx+++ b/src/components/features/conversation/conversation-tabs/conversation-tabs-context-menu.tsx@@ -4,7 +4,10 @@ import { ContextMenuListItem } from "../../context-menu/context-menu-list-item";import { useClickOutsideElement } from "#/hooks/use-click-outside-element";import { useConversationId } from "#/hooks/use-conversation-id";import { useConversationLocalStorageState } from "#/utils/conversation-local-storage";-import { useConversationStore } from "#/stores/conversation-store";+import {+ useConversationStore,+ type ConversationTab,+} from "#/stores/conversation-store";import { I18nKey } from "#/i18n/declaration";import TerminalIcon from "#/icons/terminal.svg?react";import GlobeIcon from "#/icons/globe.svg?react";@@ -29,9 +32,12 @@ export function ConversationTabsContextMenu({const ref = useClickOutsideElement<HTMLUListElement>(onClose);const { t } = useTranslation("openhands");const { conversationId } = useConversationId();- const { state, setUnpinnedTabs, setRightPanelShown } =- useConversationLocalStorageState(conversationId);- const { selectedTab, isRightPanelShown, setHasRightPanelToggled } =+ const {+ state,+ setUnpinnedTabs,+ setSelectedTab: setPersistedSelectedTab,+ } = useConversationLocalStorageState(conversationId);+ const { selectedTab, isRightPanelShown, setSelectedTab } =useConversationStore();const { hasTaskList } = useTaskList();@@ -66,12 +72,29 @@ export function ConversationTabsContextMenu({const handleTabClick = (tab: string) => {if (state.unpinnedTabs.includes(tab)) {+ // Re-pinning a tabsetUnpinnedTabs(state.unpinnedTabs.filter((item) => item !== tab));} else {- setUnpinnedTabs([...state.unpinnedTabs, tab]);+ // Unpinning a tab+ const newUnpinnedTabs = [...state.unpinnedTabs, tab];+ setUnpinnedTabs(newUnpinnedTabs);++ // If we're unpinning the currently selected tab while the panel is open,+ // switch to another pinned tab instead of hiding the panelif (selectedTab === tab && isRightPanelShown) {- setHasRightPanelToggled(false);- setRightPanelShown(false);+ // Find the first tab that will still be pinned after this unpin+ const nextPinnedTab = visibleTabConfig.find(+ ({ tab: tabKey }) =>+ tabKey !== tab && !newUnpinnedTabs.includes(tabKey),+ );++ if (nextPinnedTab) {+ // Switch to another pinned tab+ setSelectedTab(nextPinnedTab.tab as ConversationTab);+ setPersistedSelectedTab(nextPinnedTab.tab as ConversationTab);+ }+ // If no other tabs are pinned, the panel will still show the last tab's content+ // but the tab won't be highlighted (which is acceptable behavior)}}};diff --git a/src/components/features/conversation/right-panel-toggle.tsx b/src/components/features/conversation/right-panel-toggle.tsxnew file mode 100644index 0000000000..6df6ddeab1--- /dev/null+++ b/src/components/features/conversation/right-panel-toggle.tsx@@ -0,0 +1,64 @@+import { useTranslation } from "react-i18next";+import { useConversationId } from "#/hooks/use-conversation-id";+import { useConversationLocalStorageState } from "#/utils/conversation-local-storage";+import { useConversationStore } from "#/stores/conversation-store";+import { I18nKey } from "#/i18n/declaration";+import { cn } from "#/utils/utils";+import BlockDrawerLeftIcon from "#/icons/block-drawer-left.svg?react";+import { ChatActionTooltip } from "../chat/chat-action-tooltip";++interface RightPanelToggleProps {+ className?: string;+}++/**+ * Toggle button for showing/hiding the right panel.+ * This component is placed in the chat header so users can always+ * restore the panel, even when it's hidden.+ */+export function RightPanelToggle({ className }: RightPanelToggleProps) {+ const { t } = useTranslation("openhands");+ const { conversationId } = useConversationId();+ const { setRightPanelShown } =+ useConversationLocalStorageState(conversationId);+ const { isRightPanelShown, setHasRightPanelToggled, setSelectedTab } =+ useConversationStore();++ const handleToggle = () => {+ const newState = !isRightPanelShown;+ setHasRightPanelToggled(newState);+ setRightPanelShown(newState);++ // If opening the panel and no tab is selected, default to files+ if (newState) {+ const { selectedTab } = useConversationStore.getState();+ if (!selectedTab) {+ setSelectedTab("files");+ }+ }+ };++ const tooltipText = isRightPanelShown+ ? t(I18nKey.COMMON$HIDE_PANEL)+ : t(I18nKey.COMMON$SHOW_PANEL);++ return (+ <ChatActionTooltip tooltip={tooltipText} ariaLabel={tooltipText}>+ <button+ type="button"+ onClick={handleToggle}+ className={cn(+ "p-1 rounded-md cursor-pointer transition-colors",+ "text-[#9299AA] hover:text-white hover:bg-white/10",+ isRightPanelShown && "text-white bg-white/10",+ className,+ )}+ aria-label={tooltipText}+ aria-pressed={isRightPanelShown}+ data-testid="right-panel-toggle"+ >+ <BlockDrawerLeftIcon className="w-5 h-5" />+ </button>+ </ChatActionTooltip>+ );+}diff --git a/src/i18n/translation.json b/src/i18n/translation.jsonindex ad5c5e1bc6..b30b44c4d8 100644--- a/src/i18n/translation.json+++ b/src/i18n/translation.json@@ -20450,6 +20450,40 @@"uk": "Більше опцій","ca": "Més opcions"},+ "COMMON$SHOW_PANEL": {+ "en": "Show panel",+ "ja": "パネルを表示",+ "zh-CN": "显示面板",+ "zh-TW": "顯示面板",+ "ko-KR": "패널 표시",+ "no": "Vis panel",+ "it": "Mostra pannello",+ "pt": "Mostrar painel",+ "es": "Mostrar panel",+ "ar": "إظهار اللوحة",+ "fr": "Afficher le panneau",+ "tr": "Paneli göster",+ "de": "Panel anzeigen",+ "uk": "Показати панель",+ "ca": "Mostra el panell"+ },+ "COMMON$HIDE_PANEL": {+ "en": "Hide panel",+ "ja": "パネルを非表示",+ "zh-CN": "隐藏面板",+ "zh-TW": "隱藏面板",+ "ko-KR": "패널 숨기기",+ "no": "Skjul panel",+ "it": "Nascondi pannello",+ "pt": "Ocultar painel",+ "es": "Ocultar panel",+ "ar": "إخفاء اللوحة",+ "fr": "Masquer le panneau",+ "tr": "Paneli gizle",+ "de": "Panel ausblenden",+ "uk": "Сховати панель",+ "ca": "Amaga el panell"+ },"COMMON$CREATE_A_PLAN": {"en": "Create a plan","ja": "プランを作成する",