Skip to content

Commit 93ae709

Browse files
committed
feat(ui): the action blocks forward and draw danger, the bridge for destructive is gone
Claude-Session: https://claude.ai/code/session_01WGufzeYWDZN6LkXji5ziLF Co-authored-by: Claude <noreply@anthropic.com>
1 parent ea7766a commit 93ae709

13 files changed

Lines changed: 147 additions & 65 deletions

File tree

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
---
2+
'@objectstack/spec': minor
3+
'@object-ui/components': minor
4+
'@object-ui/types': minor
5+
'@object-ui/plugin-detail': minor
6+
---
7+
8+
feat(spec)!: the action blocks spell the destructive variant `danger`, the word `ActionSchema.variant` uses
9+
10+
An action's variant was spelled in two dialects. `ActionSchema.variant`, the declaration the action runner dispatches, takes `primary | secondary | danger | ghost | link`. The four action blocks (`action:button`, `action:icon`, `action:group`, `action:menu`) and the group/menu members took the Button primitive's `default | destructive | outline | secondary | ghost | link` (plus `primary` on the button, the icon and the members) and refused `danger`. So one destructive action was `danger` as a declaration and `destructive` as a block, and each block renderer translated between the two.
11+
12+
The block rows now take `danger` in place of `destructive`: `default | danger | outline | secondary | ghost | link`, plus `primary` where it was accepted before. `danger` draws the destructive button (a red item in a dropdown or `action:menu`) and asks a `confirmText` question through the destructive confirm button. `destructive` is refused at `variant` with the rename. Other components that draw the Button primitive directly (`element:button`, toasts, alerts, badges and the like) keep `destructive`, the primitive's own word, and are not touched.
13+
14+
The four block renderers forward `danger` to the runner as it is and draw it as the primitive's `destructive`. They no longer read `destructive`: stored pages are rewritten by the conversion below, so no renderer keeps a bridge for the old word. `UIActionSchema.variant` (`@object-ui/types`) follows the rows by reference. The record detail views' Delete entry in the `⋯` menu is spelled `danger` too.
15+
16+
Stored rows and older built artifacts: the ADR-0087 D2 conversion `page-action-block-variant-destructive-to-danger` rewrites `variant: 'destructive'` to `'danger'` on the four blocks' `properties.variant` and on each `action:group` / `action:menu` member's `variant`, at every position a page nests a component (regions, slots, nested containers). A stored `page` row is rewritten when it is rehydrated, so it keeps drawing the destructive button and confirming through the destructive confirm button. The conversion is retired from the load path, so a source that still writes `destructive` on a block is refused, not rewritten. The D3 entry `ui-page-action-block-variant-destructive-refused` carries the judgment for `os migrate meta`.
17+
18+
Clause-②: no (narrowing) — the action block rows refuse `destructive`, a value they used to accept. `danger` takes its place on the same rows.
19+
20+
Metadata-protocol: narrowed (`variant: 'destructive'` is refused on the action blocks and their members; write `danger`)
21+
22+
<!-- adr-0087: registered page-action-block-variant-destructive-to-danger, ui-page-action-block-variant-destructive-refused -->
23+
24+
**BREAKING** for an author who wrote `variant: 'destructive'` on an action block.
25+
26+
**`destructive` → `danger`.**
27+
28+
- **Before.** `{ type: 'action:button', properties: { label: 'Purge', actionType: 'script', variant: 'destructive' } }` parsed; `variant: 'danger'` was refused.
29+
- **Now.** `destructive` is refused at `variant` (or at `actions.N.variant` on a group or menu member) with a message naming the rename.
30+
- **Fix.** Write `variant: 'danger'` on the block or member. Nothing else changes: it draws the same destructive button. `os migrate meta --from 17 --write` applies the rename to your sources.

‎ui/apps/console/src/__tests__/registry-inputs-spec-parity.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2854,7 +2854,7 @@ const MEMBER_PINS: Record<string, MemberPin> = {
28542854
},
28552855
'action:menu.actions': {
28562856
file: 'packages/components/src/renderers/action/__tests__/action-group-menu-inputs-11168.test.tsx',
2857-
pins: 'Members are ACTION OBJECTS, one menu item each, read through the real `SchemaRenderer` with the Radix menu opened: `label` is the item text (falling back to `name`), a member\'s own `visible` hides and its own `disabled` greys THAT item (a sibling is the control), `tags: [separator-before]` draws the divider, `variant: destructive` paints the item, and selecting an item hands the runner the member under its OWN `type` with its own keys (`target`, `objectName`). The list kind is pinned against the contract: the spec refuses an `object` at `actions` by kind and accepts a list of objects (objectui#11168 slice 1).',
2857+
pins: 'Members are ACTION OBJECTS, one menu item each, read through the real `SchemaRenderer` with the Radix menu opened: `label` is the item text (falling back to `name`), a member\'s own `visible` hides and its own `disabled` greys THAT item (a sibling is the control), `tags: [separator-before]` draws the divider, `variant: danger` paints the item, and selecting an item hands the runner the member under its OWN `type` with its own keys (`target`, `objectName`). The list kind is pinned against the contract: the spec refuses an `object` at `actions` by kind and accepts a list of objects (objectui#11168 slice 1).',
28582858
},
28592859
'action:menu.visible': {
28602860
file: 'packages/components/src/renderers/action/__tests__/action-group-menu-inputs-11168.test.tsx',

‎ui/packages/app-shell/src/views/RecordDetailView.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3579,7 +3579,7 @@ export function RecordDetailView({ dataSource, objects, onEdit, objectNameOverri
35793579
icon: 'trash',
35803580
type: 'script',
35813581
locations: ['record_header'],
3582-
variant: 'destructive',
3582+
variant: 'danger',
35833583
order: 120,
35843584
component: 'action:menu',
35853585
// objectui#4213 — `delete.disabledWhen` greys the overflow entry, the

‎ui/packages/components/src/renderers/action/__tests__/action-group-menu-inputs-11168.test.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ describe('action:group — the member shape of `actions` (the MEMBER-PIN directi
250250
member('shown'),
251251
member('hidden', { visible: false }),
252252
member('greyed', { disabled: true }),
253-
member('loud', { variant: 'destructive', size: 'lg', className: 'member-class' }),
253+
member('loud', { variant: 'danger', size: 'lg', className: 'member-class' }),
254254
],
255255
});
256256
expect(screen.getByRole('button', { name: 'SHOWN' })).toBeEnabled();
@@ -369,7 +369,7 @@ describe('action:menu — the member shape of `actions` (the MEMBER-PIN directio
369369
member('shown'),
370370
member('hidden', { visible: false }),
371371
member('greyed', { disabled: true }),
372-
{ name: 'nameonly', type: 'run', tags: ['separator-before'], variant: 'destructive' },
372+
{ name: 'nameonly', type: 'run', tags: ['separator-before'], variant: 'danger' },
373373
],
374374
});
375375
const menu = await openMenu(screen.getByRole('button', { name: MORE }));

‎ui/packages/components/src/renderers/action/__tests__/action-variant-confirm-26665.test.tsx‎

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@
77
*/
88

99
/**
10-
* objectstack#26665 — a `destructive` action block confirms through the
11-
* destructive button.
10+
* objectstack#26665, objectstack#26779 — a `danger` action block confirms
11+
* through the destructive button.
1212
*
1313
* The runner paints its confirm button destructive when the action it runs
14-
* declares `variant: 'danger'` (`confirmOptions`, objectstack#26580). The four
15-
* action blocks speak the spec's BLOCK dialect, where that value is spelled
16-
* `destructive`, and before this card none of them forwarded `variant` at all,
17-
* so a destructive block asked its question through a neutral button. Each
18-
* renderer now forwards its variant through `toRunnerVariant`.
14+
* declares `variant: 'danger'` (`confirmOptions`, objectstack#26580). Before
15+
* objectstack#26665 none of the four action blocks forwarded `variant` at all,
16+
* so a destructive block asked its question through a neutral button. Since
17+
* objectstack#26779 the blocks spell that value `danger` too, the runner's
18+
* word, and each renderer forwards it as it is through `toRunnerVariant`.
1919
*
2020
* Every row reads the confirm handler's own call, the artefact the dialog is
2121
* drawn from, and first asserts it was called once (the positive control). The
@@ -37,7 +37,7 @@ import '../action-button';
3737
import '../action-icon';
3838
import '../action-group';
3939
import '../action-menu';
40-
import { toRunnerVariant } from '../runner-variant';
40+
import { toButtonVariant, toRunnerVariant } from '../runner-variant';
4141

4242
const ACTION = {
4343
name: 'purge_history',
@@ -82,9 +82,9 @@ async function confirmOptionsFor(type: string, schema: Record<string, unknown>,
8282
return confirm.mock.calls[0][1];
8383
}
8484

85-
describe.each(SURFACES)('%s forwards its variant in the runner dialect (objectstack#26665)', (type, schemaFor, click) => {
86-
it('`destructive` confirms through the destructive button', async () => {
87-
expect(await confirmOptionsFor(type, schemaFor('destructive'), click)).toEqual({
85+
describe.each(SURFACES)('%s forwards its variant to the runner (objectstack#26665, objectstack#26779)', (type, schemaFor, click) => {
86+
it('`danger` confirms through the destructive button', async () => {
87+
expect(await confirmOptionsFor(type, schemaFor('danger'), click)).toEqual({
8888
title: 'Purge history',
8989
confirmText: 'Purge history',
9090
destructive: true,
@@ -99,9 +99,9 @@ describe.each(SURFACES)('%s forwards its variant in the runner dialect (objectst
9999
});
100100
});
101101

102-
describe('toRunnerVariant (objectstack#26665)', () => {
103-
it('maps the block dialect onto the action dialect', () => {
104-
expect(toRunnerVariant('destructive')).toBe('danger');
102+
describe('toRunnerVariant (objectstack#26779)', () => {
103+
it('forwards the values the action dialect shares, `danger` as it is', () => {
104+
expect(toRunnerVariant('danger')).toBe('danger');
105105
expect(toRunnerVariant('primary')).toBe('primary');
106106
expect(toRunnerVariant('secondary')).toBe('secondary');
107107
expect(toRunnerVariant('ghost')).toBe('ghost');
@@ -110,4 +110,22 @@ describe('toRunnerVariant (objectstack#26665)', () => {
110110
expect(toRunnerVariant('outline')).toBeUndefined();
111111
expect(toRunnerVariant(undefined)).toBeUndefined();
112112
});
113+
114+
it('CONTROL: the retired block spelling `destructive` is not read', () => {
115+
expect(toRunnerVariant('destructive' as never)).toBeUndefined();
116+
});
117+
});
118+
119+
describe('toButtonVariant (objectstack#26779)', () => {
120+
it('draws `danger` as the Button primitive\'s `destructive`, `primary` as `default`', () => {
121+
expect(toButtonVariant('danger', 'ghost')).toBe('destructive');
122+
expect(toButtonVariant('primary', 'ghost')).toBe('default');
123+
expect(toButtonVariant('outline', 'ghost')).toBe('outline');
124+
expect(toButtonVariant('link', 'ghost')).toBe('link');
125+
expect(toButtonVariant(undefined, 'ghost')).toBe('ghost');
126+
});
127+
128+
it('CONTROL: the retired block spelling `destructive` draws the renderer default', () => {
129+
expect(toButtonVariant('destructive' as never, 'outline')).toBe('outline');
130+
});
113131
});

‎ui/packages/components/src/renderers/action/action-bar.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
* location: 'record_header',
4242
* actions: [
4343
* { name: 'mark_complete', label: 'Mark Complete', type: 'script', icon: 'check', component: 'action:button' },
44-
* { name: 'delete', label: 'Delete', type: 'api', icon: 'trash', variant: 'destructive', component: 'action:button' },
44+
* { name: 'delete', label: 'Delete', type: 'api', icon: 'trash', variant: 'danger', component: 'action:button' },
4545
* ],
4646
* }} />
4747
* ```

‎ui/packages/components/src/renderers/action/action-button.tsx‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import { resolveIcon } from './resolve-icon';
3131
import { hasDeclaredVisibilityGate } from './visibility-gate';
3232
import { useAutoTriggerOnce } from './auto-trigger';
3333
import { readStaticParamValues } from './static-params';
34-
import { toRunnerVariant } from './runner-variant';
34+
import { toButtonVariant, toRunnerVariant } from './runner-variant';
3535
import { DisabledReasonTrigger, describedByWithReason, useDisabledReason } from './disabled-reason';
3636
import type { RendererHostProps } from '../../lib/renderer-host-props';
3737

@@ -204,8 +204,9 @@ const ActionButtonRenderer = forwardRef<
204204
// Resolve icon
205205
const Icon = resolveIcon(schema.icon);
206206

207-
// Map schema variant to Shadcn button variant
208-
const variant = schema.variant === 'primary' ? 'default' : (schema.variant || 'default');
207+
// Map schema variant to Shadcn button variant: `danger` draws the
208+
// primitive's `destructive` (objectstack#26779). See `./runner-variant`.
209+
const variant = toButtonVariant(schema.variant, 'default');
209210
const size = schema.size === 'md' ? 'default' : (schema.size || 'default');
210211

211212
const handleClick = useCallback(async () => {
@@ -326,9 +327,9 @@ const ActionButtonRenderer = forwardRef<
326327
// objectui#12941.
327328
operation: schema.operation,
328329
confirmText: schema.confirmText,
329-
// The block's `variant`, in the runner's dialect: a `destructive`
330-
// button confirms through the destructive button, as a `danger`
331-
// action does (objectstack#26665). See `./runner-variant`.
330+
// The block's `variant`, forwarded: a `danger` button confirms
331+
// through the destructive button, as a `danger` action does
332+
// (objectstack#26665, objectstack#26779). See `./runner-variant`.
332333
variant: toRunnerVariant(schema.variant),
333334
successMessage: schema.successMessage,
334335
// Success copy per handler outcome (spec 17.6.0, objectui#11344): the
@@ -525,7 +526,7 @@ ComponentRegistry.register('button', ActionButtonRenderer, {
525526
{
526527
name: 'variant',
527528
type: 'enum',
528-
enum: ['default', 'primary', 'secondary', 'destructive', 'outline', 'ghost'],
529+
enum: ['default', 'primary', 'secondary', 'danger', 'outline', 'ghost'],
529530
},
530531
// objectui#11168 slice 2 — the five sizes the spec row declares, each
531532
// measured through the real `SchemaRenderer`: `default`, `sm`, `lg` and

‎ui/packages/components/src/renderers/action/action-group.tsx‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import { Loader2, ChevronDown } from 'lucide-react';
3636
import { resolveIcon } from './resolve-icon';
3737
import { hasDeclaredVisibilityGate } from './visibility-gate';
3838
import { readActionEntryParamValues } from './static-params';
39-
import { toRunnerVariant } from './runner-variant';
39+
import { toButtonVariant, toRunnerVariant } from './runner-variant';
4040
import {
4141
DisabledReasonMenuLabel,
4242
DisabledReasonTrigger,
@@ -135,7 +135,7 @@ const InlineActionButton: React.FC<{
135135
);
136136

137137
const Icon = resolveIcon(action.icon);
138-
const btnVariant = (action.variant as string) === 'primary' ? 'default' : (action.variant || variant || 'outline');
138+
const btnVariant = toButtonVariant((action.variant || variant) as UIActionSchema['variant'], 'outline');
139139
const btnSize = action.size === 'md' ? 'default' : (action.size || size || 'sm');
140140

141141
const handleClick = useCallback(async () => {
@@ -258,7 +258,7 @@ export const DropdownActionItem: React.FC<{
258258
await onSelect(action);
259259
}}
260260
className={cn(
261-
(action.variant as string) === 'destructive' && 'text-destructive focus:text-destructive',
261+
action.variant === 'danger' && 'text-destructive focus:text-destructive',
262262
action.className,
263263
)}
264264
>
@@ -431,7 +431,7 @@ const ActionGroupRenderer = forwardRef<HTMLDivElement, { schema: ActionGroupSche
431431
<DropdownMenuTrigger asChild>
432432
<Button
433433
type="button"
434-
variant={(schema.variant || 'outline') as any}
434+
variant={toButtonVariant(schema.variant as UIActionSchema['variant'], 'outline')}
435435
size={(schema.size === 'md' ? 'default' : (schema.size || 'default')) as any}
436436
className={cn(schema.className, className)}
437437
// `hostDisabled` leads the OR (objectui#9131) — see `action:button`.

‎ui/packages/components/src/renderers/action/action-icon.tsx‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import { resolveIcon } from './resolve-icon';
2727
import { hasDeclaredVisibilityGate } from './visibility-gate';
2828
import { useAutoTriggerOnce } from './auto-trigger';
2929
import { readStaticParamValues } from './static-params';
30-
import { toRunnerVariant } from './runner-variant';
30+
import { toButtonVariant, toRunnerVariant } from './runner-variant';
3131
import { DisabledReasonTrigger, describedByWithReason, useDisabledReason } from './disabled-reason';
3232
import type { RendererHostProps } from '../../lib/renderer-host-props';
3333

@@ -126,7 +126,7 @@ const ActionIconRenderer = forwardRef<
126126
);
127127

128128
const Icon = resolveIcon(schema.icon);
129-
const variant = schema.variant === 'primary' ? 'default' : (schema.variant || 'ghost');
129+
const variant = toButtonVariant(schema.variant, 'ghost');
130130
const size = 'icon';
131131

132132
const handleClick = useCallback(async () => {
@@ -366,7 +366,7 @@ ComponentRegistry.register('icon', ActionIconRenderer, {
366366
{
367367
name: 'variant',
368368
type: 'enum',
369-
enum: ['default', 'secondary', 'destructive', 'outline', 'ghost'],
369+
enum: ['default', 'secondary', 'danger', 'outline', 'ghost'],
370370
},
371371
{ name: 'className', type: 'string' },
372372
{

‎ui/packages/components/src/renderers/action/action-menu.tsx‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import { resolveIcon } from './resolve-icon';
3434
import { hasDeclaredVisibilityGate } from './visibility-gate';
3535
import { useAutoTriggerOnce } from './auto-trigger';
3636
import { readActionEntryParamValues } from './static-params';
37-
import { toRunnerVariant } from './runner-variant';
37+
import { toButtonVariant, toRunnerVariant } from './runner-variant';
3838
import { DisabledReasonMenuLabel, menuItemReasonAria, useDisabledReason } from './disabled-reason';
3939
import type { RendererHostProps } from '../../lib/renderer-host-props';
4040

@@ -151,7 +151,7 @@ export const ActionMenuItem: React.FC<{
151151
onExecute(action);
152152
}}
153153
className={cn(
154-
(action.variant as string) === 'destructive' && 'text-destructive focus:text-destructive',
154+
action.variant === 'danger' && 'text-destructive focus:text-destructive',
155155
action.className,
156156
)}
157157
>
@@ -247,7 +247,7 @@ const ActionMenuRenderer = forwardRef<HTMLButtonElement, { schema: ActionMenuSch
247247
});
248248

249249
const TriggerIcon = resolveIcon(schema.icon) || MoreHorizontal;
250-
const variant = schema.variant || 'ghost';
250+
const variant = toButtonVariant(schema.variant as UIActionSchema['variant'], 'ghost');
251251
const size = schema.size || 'icon';
252252

253253
const handleExecute = useCallback(

0 commit comments

Comments
 (0)