Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .changeset/26580-confirm-dialog-names-action.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
'@object-ui/core': patch
---

fix(core): a declared action's confirm dialog is titled with the action's label, and a danger action's confirm button is destructive

Clause-②: no
Metadata-protocol: none

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:

- `title` and `confirmText` are the action's `label`, already localized by the surface that dispatches it.
- `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.
- 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.

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.
47 changes: 39 additions & 8 deletions ui/packages/core/src/actions/ActionRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -555,14 +555,16 @@ export type ActionRunnerHandler = ((
* Confirmation handler — replaces window.confirm.
* Consumers can provide an async implementation (e.g., Shadcn AlertDialog).
*
* `options` is LIVE, and its producer is not in this file — searching the
* runner alone will tell you otherwise. The only call site here passes one
* argument (the structured `confirm` arm that used to forward a bag was
* retired, objectui#4314), so a runner-scoped sweep reads this parameter as
* declared-but-never-produced and files it for removal. That has already
* happened once: objectui#5205, ruled KEEP on 2026-08-22.
* `options` is LIVE. The runner's own call site produces it for a declared
* action that has a label or `variant: 'danger'` (see `confirmOptions`): the
* dialog is titled with the action's label, its confirm button says the label,
* and a danger action paints that button destructive. Before that, the only
* call site here passed one argument (the structured `confirm` arm that used
* to forward a bag was retired, objectui#4314), so a runner-scoped sweep read
* this parameter as declared-but-never-produced and filed it for removal:
* objectui#5205, ruled KEEP on 2026-08-22.
*
* The producer bypasses the runner entirely. `handleDeleteView` in
* Other producers bypass the runner entirely. `handleDeleteView` in
* `packages/app-shell/src/views/ObjectView.tsx` — the admin "delete saved
* view" confirmation — invokes a `ConfirmationHandler` with all three fields
* populated and localized (`console.objectView.deleteViewTitle` / `.delete` /
Expand Down Expand Up @@ -1541,9 +1543,17 @@ export class ActionRunner {
// the runner's context alone: a row dispatch binds no `record` there, so
// a hole the record header fills was shown raw from a list row
// (objectui#12967).
//
// The dialog names the action it confirms: its label titles the dialog
// and labels the confirm button, and `variant: 'danger'` paints that
// button destructive (see `confirmOptions`). An action with neither is
// asked with the message alone, and the host's generic copy stands.
const confirmMessage = this.confirmMessage(action);
if (confirmMessage !== undefined) {
const confirmed = await this.confirmHandler(confirmMessage);
const confirmOptions = this.confirmOptions(action);
const confirmed = await (confirmOptions
? this.confirmHandler(confirmMessage, confirmOptions)
: this.confirmHandler(confirmMessage));
if (!confirmed) {
return { success: false, error: 'Action cancelled by user' };
}
Expand Down Expand Up @@ -1873,6 +1883,27 @@ export class ActionRunner {
);
}

/**
* The confirm dialog's chrome for a declared action, or `undefined` when the
* action carries nothing to name it with.
*
* The action already declares both inputs — no new key: `label` (already
* resolved against the locale's bundle by the surface that dispatches it,
* `useActionTextLocalizer`) becomes the dialog's title and its confirm
* button, and the spec's `variant: 'danger'` makes that button destructive,
* the style the record Delete asks with. The cancel button keeps the host's
* own copy.
*/
private confirmOptions(action: ActionDef): Parameters<ConfirmationHandler>[1] {
const label = action.label || undefined;
const destructive = action.variant === 'danger';
if (label === undefined && !destructive) return undefined;
return {
...(label !== undefined ? { title: label, confirmText: label } : {}),
...(destructive ? { destructive } : {}),
};
}

/**
* The record a dispatch runs against, for its copy templates: the row the
* dispatch carries (`params._rowRecord`), else the context's record — the
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/**
* ObjectUI
* Copyright (c) 2024-present ObjectStack Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

/**
* objectstack#26580 — a declared action's confirm dialog names the action.
*
* Measured before this card: the runner called its `ConfirmationHandler` with
* the message alone, so the console's `ActionConfirmDialog` always fell back
* to its generic `actionConfirm.title` / `.confirm` chrome, and a
* `variant: 'danger'` action was confirmed through a neutral button. The
* runner now hands the handler's existing `options` bag the action's own
* label (title and confirm button) and its danger variant (`destructive`).
*/
import { describe, it, expect, vi } from 'vitest';
import { ActionRunner, type ActionDef } from '../ActionRunner';

async function confirmCallFor(def: ActionDef): Promise<unknown[]> {
const runner = new ActionRunner({ objectName: 'crm_deal', record: { id: 'd1' } });
const confirm = vi.fn().mockResolvedValue(false);
runner.setConfirmHandler(confirm);
const result = await runner.execute(def);
expect(result.success).toBe(false);
expect(confirm).toHaveBeenCalledTimes(1);
return confirm.mock.calls[0];
}

describe('the confirm dialog names the action it confirms (objectstack#26580)', () => {
it('the label titles the dialog and labels the confirm button', async () => {
expect(await confirmCallFor({
name: 'close_won',
label: 'Close as won',
onClick: () => {},
confirmText: 'Mark this deal as won?',
})).toEqual(['Mark this deal as won?', { title: 'Close as won', confirmText: 'Close as won' }]);
});

it('a danger action paints the confirm button destructive', async () => {
expect(await confirmCallFor({
name: 'purge',
label: 'Purge history',
variant: 'danger',
onClick: () => {},
confirmText: 'This cannot be undone.',
})).toEqual([
'This cannot be undone.',
{ title: 'Purge history', confirmText: 'Purge history', destructive: true },
]);
});

it('a nameless danger action still asks destructively, under the host\'s own title', async () => {
expect(await confirmCallFor({
variant: 'danger',
onClick: () => {},
confirmText: 'Really?',
})).toEqual(['Really?', { destructive: true }]);
});

it('CONTROL: an action with neither a label nor the danger variant is asked with the message alone', async () => {
expect(await confirmCallFor({
variant: 'primary',
onClick: () => {},
confirmText: 'Proceed?',
})).toEqual(['Proceed?']);
});

it('a cancel still stops the run', async () => {
const onClick = vi.fn();
await confirmCallFor({ label: 'Archive', variant: 'danger', onClick, confirmText: 'Archive it?' });
expect(onClick).not.toHaveBeenCalled();
});
});
21 changes: 21 additions & 0 deletions ui/scripts/check-action-forward-parity.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,27 @@ export const JUSTIFIED = {
])
),

...Object.fromEntries(
["action:button", "action:icon", "action:group", "action:menu"].map((surface) => [
`${surface}:variant`,
{
reason:
"Consumed HERE, in another vocabulary. The runner reads `variant` for one purpose: " +
"`variant: 'danger'` paints the confirm dialog's button destructive (`confirmOptions` in " +
"ActionRunner.ts, objectstack#26580), against the spec's enum on `ActionDef` " +
"(`primary | secondary | danger | ghost | link`). These renderers' `variant` is " +
"`@object-ui/types`' `UIActionSchema.variant`, the button-style vocabulary " +
"(`default | primary | secondary | destructive | outline | ghost`), which each renderer " +
"maps onto its own control and `action:group` / `action:menu` read as `'destructive'`. " +
"Forwarded raw it does not type-check against `ActionDef` and carries no `danger` for the " +
"runner to read; mapping `destructive` to `danger` is a dialect decision, not a forward. " +
"The spread-based hosts (DeclaredActionsBar's dispatch spreads the localized " +
"declaration) carry the declaration's own `variant`.",
issue: 26580,
},
])
),

// ── Read off the declaration, never off the node ───────────────────────────
...Object.fromEntries(
["action:button", "action:icon", "action:group", "action:menu"].map((surface) => [
Expand Down
Loading