Skip to content

Commit 6307efe

Browse files
committed
feat(spec): InlineActionSchema picks description, so an inline action's param dialog can say what it does
An inline action (`element:button`'s `properties.action`) was refused `description` as an unknown key, although the button's renderer already forwards it to the runner and the console's param dialog draws it under its title. The pick now takes ActionSchema's own field (the `template` slot with the inline locale-map arm). The docblock records the one remaining window: the inline copy localizer does not yet collapse a locale-map `description`, so it reaches the dialog unresolved until the renderer half lands. It also corrects the `bodyExtra` paragraph, whose forward-list gap has closed. Claude-Session: https://claude.ai/code/session_01ADHkmT9dnPvF2SeYafuvmH Co-authored-by: Claude <noreply@anthropic.com>
1 parent 27c1c55 commit 6307efe

4 files changed

Lines changed: 131 additions & 24 deletions

File tree

‎packages/spec/src/ui/action-description.test.ts‎

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@
1616
// These pins hold the key open to the input shapes `label` takes (a string or
1717
// an inline locale map; since #27948 a string is the `template` slot's
1818
// shorthand and parses to its envelope), and hold the
19-
// three things this change must NOT do: relax the strict shape, widen the
20-
// INLINE action surface ahead of its renderer, or re-point the action PARAM's
21-
// `description` → `helpText` alias, which is a different surface and still
22-
// correct.
19+
// two things this change must NOT do: relax the strict shape, or re-point the
20+
// action PARAM's `description` → `helpText` alias, which is a different surface
21+
// and still correct. The INLINE action surface took the key later, once
22+
// `element:button`'s renderer forwarded it (cloud#3281, ruling A); its pins
23+
// live in `inline-action.test.ts`.
2324

2425
import { describe, it, expect } from 'vitest';
2526
import { z } from 'zod';
@@ -148,22 +149,22 @@ describe('the surfaces the action `description` key deliberately does NOT widen'
148149
expect(issue?.message).toContain('helpText');
149150
});
150151

151-
it('an INLINE action still refuses it — the pick widens when a renderer widens, not before', () => {
152+
it('an INLINE action takes it too — the pick widened once element:button forwarded it', () => {
152153
// `InlineActionSchema` forwards exactly what `element:button`'s renderer
153-
// honours. That renderer has no description slot, so picking the key here
154-
// would declare a field no renderer reads — the failure that schema exists
155-
// to stop (`bodyExtra` is the one knowing exception, ruled in #5777).
154+
// honours, and that renderer now hands `description` to the runner, whose
155+
// param dialog draws it (cloud#3281, ruling A). Same field, same parse.
156156
const result = InlineActionSchema.safeParse({
157157
type: 'url',
158158
target: '/docs',
159159
label: 'Docs',
160-
description: 'Not honoured by element:button',
160+
description: 'Opens the product documentation.',
161161
});
162162

163-
expect(result.success).toBe(false);
164-
const issue = result.success ? undefined : result.error.issues[0];
165-
expect(issue?.code).toBe('unrecognized_keys');
166-
expect(issue?.message).toContain('description');
163+
expect(result.success).toBe(true);
164+
expect(result.success && result.data.description).toEqual({
165+
dialect: 'template',
166+
source: 'Opens the product documentation.',
167+
});
167168
});
168169
});
169170

‎packages/spec/src/ui/action.zod.ts‎

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2567,16 +2567,27 @@ export function normalizeInlineAction(value: unknown): unknown {
25672567
* issue's option C names. The pick is therefore what makes the ruled direction
25682568
* A reachable from a page, and it is deliberately taken before objectui's half.
25692569
*
2570-
* The divergence that buys, stated rather than hidden: objectui's
2571-
* `element:button` renderer builds an explicit forward list
2572-
* (`packages/components/src/renderers/basic/elements.tsx`) that does not yet
2573-
* include `bodyExtra`, so between this landing and that follow-up an inline
2574-
* `bodyExtra` validates, publishes, and is dropped one hop before the runner.
2575-
* The runner and the console `apiHandler` below it already read the key — the
2576-
* missing hop is the forward list alone. Direction of the window: spec accepts
2577-
* ahead of the renderer, never the reverse. Tracked as the objectui card the
2578-
* ruling splits out under `Blocked-by:` this change; the general rule above is
2579-
* unchanged for every other field.
2570+
* That window has since closed: the `element:button` renderer's explicit
2571+
* forward list (`ui/packages/components/src/renderers/basic/elements.tsx`) now
2572+
* carries `bodyExtra` to the runner, and the console `apiHandler` below it reads
2573+
* the key. Direction of such a window: spec accepts ahead of the renderer, never
2574+
* the reverse.
2575+
*
2576+
* **`description` is picked because the renderer already forwards it.** The
2577+
* same forward list hands `action.description` to the runner, and the console's
2578+
* param-collection handler (`ui/packages/app-shell/src/hooks/useConsoleActionRuntime.tsx`)
2579+
* draws it as the line under the param dialog's title — the handler that draws
2580+
* a registered action's `description`, bundle lookup by the action's `name`
2581+
* first, the authored text as the fallback. Without the pick an inline action
2582+
* could not say what it does, and the dialog showed its generic line instead.
2583+
*
2584+
* One window remains, stated rather than hidden: the inline copy localizer
2585+
* (`ui/packages/react/src/hooks/useActionTextLocalizer.ts`) collapses to the
2586+
* user's language only the keys its `DECLARED_COPY_KEYS` lists — `confirmText`,
2587+
* `successMessage`, `errorMessage` — and `description` is not one of them. So
2588+
* until the renderer half lands, an inline locale map (`{ en, "zh-CN" }`) on
2589+
* `description` reaches the dialog unresolved. Same direction as above: spec
2590+
* accepts ahead of the renderer, never the reverse.
25802591
*/
25812592
export const InlineActionSchema = lazySchema(() => z.preprocess(
25822593
normalizeInlineAction,
@@ -2589,6 +2600,9 @@ export const InlineActionSchema = lazySchema(() => z.preprocess(
25892600
method: true,
25902601
params: true,
25912602
bodyExtra: true,
2603+
// objectstack-ai/cloud#3281 (ruling A): the param dialog's explanatory
2604+
// line. The localizer half that resolves its locale map is #29249.
2605+
description: true,
25922606
confirmText: true,
25932607
successMessage: true,
25942608
errorMessage: true,

‎packages/spec/src/ui/inline-action-type.test.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,13 @@ const apiAction: InlineAction = {
3737
refreshAfter: true,
3838
};
3939
const namedModal: InlineAction = { name: 'open_upgrade', label: 'Upgrade', type: 'modal', target: 'upgrade_dialog' };
40+
// `description` follows the pick into the derived type, in both of its input shapes.
41+
const describedInvite: InlineAction = {
42+
type: 'api',
43+
target: '/api/v1/auth/organization/invite-member',
44+
description: { en: 'Sends an invitation e-mail.', 'zh-CN': '发送邀请邮件。' },
45+
};
46+
const describedPlain: InlineAction = { type: 'url', target: '/docs', description: 'Opens the documentation.' };
4047

4148
// ── What `InlineAction` refuses at compile time ──────────────────────────────────────────────
4249

@@ -56,6 +63,8 @@ describe('InlineAction is an inline action body, not unknown', () => {
5663
['a url action', urlAction],
5764
['an api action with a static payload', apiAction],
5865
['a named modal action', namedModal],
66+
['an api action with a locale-map description', describedInvite],
67+
['a url action with a plain description', describedPlain],
5968
])('%s typed as InlineAction parses', (_label, body) => {
6069
expect(InlineActionSchema.safeParse(body).success).toBe(true);
6170
});

‎packages/spec/src/ui/inline-action.test.ts‎

Lines changed: 84 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import { ElementButtonPropsSchema } from './component.zod';
2828
/** The fields an inline action admits, in the order they are picked. */
2929
const INLINE_FIELDS = [
3030
'type', 'name', 'label', 'target', 'openIn', 'method', 'params', 'bodyExtra',
31-
'confirmText', 'successMessage', 'errorMessage', 'refreshAfter', 'opensInNewTab',
31+
'description', 'confirmText', 'successMessage', 'errorMessage', 'refreshAfter', 'opensInNewTab',
3232
] as const;
3333

3434
/** Reach the inner object through the preprocess → object → refine chain. */
@@ -63,6 +63,7 @@ describe('InlineActionSchema is derived from ActionSchema, not restated', () =>
6363
method: 'POST' as const,
6464
params: [],
6565
bodyExtra: { resend: true },
66+
description: 'Sends the invitation again.',
6667
confirmText: 'Sure?',
6768
successMessage: 'Done',
6869
errorMessage: 'Failed',
@@ -205,6 +206,88 @@ describe('InlineActionSchema — `bodyExtra` is the payload key, `params` is not
205206
});
206207
});
207208

209+
/**
210+
* The param dialog's explanatory line (cloud#3281, ruling A). `element:button`'s
211+
* forward list already hands `description` to the runner and the console's
212+
* param-collection handler draws it under the dialog title, so the pick follows
213+
* the renderer here rather than leading it. The field is `ActionSchema`'s own —
214+
* the same `template` slot with the inline locale-map arm — not a restatement.
215+
*/
216+
describe('InlineActionSchema — `description` says what the action does', () => {
217+
/** The cloud invitation dialog's shape: an inline `api` action that collects params. */
218+
const invite = {
219+
type: 'api' as const,
220+
target: '/api/v1/auth/organization/invite-member',
221+
params: [{ name: 'email', label: 'Email', type: 'email' as const, required: true }],
222+
};
223+
224+
it('accepts a plain string and keeps it, as the `template` envelope it is shorthand for', () => {
225+
const r = InlineActionSchema.safeParse({
226+
...invite,
227+
description: 'Your colleague gets an e-mail and joins with the chosen role after accepting.',
228+
});
229+
expect(r.success, JSON.stringify((r as { error?: unknown }).error)).toBe(true);
230+
expect(r.data?.description).toEqual({
231+
dialect: 'template',
232+
source: 'Your colleague gets an e-mail and joins with the chosen role after accepting.',
233+
});
234+
});
235+
236+
it('accepts an inline locale map and keeps it verbatim', () => {
237+
const localized = {
238+
en: 'Your colleague gets an e-mail and joins after accepting.',
239+
'zh-CN': '对方会收到邀请邮件,接受后以所选角色加入。',
240+
};
241+
const r = InlineActionSchema.safeParse({ ...invite, description: localized });
242+
expect(r.success, JSON.stringify((r as { error?: unknown }).error)).toBe(true);
243+
expect(r.data?.description).toEqual(localized);
244+
});
245+
246+
it('still parses without one, and adds none', () => {
247+
const r = InlineActionSchema.safeParse(invite);
248+
expect(r.success, JSON.stringify((r as { error?: unknown }).error)).toBe(true);
249+
expect(r.data).not.toHaveProperty('description');
250+
});
251+
252+
it('takes the field ActionSchema declares, so both doors refuse a bad value alike', () => {
253+
// Shared field factory, not a restated key: a value the registered door
254+
// refuses by shape is refused inline too, at the same path, same code.
255+
const codeAt = (r: { success: boolean; error?: z.ZodError }) =>
256+
r.error?.issues.find(i => i.path.join('.') === 'description')?.code;
257+
const inline = InlineActionSchema.safeParse({ ...invite, description: 42 });
258+
const registered = ActionSchema.safeParse({ name: 'invite', label: 'Invite', ...invite, description: 42 });
259+
expect(inline.success).toBe(false);
260+
expect(registered.success).toBe(false);
261+
expect(codeAt(inline)).toBeDefined();
262+
expect(codeAt(inline)).toBe(codeAt(registered));
263+
});
264+
265+
it('reaches parse output through element:button, the surface that forwards it', () => {
266+
const r = ElementButtonPropsSchema.safeParse({
267+
label: { en: 'Invite member', 'zh-CN': '邀请成员' },
268+
action: { ...invite, description: { en: 'Sends an invitation e-mail.', 'zh-CN': '发送邀请邮件。' } },
269+
});
270+
expect(r.success, JSON.stringify((r as { error?: unknown }).error)).toBe(true);
271+
expect((r.data as { action: { description: unknown } }).action.description)
272+
.toEqual({ en: 'Sends an invitation e-mail.', 'zh-CN': '发送邀请邮件。' });
273+
});
274+
275+
it.each([
276+
['icon', { icon: 'mail' }],
277+
['variant', { variant: 'primary' }],
278+
['body', { body: 'return 1' }],
279+
['cancelText', { cancelText: 'Back' }],
280+
['submitText', { submitText: 'Send' }],
281+
])('CONTROL: the widening is `description` alone — `%s` is still an unknown key inline', (key, extra) => {
282+
const r = InlineActionSchema.safeParse({ ...invite, ...extra });
283+
expect(r.success).toBe(false);
284+
const issues = (r as { error: z.ZodError }).error.issues;
285+
const unknown = issues.find(i => i.code === 'unrecognized_keys') as { keys?: string[] } | undefined;
286+
expect(unknown, JSON.stringify(issues)).toBeDefined();
287+
expect(unknown!.keys).toEqual([key]);
288+
});
289+
});
290+
208291
/**
209292
* #6828 — the THIRD meaning of `params`, and why one prescription is not enough.
210293
*

0 commit comments

Comments
 (0)