Skip to content

πŸ™Œ OpenHands: AI-Driven Development

fix(frontend): hide right panel when active tab is unpinned (#13648)

Hiep Lee1afc95b6c76
diff --git a/frontend/__tests__/components/features/conversation/conversation-tabs-context-menu.test.tsx b/frontend/__tests__/components/features/conversation/conversation-tabs-context-menu.test.tsx
index dea587f26f..9944b8e391 100644
--- a/frontend/__tests__/components/features/conversation/conversation-tabs-context-menu.test.tsx
+++ b/frontend/__tests__/components/features/conversation/conversation-tabs-context-menu.test.tsx
@@ -2,6 +2,7 @@ import { render, screen } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { describe, it, expect, vi, beforeEach } from "vitest";
import { ConversationTabsContextMenu } from "#/components/features/conversation/conversation-tabs/conversation-tabs-context-menu";
+import { useConversationStore } from "#/stores/conversation-store";
const CONVERSATION_ID = "conv-abc123";
@@ -21,6 +22,11 @@ describe("ConversationTabsContextMenu", () => {
beforeEach(() => {
localStorage.clear();
mockHasTaskList = false;
+ useConversationStore.setState({
+ selectedTab: "editor",
+ isRightPanelShown: true,
+ hasRightPanelToggled: true,
+ });
});
it("should render nothing when isOpen is false", () => {
@@ -69,6 +75,33 @@ describe("ConversationTabsContextMenu", () => {
expect(storedState.unpinnedTabs).not.toContain("terminal");
});
+ it("should close the right panel when unpinning the currently active tab", async () => {
+ const user = userEvent.setup();
+
+ render(<ConversationTabsContextMenu isOpen={true} onClose={vi.fn()} />);
+
+ await user.click(screen.getByText("COMMON$CHANGES"));
+
+ 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 not close the right panel when unpinning a non-active tab", async () => {
+ const user = userEvent.setup();
+
+ render(<ConversationTabsContextMenu isOpen={true} onClose={vi.fn()} />);
+
+ await user.click(screen.getByText("COMMON$TERMINAL"));
+
+ const storeState = useConversationStore.getState();
+ expect(storeState.hasRightPanelToggled).toBe(true);
+ });
+
describe("with tasklist", () => {
beforeEach(() => {
mockHasTaskList = true;
diff --git a/frontend/src/components/features/conversation/conversation-tabs/conversation-tabs-context-menu.tsx b/frontend/src/components/features/conversation/conversation-tabs/conversation-tabs-context-menu.tsx
index e90817f56c..58ceae666a 100644
--- a/frontend/src/components/features/conversation/conversation-tabs/conversation-tabs-context-menu.tsx
+++ b/frontend/src/components/features/conversation/conversation-tabs/conversation-tabs-context-menu.tsx
@@ -4,6 +4,7 @@ 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 { I18nKey } from "#/i18n/declaration";
import TerminalIcon from "#/icons/terminal.svg?react";
import GlobeIcon from "#/icons/globe.svg?react";
@@ -28,8 +29,10 @@ export function ConversationTabsContextMenu({
const ref = useClickOutsideElement<HTMLUListElement>(onClose);
const { t } = useTranslation();
const { conversationId } = useConversationId();
- const { state, setUnpinnedTabs } =
+ const { state, setUnpinnedTabs, setRightPanelShown } =
useConversationLocalStorageState(conversationId);
+ const { selectedTab, isRightPanelShown, setHasRightPanelToggled } =
+ useConversationStore();
const { hasTaskList } = useTaskList();
@@ -61,6 +64,10 @@ export function ConversationTabsContextMenu({
setUnpinnedTabs(state.unpinnedTabs.filter((item) => item !== tab));
} else {
setUnpinnedTabs([...state.unpinnedTabs, tab]);
+ if (selectedTab === tab && isRightPanelShown) {
+ setHasRightPanelToggled(false);
+ setRightPanelShown(false);
+ }
}
};