Skip to content

Commit 5166dcf

Browse files
fix(ui): couple dashboard side panel to split mode
1 parent 35b6fd8 commit 5166dcf

12 files changed

Lines changed: 166 additions & 27 deletions

‎ui/src/e2e/board-split-transcript.e2e.test.ts‎

Lines changed: 72 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ describeControlUiE2e("Board split transcript restore", () => {
171171
await page.locator(".board-session-surface").waitFor();
172172
await page.getByText("Message number 39:").first().waitFor({ timeout: 15_000 });
173173

174-
const mode = (value: "split" | "dashboard") =>
174+
const mode = (value: "chat" | "split" | "dashboard") =>
175175
page.locator(`wa-radio.settings-segmented__btn[value="${value}"]`);
176176

177177
// Defer each dock update so the pane render that stamps the transcript into
@@ -267,8 +267,17 @@ describeControlUiE2e("Board split transcript restore", () => {
267267
}
268268
}, 120_000);
269269

270-
it("closes and reopens the whole multi-tab dashboard side panel", async () => {
271-
const context = await browser.newContext({ viewport: { width: 1400, height: 900 } });
270+
it("transitions between Dashboard and Split with the whole side panel", async () => {
271+
const recordProof = process.env.OPENCLAW_UI_E2E_RECORD === "1";
272+
if (recordProof) {
273+
await mkdir(proofDir, { recursive: true });
274+
}
275+
const context = await browser.newContext({
276+
viewport: { width: 1400, height: 900 },
277+
...(recordProof
278+
? { recordVideo: { dir: proofDir, size: { width: 1400, height: 900 } } }
279+
: {}),
280+
});
272281
contexts.add(context);
273282
const page = await context.newPage();
274283
const gateway = await installMockGateway(page, {
@@ -284,7 +293,13 @@ describeControlUiE2e("Board split transcript restore", () => {
284293
],
285294
methodResponses: {
286295
"board.get": boardSnapshot("right"),
287-
"board.update": boardSnapshot("right", 2),
296+
"board.update": {
297+
sequence: [
298+
boardSnapshot("hidden", 2),
299+
boardSnapshot("right", 3),
300+
boardSnapshot("hidden", 4),
301+
],
302+
},
288303
"browser.request": {
289304
cases: [
290305
{ match: { method: "GET", path: "/tabs" }, response: { running: false, tabs: [] } },
@@ -299,6 +314,17 @@ describeControlUiE2e("Board split transcript restore", () => {
299314

300315
const board = page.locator(".board-session-surface__board");
301316
const sidePanel = page.locator(".side-panel");
317+
const mode = (value: "chat" | "split" | "dashboard") =>
318+
page.locator(`wa-radio.settings-segmented__btn[value="${value}"]`);
319+
const activeMode = () =>
320+
page.locator("wa-radio.settings-segmented__btn--active").getAttribute("value");
321+
const recordStep = async (name: string) => {
322+
if (!recordProof) {
323+
return;
324+
}
325+
await page.screenshot({ path: path.join(proofDir, `${name}.png`) });
326+
await page.waitForTimeout(500);
327+
};
302328
await sidePanel.waitFor();
303329
const expectedTabLabels = ["Board chat", "Browser", "Terminal"];
304330
await expectSidePanelTabs(page, expectedTabLabels);
@@ -310,19 +336,45 @@ describeControlUiE2e("Board split transcript restore", () => {
310336
(element) => element.getBoundingClientRect().width,
311337
);
312338

313-
await sidePanel.getByRole("button", { name: "Close", exact: true }).click();
339+
await mode("dashboard").click();
314340

315341
await expect.poll(() => sidePanel.count()).toBe(0);
316342
await expect
317343
.poll(() => board.evaluate((element) => element.getBoundingClientRect().width))
318344
.toBeGreaterThan(widthBeforeClose);
319-
expect(await gateway.getRequests("board.update")).toEqual([]);
345+
await expect.poll(() => activeMode()).toBe("dashboard");
346+
expect(await gateway.getRequests("board.update")).toHaveLength(1);
347+
await recordStep("transition-01-dashboard");
320348

321349
await page.getByRole("button", { name: "Side panel", exact: true }).click();
322350
await sidePanel.waitFor();
323351
await expectSidePanelTabs(page, expectedTabLabels);
324352
expect(await sidePanel.locator('[data-panel-slot="chat"]').count()).toBe(1);
325-
expect(await gateway.getRequests("board.update")).toEqual([]);
353+
await expect.poll(() => activeMode()).toBe("split");
354+
expect(await gateway.getRequests("board.update")).toHaveLength(2);
355+
await recordStep("transition-02-split-reopened");
356+
357+
await sidePanel.getByRole("button", { name: "Close", exact: true }).click();
358+
359+
await expect.poll(() => sidePanel.count()).toBe(0);
360+
await expect.poll(() => activeMode()).toBe("dashboard");
361+
expect(await gateway.getRequests("board.update")).toHaveLength(3);
362+
await recordStep("transition-03-panel-closed");
363+
await mode("chat").click();
364+
await expect.poll(() => activeMode()).toBe("chat");
365+
await expect.poll(() => sidePanel.count()).toBe(0);
366+
await recordStep("transition-04-chat");
367+
await mode("dashboard").click();
368+
await expect.poll(() => activeMode()).toBe("dashboard");
369+
await expect.poll(() => sidePanel.count()).toBe(0);
370+
expect(await gateway.getRequests("board.update")).toHaveLength(3);
371+
await recordStep("transition-05-dashboard-final");
372+
if (recordProof) {
373+
const video = page.video();
374+
await context.close();
375+
contexts.delete(context);
376+
await video?.saveAs(path.join(proofDir, "dashboard-side-panel-transition.webm"));
377+
}
326378
}, 120_000);
327379

328380
it("activates Side chat from a split dashboard panel", async () => {
@@ -438,7 +490,7 @@ describeControlUiE2e("Board split transcript restore", () => {
438490
}
439491
}, 120_000);
440492

441-
it("closes and reopens sole projected Board chat from either close control", async () => {
493+
it("transitions sole Board chat from either close control", async () => {
442494
const context = await browser.newContext({ viewport: { width: 1400, height: 900 } });
443495
contexts.add(context);
444496
const page = await context.newPage();
@@ -447,7 +499,14 @@ describeControlUiE2e("Board split transcript restore", () => {
447499
featureMethods: ["board.get", "board.update", "chat.metadata", "chat.startup"],
448500
methodResponses: {
449501
"board.get": boardSnapshot("right"),
450-
"board.update": boardSnapshot("right", 2),
502+
"board.update": {
503+
sequence: [
504+
boardSnapshot("hidden", 2),
505+
boardSnapshot("right", 3),
506+
boardSnapshot("hidden", 4),
507+
boardSnapshot("right", 5),
508+
],
509+
},
451510
},
452511
});
453512
await showDashboard(page);
@@ -464,21 +523,22 @@ describeControlUiE2e("Board split transcript restore", () => {
464523
await expect.poll(() => sidePanel.count()).toBe(0);
465524
expect(await headerToggle.getAttribute("aria-expanded")).toBe("false");
466525
expect(await headerToggle.getAttribute("aria-label")).toBe("Side panel");
467-
expect(await gateway.getRequests("board.update")).toEqual([]);
526+
expect(await gateway.getRequests("board.update")).toHaveLength(1);
468527

469528
await headerToggle.click();
470529
await sidePanel.waitFor();
471530
await expectSidePanelTabs(page, ["Board chat"]);
472531
expect(await headerToggle.getAttribute("aria-expanded")).toBe("true");
473-
expect(await gateway.getRequests("board.update")).toEqual([]);
532+
expect(await gateway.getRequests("board.update")).toHaveLength(2);
474533

475534
await headerToggle.click();
476535
await expect.poll(() => sidePanel.count()).toBe(0);
477536
expect(await headerToggle.getAttribute("aria-expanded")).toBe("false");
478-
expect(await gateway.getRequests("board.update")).toEqual([]);
537+
expect(await gateway.getRequests("board.update")).toHaveLength(3);
479538

480539
await headerToggle.click();
481540
await sidePanel.waitFor();
482541
await expectSidePanelTabs(page, ["Board chat"]);
542+
expect(await gateway.getRequests("board.update")).toHaveLength(4);
483543
}, 120_000);
484544
});

‎ui/src/pages/chat/chat-pane-base.ts‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ export abstract class ChatPaneBase extends OpenClawLightDomElement {
287287
if (renderedLayout.columns[0]?.panels.some((panel) => panel.slot === "companion")) {
288288
this.setSessionObserverVisibility(open);
289289
}
290-
state.updateSidebarLayout(setSidebarOpen(renderedLayout, open));
290+
this.commitSidebarLayout(setSidebarOpen(renderedLayout, open));
291291
}
292292

293293
protected requestSessionRail(intent: "open" | "toggle"): void {
@@ -297,11 +297,11 @@ export abstract class ChatPaneBase extends OpenClawLightDomElement {
297297
}
298298
const visible = this.selectedSessionRailMode(state.sessionKey) === "expanded";
299299
if (intent === "toggle" && visible) {
300-
state.updateSidebarLayout(closeSlot(state.sidebarLayout, "companion"));
300+
this.commitSidebarLayout(closeSlot(state.sidebarLayout, "companion"));
301301
this.setSessionObserverVisibility(false);
302302
return;
303303
}
304-
state.updateSidebarLayout(openSlot(state.sidebarLayout, "companion"));
304+
this.commitSidebarLayout(openSlot(state.sidebarLayout, "companion"));
305305
this.setSessionObserverVisibility(true);
306306
}
307307

@@ -487,6 +487,7 @@ export abstract class ChatPaneBase extends OpenClawLightDomElement {
487487
}
488488

489489
protected abstract refreshSessionPullRequests(options?: { refresh?: boolean }): Promise<void>;
490+
protected abstract commitSidebarLayout(layout: SidebarLayout): void;
490491
protected abstract refreshSwarmRoster(): void;
491492
protected abstract resolveBoardProvider(): BoardProvider;
492493
protected abstract handleBoardCommand(event: BoardCommandEvent): void;

‎ui/src/pages/chat/chat-pane-board.test.ts‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ type TestChatPane = HTMLElement & {
5656
routeFace: "chat" | "dashboard";
5757
onFaceChange?: (paneId: string, sessionKey: string, face: "chat" | "dashboard") => void;
5858
confirmConversationReset: () => Promise<boolean>;
59+
commitSidebarLayout: (layout: ChatPageHost["sidebarLayout"]) => void;
5960
settleResetConfirmation: (confirmed: boolean) => void;
6061
updated: () => void;
6162
handleBoardCommand: (event: BoardCommandEvent) => void;
@@ -173,6 +174,26 @@ afterEach(() => {
173174
});
174175

175176
describe("chat pane board shell", () => {
177+
it("couples explicit side-panel visibility to the Board dock", () => {
178+
const pane = createTestPane();
179+
const provider = mockBoardProvider("agent:main:current");
180+
const applyOps = vi.spyOn(provider, "applyOps");
181+
pane.boardProvider = provider;
182+
pane.routeFace = "dashboard";
183+
pane.handleBoardDockChange("hidden");
184+
applyOps.mockClear();
185+
186+
pane.commitSidebarLayout(openSlot(pane.state.sidebarLayout, "terminal"));
187+
expect(applyOps).toHaveBeenLastCalledWith([
188+
{ kind: "tab_update", tabId: "main", chatDock: "right" },
189+
]);
190+
191+
pane.commitSidebarLayout({ ...pane.state.sidebarLayout, open: false });
192+
expect(applyOps).toHaveBeenLastCalledWith([
193+
{ kind: "tab_update", tabId: "main", chatDock: "hidden" },
194+
]);
195+
});
196+
176197
it("does not hydrate the swarm after becoming hidden during module loading", async () => {
177198
vi.useFakeTimers();
178199
const list = vi.fn().mockResolvedValue({ sessions: [] });

‎ui/src/pages/chat/chat-pane-board.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,16 @@ import {
5050

5151
export abstract class ChatPaneBoard extends ChatPaneHistory {
5252
protected commitSidebarLayout(layout: SidebarLayout): void {
53+
// User panel intents and the Board mode must move together. Restored state
54+
// bypasses this seam so loading a session never mutates its active tab.
55+
const board = this.resolveBoardView();
56+
if (board.hasBoard && board.face === "dashboard" && board.provider.canMutate) {
57+
if (layout.open === true && board.dock === "hidden") {
58+
this.handleBoardDockChange(board.reopenDock);
59+
} else if (layout.open !== true && (board.dock === "left" || board.dock === "right")) {
60+
this.handleBoardDockChange("hidden");
61+
}
62+
}
5363
const state = this.state;
5464
if (!state) {
5565
return;

‎ui/src/pages/chat/chat-pane-discussion.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ export abstract class ChatPaneDiscussion extends ChatPaneSessionMenu {
144144
this.paneWidth >= SIDEBAR_NARROW_BREAKPOINT_PX
145145
? (fitSidebarLayout(opened, this.paneWidth) ?? opened)
146146
: opened;
147-
state.updateSidebarLayout(fitted);
147+
this.commitSidebarLayout(fitted);
148148
if (discussionPanel) {
149149
state.updateSidebarActivePanel(discussionPanel.id);
150150
}
@@ -181,7 +181,7 @@ export abstract class ChatPaneDiscussion extends ChatPaneSessionMenu {
181181
label,
182182
onToggle: () =>
183183
active
184-
? state.updateSidebarLayout(closeSlot(state.sidebarLayout, "discussion"))
184+
? this.commitSidebarLayout(closeSlot(state.sidebarLayout, "discussion"))
185185
: this.openSessionDiscussionSlot(),
186186
};
187187
}

‎ui/src/pages/chat/chat-pane-lifecycle.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ export abstract class ChatPaneLifecycle extends ChatPaneSessionCreation {
9292
},
9393
pending: this.pendingPanelToggleRequests,
9494
requestUpdate: () => this.requestUpdate(),
95+
updateSidebarLayout: (layout) => this.commitSidebarLayout(layout),
9596
});
9697

9798
private chatRouteReadyReported = false;
@@ -313,7 +314,7 @@ export abstract class ChatPaneLifecycle extends ChatPaneSessionCreation {
313314
if (visible) {
314315
releaseAttachmentWorkspaceOwner(state, slot);
315316
}
316-
state.updateSidebarLayout(
317+
this.commitSidebarLayout(
317318
visible ? closeSlot(state.sidebarLayout, slot) : openSlot(state.sidebarLayout, slot),
318319
);
319320
};

‎ui/src/pages/chat/chat-pane-rails.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,13 @@ export function createChatPaneRails(params: {
2424
presented: boolean;
2525
gatewaySnapshot: ChatPaneGatewaySnapshot;
2626
setObserverVisibility: (visible: boolean) => void;
27+
updateSidebarLayout: ChatPageHost["updateSidebarLayout"];
2728
}) {
2829
const { state, sidebarLayout } = params;
2930
const hasPanelSlot = (slot: SidebarSlotId) =>
3031
sidebarLayout.columns[0]?.panels.some((panel) => panel.slot === slot) === true;
3132
const openPanelSlot = (slot: SidebarSlotId) => {
32-
state.updateSidebarLayout(openSlot(state.sidebarLayout, slot));
33+
params.updateSidebarLayout(openSlot(sidebarLayout, slot));
3334
if (slot === "companion") {
3435
params.setObserverVisibility(true);
3536
}
@@ -39,7 +40,7 @@ export function createChatPaneRails(params: {
3940
params.setObserverVisibility(false);
4041
}
4142
releaseAttachmentWorkspaceOwner(state, slot);
42-
state.updateSidebarLayout(closeSlot(state.sidebarLayout, slot));
43+
params.updateSidebarLayout(closeSlot(sidebarLayout, slot));
4344
};
4445
const togglePanelSlot = (slot: SidebarSlotId) =>
4546
hasPanelSlot(slot) ? closePanelSlot(slot) : openPanelSlot(slot);

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ export class ChatPane extends ChatPaneLayoutRender {
234234
presented: this.presented,
235235
gatewaySnapshot,
236236
setObserverVisibility: this.setSessionObserverVisibility,
237+
updateSidebarLayout: (layout) => this.commitSidebarLayout(layout),
237238
});
238239
const selfUser = resolveCurrentSelfUser({
239240
snapshotUser: gatewaySnapshot.selfUser,

‎ui/src/pages/chat/chat-pane-session-panel-toggle.ts‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ interface SessionPanelToggleControllerOptions {
2323
current: () => ActivePanelOwner | null;
2424
pending: Map<SessionPanelToggleSlot, Event>;
2525
requestUpdate: () => void;
26+
updateSidebarLayout: (layout: ChatPageHost["sidebarLayout"]) => void;
2627
}
2728

2829
/** Owns shell-to-pane panel intent handoff for the active chat presentation. */
@@ -38,7 +39,7 @@ export class ChatPaneSessionPanelToggleController {
3839
const detail = event instanceof CustomEvent ? event.detail : null;
3940
if (detail?.open === false) {
4041
this.options.pending.delete(slot);
41-
owner.state.updateSidebarLayout(closeSlot(owner.state.sidebarLayout, slot));
42+
this.options.updateSidebarLayout(closeSlot(owner.state.sidebarLayout, slot));
4243
return true;
4344
}
4445
if (slot === "terminal") {
@@ -54,11 +55,11 @@ export class ChatPaneSessionPanelToggleController {
5455
deferUntilHostChange: !embeddedTerminalMounted,
5556
});
5657
}
57-
owner.state.updateSidebarLayout(openSlot(owner.state.sidebarLayout, slot));
58+
this.options.updateSidebarLayout(openSlot(owner.state.sidebarLayout, slot));
5859
return true;
5960
}
6061
this.options.pending.set(slot, event);
61-
owner.state.updateSidebarLayout(openSlot(owner.state.sidebarLayout, slot));
62+
this.options.updateSidebarLayout(openSlot(owner.state.sidebarLayout, slot));
6263
void Promise.all([
6364
customElements.whenDefined("openclaw-chat-sidebar-region"),
6465
customElements.whenDefined(tagName),

0 commit comments

Comments
 (0)