Skip to content

Commit 408466d

Browse files
committed
fix(fields): resolveActionParams reads a template-envelope helpText (#27948)
ActionParam.helpText is a template slot since step 2, so the spec's ActionParam was no longer assignable to fields' RawActionParam (Type Check UI, resolveActionParams.test.ts). RawActionParam.helpText is now unknown and every emit reads it through actionCopySource; a field-backed param whose envelope carries no text falls back to the field's own help. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01L9qibwQ8tWwY7TiHQPMCHR
1 parent a8f9f1c commit 408466d

3 files changed

Lines changed: 63 additions & 5 deletions

File tree

‎.changeset/27948-action-copy-envelope-readers.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
---
22
'@object-ui/core': patch
33
'@object-ui/react': patch
4+
'@object-ui/fields': patch
45
---
56

67
fix(core,react): an action's `description`, a param's `helpText` and an `outcomeMessages` entry read the `template` envelope
@@ -13,6 +14,8 @@ objectstack#27948 step 2 types these three as `template` slots, so a served acti
1314
- **Param dialog.** The runner hands the param-collection handler the action and params with `description` and each `helpText` reduced to their text (`actionCopyText`), so the dialog draws the sentence, never `[object Object]`; a locale map is handed on unchanged for the host to localize.
1415
- **Outcome toast.** `useActionTextLocalizer` keeps an `outcomeMessages` envelope's shape (a bundle entry replaces its `source`) instead of collapsing it to the word "template", and the runner fills the envelope's holes as it fills the string's.
1516

17+
- **Param fields.** `@object-ui/fields`' `resolveActionParams` reads a param's `helpText` through `actionCopySource`, so an envelope yields its sentence (a field-backed param with no text falls back to the field's own help) and `ActionParam` stays assignable to its `RawActionParam`.
18+
1619
- **Studio's action preview** (`@object-ui/app-shell`, unpublished) draws a param's `helpText`, `confirmText` and `successMessage` from the envelope's `source`: it drew `helpText` raw (an object as a React child) and read the other two as a locale map, which showed the word "template".
1720

1821
What to do: nothing. `${…}` copy written before the migration keeps reading.
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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#27948 (ruling A, step 2) — a param's `helpText` is a `template`
11+
* slot, so the spec's authoring type (and a served param) can carry
12+
* `{ dialect: 'template', source }` where it carried a string. `RawActionParam`
13+
* said `string`, so the public authoring type stopped being assignable to it
14+
* (the `Type Check UI` red), and an envelope carried through untouched would
15+
* reach `ActionParamDialog` as an object. The resolver emits the text.
16+
*/
17+
import { describe, it, expect } from 'vitest';
18+
import type { ActionParam } from '@object-ui/types';
19+
import { resolveActionParams, type ResolveActionParamsContext, type RawActionParam } from '@object-ui/fields';
20+
21+
const ctx = (): ResolveActionParamsContext => ({
22+
objectName: 'crm_account',
23+
objects: [{ name: 'crm_account', fields: { reason: { type: 'text', label: 'Reason', description: 'The field help' } } }],
24+
fieldLabel: (_o, _f, fallback) => fallback,
25+
});
26+
27+
const HINT = 'Why {{ record.name }} is paused';
28+
const envelope = { dialect: 'template' as const, source: HINT };
29+
30+
describe('resolveActionParams reads a template-envelope helpText (objectstack#27948)', () => {
31+
it('the public authoring type is assignable, envelope included', () => {
32+
const authored: ActionParam = { name: 'reason', type: 'text', helpText: envelope };
33+
const raw: RawActionParam = authored;
34+
expect(raw.helpText).toBe(envelope);
35+
});
36+
37+
it('an inline param emits the envelope\'s text, exactly as the bare string', () => {
38+
const [fromEnvelope] = resolveActionParams([{ name: 'reason', type: 'text', helpText: envelope }], ctx());
39+
const [fromString] = resolveActionParams([{ name: 'reason', type: 'text', helpText: HINT }], ctx());
40+
expect(fromEnvelope.helpText).toBe(HINT);
41+
expect(fromEnvelope).toEqual(fromString);
42+
});
43+
44+
it('a field-backed param emits the envelope\'s text; one with no source falls back to the field\'s help', () => {
45+
expect(resolveActionParams([{ field: 'reason', helpText: envelope }], ctx())[0].helpText).toBe(HINT);
46+
expect(resolveActionParams([{ field: 'reason', helpText: { dialect: 'template' } }], ctx())[0].helpText)
47+
.toBe(resolveActionParams([{ field: 'reason' }], ctx())[0].helpText);
48+
});
49+
});

‎ui/packages/fields/src/resolveActionParams.ts‎

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
* rejects it, the server's `.strict()` parse rejects it, and this resolver
4848
* names it via {@link RESOLVED_ONLY_PARAM_KEYS} rather than reading it.
4949
*/
50-
import { EXPANDABLE_FIELD_TYPES, toPredicateRecord } from '@object-ui/core';
50+
import { EXPANDABLE_FIELD_TYPES, actionCopySource, toPredicateRecord } from '@object-ui/core';
5151
import type { ActionParamDef, ActionParamOption } from '@object-ui/core';
5252
// The form's widget fold. Imported from the barrel this module is re-exported
5353
// by — a cycle in the SOURCE graph only, and a call-time one: nothing at this
@@ -176,7 +176,13 @@ export interface RawActionParam {
176176
*/
177177
options?: RawActionParamOption[];
178178
placeholder?: string;
179-
helpText?: string;
179+
/**
180+
* The hint under the input. A `template` slot since objectstack#27948: the
181+
* bare string, or the parsed `{ dialect: 'template', source }` envelope a
182+
* served param carries; read through `actionCopySource`, so the resolved
183+
* param's `helpText` is always the text.
184+
*/
185+
helpText?: unknown;
180186
defaultValue?: unknown;
181187
/** When true, seed defaultValue from the row record using the field name. */
182188
defaultFromRow?: boolean;
@@ -609,7 +615,7 @@ export function resolveActionParam(
609615
required: param.required ?? false,
610616
options: authoredOptions,
611617
placeholder: param.placeholder,
612-
helpText: param.helpText,
618+
helpText: actionCopySource(param.helpText),
613619
defaultValue: rowDefault ?? param.defaultValue,
614620
visible: normaliseVisible(param.visible),
615621
// This output is built key by key, so an authored key that is not
@@ -669,7 +675,7 @@ export function resolveActionParam(
669675
required: param.required ?? false,
670676
options: authoredOptions,
671677
placeholder: param.placeholder,
672-
helpText: param.helpText,
678+
helpText: actionCopySource(param.helpText),
673679
defaultValue: rowDefault ?? param.defaultValue,
674680
visible: normaliseVisible(param.visible),
675681
carryOver: param.carryOver,
@@ -834,7 +840,7 @@ export function resolveActionParam(
834840
// form shares (`fieldHelpText`, objectui#12213): the spec's
835841
// `inlineHelpText`, then `description`, an empty string reading as absent.
836842
// A served `help` key is not read.
837-
helpText: param.helpText ?? fieldHelpText(field),
843+
helpText: actionCopySource(param.helpText) ?? fieldHelpText(field),
838844
defaultValue: rowDefault ?? param.defaultValue ?? field.defaultValue,
839845
visible: normaliseVisible(param.visible),
840846
// A declaration of the PARAM, never inherited from the field.

0 commit comments

Comments
 (0)