Skip to content

Commit 928a680

Browse files
feat(ui): unify operator notice presentation
1 parent b8d6e79 commit 928a680

42 files changed

Lines changed: 779 additions & 348 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎scripts/control-ui-mock-dev.ts‎

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,7 @@ function buildUpdateFixture(fixture: CliOptions["fixture"], nowMs: number): Upda
258258
const repoRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
259259
const uiRoot = path.join(repoRoot, "ui");
260260
const boardFixturePath = "/__fixtures/board/";
261+
const noticesFixturePath = "/__fixtures/notices/";
261262
const boardFixtureHtml = `<!doctype html>
262263
<html lang="en">
263264
<head>
@@ -300,6 +301,34 @@ const boardFixtureHtml = `<!doctype html>
300301
<script type="module" src="/src/test-helpers/board-fixture.ts"></script>
301302
</body>
302303
</html>`;
304+
const noticesFixtureHtml = `<!doctype html>
305+
<html lang="en">
306+
<head>
307+
<meta charset="UTF-8" />
308+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
309+
<meta name="color-scheme" content="dark light" />
310+
<title>OpenClaw Notice Inventory</title>
311+
<script>
312+
const requestedTheme = new URLSearchParams(location.search).get("theme");
313+
const mediaQuery = matchMedia("(prefers-color-scheme: light)");
314+
const applyTheme = () => {
315+
const mode = requestedTheme || (mediaQuery.matches ? "light" : "dark");
316+
document.documentElement.dataset.theme = mode;
317+
document.documentElement.dataset.themeMode = mode;
318+
document.documentElement.className = "wa-" + mode;
319+
document.documentElement.style.colorScheme = mode;
320+
};
321+
applyTheme();
322+
mediaQuery.addEventListener("change", applyTheme);
323+
</script>
324+
<link rel="stylesheet" href="/src/styles.css" />
325+
<style>body { margin: 0; min-width: 320px; min-height: 100vh; background: var(--bg); }</style>
326+
</head>
327+
<body>
328+
<div id="app"></div>
329+
<script type="module" src="/src/test-helpers/notices-fixture.ts"></script>
330+
</body>
331+
</html>`;
303332

304333
function mockFileHash(value: string): string {
305334
return createHash("sha256").update(value, "utf8").digest("hex");
@@ -3205,6 +3234,24 @@ function createBoardFixturePlugin(): Plugin {
32053234
};
32063235
}
32073236

3237+
function createNoticesFixturePlugin(): Plugin {
3238+
return {
3239+
name: "openclaw-control-ui-notices-fixture",
3240+
configureServer(server) {
3241+
server.middlewares.use(noticesFixturePath, (_req, res, next) => {
3242+
void server
3243+
.transformIndexHtml(noticesFixturePath, noticesFixtureHtml)
3244+
.then((html) => {
3245+
res.statusCode = 200;
3246+
res.setHeader("content-type", "text/html; charset=utf-8");
3247+
res.end(html);
3248+
})
3249+
.catch((error: unknown) => next(error as Error));
3250+
});
3251+
},
3252+
};
3253+
}
3254+
32083255
function hostForUrl(boundAddress: string, requestedHost: string): string {
32093256
const host = boundAddress === "0.0.0.0" || boundAddress === "::" ? requestedHost : boundAddress;
32103257
const reachableHost = host === "0.0.0.0" || host === "::" ? "127.0.0.1" : host;
@@ -3259,7 +3306,11 @@ const server = await createServer({
32593306
: {}),
32603307
include: ["lit/directives/repeat.js"],
32613308
},
3262-
plugins: [createMockGatewayPlugin(scenario), createBoardFixturePlugin()],
3309+
plugins: [
3310+
createMockGatewayPlugin(scenario),
3311+
createBoardFixturePlugin(),
3312+
createNoticesFixturePlugin(),
3313+
],
32633314
publicDir: path.join(uiRoot, "public"),
32643315
resolve: {
32653316
alias: [
@@ -3282,5 +3333,8 @@ console.log(`[control-ui-mock] ${resolveServerUrl(server, options.host)}`);
32823333
console.log(
32833334
`[control-ui-mock] board fixture: ${resolveServerUrl(server, options.host, boardFixturePath)}`,
32843335
);
3336+
console.log(
3337+
`[control-ui-mock] notices fixture: ${resolveServerUrl(server, options.host, noticesFixturePath)}`,
3338+
);
32853339
await waitForShutdown();
32863340
await server.close();

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ class OpenClawShell
577577
}
578578
void import("../lib/chat/composer-draft-retirement.runtime.ts").then(
579579
({ retireDeletedComposerDrafts }) => retireDeletedComposerDrafts(context, deletedSessions),
580-
() => showToast({ message: t("sessionsView.draftCleanupFailed") }),
580+
() => showToast({ message: t("sessionsView.draftCleanupFailed"), variant: "warning" }),
581581
);
582582
}
583583

‎ui/src/app/update-success-notice.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ describe("update success notice", () => {
3333

3434
expect(showToastMock).toHaveBeenCalledWith({
3535
message: "Gateway updated · now on abcdef1.",
36+
variant: "success",
3637
});
3738
});
3839
});

‎ui/src/app/update-success-notice.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export function announceVerifiedUpdateInstall(identity: UpdateInstallIdentity):
4242
}
4343
if (!reloadControlUiIfStale(identity)) {
4444
takeRecordedUpdateSuccess();
45-
showToast({ message: formatUpdateSuccess(identity) });
45+
showToast({ message: formatUpdateSuccess(identity), variant: "success" });
4646
}
4747
}
4848

@@ -62,5 +62,5 @@ export function announceRecordedUpdateSuccess(): void {
6262
} catch {
6363
return;
6464
}
65-
showToast({ message: formatUpdateSuccess(identity) });
65+
showToast({ message: formatUpdateSuccess(identity), variant: "success" });
6666
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,8 @@ class AppSidebar extends AppSidebarSessionNavigationElement implements SessionLi
441441
}}
442442
>${t("chat.sidebar.sectionHiddenRecovery")}</a
443443
>`,
444+
variant: "info",
445+
key: `sidebar-section-hidden:${catalogId}`,
444446
actionLabel: t("common.undo"),
445447
onAction: () => setStoredSessionCatalogHidden(catalogId, false),
446448
durationMs: 12_000,

‎ui/src/components/board/board-view.test.ts‎

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -775,9 +775,7 @@ describe("openclaw-board-view", () => {
775775
await vi.waitFor(() => expect(allow?.disabled).toBe(false));
776776
});
777777

778-
it("toasts failed rejection while keeping controls and leaves successful decisions quiet", async () => {
779-
const toastHost = document.createElement("openclaw-toast-host");
780-
document.body.append(toastHost);
778+
it("keeps failed decisions inline and leaves successful decisions quiet", async () => {
781779
const grant = vi.fn(async (_name: string, decision: "granted" | "rejected") => {
782780
if (decision === "rejected") {
783781
throw new Error("approval service unavailable");
@@ -790,16 +788,11 @@ describe("openclaw-board-view", () => {
790788
allow?.click();
791789
await vi.waitFor(() => expect(grant).toHaveBeenCalledWith("alpha", "granted"));
792790
await vi.waitFor(() => expect(reject?.disabled).toBe(false));
793-
expect(toastHost.querySelector(".app-toast")).toBeNull();
794-
795791
reject?.click();
796792
await vi.waitFor(() => {
797793
expect(
798794
view.querySelector('[data-test-id="board-widget-action-error"]')?.textContent,
799795
).toContain("approval service unavailable");
800-
expect(toastHost.querySelector(".app-toast__message")?.textContent).toContain(
801-
"Could not reject widget access. Try again.",
802-
);
803796
});
804797
expect(allow?.disabled).toBe(false);
805798
expect(reject?.disabled).toBe(false);

‎ui/src/components/board/board-widget-cell.ts‎

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import {
2020
type PluginBoardWidgetRenderer,
2121
} from "../../lib/board/widgets/index.ts";
2222
import { formatUiError } from "../../lib/format-error.ts";
23-
import { showToast } from "../../lib/toast.ts";
2423
import { OpenClawLightDomElement } from "../../lit/openclaw-element.ts";
2524
import { renderBoardMcpAppContent } from "./board-mcp-app-content.ts";
2625
import { BoardMcpAppLifecycle } from "./board-mcp-app-lifecycle.ts";
@@ -154,7 +153,7 @@ class OpenClawBoardWidgetCell extends OpenClawLightDomElement {
154153
super.disconnectedCallback();
155154
}
156155

157-
private async runAction(action: () => Promise<void>, failureMessage?: string): Promise<void> {
156+
private async runAction(action: () => Promise<void>): Promise<void> {
158157
if (this.actionPending || this.busy) {
159158
return;
160159
}
@@ -165,9 +164,6 @@ class OpenClawBoardWidgetCell extends OpenClawLightDomElement {
165164
await action();
166165
} catch (error) {
167166
this.actionError = formatUiError(error);
168-
if (failureMessage) {
169-
showToast({ message: failureMessage });
170-
}
171167
} finally {
172168
this.actionPending = false;
173169
}
@@ -178,10 +174,7 @@ class OpenClawBoardWidgetCell extends OpenClawLightDomElement {
178174
callbacks: BoardWidgetCellCallbacks,
179175
decision: BoardGrantDecision,
180176
): void {
181-
const failureMessage = t(
182-
decision === "granted" ? "board.widget.allowFailed" : "board.widget.rejectFailed",
183-
);
184-
void this.runAction(() => callbacks.grant(widget.name, decision), failureMessage);
177+
void this.runAction(() => callbacks.grant(widget.name, decision));
185178
}
186179

187180
private handleMenuSelect(

‎ui/src/components/modal-dialog.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ describe("openclaw-modal-dialog", () => {
116116
const { modal } = await renderModal();
117117
const moveBefore = vi.spyOn(Element.prototype, "moveBefore");
118118

119-
showToast({ message: "Saved" });
119+
showToast({ message: "Saved", variant: "success" });
120120
modal.hide();
121121
await modal.updateComplete;
122122
await appHost.updateComplete;

‎ui/src/components/session-organizer-batch-mutations.test.ts‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,6 @@ describe("session organizer destructive confirmations", () => {
491491
},
492492
],
493493
});
494-
const alertSpy = vi.spyOn(window, "alert").mockImplementation(() => undefined);
495494

496495
const pending = deleteSessionsBatch(harness.host, rows, harness.scope);
497496
const actions = await waitForConfirmDialogActions();
@@ -517,10 +516,10 @@ describe("session organizer destructive confirmations", () => {
517516
]);
518517
expect(harness.publishSessionMutationError).toHaveBeenCalledWith(harness.scope, retryError);
519518
expect(retryError).not.toContain("GatewayRequestError");
520-
expect(alertSpy).toHaveBeenCalledWith(
521-
"Managed Worktrees:\nopenclaw/busy — live run or cleanup active",
522-
);
523-
alertSpy.mockRestore();
519+
expect(showToast).toHaveBeenCalledWith({
520+
message: "Managed Worktrees:\nopenclaw/busy — live run or cleanup active",
521+
variant: "warning",
522+
});
524523
});
525524

526525
it.each(destructiveOperations)("sends no $name request when cancelled", async (operation) => {
@@ -553,7 +552,10 @@ describe("session organizer destructive confirmations", () => {
553552
// The abort resolves the dialog to `false`, same as a user cancel, so the
554553
// operator needs a distinct, visible outcome or their lost intent reads
555554
// as a click that simply did nothing.
556-
expect(showToast).toHaveBeenCalledWith({ message: operation.staleMessage });
555+
expect(showToast).toHaveBeenCalledWith({
556+
message: operation.staleMessage,
557+
variant: "warning",
558+
});
557559

558560
// A fresh confirmation (the reconnect's own retry) must be able to open
559561
// immediately; a stale dialog holding the shared lock would block it.
@@ -596,6 +598,7 @@ describe("session organizer destructive confirmations", () => {
596598
// the no-access branch, so the operator learns where it went.
597599
expect(showToast).toHaveBeenCalledWith({
598600
message: "Managed Worktrees:\nfeature — cleanup failed",
601+
variant: "warning",
599602
});
600603
});
601604

‎ui/src/components/session-organizer-catalog.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ export async function deleteSessionGroup(
106106
// too, so without this order the operator's lost intent would look like an
107107
// ordinary cancel instead of the reconnect that actually dropped it.
108108
if (!host.sessionData.isSessionMutationScopeCurrent(scope)) {
109-
showToast({ message: t("sessionsView.deleteGroupStale", { group }) });
109+
showToast({ message: t("sessionsView.deleteGroupStale", { group }), variant: "warning" });
110110
return false;
111111
}
112112
if (!confirmed) {

0 commit comments

Comments
 (0)