Skip to content

Commit 95c3315

Browse files
committed
refactor(ui): colocate sidebar panel header actions
1 parent 4142af3 commit 95c3315

5 files changed

Lines changed: 115 additions & 73 deletions

File tree

‎ui/src/e2e/chat-sidebar-panel-contract.e2e.test.ts‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,29 @@ async function readColdOpenOutcome(page: Page): Promise<ColdOpenOutcome> {
102102
}
103103

104104
suite.define(() => {
105+
it("preserves the production header-action shapes for Side chat and Discussion", async () => {
106+
const context = await suite.newBrowserContext({ serviceWorkers: "block" });
107+
const page = await context.newPage();
108+
const choices = await openColdSidebar(page);
109+
110+
await choices.filter({ hasText: "Side chat" }).click();
111+
const contentActions = page.locator(".side-panel__action-group--content");
112+
const companionMenu = contentActions.locator("wa-dropdown.chat-session-rail__menu");
113+
await companionMenu.waitFor();
114+
expect(await companionMenu.count()).toBe(1);
115+
expect(await contentActions.locator(":scope > button").count()).toBe(0);
116+
117+
await page.locator(".side-panel-type-menu__trigger").click();
118+
await page.locator(".side-panel-type-menu__item").filter({ hasText: "Discussion" }).click();
119+
const discussionAction = contentActions.locator(
120+
':scope > a.rail-header__action[target="_blank"]',
121+
);
122+
await discussionAction.waitFor();
123+
expect(await discussionAction.getAttribute("href")).toBe("https://discussion.example/session");
124+
125+
await suite.closeBrowserContext(context);
126+
});
127+
105128
it("accounts for every offered slot when opened cold", async () => {
106129
const probeContext = await suite.newBrowserContext({ serviceWorkers: "block" });
107130
const probePage = await probeContext.newPage();

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

Lines changed: 68 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,11 @@ type SidebarPanelDefinitionParams = {
3131
onCompanionSubmit: (question: string) => void;
3232
onCompanionDraftChange: (draft: string) => void;
3333
onCompanionVisibilityChange: (visible: boolean) => void;
34+
connected: boolean;
35+
pendingQuestion: string | null;
36+
onClearCompanion: () => void;
3437
discussion: SessionDiscussionPanelConfig | null;
38+
discussionOpenUrl: string | null;
3539
discussionSourceGeneration: number;
3640
};
3741

@@ -46,66 +50,13 @@ type SidebarPanelTextKey =
4650
| "tasks"
4751
| "terminal";
4852

49-
/**
50-
* Header actions contributed by the panels that own content actions. Panels
51-
* have no header of their own in the tabbed model, so anything acting on the
52-
* active panel — the destructive side-chat clear, the discussion's external
53-
* link — is only reachable through the shared side-panel header.
54-
*/
55-
export function sidePanelHeaderActions(params: {
56-
connected: boolean;
57-
pendingQuestion: string | null;
58-
discussionOpenUrl: string | null;
59-
onClearCompanion: () => void;
60-
}): SidebarPanelTemplates {
61-
return {
62-
...(params.discussionOpenUrl
63-
? {
64-
discussion: html`<a
65-
class="rail-header__action"
66-
href=${params.discussionOpenUrl}
67-
target="_blank"
68-
rel="noopener"
69-
aria-label=${t("chat.sessionDiscussion.openExternal")}
70-
title=${t("chat.sessionDiscussion.openExternal")}
71-
>${icons.externalLink}</a
72-
>`,
73-
}
74-
: {}),
75-
companion: html`<wa-dropdown
76-
class="chat-session-rail__menu"
77-
placement="bottom-end"
78-
@wa-select=${(event: CustomEvent<{ item: { value?: string } }>) => {
79-
if (event.detail.item.value === "clear") {
80-
params.onClearCompanion();
81-
}
82-
}}
83-
>
84-
<button
85-
slot="trigger"
86-
class="rail-header__action"
87-
type="button"
88-
aria-label=${t("chat.rail.moreActions")}
89-
aria-haspopup="menu"
90-
aria-expanded="false"
91-
>
92-
${icons.moreHorizontal}
93-
</button>
94-
<wa-dropdown-item
95-
value="clear"
96-
?disabled=${!params.connected || params.pendingQuestion !== null}
97-
>
98-
${t("chat.rail.clear")}
99-
</wa-dropdown-item>
100-
</wa-dropdown>`,
101-
};
102-
}
103-
10453
/** One ordered declaration for every chat side-panel slot. */
10554
export function sidebarPanelDefinitions(
10655
params?: SidebarPanelDefinitionParams,
10756
): SidebarPanelDefinition[] {
10857
const state = params?.state;
58+
// Metadata-only definitions have no pane context, so they describe types without offering tabs.
59+
const hasPaneContext = params !== undefined;
10960
const terminalAvailable = state?.terminalAvailable === true;
11061
const browserAvailable = state?.browserPanelAvailable === true;
11162
const desktopAvailable = params?.desktopAvailable === true;
@@ -114,14 +65,15 @@ export function sidebarPanelDefinitions(
11465
textKey: SidebarPanelTextKey,
11566
icon: TemplateResult,
11667
content: TemplateResult | typeof nothing | null,
117-
options?: { available?: boolean; shortcut?: string },
68+
options?: { available?: boolean; headerAction?: TemplateResult; shortcut?: string },
11869
): SidebarPanelDefinition => ({
11970
slot,
12071
label: t(`chat.sidePanel.${textKey}`),
12172
icon,
122-
available: options?.available ?? params !== undefined,
73+
available: options?.available ?? hasPaneContext,
12374
content,
12475
empty: { description: t(`chat.sidePanel.${textKey}Empty`) },
76+
...(options?.headerAction ? { headerAction: options.headerAction } : {}),
12577
...(options?.shortcut ? { shortcut: options.shortcut } : {}),
12678
});
12779
const terminal =
@@ -193,11 +145,59 @@ export function sidebarPanelDefinitions(
193145
definePanel("workspace", "files", icons.fileText, params?.workspace ?? null, {
194146
shortcut: "⇧⌘B",
195147
}),
196-
definePanel("companion", "companion", icons.bot, companion),
148+
definePanel(
149+
"companion",
150+
"companion",
151+
icons.bot,
152+
companion,
153+
params
154+
? {
155+
headerAction: html`<wa-dropdown
156+
class="chat-session-rail__menu"
157+
placement="bottom-end"
158+
@wa-select=${(event: CustomEvent<{ item: { value?: string } }>) => {
159+
if (event.detail.item.value === "clear") {
160+
params.onClearCompanion();
161+
}
162+
}}
163+
>
164+
<button
165+
slot="trigger"
166+
class="rail-header__action"
167+
type="button"
168+
aria-label=${t("chat.rail.moreActions")}
169+
aria-haspopup="menu"
170+
aria-expanded="false"
171+
>
172+
${icons.moreHorizontal}
173+
</button>
174+
<wa-dropdown-item
175+
value="clear"
176+
?disabled=${!params.connected || params.pendingQuestion !== null}
177+
>
178+
${t("chat.rail.clear")}
179+
</wa-dropdown-item>
180+
</wa-dropdown>`,
181+
}
182+
: undefined,
183+
),
197184
definePanel("tasks", "tasks", icons.listChecks, params?.tasks ?? null),
198185
definePanel("desktop", "desktop", icons.monitor, desktop, { available: desktopAvailable }),
199186
definePanel("discussion", "discussion", icons.messageSquare, discussion, {
200187
available: discussion !== null,
188+
...(params?.discussionOpenUrl
189+
? {
190+
headerAction: html`<a
191+
class="rail-header__action"
192+
href=${params.discussionOpenUrl}
193+
target="_blank"
194+
rel="noopener"
195+
aria-label=${t("chat.sessionDiscussion.openExternal")}
196+
title=${t("chat.sessionDiscussion.openExternal")}
197+
>${icons.externalLink}</a
198+
>`,
199+
}
200+
: {}),
201201
}),
202202
definePanel("chat", "boardChat", icons.messageSquare, params?.chat ?? null, {
203203
available: params?.hasBoard === true,
@@ -222,3 +222,13 @@ export function sidebarPanelTemplates(
222222
}
223223
return templates;
224224
}
225+
226+
export function sidebarPanelActions(definitions: SidebarPanelDefinition[]): SidebarPanelTemplates {
227+
const actions: SidebarPanelTemplates = {};
228+
for (const definition of definitions) {
229+
if (definition.headerAction) {
230+
actions[definition.slot] = definition.headerAction;
231+
}
232+
}
233+
return actions;
234+
}

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ import { requiresChatModelSetup } from "./chat-model-setup.ts";
2828
import { ChatPaneBrowserAnnotationRender } from "./chat-pane-browser-annotation-render.ts";
2929
import {
3030
availableSidebarSlots,
31+
sidebarPanelActions,
3132
sidebarPanelDefinitions,
3233
sidebarPanelTemplates,
33-
sidePanelHeaderActions,
3434
} from "./chat-pane-embedded-panels.ts";
3535
import {
3636
createChatPaneSessionActionCallbacks,
@@ -658,11 +658,16 @@ export class ChatPane extends ChatPaneBrowserAnnotationRender {
658658
onCompanionDraftChange: (draft) =>
659659
this.sessionCompanionThreads.setDraft(state.sessionKey, draft, currentAgentId),
660660
onCompanionVisibilityChange: this.setSessionObserverVisibility,
661+
connected: state.connected,
662+
pendingQuestion: companionThread.pendingQuestion,
663+
onClearCompanion: () => void this.clearSessionCompanion(),
661664
discussion,
665+
discussionOpenUrl: discussion?.openUrl ?? null,
662666
discussionSourceGeneration: this.connectionGeneration,
663667
});
664668
const availableSlots = availableSidebarSlots(panelDefinitions);
665669
const panelTemplates = sidebarPanelTemplates(panelDefinitions);
670+
const panelActions = sidebarPanelActions(panelDefinitions);
666671
const content = renderSidebarRegion({
667672
availableWidth: this.paneWidth,
668673
availableSlots,
@@ -678,12 +683,7 @@ export class ChatPane extends ChatPaneBrowserAnnotationRender {
678683
}),
679684
layout: sidebarLayout,
680685
panelDefinitions,
681-
panelActions: sidePanelHeaderActions({
682-
connected: state.connected,
683-
pendingQuestion: companionThread.pendingQuestion,
684-
discussionOpenUrl: discussion?.openUrl ?? null,
685-
onClearCompanion: () => void this.clearSessionCompanion(),
686-
}),
686+
panelActions,
687687
narrow: this.paneWidth < SIDEBAR_NARROW_BREAKPOINT_PX,
688688
panelTemplates,
689689
primary,

‎ui/src/pages/chat/components/chat-sidebar-region-types.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export type SidebarPanelDefinition = {
1010
shortcut?: string;
1111
available: boolean;
1212
content: TemplateResult | typeof nothing | null;
13+
headerAction?: TemplateResult;
1314
empty: {
1415
description: string;
1516
action?: TemplateResult;

‎ui/src/pages/chat/components/chat-sidebar-region.test.ts‎

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import { html } from "lit";
44
import { afterEach, describe, expect, it, vi } from "vitest";
55
import "../../../components/resizable-divider.ts";
6-
import { sidePanelHeaderActions } from "../chat-pane-embedded-panels.ts";
76
import {
87
openSlot,
98
setSidebarDock,
@@ -82,15 +81,24 @@ describe("chat sidebar region", () => {
8281
expect(root(region).querySelector('[data-panel="detail"]')).not.toBeNull();
8382
});
8483

85-
it("keeps the destructive companion clear reachable, behind the active panel's overflow menu", async () => {
84+
it("renders the active panel's supplied dropdown without hoisting its destructive action", async () => {
8685
const onClear = vi.fn();
8786
const region = await createRegion(openSlot(openSlot({ columns: [] }, "detail"), "companion"));
88-
region.panelActions = sidePanelHeaderActions({
89-
connected: true,
90-
pendingQuestion: null,
91-
discussionOpenUrl: null,
92-
onClearCompanion: onClear,
93-
});
87+
// This representative action exercises the region contract; the app E2E
88+
// separately verifies the production Side chat action's exact markup.
89+
region.panelActions = {
90+
companion: html`<wa-dropdown
91+
class="chat-session-rail__menu"
92+
@wa-select=${(event: CustomEvent<{ item: { value?: string } }>) => {
93+
if (event.detail.item.value === "clear") {
94+
onClear();
95+
}
96+
}}
97+
>
98+
<button slot="trigger" type="button">More</button>
99+
<wa-dropdown-item value="clear">Clear</wa-dropdown-item>
100+
</wa-dropdown>`,
101+
};
94102
await region.updateComplete;
95103

96104
const actions = root(region).querySelector(".side-panel__action-group--content");

0 commit comments

Comments
 (0)