Skip to content

Commit 42bacaa

Browse files
authored
feat(ui): call chat sessions threads and quiet the sidebar sections (#110933)
* feat(ui): call chat sessions threads and quiet the sidebar sections Thread naming on every creation surface (new-thread page, draft row, + tooltips, untitled-thread fallback, New Chat guard toasts). The draft placeholder now renders as the first item inside the Threads section and genuinely expands a collapsed section so the header toggle stays honest. Empty sidebar sections no longer render (Coding keeps its CLI-catalog exception); expanded section headers reveal their chevron only on hover/focus while collapsed headers keep chevron + count. The new-thread button moves from the macOS titlebar strip into the sidebar brand row next to the agent picker (bigger, offline-aware); the titlebar + renders only while the rail is collapsed. Mobile drawer shows the new + as well. * fix(ui): keep empty custom groups and the mid-drag Threads drop target Empty-section hiding narrows to the Threads zone at rest: user-created categories stay visible when empty (New group… creation and drag-into-group flows depend on them), and an empty Threads section reappears while a session drag is in flight so drag-to-unpin keeps its drop target. * test(ui): drag-to-unpin targets the sessions surface The empty Threads section only materializes mid-drag, so Playwright cannot pre-resolve it as a drop target; the sessions container's drop handler owns the unpin and sends {pinned:false} without a category reset.
1 parent 81362bf commit 42bacaa

21 files changed

Lines changed: 321 additions & 104 deletions

‎ui/src/app/app-host.test.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,7 @@ describe("OpenClaw shell keyboard shortcuts", () => {
642642
expect(navigate).toHaveBeenCalledWith("new-session", { search: "?agent=agent%2Fa" });
643643
});
644644

645-
it("keeps search and new-session controls in the expanded native titlebar", async () => {
645+
it("keeps the new-thread control in the native titlebar only while collapsed", async () => {
646646
const onOpenPalette = vi.fn();
647647
const onOpenNewSession = vi.fn();
648648
const controls = document.createElement(
@@ -656,6 +656,10 @@ describe("OpenClaw shell keyboard shortcuts", () => {
656656
await controls.updateComplete;
657657

658658
controls.querySelector<HTMLButtonElement>(".macos-titlebar-controls__search")?.click();
659+
expect(controls.querySelector(".macos-titlebar-controls__new-session")).toBeNull();
660+
661+
controls.navCollapsed = true;
662+
await controls.updateComplete;
659663
controls.querySelector<HTMLButtonElement>(".macos-titlebar-controls__new-session")?.click();
660664

661665
expect(onOpenPalette).toHaveBeenCalledOnce();

‎ui/src/components/app-sidebar-session-list.ts‎

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { html, nothing, type TemplateResult } from "lit";
1+
import { html, nothing, type PropertyValues, type TemplateResult } from "lit";
22
import { state } from "lit/decorators.js";
33
import { keyed } from "lit/directives/keyed.js";
44
import { titleForRoute } from "../app-navigation.ts";
@@ -35,6 +35,20 @@ const SIDEBAR_VISIBLE_CHILD_SESSION_LIMIT = 4;
3535
export abstract class AppSidebarSessionListElement extends AppSidebarMenusElement {
3636
@state() protected catalogProjectGrouping = loadStoredSidebarCatalogGrouping();
3737

38+
protected override willUpdate(changed: PropertyValues<this>) {
39+
super.willUpdate(changed);
40+
// A fresh draft must be visible where it will live: genuinely expand a
41+
// collapsed Threads section (persisted) instead of overriding at render
42+
// time, so the header toggle keeps matching the visible state.
43+
if (
44+
changed.has("draftSessionAgentId") &&
45+
this.draftSessionAgentId &&
46+
this.collapsedSessionSections.has("ungrouped")
47+
) {
48+
this.toggleSessionSection("ungrouped");
49+
}
50+
}
51+
3852
private renderSessionState(session: SidebarRecentSession) {
3953
if (session.hasActiveRun || (session.isChild && session.status === "running")) {
4054
return html`<span
@@ -330,6 +344,7 @@ export abstract class AppSidebarSessionListElement extends AppSidebarMenusElemen
330344
totalRowCount?: number;
331345
},
332346
trailing: TemplateResult | typeof nothing = nothing,
347+
showDraft = false,
333348
) {
334349
const totalRowCount = section.totalRowCount ?? section.rows.length;
335350
const group = section.category;
@@ -501,8 +516,9 @@ export abstract class AppSidebarSessionListElement extends AppSidebarMenusElemen
501516
${collapsed
502517
? nothing
503518
: html`
504-
${section.rows.length > 0
519+
${section.rows.length > 0 || showDraft
505520
? html`<div class="sidebar-recent-sessions__list" role="list" aria-label=${label}>
521+
${showDraft ? this.renderDraftSessionRow() : nothing}
506522
${section.rows.map((session) => this.renderSessionTree(session))}
507523
</div>`
508524
: nothing}
@@ -534,8 +550,8 @@ export abstract class AppSidebarSessionListElement extends AppSidebarMenusElemen
534550
) {
535551
const { sections, expandedRows, visibleRows } = this.zonedVisibleSections(rows);
536552
return html`
537-
${options.showDraft ? this.renderDraftSessionRow() : nothing}
538553
${sections.map((section) => {
554+
const showDraft = section.id === "ungrouped" && options.showDraft;
539555
if (section.id === "work") {
540556
// Coding hosts live work/ACP rows plus the CLI catalogs; hide the
541557
// whole zone when both are empty.
@@ -544,7 +560,19 @@ export abstract class AppSidebarSessionListElement extends AppSidebarMenusElemen
544560
}
545561
return this.renderSessionSection(section, options.codingTrailing ?? nothing);
546562
}
547-
return this.renderSessionSection(section);
563+
// Threads hides its bare header when empty, except while a draft needs
564+
// a home or a session drag needs the unpin drop target. Empty custom
565+
// categories keep rendering: they are user-created containers and the
566+
// "New group…" / drag-into-group flows depend on seeing them.
567+
if (
568+
section.id === "ungrouped" &&
569+
section.totalRowCount === 0 &&
570+
!showDraft &&
571+
this.draggingSessionKey === null
572+
) {
573+
return nothing;
574+
}
575+
return this.renderSessionSection(section, nothing, showDraft);
548576
})}
549577
${this.renderSessionPagination(expandedRows, visibleRows.length)}
550578
`;

‎ui/src/components/app-sidebar.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@ import "../test-helpers/app-sidebar-cases/group-mutations.ts";
1414
import "../test-helpers/app-sidebar-cases/interactions.ts";
1515
import "../test-helpers/app-sidebar-cases/sidebar-scroll.ts";
1616
import "../test-helpers/app-sidebar-cases/sessions.ts";
17+
import "../test-helpers/app-sidebar-cases/session-list-sections.ts";
1718
import "../test-helpers/app-sidebar-cases/sidebar-zone.ts";

‎ui/src/components/app-sidebar.ts‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ class AppSidebar extends AppSidebarSessionListElement {
9898
}
9999

100100
protected override willUpdate(changed: PropertyValues<this>) {
101+
super.willUpdate(changed);
101102
if (changed.has("connected")) {
102103
this.syncOfflineIndicator();
103104
}
@@ -140,6 +141,8 @@ class AppSidebar extends AppSidebarSessionListElement {
140141
const cardAvatarText =
141142
(cardAgent ? resolveAgentTextAvatar(cardAgent) : null) ??
142143
(cardName || cardAgentId).slice(0, 1).toUpperCase();
144+
// The sidebar action follows gateway availability; collapsed native chrome
145+
// keeps its separate offline-tolerant ⌘N mirror.
143146
return html`
144147
<div class="sidebar-brand">
145148
<openclaw-sidebar-agent-card
@@ -155,6 +158,21 @@ class AppSidebar extends AppSidebarSessionListElement {
155158
.onToggleMenu=${(trigger: HTMLElement) => this.toggleAgentMenu(trigger)}
156159
></openclaw-sidebar-agent-card>
157160
<div class="sidebar-brand__actions">
161+
<openclaw-tooltip
162+
.content=${this.connected
163+
? t("chat.runControls.newSession")
164+
: t("chat.runControls.newSessionDisconnected")}
165+
>
166+
<button
167+
class="sidebar-brand__icon sidebar-brand__new-thread"
168+
type="button"
169+
@click=${() => this.onOpenNewSession?.(this.expandedAgentId())}
170+
aria-label=${t("chat.runControls.newSession")}
171+
?disabled=${!this.connected}
172+
>
173+
${icons.plus}
174+
</button>
175+
</openclaw-tooltip>
158176
${this.renderSearch()}
159177
<openclaw-tooltip .content=${`${collapseLabel} (⌘B)`}>
160178
<button

‎ui/src/components/macos-titlebar-controls.ts‎

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,16 @@ class MacosTitlebarControls extends OpenClawLightDomContentsElement {
5151
onClick: this.onOpenPalette,
5252
className: "macos-titlebar-controls__search",
5353
})}
54-
${this.renderButton({
55-
// Deliberately not connection-gated: it mirrors the native
56-
// ⌘N menu item (handleNativeNewSession), and the new-session
57-
// route is offline-tolerant. Window chrome stays state-free.
58-
label: t("chat.runControls.newSession"),
59-
icon: icons.plus,
60-
onClick: this.onOpenNewSession,
61-
className: "macos-titlebar-controls__new-session",
62-
})}
54+
${this.navCollapsed
55+
? this.renderButton({
56+
// While the sidebar rail is collapsed, this mirrors the native
57+
// ⌘N item and stays deliberately free of connection state.
58+
label: t("chat.runControls.newSession"),
59+
icon: icons.plus,
60+
onClick: this.onOpenNewSession,
61+
className: "macos-titlebar-controls__new-session",
62+
})
63+
: nothing}
6364
`
6465
: nothing}
6566
</nav>

‎ui/src/e2e/chat-flow.e2e.test.ts‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1864,10 +1864,8 @@ describeControlUiE2e("Control UI mocked Gateway E2E", () => {
18641864
await composer.fill("");
18651865

18661866
// The background hydrate must not take the shared sessions loading
1867-
// flag, which would disable New Session for the whole request.
1868-
expect(await page.getByRole("button", { name: "New session" }).first().isEnabled()).toBe(
1869-
true,
1870-
);
1867+
// flag, which would disable New thread for the whole request.
1868+
expect(await page.getByRole("button", { name: "New thread" }).first().isEnabled()).toBe(true);
18711869

18721870
await gateway.resolveDeferred("sessions.list");
18731871
await page
@@ -1890,7 +1888,7 @@ describeControlUiE2e("Control UI mocked Gateway E2E", () => {
18901888

18911889
try {
18921890
await page.goto(`${server.baseUrl}chat`);
1893-
const newSessionButton = page.locator("openclaw-app-sidebar .sidebar-new-session");
1891+
const newSessionButton = page.locator("openclaw-app-sidebar .sidebar-brand__new-thread");
18941892
await newSessionButton.waitFor({ state: "visible", timeout: 10_000 });
18951893
await newSessionButton.click();
18961894

‎ui/src/e2e/native-nav-sidebar-toggle.e2e.test.ts‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -197,16 +197,17 @@ describeControlUiE2e("Control UI native-nav sidebar toggle E2E", () => {
197197
const back = toolbar.getByRole("button", { name: "Back" });
198198
const forward = toolbar.getByRole("button", { name: "Forward" });
199199
const search = toolbar.getByRole("button", { name: "Open command palette" });
200-
const newSession = toolbar.getByRole("button", { name: "New session" });
200+
const newThread = toolbar.getByRole("button", { name: "New thread" });
201201
await expect.poll(() => back.isDisabled()).toBe(true);
202202
await expect.poll(() => forward.isDisabled()).toBe(true);
203203
await expect.poll(() => search.isVisible()).toBe(true);
204-
await expect.poll(() => newSession.isVisible()).toBe(true);
204+
await expect.poll(() => newThread.count()).toBe(0);
205205

206206
await toolbar.getByRole("button", { name: "Collapse sidebar" }).click();
207207
await expect
208208
.poll(() => page.locator(".shell").getAttribute("class"))
209209
.toContain("shell--nav-collapsed");
210+
await expect.poll(() => newThread.isVisible()).toBe(true);
210211
await search.click();
211212
await expect.poll(() => page.locator(".cmd-palette-overlay").isVisible()).toBe(true);
212213
await page.keyboard.press("Escape");
@@ -230,7 +231,7 @@ describeControlUiE2e("Control UI native-nav sidebar toggle E2E", () => {
230231
await expect.poll(() => back.isDisabled()).toBe(true);
231232
await expect.poll(() => forward.isDisabled()).toBe(false);
232233

233-
await newSession.click();
234+
await newThread.click();
234235
await expect.poll(() => new URL(page.url()).pathname).toBe("/new");
235236
await toolbar.getByRole("button", { name: "Expand sidebar" }).click();
236237
await expect
@@ -256,7 +257,7 @@ describeControlUiE2e("Control UI native-nav sidebar toggle E2E", () => {
256257
await expect
257258
.poll(() => toolbar.getByRole("button", { name: "Open command palette" }).count())
258259
.toBe(0);
259-
await expect.poll(() => toolbar.getByRole("button", { name: "New session" }).count()).toBe(0);
260+
await expect.poll(() => toolbar.getByRole("button", { name: "New thread" }).count()).toBe(0);
260261
});
261262

262263
it("keeps the document root scroll-locked in the Settings takeover", async () => {

0 commit comments

Comments
 (0)