Skip to content

Commit 47b6392

Browse files
fix(core): a declared action's confirm dialog names the action (#26663)
<!-- claude-projects-attribution: {"github_login":"zhuangjianguo"} --> _Requested by **Steedos** · [project thread](https://claude.ai/code/project/chan_018ETKaNwMZCNRYD7D8Q9Ubb?thread=cmsg_018ETKaNwMZCNRYD7D8Q9UbbMRFuRAeCbsTfQZ2W3U1Pq6)_ Fixes #26580 Clause-②: no Metadata-protocol: none ## 维护者速读 - **改了什么**:点一个声明了 `confirmText` 的动作时,确认框的标题和确认按钮现在显示动作自己的名字(如「标记为赢单」),`variant: 'danger'` 的动作确认按钮变成红色危险样式。以前一律是「确认操作」+ 中性的「继续」。 - **为什么改**:用户在确认框里看不出自己确认的是哪个动作,危险操作也没有危险提示;Record Delete 早已这样做,声明式动作没有。 - **风险与回滚**:低。只改 `ActionRunner` 的一个调用点,把已有的 `options` 参数传给已有的确认处理器;没有新键。另在 ui 门禁 `check-action-forward-parity` 的豁免表加四条(四个 action 渲染器的 `variant` 是按钮样式词表,不转给 runner)。回滚即 revert 本 PR。 - **先看**:`ui/packages/core/src/actions/ActionRunner.ts` 的确认调用点与新的 `confirmOptions`;`ui/packages/core/src/actions/__tests__/ActionRunner.confirmNamesAction-26580.test.ts`;`ui/scripts/check-action-forward-parity.mjs` 新增的四条 JUSTIFIED。 - **两分钟验证**:`cd ui && pnpm exec vitest run packages/core/src/actions/__tests__/ActionRunner.confirmNamesAction-26580.test.ts`,预期 5 个用例全绿;或在控制台点一个带确认文案的危险动作,确认框标题是动作名、按钮是红色的动作名。 - **需要你做的**:无,席位落地。 ## What changes `ActionRunner` asked its `ConfirmationHandler` with the confirm message alone, so the console's `ActionConfirmDialog` always fell back to its generic `actionConfirm.title` / `actionConfirm.confirm` copy ("Confirm Action" / "Continue", 「确认操作」 / 「继续」), and a `variant: 'danger'` action confirmed through a neutral button. The runner now fills the handler's existing `options` bag from what the action already declares (no new key, per triage comment 6437776331): - `title` and `confirmText` are the action's `label`. Every console surface resolves the label against the locale's bundle before dispatch (`useActionTextLocalizer`), so the runner receives the localized string. - `destructive: true` when the action declares the spec's `variant: 'danger'` (`ActionSchema.variant`, `packages/spec/src/ui/action.zod.ts`), the same flag the record Delete passes, which paints the confirm button with `buttonVariants({ variant: 'destructive' })`. - The cancel button keeps the host's copy. An action with neither a label nor the danger variant is asked with the message alone, exactly as before. `ActionConfirmDialog.tsx` and `useConsoleActionRuntime` needed no change: both already forward and render `title`, `confirmText` and `destructive`. The `ConfirmationHandler` type is unchanged; its doc comment now names the runner as one of the bag's producers. Where the danger-to-destructive styling lives: the runner turns the spec's `variant: 'danger'` into the handler's `destructive: true` (`confirmOptions` in `ui/packages/core/src/actions/ActionRunner.ts`). The dialog turns `destructive` into the style: `ActionConfirmDialog.tsx` sets the confirm button's `className` to `buttonVariants({ variant: 'destructive' })` from `@object-ui/components` (unchanged since objectui#11695). No other mapping is added. **Gate table, one file outside the first claim (claim amended, comment 6440643307).** The runner now reads `action.variant`, so `ui/scripts/check-action-forward-parity.mjs` owed `variant` on `action:button`, `action:icon`, `action:group` and `action:menu`. Those renderers' `variant` is `@object-ui/types`' `UIActionSchema.variant`, the button-style vocabulary (`default | primary | secondary | destructive | outline | ghost`), consumed at the renderer; the runner reads the spec enum on `ActionDef` (`primary | secondary | danger | ghost | link`). Forwarding it raw does not type-check and carries no `danger`, so the four omissions are JUSTIFIED entries (issue 26580), not forwards. The vocabulary gap itself is left open; see Acceptance notes. ## Tests - New `ui/packages/core/src/actions/__tests__/ActionRunner.confirmNamesAction-26580.test.ts` (5 tests): a labelled action passes `{ title, confirmText }`; a labelled danger action adds `destructive: true`; a labelless danger action passes `{ destructive: true }` only; a CONTROL action with neither is called with the message alone; a cancel still stops the run. - Ablation (one-off, not kept): `scripts/ablation-replace.mjs` replaced `this.confirmHandler(confirmMessage, confirmOptions)` with `this.confirmHandler(confirmMessage)` (anchor 1 to 0, blob `888cfb538c5d` to `926b95771ab6`). The new file went red: Tests 3 failed, 2 passed (the CONTROL and the cancel case stay green, as expected). Restored to the HEAD blob with `git diff HEAD` empty. - The test imports the runner from source (`../ActionRunner`), so no `dist/` rebuild sits between the mutation and the run. ## Acceptance notes - The existing one-argument pins (`ActionRunner.test.ts` "should show confirmation", `ActionRunner.callContext-13063.test.ts`) use actions with no label, so they still hold unchanged; that is the CONTROL path. - The confirm button repeats the action's label, as triage asked. A surface whose action reaches the runner without a label still shows the generic chrome. - Open, not built here: an `action:button` / `action:icon` / `action:group` / `action:menu` node styled `variant: 'destructive'` (the `UIActionSchema` spelling) gets a neutral confirm button, because the runner reads only the spec's `danger`. Closing it needs a decision on the two vocabularies (map one onto the other, or retire one); it is reported to the seat as an open question. Declared actions dispatched by the console's spread-based hosts (`DeclaredActionsBar`, `page:header`'s `dispatchHeaderAction`) carry the declaration's own spec `variant` and are covered. ## Verification All readings at head `84482207` unless named. The core suite and type-check ran at `88581363`; the later commit touches only `ui/scripts/check-action-forward-parity.mjs`, so they still hold. <details><summary>Touched package: @object-ui/core</summary> - `bash scripts/pm/os-verify-lock.sh -c 'cd ui && pnpm exec vitest run packages/core/ --maxWorkers=2'` (after `--filter '@object-ui/core^...' build`): Test Files 214 passed (214), Tests 4105 passed, 27 skipped; VERDICT command-exit 0. - `pnpm --filter @object-ui/core run type-check` (`tsc --noEmit && tsc -p tsconfig.test.json`, so the tests are covered): exit 0. </details> <details><summary>ui scripts suite and the forward-parity gate</summary> - `node ui/scripts/check-action-forward-parity.mjs`: exit 0 (action:button owes 29, forwards 25; icon, group, menu owe 29, forward 23; payloads excess-property CHECKED). - `pnpm --dir ui exec vitest run scripts/` under the lock, after `--filter '@object-ui/app-shell^...' build`: Test Files 178 passed, 2 skipped (180); Tests 5065 passed, 2 skipped. Before the JUSTIFIED entries it was red on `check-action-forward-parity.test.ts > the real repository > is green` (the four `variant` drops); the run before the closure build also failed `unit-registry-absence-collision.test.ts` on unbuilt workspace packages, a prerequisite, green after the build. </details> <details><summary>Derived gates: 34 of 34, all exit 0</summary> `node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstack` at `84482207` derived 34 commands from 4 changed paths; each ran with its exit code captured before any pipe (the PR-body gates read this body through `GITHUB_EVENT_PATH`; `check:type-check-debt` under the lock). Reconciliation: `--ran` answered "34 derived famil(ies) accounted for — 34 run, 0 NOT-MEASURED (a DERIVED zero — all 34 recorded an exit code and none of them is 3)". `check-partof-closing-keyword.mjs` on this body: exit 0. </details> Dogfood battery: not owed (no `!` in the title, no `(narrowing)` arm). --- _Generated by [Claude Code](https://claude.ai/code/session_01QsR2jSVZrd3f8WgEZrkUCu)_ --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent a71564f commit 47b6392

4 files changed

Lines changed: 152 additions & 8 deletions

File tree

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
'@object-ui/core': patch
3+
---
4+
5+
fix(core): a declared action's confirm dialog is titled with the action's label, and a danger action's confirm button is destructive
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
Before, clicking an action that declares `confirmText` always opened a dialog titled 「确认操作」 / "Confirm Action" with a neutral 「继续」 / "Continue" button: the action's own label and its `variant: 'danger'` never reached the dialog. `ActionRunner` now hands its `ConfirmationHandler` the existing `options` bag:
11+
12+
- `title` and `confirmText` are the action's `label`, already localized by the surface that dispatches it.
13+
- `destructive: true` when the action declares `variant: 'danger'`, which paints the console's confirm button in the destructive style, as the record Delete already does.
14+
- The cancel button keeps the host's own copy. An action with neither a label nor the danger variant is asked with the message alone, as before.
15+
16+
What to do: nothing. No key is added; the action already declares its label and variant. A custom `ConfirmationHandler` that ignores its second argument behaves as before.

‎ui/packages/core/src/actions/ActionRunner.ts‎

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -547,14 +547,16 @@ export type ActionRunnerHandler = ((
547547
* Confirmation handler — replaces window.confirm.
548548
* Consumers can provide an async implementation (e.g., Shadcn AlertDialog).
549549
*
550-
* `options` is LIVE, and its producer is not in this file — searching the
551-
* runner alone will tell you otherwise. The only call site here passes one
552-
* argument (the structured `confirm` arm that used to forward a bag was
553-
* retired, objectui#4314), so a runner-scoped sweep reads this parameter as
554-
* declared-but-never-produced and files it for removal. That has already
555-
* happened once: objectui#5205, ruled KEEP on 2026-08-22.
550+
* `options` is LIVE. The runner's own call site produces it for a declared
551+
* action that has a label or `variant: 'danger'` (see `confirmOptions`): the
552+
* dialog is titled with the action's label, its confirm button says the label,
553+
* and a danger action paints that button destructive. Before that, the only
554+
* call site here passed one argument (the structured `confirm` arm that used
555+
* to forward a bag was retired, objectui#4314), so a runner-scoped sweep read
556+
* this parameter as declared-but-never-produced and filed it for removal:
557+
* objectui#5205, ruled KEEP on 2026-08-22.
556558
*
557-
* The producer bypasses the runner entirely. `handleDeleteView` in
559+
* Other producers bypass the runner entirely. `handleDeleteView` in
558560
* `packages/app-shell/src/views/ObjectView.tsx` — the admin "delete saved
559561
* view" confirmation — invokes a `ConfirmationHandler` with all three fields
560562
* populated and localized (`console.objectView.deleteViewTitle` / `.delete` /
@@ -1533,9 +1535,17 @@ export class ActionRunner {
15331535
// the runner's context alone: a row dispatch binds no `record` there, so
15341536
// a hole the record header fills was shown raw from a list row
15351537
// (objectui#12967).
1538+
//
1539+
// The dialog names the action it confirms: its label titles the dialog
1540+
// and labels the confirm button, and `variant: 'danger'` paints that
1541+
// button destructive (see `confirmOptions`). An action with neither is
1542+
// asked with the message alone, and the host's generic copy stands.
15361543
const confirmMessage = this.confirmMessage(action);
15371544
if (confirmMessage !== undefined) {
1538-
const confirmed = await this.confirmHandler(confirmMessage);
1545+
const confirmOptions = this.confirmOptions(action);
1546+
const confirmed = await (confirmOptions
1547+
? this.confirmHandler(confirmMessage, confirmOptions)
1548+
: this.confirmHandler(confirmMessage));
15391549
if (!confirmed) {
15401550
return { success: false, error: 'Action cancelled by user' };
15411551
}
@@ -1865,6 +1875,27 @@ export class ActionRunner {
18651875
);
18661876
}
18671877

1878+
/**
1879+
* The confirm dialog's chrome for a declared action, or `undefined` when the
1880+
* action carries nothing to name it with.
1881+
*
1882+
* The action already declares both inputs — no new key: `label` (already
1883+
* resolved against the locale's bundle by the surface that dispatches it,
1884+
* `useActionTextLocalizer`) becomes the dialog's title and its confirm
1885+
* button, and the spec's `variant: 'danger'` makes that button destructive,
1886+
* the style the record Delete asks with. The cancel button keeps the host's
1887+
* own copy.
1888+
*/
1889+
private confirmOptions(action: ActionDef): Parameters<ConfirmationHandler>[1] {
1890+
const label = action.label || undefined;
1891+
const destructive = action.variant === 'danger';
1892+
if (label === undefined && !destructive) return undefined;
1893+
return {
1894+
...(label !== undefined ? { title: label, confirmText: label } : {}),
1895+
...(destructive ? { destructive } : {}),
1896+
};
1897+
}
1898+
18681899
/**
18691900
* The record a dispatch runs against, for its copy templates: the row the
18701901
* dispatch carries (`params._rowRecord`), else the context's record — the
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/**
2+
* ObjectUI
3+
* Copyright (c) 2024-present ObjectStack Inc.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
/**
10+
* objectstack#26580 — a declared action's confirm dialog names the action.
11+
*
12+
* Measured before this card: the runner called its `ConfirmationHandler` with
13+
* the message alone, so the console's `ActionConfirmDialog` always fell back
14+
* to its generic `actionConfirm.title` / `.confirm` chrome, and a
15+
* `variant: 'danger'` action was confirmed through a neutral button. The
16+
* runner now hands the handler's existing `options` bag the action's own
17+
* label (title and confirm button) and its danger variant (`destructive`).
18+
*/
19+
import { describe, it, expect, vi } from 'vitest';
20+
import { ActionRunner, type ActionDef } from '../ActionRunner';
21+
22+
async function confirmCallFor(def: ActionDef): Promise<unknown[]> {
23+
const runner = new ActionRunner({ objectName: 'crm_deal', record: { id: 'd1' } });
24+
const confirm = vi.fn().mockResolvedValue(false);
25+
runner.setConfirmHandler(confirm);
26+
const result = await runner.execute(def);
27+
expect(result.success).toBe(false);
28+
expect(confirm).toHaveBeenCalledTimes(1);
29+
return confirm.mock.calls[0];
30+
}
31+
32+
describe('the confirm dialog names the action it confirms (objectstack#26580)', () => {
33+
it('the label titles the dialog and labels the confirm button', async () => {
34+
expect(await confirmCallFor({
35+
name: 'close_won',
36+
label: 'Close as won',
37+
onClick: () => {},
38+
confirmText: 'Mark this deal as won?',
39+
})).toEqual(['Mark this deal as won?', { title: 'Close as won', confirmText: 'Close as won' }]);
40+
});
41+
42+
it('a danger action paints the confirm button destructive', async () => {
43+
expect(await confirmCallFor({
44+
name: 'purge',
45+
label: 'Purge history',
46+
variant: 'danger',
47+
onClick: () => {},
48+
confirmText: 'This cannot be undone.',
49+
})).toEqual([
50+
'This cannot be undone.',
51+
{ title: 'Purge history', confirmText: 'Purge history', destructive: true },
52+
]);
53+
});
54+
55+
it('a nameless danger action still asks destructively, under the host\'s own title', async () => {
56+
expect(await confirmCallFor({
57+
variant: 'danger',
58+
onClick: () => {},
59+
confirmText: 'Really?',
60+
})).toEqual(['Really?', { destructive: true }]);
61+
});
62+
63+
it('CONTROL: an action with neither a label nor the danger variant is asked with the message alone', async () => {
64+
expect(await confirmCallFor({
65+
variant: 'primary',
66+
onClick: () => {},
67+
confirmText: 'Proceed?',
68+
})).toEqual(['Proceed?']);
69+
});
70+
71+
it('a cancel still stops the run', async () => {
72+
const onClick = vi.fn();
73+
await confirmCallFor({ label: 'Archive', variant: 'danger', onClick, confirmText: 'Archive it?' });
74+
expect(onClick).not.toHaveBeenCalled();
75+
});
76+
});

‎ui/scripts/check-action-forward-parity.mjs‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,27 @@ export const JUSTIFIED = {
305305
])
306306
),
307307

308+
...Object.fromEntries(
309+
["action:button", "action:icon", "action:group", "action:menu"].map((surface) => [
310+
`${surface}:variant`,
311+
{
312+
reason:
313+
"Consumed HERE, in another vocabulary. The runner reads `variant` for one purpose: " +
314+
"`variant: 'danger'` paints the confirm dialog's button destructive (`confirmOptions` in " +
315+
"ActionRunner.ts, objectstack#26580), against the spec's enum on `ActionDef` " +
316+
"(`primary | secondary | danger | ghost | link`). These renderers' `variant` is " +
317+
"`@object-ui/types`' `UIActionSchema.variant`, the button-style vocabulary " +
318+
"(`default | primary | secondary | destructive | outline | ghost`), which each renderer " +
319+
"maps onto its own control and `action:group` / `action:menu` read as `'destructive'`. " +
320+
"Forwarded raw it does not type-check against `ActionDef` and carries no `danger` for the " +
321+
"runner to read; mapping `destructive` to `danger` is a dialect decision, not a forward. " +
322+
"The spread-based hosts (DeclaredActionsBar's dispatch spreads the localized " +
323+
"declaration) carry the declaration's own `variant`.",
324+
issue: 26580,
325+
},
326+
])
327+
),
328+
308329
// ── Read off the declaration, never off the node ───────────────────────────
309330
...Object.fromEntries(
310331
["action:button", "action:icon", "action:group", "action:menu"].map((surface) => [

0 commit comments

Comments
 (0)