Skip to content

Commit 3dc03f9

Browse files
fix(ui): confirm destructive sidebar session actions in-app (#121286)
* fix(ui): confirm destructive sidebar session actions in-app The sessions sidebar still gated batch delete, single delete, cloud-worker stop, and preserved-worktree removal on native window.confirm. In an embedded WebView without a dialog bridge that call resolves false, so each action returned early with no request, no error, and no visible outcome. PR #118250 introduced showConfirmDialog and converted the Sessions, Worktrees, and Nodes pages but not the sidebar operations layer, leaving one product action with two confirmation mechanisms. Route all four sites through the same helper and let the already-present post-decision scope guards do their job, extracting the cloud-worker reclaim guard above the await so the modal never opens for a stop this surface never performs. Closes #121275 * feat(ui): let operators opt out of the session delete confirm Session deletes are the repeatable, per-row destructive action in the sidebar, so their confirm now offers "Don't ask me again". Stopping a cloud worker and removing a preserved worktree deliberately get no opt-out: the first is a rare shared-resource action, the second destroys the only copy of uncommitted work. The checkbox exists only for callers that pass a skip preference, so the serious confirms stay unskippable by construction. The preference is device-local in UiSettings rather than a synced ui.prefs key, so opting out on one browser cannot lower the bar on the operator's other devices. Appearance -> Sidebar carries the matching toggle with the standard reset affordance, which is how asking gets turned back on. * fix(ui): scope the delete opt-out copy and refresh its settings view Autoreview surfaced two preference-consistency defects. The setting copy promised a general "session or a selection" policy, but only the sidebar honours it; the Sessions page delete paths still prompt. Extending the preference there would cross into another owner's in-flight surface, so narrow the copy to what actually ships and keep the extension as the recorded follow-up. Persisting the opt-out also wrote local storage without notifying the appearance subscription, so a mounted Settings -> Appearance kept showing the toggle enabled while deletes already skipped the prompt. Publish the refresh through the scope's theme capability after persisting. * fix(ui): space the confirm opt-out away from the message copy The checkbox rendered flush under the message with no separation, so it read as a third line of the paragraph rather than a distinct control, and the group crowded the action row. Give it the 12px separation the details block already uses in this card, keeping the 16px action gap below, plus the 10px control gap and 16px box the config-form checkboxes use so the box and label align. Verified in light and dark at desktop and mobile widths. * fix(ui): use the cursor-action token on the confirm opt-out The spacing fix hardcoded cursor: pointer, which the Control UI cursor policy forbids outside link rules; controls consume var(--cursor-action) so the hand stays configurable from one place. Caught by ui/src/styles/cursor-policy.node.test.ts. Token resolves to the same hand, so the published dialog captures are unaffected. * fix(ui): keep the delete opt-out to the surface its setting names deleteSession is shared: the chat-pane header menu calls it too. The skip preference was applied inside the operation, so opting out from the sidebar also silenced future header confirmations while the setting text promised it applied to sidebar deletes only. Make the opt-out opt-in per caller with a default that keeps asking, and let the sidebar be the one caller that offers it. The header and any future caller now match the copy without having to remember anything. * refactor(ui): split the session group catalog out of the operations runtime Adding the in-app group confirm on main pushed session-organizer-operations.runtime.ts past the 700-line ceiling once this branch's session confirms landed beside it. Move the catalog and section-order operations into their own module. They write the group catalog directly and never touch session rows, so the dependency runs one way and no import cycle appears. The shared access gate moves to the batch-mutations sibling both now import, and the runtime keeps re-exporting the catalog names the controller loads as one namespace.
1 parent 79dcf48 commit 3dc03f9

25 files changed

Lines changed: 1242 additions & 636 deletions

‎ui/src/app/settings.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ export const UI_APPEARANCE_DEFAULTS = {
179179
composerHoldToRecord: true,
180180
lobsterPetVisits: true,
181181
lobsterPetSounds: false,
182+
sessionDeleteConfirm: true,
182183
} as const;
183184

184185
export type UiSettings = {
@@ -216,6 +217,10 @@ export type UiSettings = {
216217
locale?: string;
217218
lobsterPetVisits?: boolean; // Whether the sidebar lobster pet drops by (default true)
218219
lobsterPetSounds?: boolean; // Opt-in poke/pet chirps from the lobster (default false)
220+
// Confirm before deleting sessions (default true). Device-local on purpose:
221+
// opting out on one browser must not lower the bar on the operator's others,
222+
// so this stays out of the synced ui.prefs set in server-prefs-state.ts.
223+
sessionDeleteConfirm?: boolean;
219224
};
220225

221226
type LastActiveSessionHost = {
@@ -551,6 +556,7 @@ export function loadSettings(): UiSettings {
551556
locale: isSupportedLocale(parsed.locale) ? parsed.locale : undefined,
552557
...(parsed.lobsterPetVisits === false ? { lobsterPetVisits: false } : {}),
553558
...(parsed.lobsterPetSounds === true ? { lobsterPetSounds: true } : {}),
559+
...(parsed.sessionDeleteConfirm === false ? { sessionDeleteConfirm: false } : {}),
554560
};
555561
// Scoped blobs from builds that persisted tokens durably get rewritten once
556562
// so the plaintext token leaves localStorage.
@@ -693,6 +699,8 @@ function persistSettings(next: UiSettings, options: { selectGateway?: boolean }
693699
// off; only an explicit opt-in persists.
694700
...(next.lobsterPetVisits === false ? { lobsterPetVisits: false } : {}),
695701
...(next.lobsterPetSounds === true ? { lobsterPetSounds: true } : {}),
702+
// Only the opted-out value is persisted; absence means the safe default.
703+
...(next.sessionDeleteConfirm === false ? { sessionDeleteConfirm: false } : {}),
696704
};
697705
const serialized = JSON.stringify(persisted);
698706
unpersistedSettings = next;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import "../test-helpers/app-sidebar-cases/pull-request-state.ts";
2626
import "../test-helpers/app-sidebar-cases/section-reordering.ts";
2727
import "../test-helpers/app-sidebar-cases/session-delete-access.ts";
2828
import "../test-helpers/app-sidebar-cases/session-indicators.ts";
29+
import "../test-helpers/app-sidebar-cases/session-mutations.ts";
2930
import "../test-helpers/app-sidebar-cases/sidebar-scroll.ts";
3031
import "../test-helpers/app-sidebar-cases/sessions.ts";
3132
import "../test-helpers/app-sidebar-cases/session-ownership.ts";

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

Lines changed: 71 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,22 @@
11
/* @vitest-environment jsdom */
22

3-
import { afterEach, beforeEach, describe, expect, it } from "vitest";
3+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
44
import { getRenderedModalDialog, installDialogPolyfill } from "../test-helpers/modal-dialog.ts";
55
import { showConfirmDialog } from "./confirm-dialog.ts";
66

77
let restoreDialogPolyfill: () => void;
88

9+
function tickSkipCheckbox() {
10+
const checkbox = document.body.querySelector<HTMLInputElement>(
11+
'.exec-approval-skip input[type="checkbox"]',
12+
);
13+
if (!checkbox) {
14+
throw new Error("Expected the skip-preference checkbox");
15+
}
16+
checkbox.checked = true;
17+
checkbox.dispatchEvent(new Event("change"));
18+
}
19+
920
function findButton(label: string): HTMLButtonElement {
1021
const button = [...document.body.querySelectorAll("button")].find(
1122
(candidate) => candidate.textContent?.trim() === label,
@@ -67,6 +78,65 @@ describe("showConfirmDialog", () => {
6778
expect(document.body.querySelector("openclaw-modal-dialog")).toBeNull();
6879
});
6980

81+
it("offers the opt-out only when a skip preference is supplied", async () => {
82+
const plain = showConfirmDialog({ message: "Continue?" });
83+
await getRenderedModalDialog(document.body);
84+
expect(document.body.querySelector(".exec-approval-skip")).toBeNull();
85+
findButton("Cancel").click();
86+
await expect(plain).resolves.toBe(false);
87+
88+
const remember = vi.fn();
89+
const offered = showConfirmDialog({
90+
message: "Delete?",
91+
skipPreference: { skipped: false, remember },
92+
});
93+
await getRenderedModalDialog(document.body);
94+
95+
expect(document.body.querySelector(".exec-approval-skip")).toBeInstanceOf(HTMLElement);
96+
findButton("Confirm").click();
97+
await expect(offered).resolves.toBe(true);
98+
expect(remember).not.toHaveBeenCalled();
99+
});
100+
101+
it("remembers the opt-out only when the operator confirms with it ticked", async () => {
102+
const remember = vi.fn();
103+
const cancelled = showConfirmDialog({
104+
message: "Delete?",
105+
skipPreference: { skipped: false, remember },
106+
});
107+
await getRenderedModalDialog(document.body);
108+
tickSkipCheckbox();
109+
findButton("Cancel").click();
110+
111+
await expect(cancelled).resolves.toBe(false);
112+
expect(remember).not.toHaveBeenCalled();
113+
114+
const confirmed = showConfirmDialog({
115+
message: "Delete?",
116+
skipPreference: { skipped: false, remember },
117+
});
118+
await getRenderedModalDialog(document.body);
119+
tickSkipCheckbox();
120+
findButton("Confirm").click();
121+
122+
await expect(confirmed).resolves.toBe(true);
123+
expect(remember).toHaveBeenCalledOnce();
124+
});
125+
126+
it("resolves an opted-out confirmation without rendering a modal", async () => {
127+
const remember = vi.fn();
128+
129+
const result = showConfirmDialog({
130+
message: "Delete?",
131+
skipPreference: { skipped: true, remember },
132+
});
133+
134+
await expect(result).resolves.toBe(true);
135+
expect(document.body.querySelector("openclaw-modal-dialog")).toBeNull();
136+
// Re-remembering a stored choice would rewrite the preference on every run.
137+
expect(remember).not.toHaveBeenCalled();
138+
});
139+
70140
it("rejects a reentrant confirmation instead of stacking or replaying it", async () => {
71141
const first = showConfirmDialog({ title: "First", message: "First action" });
72142
const second = showConfirmDialog({ title: "Second", message: "Second action" });

‎ui/src/components/confirm-dialog.ts‎

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,18 @@ import { html, nothing, render } from "lit";
33
import { t } from "../i18n/index.ts";
44
import "./modal-dialog.ts";
55

6+
/**
7+
* Opt-out for confirms whose action is repeatable and recoverable. Callers own
8+
* the storage; passing this is what makes the checkbox exist at all, so serious
9+
* confirms stay unskippable by simply not offering one.
10+
*/
11+
export type ConfirmDialogSkipPreference = {
12+
/** True when the operator already chose to stop being asked. */
13+
skipped: boolean;
14+
/** Persists that choice; runs only when they confirm with the box ticked. */
15+
remember: () => void;
16+
};
17+
618
export type ConfirmDialogOptions = {
719
title?: string;
820
message: string;
@@ -11,6 +23,7 @@ export type ConfirmDialogOptions = {
1123
cancelLabel?: string;
1224
danger?: boolean;
1325
signal?: AbortSignal;
26+
skipPreference?: ConfirmDialogSkipPreference;
1427
};
1528

1629
let confirmationActive = false;
@@ -23,6 +36,7 @@ function presentConfirmDialog(options: ConfirmDialogOptions): Promise<boolean> {
2336
document.body.append(host);
2437
return new Promise((resolve) => {
2538
let settled = false;
39+
let skipRequested = false;
2640
const finish = (confirmed: boolean) => {
2741
if (settled) {
2842
return;
@@ -55,11 +69,27 @@ function presentConfirmDialog(options: ConfirmDialogOptions): Promise<boolean> {
5569
${options.details
5670
? html`<div class="exec-approval-command mono">${options.details}</div>`
5771
: nothing}
72+
${options.skipPreference
73+
? html`<label class="field checkbox exec-approval-skip">
74+
<input
75+
type="checkbox"
76+
@change=${(event: Event) => {
77+
skipRequested = (event.target as HTMLInputElement).checked;
78+
}}
79+
/>
80+
<span>${t("common.dontAskAgain")}</span>
81+
</label>`
82+
: nothing}
5883
<div class="exec-approval-actions">
5984
<button
6085
type="button"
6186
class="btn ${options.danger ? "danger" : "primary"}"
62-
@click=${() => finish(true)}
87+
@click=${() => {
88+
if (skipRequested) {
89+
options.skipPreference?.remember();
90+
}
91+
finish(true);
92+
}}
6393
>
6494
${options.confirmLabel ?? t("common.confirm")}
6595
</button>
@@ -77,6 +107,11 @@ function presentConfirmDialog(options: ConfirmDialogOptions): Promise<boolean> {
77107

78108
/** Native confirms block reentrancy; reject a second request instead of replaying it later. */
79109
export function showConfirmDialog(options: ConfirmDialogOptions): Promise<boolean> {
110+
// An operator who opted out gets the action itself, not a modal they already
111+
// answered. Only callers that opted into a skip preference can reach this.
112+
if (options.skipPreference?.skipped) {
113+
return Promise.resolve(true);
114+
}
80115
if (confirmationActive) {
81116
return Promise.resolve(false);
82117
}

0 commit comments

Comments
 (0)