Skip to content

Commit 6ae7a86

Browse files
authored
fix(ui): restore terminal button in chat header (#120436)
* fix(ui): restore terminal button in chat header * test(ui): follow background task props API Remove the callback option retired by #120463 so the terminal header regression test type-checks on current main.
1 parent 2cfacdb commit 6ae7a86

4 files changed

Lines changed: 78 additions & 10 deletions

File tree

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import { ChatPaneContext } from "./chat-pane-context.ts";
2424
import { headerPlatformByClient } from "./chat-pane-shared.ts";
2525
import { readChatSessionActionAccess } from "./chat-session-action-access.ts";
2626
import { patchChatSessionLabel } from "./chat-state-route.ts";
27-
import { renderCatalogTerminalButton } from "./components/catalog-terminal-button.ts";
2827
import { renderBackgroundTasksToggle } from "./components/chat-background-tasks-render.ts";
2928
import type { BackgroundTasksProps } from "./components/chat-background-tasks.types.ts";
3029
import { isChatRunWorking } from "./components/chat-composer.ts";
@@ -40,6 +39,7 @@ import {
4039
renderSessionWorkspaceToggle,
4140
type SessionWorkspaceProps,
4241
} from "./components/chat-session-workspace.ts";
42+
import { renderChatTerminalButton } from "./components/chat-terminal-button.ts";
4343
import type { SessionDiscussionPanelConfig } from "./components/session-discussion-panel.ts";
4444
import { hasAbortableSessionRun } from "./run-lifecycle.ts";
4545
import {
@@ -166,7 +166,11 @@ export abstract class ChatPaneHeader extends ChatPaneContext {
166166
canReveal,
167167
copiedAction: this.headerCopiedAction,
168168
renameDisabledReason,
169-
terminalAction: renderCatalogTerminalButton(this.state, this.catalogSession),
169+
terminalAction: renderChatTerminalButton(
170+
this.state,
171+
this.catalogSession,
172+
sessionWorkspace.onToggleTerminal,
173+
),
170174
discussionAction: this.renderSessionDiscussionAction(),
171175
diffAction: renderSessionDiffToggle(sessionWorkspace),
172176
backgroundTasksAction: renderBackgroundTasksToggle(backgroundTasks),
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/* @vitest-environment jsdom */
2+
3+
import { render } from "lit";
4+
import { describe, expect, it, vi } from "vitest";
5+
import type { GatewayBrowserClient } from "../../api/gateway.ts";
6+
import type { GatewaySessionRow } from "../../api/types.ts";
7+
import {
8+
TERMINAL_PANEL_TOGGLE_EVENT,
9+
type TerminalPanelToggleDetail,
10+
} from "../../components/panel-toggle-contract.ts";
11+
import type { SessionCapability } from "../../lib/sessions/index.ts";
12+
import { createTestChatPane } from "./chat-pane.test-support.ts";
13+
import { createBackgroundTasksProps } from "./components/chat-background-tasks.ts";
14+
import { createSessionWorkspaceProps } from "./components/chat-session-workspace.ts";
15+
16+
describe("chat pane terminal action", () => {
17+
it("renders only when available and opens the terminal dock", () => {
18+
const client = { request: vi.fn() } as unknown as GatewayBrowserClient;
19+
const { pane, state } = createTestChatPane({ client, sessions: {} as SessionCapability });
20+
const session = {
21+
key: state.sessionKey,
22+
kind: "direct",
23+
updatedAt: 0,
24+
} satisfies GatewaySessionRow;
25+
state.terminalAvailable = true;
26+
const container = document.createElement("div");
27+
const renderHeader = () =>
28+
render(
29+
pane.renderPaneHeader(
30+
createSessionWorkspaceProps(state),
31+
createBackgroundTasksProps(state),
32+
session,
33+
false,
34+
undefined,
35+
false,
36+
),
37+
container,
38+
);
39+
const events: CustomEvent<TerminalPanelToggleDetail>[] = [];
40+
const listener = (event: Event) => events.push(event as CustomEvent<TerminalPanelToggleDetail>);
41+
window.addEventListener(TERMINAL_PANEL_TOGGLE_EVENT, listener);
42+
try {
43+
renderHeader();
44+
const button = container.querySelector<HTMLButtonElement>('[aria-label="Toggle terminal"]');
45+
expect(button).not.toBeNull();
46+
button?.click();
47+
expect(events).toHaveLength(1);
48+
expect(events[0]?.detail).toEqual({ dock: "right", open: true });
49+
50+
state.terminalAvailable = false;
51+
renderHeader();
52+
expect(container.querySelector('[aria-label="Toggle terminal"]')).toBeNull();
53+
} finally {
54+
window.removeEventListener(TERMINAL_PANEL_TOGGLE_EVENT, listener);
55+
}
56+
});
57+
});

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import type { GatewayBrowserClient } from "../../api/gateway.ts";
1515
import type { GatewaySessionRow } from "../../api/types.ts";
1616
import type { ApplicationContext } from "../../app/context.ts";
1717
import { createInitialUserMessageHandoff } from "../../app/initial-user-message-handoff.ts";
18+
import { TERMINAL_PANEL_TOGGLE_EVENT } from "../../components/panel-toggle-contract.ts";
1819
import { buildCatalogSessionKey, type CatalogSessionKey } from "../../lib/sessions/catalog-key.ts";
1920
import type { SessionCapability } from "../../lib/sessions/index.ts";
2021
import {
@@ -720,11 +721,11 @@ describe("chat pane catalog session lifecycle", () => {
720721
const listener = (event: Event) => {
721722
detail = (event as CustomEvent).detail;
722723
};
723-
window.addEventListener("openclaw:terminal-toggle", listener);
724+
window.addEventListener(TERMINAL_PANEL_TOGGLE_EVENT, listener);
724725
try {
725726
(container.querySelector('[aria-label="Open in terminal"]') as HTMLElement).click();
726727
} finally {
727-
window.removeEventListener("openclaw:terminal-toggle", listener);
728+
window.removeEventListener(TERMINAL_PANEL_TOGGLE_EVENT, listener);
728729
}
729730
expect(detail).toEqual({ open: true, catalog: key });
730731
});

ui/src/pages/chat/components/catalog-terminal-button.ts renamed to ui/src/pages/chat/components/chat-terminal-button.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Catalog viewer header action for opening an eligible native session in a terminal.
1+
// Chat header action for toggling the native terminal or resuming an eligible catalog session.
22
import { html, nothing } from "lit";
33
import type { SessionCatalogSession } from "../../../../../packages/gateway-protocol/src/index.js";
44
import { icons } from "../../../components/icons.ts";
@@ -7,21 +7,27 @@ import { t } from "../../../i18n/index.ts";
77
import { parseCatalogSessionKey } from "../../../lib/sessions/catalog-key.ts";
88
import { openCatalogSessionInTerminal } from "../../../lib/sessions/catalog-terminal.ts";
99

10-
export function renderCatalogTerminalButton(
10+
export function renderChatTerminalButton(
1111
state: { sessionKey: string; terminalAvailable?: boolean } | null | undefined,
1212
session: SessionCatalogSession | null,
13+
onToggleTerminal: (() => void) | undefined,
1314
) {
1415
const catalogKey = state ? parseCatalogSessionKey(state.sessionKey) : null;
15-
if (!catalogKey || !session?.canOpenTerminal || !state?.terminalAvailable) {
16+
if (
17+
(catalogKey && (!state?.terminalAvailable || !session?.canOpenTerminal)) ||
18+
(!catalogKey && !onToggleTerminal)
19+
) {
1620
return nothing;
1721
}
22+
const label = catalogKey ? t("chat.catalog.openInTerminal") : t("terminal.toggle");
1823
return html`
19-
<openclaw-tooltip .content=${t("chat.catalog.openInTerminal")}>
24+
<openclaw-tooltip .content=${label}>
2025
<button
2126
class="btn btn--ghost btn--icon chat-icon-btn"
2227
type="button"
23-
aria-label=${t("chat.catalog.openInTerminal")}
24-
@click=${() => openCatalogSessionInTerminal(catalogKey)}
28+
aria-label=${label}
29+
@click=${() =>
30+
catalogKey ? openCatalogSessionInTerminal(catalogKey) : onToggleTerminal?.()}
2531
>
2632
${icons.terminal}
2733
</button>

0 commit comments

Comments
 (0)