Skip to content

Commit 3fa31a7

Browse files
fix(ui): make dashboard side panels enter split view (#130426)
* fix(ui): hide unavailable discussion panel * fix(ui): couple dashboard side panel to split mode
1 parent 99a2434 commit 3fa31a7

15 files changed

Lines changed: 243 additions & 28 deletions

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

Lines changed: 120 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 () => {
@@ -390,7 +442,55 @@ describeControlUiE2e("Board split transcript restore", () => {
390442
}
391443
}, 120_000);
392444

393-
it("closes and reopens sole projected Board chat from either close control", async () => {
445+
it("does not offer Discussion when the gateway has no discussion provider", async () => {
446+
const recordProof = process.env.OPENCLAW_UI_E2E_RECORD === "1";
447+
if (recordProof) {
448+
await mkdir(proofDir, { recursive: true });
449+
}
450+
const context = await browser.newContext({
451+
viewport: { width: 1400, height: 900 },
452+
...(recordProof
453+
? { recordVideo: { dir: proofDir, size: { width: 1400, height: 900 } } }
454+
: {}),
455+
});
456+
contexts.add(context);
457+
const page = await context.newPage();
458+
const gateway = await installMockGateway(page, {
459+
sessionKey,
460+
featureMethods: ["board.get", "chat.metadata", "chat.startup", "session.discussion.info"],
461+
methodResponses: {
462+
"board.get": boardSnapshot("right"),
463+
"session.discussion.info": { state: "none" },
464+
},
465+
});
466+
467+
try {
468+
await showDashboard(page);
469+
const sidePanel = page.locator(".side-panel");
470+
await sidePanel.waitFor();
471+
await expect
472+
.poll(() =>
473+
gateway.getRequests("session.discussion.info").then((requests) => requests.length),
474+
)
475+
.toBe(1);
476+
await sidePanel.getByRole("button", { name: "Add side panel tab" }).click();
477+
await expect
478+
.poll(() => sidePanel.locator("wa-dropdown-item").filter({ hasText: "Discussion" }).count())
479+
.toBe(0);
480+
if (recordProof) {
481+
await page.screenshot({ path: path.join(proofDir, "03-discussion-hidden.png") });
482+
}
483+
} finally {
484+
const video = page.video();
485+
await context.close();
486+
contexts.delete(context);
487+
if (recordProof && video) {
488+
await video.saveAs(path.join(proofDir, "dashboard-discussion-unavailable.webm"));
489+
}
490+
}
491+
}, 120_000);
492+
493+
it("transitions sole Board chat from either close control", async () => {
394494
const context = await browser.newContext({ viewport: { width: 1400, height: 900 } });
395495
contexts.add(context);
396496
const page = await context.newPage();
@@ -399,7 +499,14 @@ describeControlUiE2e("Board split transcript restore", () => {
399499
featureMethods: ["board.get", "board.update", "chat.metadata", "chat.startup"],
400500
methodResponses: {
401501
"board.get": boardSnapshot("right"),
402-
"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+
},
403510
},
404511
});
405512
await showDashboard(page);
@@ -416,21 +523,22 @@ describeControlUiE2e("Board split transcript restore", () => {
416523
await expect.poll(() => sidePanel.count()).toBe(0);
417524
expect(await headerToggle.getAttribute("aria-expanded")).toBe("false");
418525
expect(await headerToggle.getAttribute("aria-label")).toBe("Side panel");
419-
expect(await gateway.getRequests("board.update")).toEqual([]);
526+
expect(await gateway.getRequests("board.update")).toHaveLength(1);
420527

421528
await headerToggle.click();
422529
await sidePanel.waitFor();
423530
await expectSidePanelTabs(page, ["Board chat"]);
424531
expect(await headerToggle.getAttribute("aria-expanded")).toBe("true");
425-
expect(await gateway.getRequests("board.update")).toEqual([]);
532+
expect(await gateway.getRequests("board.update")).toHaveLength(2);
426533

427534
await headerToggle.click();
428535
await expect.poll(() => sidePanel.count()).toBe(0);
429536
expect(await headerToggle.getAttribute("aria-expanded")).toBe("false");
430-
expect(await gateway.getRequests("board.update")).toEqual([]);
537+
expect(await gateway.getRequests("board.update")).toHaveLength(3);
431538

432539
await headerToggle.click();
433540
await sidePanel.waitFor();
434541
await expectSidePanelTabs(page, ["Board chat"]);
542+
expect(await gateway.getRequests("board.update")).toHaveLength(4);
435543
}, 120_000);
436544
});

‎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
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/* @vitest-environment jsdom */
2+
3+
import { describe, expect, it } from "vitest";
4+
import { availableSidebarSlots, sidebarPanelDefinitions } from "./chat-pane-embedded-panels.ts";
5+
import type { SessionDiscussionPanelConfig } from "./components/session-discussion-panel.ts";
6+
7+
function discussionSlots(discussionAvailable: boolean) {
8+
const discussion = {} as SessionDiscussionPanelConfig;
9+
const definitions = sidebarPanelDefinitions({
10+
discussion,
11+
discussionAvailable,
12+
} as Parameters<typeof sidebarPanelDefinitions>[0]);
13+
return availableSidebarSlots(definitions);
14+
}
15+
16+
describe("chat pane embedded panels", () => {
17+
it("does not offer Discussion when no provider is available", () => {
18+
expect(discussionSlots(false)).not.toContain("discussion");
19+
});
20+
21+
it("offers Discussion after the provider reports it available", () => {
22+
expect(discussionSlots(true)).toContain("discussion");
23+
});
24+
});

‎ui/src/pages/chat/chat-pane-embedded-panels.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ type SidebarPanelDefinitionParams = {
4747
pendingQuestion: string | null;
4848
onClearCompanion: () => void;
4949
discussion: SessionDiscussionPanelConfig | null;
50+
discussionAvailable: boolean;
5051
discussionOpenUrl: string | null;
5152
discussionSourceGeneration: number;
5253
};
@@ -228,7 +229,7 @@ export function sidebarPanelDefinitions(
228229
: {}),
229230
}),
230231
definePanel("discussion", "discussion", icons.messageSquare, discussion, {
231-
available: discussion !== null,
232+
available: discussion !== null && params?.discussionAvailable === true,
232233
...(params?.discussionOpenUrl
233234
? {
234235
headerAction: html`<a

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ export abstract class ChatPaneLayoutRender extends ChatPaneBrowserAnnotationRend
8585
${board.face === "dashboard" ? header : nothing}${this.renderBoardPrimary(board, chat)}
8686
</div>`;
8787
const discussion = this.buildSessionDiscussionPanel(state, state.sessionKey.trim());
88+
const discussionState = this.sessionDiscussionStates.get(state.sessionKey.trim());
89+
const discussionAvailable = discussionState === "available" || discussionState === "open";
8890
const desktopAvailable = isDesktopPanelAvailable(this.context.gateway.snapshot);
8991
const companionThread = this.sessionCompanionThreads.view(state.sessionKey, currentAgentId);
9092
const browserPresented =
@@ -128,6 +130,7 @@ export abstract class ChatPaneLayoutRender extends ChatPaneBrowserAnnotationRend
128130
pendingQuestion: companionThread.pendingQuestion,
129131
onClearCompanion: () => void this.clearSessionCompanion(),
130132
discussion,
133+
discussionAvailable,
131134
discussionOpenUrl: discussion?.openUrl ?? null,
132135
discussionSourceGeneration: this.connectionGeneration,
133136
});

‎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
};

0 commit comments

Comments
 (0)