Skip to content

Commit 935c555

Browse files
fix(ui): restore selected dashboard side tab (#128867)
* fix(ui): restore selected dashboard side tab * test(ui): avoid iframe in side-tab persistence fixture --------- Co-authored-by: roboclaw-bot <[email protected]> Co-authored-by: Jason (Json) <[email protected]>
1 parent f68b808 commit 935c555

4 files changed

Lines changed: 128 additions & 9 deletions

File tree

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import { expect, it } from "vitest";
2+
import {
3+
controlUiBundledSettingsStorageKey,
4+
installMockGateway,
5+
} from "../test-helpers/control-ui-e2e.ts";
6+
import { createControlUiE2eSuite } from "./control-ui-e2e-suite.test-support.ts";
7+
8+
const suite = createControlUiE2eSuite({
9+
name: "Control UI dashboard side-panel selection",
10+
startServerBeforeBrowser: true,
11+
});
12+
13+
const sessionKey = "agent:main:dashboard";
14+
const boardSnapshot = {
15+
sessionKey,
16+
revision: 1,
17+
tabs: [{ tabId: "main", title: "Main", position: 0, chatDock: "right" }],
18+
widgets: [],
19+
};
20+
21+
suite.define(() => {
22+
it("restores the previously selected side-panel tab", async () => {
23+
const context = await suite.browser.newContext({ viewport: { height: 900, width: 1280 } });
24+
const page = await context.newPage();
25+
const settingsKey = controlUiBundledSettingsStorageKey(suite.server.baseUrl);
26+
await page.addInitScript(
27+
({ key, storageKey }) => {
28+
const settings = JSON.parse(localStorage.getItem(storageKey) ?? "{}") as Record<
29+
string,
30+
unknown
31+
>;
32+
settings.boardSessionViews = { [key]: { activeTabId: "main" } };
33+
const sidebarSessionLayouts =
34+
settings.sidebarSessionLayouts && typeof settings.sidebarSessionLayouts === "object"
35+
? (settings.sidebarSessionLayouts as Record<string, unknown>)
36+
: {};
37+
settings.sidebarSessionLayouts = {
38+
...sidebarSessionLayouts,
39+
[key]: sidebarSessionLayouts[key] ?? {
40+
columns: [
41+
{
42+
id: "side-panel-column",
43+
side: "right",
44+
panels: [{ id: "terminal", slot: "terminal" }],
45+
activePanelId: "terminal",
46+
height: 360,
47+
width: 480,
48+
},
49+
],
50+
dock: "right",
51+
open: true,
52+
},
53+
};
54+
localStorage.setItem(storageKey, JSON.stringify(settings));
55+
},
56+
{ key: sessionKey, storageKey: settingsKey },
57+
);
58+
await installMockGateway(page, {
59+
sessionKey,
60+
featureMethods: ["board.get", "chat.metadata", "chat.startup", "terminal.open"],
61+
methodResponses: { "board.get": boardSnapshot },
62+
terminalEnabled: true,
63+
});
64+
65+
try {
66+
await page.goto(`${suite.server.baseUrl}dashboard`);
67+
await page.locator(".board-session-surface").waitFor();
68+
const terminal = page.getByRole("tab", { name: "Terminal", exact: true });
69+
const chat = page.getByRole("tab", { name: "Board chat", exact: true });
70+
await expect.poll(() => terminal.getAttribute("aria-selected")).toBe("true");
71+
72+
await chat.click();
73+
await expect.poll(() => chat.getAttribute("aria-selected")).toBe("true");
74+
await page.reload();
75+
await expect.poll(() => chat.getAttribute("aria-selected")).toBe("true");
76+
} finally {
77+
await context.close();
78+
}
79+
});
80+
});

‎ui/src/pages/chat/chat-pane-layout-render.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ export abstract class ChatPaneLayoutRender extends ChatPaneBrowserAnnotationRend
147147
availableSlots,
148148
callbacks: sidebarRegionCallbacks({
149149
state,
150+
layout: sidebarLayout,
150151
closePanelSlot,
151152
openPanelSlot,
152153
hideBoard: () => this.handleBoardDockChange("hidden"),

‎ui/src/pages/chat/chat-pane-sidebar-layout.test.ts‎

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@
33
import { html, render } from "lit";
44
import { afterEach, describe, expect, it, vi } from "vitest";
55
import type { ResolvedBoardView } from "./chat-pane-shared.ts";
6-
import { renderSidebarRegion, resolveSidebarLayoutForBoard } from "./chat-pane-sidebar-layout.ts";
6+
import {
7+
renderSidebarRegion,
8+
resolveSidebarLayoutForBoard,
9+
sidebarRegionCallbacks,
10+
} from "./chat-pane-sidebar-layout.ts";
11+
import type { ChatPageHost } from "./chat-state-host.ts";
712
import "./components/chat-sidebar-region.runtime.ts";
813
import { openSlot, setSidebarOpen, type SidebarLayout } from "./sidebar-layout.ts";
914

@@ -146,6 +151,41 @@ describe("chat pane sidebar layout", () => {
146151
expect(layout.columns[0]?.activePanelId).toBe("companion");
147152
});
148153

154+
it("persists a selected Board chat tab from the rendered projection", () => {
155+
const stored = openSlot({ columns: [] }, "terminal");
156+
const rendered = resolveSidebarLayoutForBoard({
157+
board: board("right"),
158+
layout: stored,
159+
paneWidth: 1_400,
160+
});
161+
const chatPanel = rendered.columns[0]?.panels.find((panel) => panel.slot === "chat");
162+
const updateSidebarLayout = vi.fn();
163+
const updateSidebarActivePanel = vi.fn();
164+
const state = {
165+
sidebarLayout: stored,
166+
updateSidebarLayout,
167+
updateSidebarActivePanel,
168+
} as unknown as ChatPageHost;
169+
170+
sidebarRegionCallbacks({
171+
state,
172+
layout: rendered,
173+
closePanelSlot: vi.fn(),
174+
openPanelSlot: vi.fn(),
175+
hideBoard: vi.fn(),
176+
forgetDiscussionUrl: vi.fn(),
177+
resizePanel: vi.fn(),
178+
setPanelOpen: vi.fn(),
179+
}).activatePanel(chatPanel!.id);
180+
181+
expect(updateSidebarLayout).toHaveBeenCalledWith(
182+
expect.objectContaining({
183+
columns: [expect.objectContaining({ activePanelId: chatPanel!.id })],
184+
}),
185+
);
186+
expect(updateSidebarActivePanel).toHaveBeenCalledWith(chatPanel!.id);
187+
});
188+
149189
it("keeps bottom and hidden board chat outside the side panel", () => {
150190
for (const dock of ["bottom", "hidden"] as const) {
151191
const layout = resolveSidebarLayoutForBoard({

‎ui/src/pages/chat/chat-pane-sidebar-layout.ts‎

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -101,17 +101,18 @@ function ensureLazyElement(key: LazyElementKey, requestUpdate: () => void) {
101101
*/
102102
export function sidebarRegionCallbacks(params: {
103103
state: ChatPageHost;
104+
layout: SidebarLayout;
104105
closePanelSlot: (slot: SidebarSlotId) => void;
105106
openPanelSlot: (slot: SidebarSlotId) => void;
106107
hideBoard: () => void;
107108
forgetDiscussionUrl: () => void;
108109
resizePanel: (columnId: string, size: number) => void;
109110
setPanelOpen: (open: boolean) => void;
110111
}): SidebarRegionCallbacks {
111-
const { state } = params;
112+
const { layout, state } = params;
112113
return {
113114
activatePanel: (panelId) => {
114-
state.updateSidebarLayout(activatePanel(state.sidebarLayout, panelId));
115+
state.updateSidebarLayout(activatePanel(layout, panelId));
115116
state.updateSidebarActivePanel(panelId);
116117
},
117118
closeSlot: (slot) => {
@@ -126,13 +127,10 @@ export function sidebarRegionCallbacks(params: {
126127
},
127128
openSlot: params.openPanelSlot,
128129
reorderPanel: (panelId, targetPanelId, placement) =>
129-
state.updateSidebarLayout(
130-
reorderPanel(state.sidebarLayout, panelId, targetPanelId, placement),
131-
),
130+
state.updateSidebarLayout(reorderPanel(layout, panelId, targetPanelId, placement)),
132131
resizePanel: params.resizePanel,
133-
setDock: (dock) => state.updateSidebarLayout(setSidebarDock(state.sidebarLayout, dock)),
134-
setExpanded: (expanded) =>
135-
state.updateSidebarLayout(setSidebarExpanded(state.sidebarLayout, expanded)),
132+
setDock: (dock) => state.updateSidebarLayout(setSidebarDock(layout, dock)),
133+
setExpanded: (expanded) => state.updateSidebarLayout(setSidebarExpanded(layout, expanded)),
136134
setOpen: params.setPanelOpen,
137135
};
138136
}

0 commit comments

Comments
 (0)