Skip to content

Commit d34cb6e

Browse files
committed
fix(ui): the #26665 changeset stops describing the retired bridge; the VS Code validator judges action block variants
Claude-Session: https://claude.ai/code/session_01WGufzeYWDZN6LkXji5ziLF Co-authored-by: Claude <noreply@anthropic.com>
1 parent 17ecbb4 commit d34cb6e

2 files changed

Lines changed: 40 additions & 4 deletions

File tree

‎.changeset/26665-action-block-destructive-confirm.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
'@object-ui/types': patch
44
---
55

6-
fix(ui): a `destructive` action block confirms through the destructive button (#26665)
6+
fix(ui): a destructive action block confirms through the destructive button (#26665)
77

88
Clause-②: no
99
Metadata-protocol: none
1010

11-
The four action blocks (`action:button`, `action:icon`, `action:group`, `action:menu`) now forward their `variant` to the action runner. `@objectstack/spec` spells the value in two dialects, each on its own surface: the blocks' rows take the Button primitive's vocabulary plus `primary`, and `ActionSchema`, which the runner dispatches, takes `primary | secondary | danger | ghost | link`. The forward translates: `destructive` becomes `danger`, `primary` / `secondary` / `ghost` / `link` pass through, and `default` / `outline` forward nothing. So a block declared `variant: 'destructive'` with a `confirmText` now asks its question through the destructive confirm button, where before it asked through a neutral one.
11+
The four action blocks (`action:button`, `action:icon`, `action:group`, `action:menu`) now forward their `variant` to the action runner, which reads it to paint the confirm button: a destructive block with a `confirmText` now asks its question through the destructive confirm button, where before it asked through a neutral one. `danger` / `primary` / `secondary` / `ghost` / `link` forward as they are, and `default` / `outline`, which an action's own `variant` has no word for, forward nothing. The destructive value is spelled `danger` on the blocks, the same word `ActionSchema.variant` uses (see the action block variant entry in this release).
1212

13-
`UIActionSchema.variant` (`@object-ui/types`) now takes the block rows' vocabulary by reference (`ActionButtonProps['variant']`), which adds `link`, a value those rows already accept. `danger` stays refused there, as the block rows refuse it.
13+
`UIActionSchema.variant` (`@object-ui/types`) now takes the block rows' vocabulary by reference (`ActionButtonProps['variant']`), which adds `link`, a value those rows already accept.

‎ui/packages/vscode-extension/src/providers/SchemaValidator.ts‎

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,8 @@ export class SchemaValidator {
229229
}
230230
}
231231

232-
// Validate button variants
232+
// Validate button variants — the `button` component draws the Button
233+
// primitive, whose destructive arm is its own word, `destructive`.
233234
if (type === 'button' && schema.variant) {
234235
const validVariants = [
235236
'default',
@@ -252,6 +253,41 @@ export class SchemaValidator {
252253
}
253254
}
254255

256+
// Validate action block variants — the action blocks speak the action
257+
// dialect: the destructive arm is `danger`, the word `ActionSchema.variant`
258+
// uses, and `destructive` is refused (objectstack#26779). `primary` is
259+
// accepted on `action:button`, `action:icon` and each container member,
260+
// not on a container's own trigger.
261+
const ACTION_BLOCK_VARIANTS = ['default', 'danger', 'outline', 'secondary', 'ghost', 'link'];
262+
const ACTION_CONTAINER_TYPES = ['action:group', 'action:menu'];
263+
const validateActionVariant = (variant: unknown, at: string, allowPrimary: boolean) => {
264+
if (variant === undefined) return;
265+
const valid = allowPrimary ? [...ACTION_BLOCK_VARIANTS, 'primary'] : ACTION_BLOCK_VARIANTS;
266+
if (typeof variant === 'string' && valid.includes(variant)) return;
267+
const range = this.findPropertyRange(document, at, 'variant');
268+
const hint = variant === 'destructive' ? " `destructive` was renamed `danger` on the action blocks: write variant: 'danger'." : '';
269+
diagnostics.push(
270+
new vscode.Diagnostic(
271+
range,
272+
`Invalid variant "${String(variant)}". Must be one of: ${valid.join(', ')}.${hint}`,
273+
vscode.DiagnosticSeverity.Warning
274+
)
275+
);
276+
};
277+
if (type === 'action:button' || type === 'action:icon') {
278+
validateActionVariant(schema.variant, path, true);
279+
}
280+
if (ACTION_CONTAINER_TYPES.includes(type)) {
281+
validateActionVariant(schema.variant, path, false);
282+
if (Array.isArray(schema.actions)) {
283+
schema.actions.forEach((member: any, index: number) => {
284+
if (member && typeof member === 'object') {
285+
validateActionVariant(member.variant, `${path}.actions[${index}]`, true);
286+
}
287+
});
288+
}
289+
}
290+
255291
// Warn about missing labels for form inputs
256292
if (
257293
(type === 'input' || type === 'textarea' || type === 'select') &&

0 commit comments

Comments
 (0)