Skip to content

Commit f91ab5a

Browse files
feat(core): an action's param dialog description, helpText and outcomeMessages fill {{ }} template holes, and still fill ${…} (#28436)
<!-- claude-projects-attribution: {"github_login":"os-tesla"} --> _Requested by **Tesla** · [project thread](https://claude.ai/code/project/chan_01AXsQkLFKRdQCqQ3RTr6Jao?thread=cmsg_01AXsQkLFKRdQCqQ3RTr6JaoBCpS3vE7HS7cD6zZzsAPjZ)_ Part of #27948 Clause-②: no Metadata-protocol: none ## 维护者速读 - 改了什么:控制台的动作文案里,参数对话框的 `description`、每个参数的 `helpText`、以及 `outcomeMessages` 现在也会填 `{{ record.x }}` / `{{ result.x }}` 这种模板洞(含 `{{ amount | currency:USD }}` 格式化),和 `confirmText` / `successMessage` 用同一个模板引擎;原来的 `${…}` 写法照旧能填。 - 为什么改:规范要求带参数的动作把确认问句从 `confirmText` 挪到 `description`,可挪过去后 `{{ record.x }}` 原样显示成花括号;裁决 A(「同意」)定五个文案键统一成 `{{ }}`,渲染端先行。这是第 1 步。 - 风险与回滚:只改 `@object-ui/core` 的动作运行器;一句话里有 `{{ }}` 就只走模板引擎(同句里的 `${…}` 当普通文字),没有就走旧的 `${…}`,现有文案行为不变;回滚即 revert 本 PR。 - 先看:ui/packages/core/src/actions/ActionRunner.ts(`dialogCopyFiller`、`composeSuccessMessage` 第一档)、ui/packages/core/src/actions/actionCopyTemplate.ts(`fillTransitionalCopy`)、ui/packages/core/src/actions/__tests__/ActionRunner.transitionalCopy-27948.test.ts。 - 两分钟验证:`cd ui && pnpm exec vitest run packages/core/src/actions/__tests__/ActionRunner.transitionalCopy-27948.test.ts`,预期 15/15 通过。 - 需要你做的:无,席位落地。 ## What changes Step 1 of #27948, ruling 6545229148, letter A (renderer first). The five action copy keys become one ADR-0032 `{{ }}` template slot. `confirmText` and `successMessage` already read it; the param dialog's `description`, each param's `helpText`, and `outcomeMessages` read only `${…}`. So an author following the spec (move the confirm question of an action with params from `confirmText` to `description`) saw `{{ record.x }}` printed raw, from the record header and from a row. - `ui/packages/core/src/actions/actionCopyTemplate.ts`: `fillTransitionalCopy(text, fillTemplate, fillLegacy)`, one dialect per sentence, the rule `confirmText` / `successMessage` kept through their own transition (objectui#13367 until objectui#13476): a sentence with a `{{ }}` hole is filled by the template engine alone, so a `${…}` token in it stays text and a filled value is never read a second time; a sentence with none keeps its `${…}` reading. - `ui/packages/core/src/actions/ActionRunner.ts`: - The `interpolate` handed to the param-collection handler is now `dialogCopyFiller(action)`: `{{ }}` holes fill over `record` (the row on a row dispatch, the page's record on the header) and the action's static `params`, exactly the roots `confirmText` reads (factored out of `confirmMessage` as `recordCopyRoots`); `${…}` still goes through `templateEvaluatorFor` (objectui#12967). Both handlers (`useConsoleActionRuntime`, `RecordDetailView`) already pass that `interpolate` to the dialog for `description` and `helpText`, so no app-shell code moves. - `composeSuccessMessage` rung 1 (`outcomeMessages`): `{{ }}` holes fill over `result` and `record`, the roots `successMessage` reads, with the viewer's locale and tenant currency; `${result.*}` still goes through `substituteScopeTokens`. - Doc comments on `ActionDef.outcomeMessages`, `ParamCollectionHandler`, `RUNNER_TEXT`, `templateEvaluatorFor` and `substituteScopeTokens` say which spelling each reads. - `.changeset/27948-action-copy-template-holes.md`: `@object-ui/core` patch. No `packages/spec/**` change: the describe text, the publish refusal of `${…}` and the migration of existing `${…}` copy are step 2, after this is on `main`. ## Tests `ui/packages/core/src/actions/__tests__/ActionRunner.transitionalCopy-27948.test.ts`, 15 pins through the real runner and `@objectstack/formula`'s `templateEngine`, reading what the host is handed (the dialog's `interpolate` output and the toast handler's argument): - `description` + `helpText`, on the header door and the row door (`params._rowRecord`, as `ObjectGrid` dispatches): the card's case (the `confirmText` sentence `Pause {{ record.display_name }}?` reads the same moved to `description`), a `${record.x}` hole still fills, an unknown `{{ x }}` hole reads exactly as `confirmText` reads it; a formatter hole; a mixed sentence (`{{ }}` wins, `${…}` stays text); a filled value is not re-read as `${…}`. - `outcomeMessages`: `{{ result.x }}`, `{{ record.x }}` from the row, a formatter hole, `${result.x}` still fills, an unknown `{{ x }}` reads as `successMessage` reads it, a mixed sentence. Reverse check against the unfixed runner (`ActionRunner.ts` and `actionCopyTemplate.ts` restored from `5da3a8ce`, test file kept): 12 failed, 3 passed. The 3 that stay green are the `${…}` keepers, which pin preservation and are meant to pass on both. Restore proven by an empty `git diff HEAD`. ## Acceptance notes - **Order inside one sentence.** One dialect per sentence, as the ruling's "decide and pin the order" asks: a `{{ }}` hole makes the whole sentence a template; `${…}` in it is text. This is the reading `confirmText` / `successMessage` had during their transition, so step 2's refusal of `${…}` changes nothing for a sentence that already has a `{{ }}` hole. - **Roots.** The dialog copy reads `record` and static `params` (not the collected values, which do not exist yet, the same as `confirmText`); `outcomeMessages` reads `result` and `record`. The `${…}` path keeps its wider scope (the whole runner context) until step 2 retires it; step 2's migration should check producers for `${user.*}`-style holes, which have no `{{ }}` root here. - **Envelope.** These three keys are still read as strings: `description` / `helpText` are localized in app-shell before `interpolate`, and `outcomeMessages` entries are read only when they are strings. If step 2 types them as template slots that parse to the `{ dialect, source }` envelope, the readers must accept the envelope first (the trap objectui#13367 closed for `confirmText` / `successMessage`), or a served entry silently falls back. - Registered producers using `${result.*}` in `outcomeMessages` / `successMessage` (platform-objects' invitation copy) are untouched; `${…}` keeps filling. ## Verification Readings at head `164cbe99` on objectstack-ai/objectstack (merge base `5da3a8ce`). <details><summary>Tests</summary> - `cd ui && pnpm exec vitest run packages/core/src/actions/__tests__/ActionRunner.transitionalCopy-27948.test.ts`: Tests 15/15 passed. - `cd ui && pnpm exec vitest run packages/core/`: Test Files 224/224, Tests 4197 passed, 27 skipped. - `cd ui && pnpm exec vitest run packages/app-shell/src/views/ActionParamDialog packages/app-shell/src/views/ObjectView.inviteOutcome-27797 packages/app-shell/src/hooks/`: Test Files 102/102, Tests 886/886. - `pnpm --filter @object-ui/core type-check` (sources and `tsconfig.test.json`): lock VERDICT command-exit 0. </details> <details><summary>Gates</summary> - Build: `env -u OS_SKIP_DTS pnpm turbo run build --filter='@object-ui/app-shell^...' --filter='!@object-ui/*'` (37/37 tasks) and `--filter='@object-ui/core^...'` (3/3), lock VERDICT command-exit 0 both. - `dispatch-gates --commands` at `164cbe99`: 34 families, each run with stdin from `/dev/null`, exit codes recorded before any pipe; all 34 exit 0 (`pnpm --dir ui exec vitest run scripts/`: Test Files 169 passed, 2 skipped). `--ran`: 34 derived, 34 run, 0 NOT-MEASURED, 0 UNRUN. - `origin/main` moved to `630b4078` after branch-off; none of the incoming files is this PR's and `git merge-tree` against it is clean. - The full CI farm (`test:repo`, the UI lanes, lint) is CI's. </details> --- _Generated by [Claude Code](https://claude.ai/code/session_01L9qibwQ8tWwY7TiHQPMCHR)_ --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 41df5eb commit f91ab5a

4 files changed

Lines changed: 276 additions & 34 deletions

File tree

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
'@object-ui/core': patch
3+
---
4+
5+
feat(core): an action's param dialog `description`, each param's `helpText` and an `outcomeMessages` entry fill `{{ }}` template holes, and still fill `${…}`
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
Step 1 of objectstack#27948 (ruling A, renderer first): the five action copy keys move to one hole syntax, ADR-0032's `{{ }}` template slot. `confirmText` and `successMessage` already read it; the other three read only `${…}`, so the confirm question an author moves from `confirmText` to `description` (as the spec asks for an action with params) printed its `{{ record.x }}` hole raw.
11+
12+
- **Param dialog `description` and `helpText`.** The `interpolate` the runner hands the param-collection handler fills a `{{ }}` hole through the template engine over `record` (the row on a row dispatch, the page's record on the record header) and the action's static `params`, the roots `confirmText` reads. Formatters work (`{{ amount | currency:USD }}`).
13+
- **`outcomeMessages`.** An entry's `{{ }}` holes are filled over `result` (the handler's payload) and `record`, the roots `successMessage` reads.
14+
- **`${…}` keeps working** on all three until the spec closes these slots (step 2). One dialect per sentence: a sentence with a `{{ }}` hole is filled by the template engine alone and a `${…}` token in it stays text; a sentence with none keeps its `${…}` reading.
15+
16+
What to do: nothing. Copy written with `${…}` reads as before; new copy can use `{{ }}`.

‎ui/packages/core/src/actions/ActionRunner.ts‎

Lines changed: 73 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import type { ActionContext, ActionResult, RunnableActionType, UIActionSchema } from '@object-ui/types';
2525
import type { Action as SpecActionInput } from '@objectstack/spec/ui';
2626
import { ExpressionEvaluator } from '../evaluator/ExpressionEvaluator.js';
27-
import { actionCopySource, fillTemplateHoles, hasTemplateHoles, type ActionCopyTemplate } from './actionCopyTemplate.js';
27+
import { actionCopySource, fillTemplateHoles, fillTransitionalCopy, hasTemplateHoles, type ActionCopyTemplate } from './actionCopyTemplate.js';
2828
import { hasDeclaredPredicate } from '../evaluator/declaredPredicate.js';
2929
import { globalUndoManager } from './UndoManager.js';
3030
import { warnOnDeprecatedObjectParams, warnOnUnknownActionKeys } from './actionKeys.js';
@@ -516,8 +516,11 @@ export interface ActionDef {
516516
* fact and this map holds the sentence for each, keyed by the snake_case
517517
* outcome name. Read by `handlePostExecution` → `composeSuccessMessage`, the
518518
* success toast's FIRST rung: the entry named by the payload's top-level
519-
* `outcome` (the payload `${result.*}` reads), then {@link successMessage},
520-
* then the runner's own default text.
519+
* `outcome` (the payload `{{ result.* }}` reads), then {@link successMessage},
520+
* then the runner's own default text. An entry's `{{ }}` holes are filled
521+
* over `result` and `record`, as `successMessage`'s are; an entry with none
522+
* keeps its `${result.*}` reading until the spec closes the slot
523+
* (objectstack#27948, ruling A, step 1).
521524
*
522525
* Derived, so an entry is an `I18nLabel` — a string or an inline per-locale
523526
* map. The runner composes from strings only: the host's localizer
@@ -644,7 +647,8 @@ export type ToastHandler = (message: string, options?: {
644647
* An author's `outcomeMessages` / `successMessage` / `errorMessage` and an
645648
* action's own error are never in this table: the host localizes authored copy
646649
* before dispatch, and the runner only fills in their holes (`{{ }}` in
647-
* `successMessage`, `${result.*}` in `outcomeMessages`).
650+
* `successMessage`; `{{ }}`, or in a sentence with none `${result.*}`, in
651+
* `outcomeMessages`).
648652
*/
649653
const RUNNER_TEXT = {
650654
completedSuccessfully: {
@@ -686,10 +690,13 @@ export type NavigationHandler = (url: string, options?: {
686690
* for collecting ActionParam values before action execution.
687691
* Returns collected values, or null if cancelled.
688692
*
689-
* `interpolate` fills the `${...}` holes of the dialog's authored copy (the
690-
* action's `description`, each param's `helpText`) in the same template scope
691-
* the runner reads `confirmText` in — for a row dispatch, the row is `record`
692-
* (see `templateEvaluatorFor`). The runner cannot fill them itself before the
693+
* `interpolate` fills the holes of the dialog's authored copy (the action's
694+
* `description`, each param's `helpText`) over the record `confirmText` reads
695+
* — for a row dispatch, the row is `record` (see `templateEvaluatorFor`). A
696+
* sentence with a `{{ }}` hole is filled by the template engine over `record`
697+
* and `params`, exactly as `confirmText` is; one with none keeps its `${...}`
698+
* reading until the spec closes the slot (objectstack#27948, ruling A, step 1;
699+
* see `dialogCopyFiller`). The runner cannot fill them itself before the
693700
* call: the handler localizes that copy AFTER it receives it (a translation
694701
* bundle entry or an inline per-locale map), so the hole has to be filled on
695702
* the text the user will actually read (objectui#12967).
@@ -1705,11 +1712,10 @@ export class ActionRunner {
17051712
// The dialog's `description` / `helpText` read the dispatch's record
17061713
// as `record`: a row dispatch binds none in the runner's context
17071714
// (objectui#12967).
1708-
const templates = this.templateEvaluatorFor(action);
17091715
const collected = await this.paramCollectionHandler(
17101716
paramDefs,
17111717
action,
1712-
(text: string) => String(templates.evaluate(text) ?? ''),
1718+
this.dialogCopyFiller(action),
17131719
run,
17141720
);
17151721
if (lastRun) {
@@ -1901,8 +1907,8 @@ export class ActionRunner {
19011907
* (`ActionSchema.outcomeMessages`, objectui#11344):
19021908
*
19031909
* 1. `outcomeMessages[outcome]`, where `outcome` is the top-level `outcome`
1904-
* of the handler's return value — the payload `${result.*}` reads, so it
1905-
* is the same fact an author writes as `${result.outcome}`;
1910+
* of the handler's return value — the payload `{{ result.* }}` reads, so
1911+
* it is the same fact an author writes as `{{ result.outcome }}`;
19061912
* 2. `successMessage`;
19071913
* 3. the runner's own default text, in its translator's language.
19081914
*
@@ -1911,10 +1917,14 @@ export class ActionRunner {
19111917
* before dispatch — and both read the same payload,
19121918
* `readActionPayload(result.data)`, as `result`.
19131919
*
1914-
* Rung 1 has its `${result.*}` tokens filled in here, through the one token
1915-
* grammar and scope `onSuccess.navigate` reads (`substituteScopeTokens`).
1916-
* Only the sink differs: a toast is text, so a value is inserted as-is, where
1917-
* a URL position percent-encodes it.
1920+
* Rung 1 is in transition to the `template` dialect (objectstack#27948,
1921+
* ruling A, step 1), one dialect per sentence (`fillTransitionalCopy`): a
1922+
* sentence with a `{{ }}` hole is filled by the template engine over the
1923+
* same two roots as rung 2, `result` and `record`; one with none keeps its
1924+
* `${result.*}` tokens, filled through the one token grammar and scope
1925+
* `onSuccess.navigate` reads (`substituteScopeTokens`). Only the sink
1926+
* differs there: a toast is text, so a value is inserted as-is, where a URL
1927+
* position percent-encodes it.
19181928
*
19191929
* Rung 2 is a `template` slot (objectui#13367, the renderer half of
19201930
* objectstack#24814): a string or the `{ dialect: 'template', source }`
@@ -1947,18 +1957,18 @@ export class ActionRunner {
19471957
&& Object.prototype.hasOwnProperty.call(outcomeMessages, outcome)
19481958
? (outcomeMessages as Record<string, unknown>)[outcome]
19491959
: undefined;
1960+
const resultRoots = { result: payload, record: this.dispatchRecord(action) };
19501961
if (typeof outcomeCopy === 'string' && outcomeCopy.trim() !== '') {
1951-
return substituteScopeTokens(outcomeCopy, { result: payload }, (value) => value);
1962+
return fillTransitionalCopy(
1963+
outcomeCopy,
1964+
(source) => fillTemplateHoles(source, resultRoots, this.displayLocale?.(), this.tenantCurrency?.()),
1965+
(source) => substituteScopeTokens(source, { result: payload }, (value) => value),
1966+
);
19521967
}
19531968
const successCopy = actionCopySource(action.successMessage);
19541969
if (successCopy !== undefined && successCopy.trim() !== '') {
19551970
return hasTemplateHoles(successCopy)
1956-
? fillTemplateHoles(
1957-
successCopy,
1958-
{ result: payload, record: this.dispatchRecord(action) },
1959-
this.displayLocale?.(),
1960-
this.tenantCurrency?.(),
1961-
)
1971+
? fillTemplateHoles(successCopy, resultRoots, this.displayLocale?.(), this.tenantCurrency?.())
19621972
: successCopy;
19631973
}
19641974
return this.runnerText(RUNNER_TEXT.completedSuccessfully);
@@ -1989,15 +1999,41 @@ export class ActionRunner {
19891999
const text = actionCopySource(declared);
19902000
if (text === undefined) return '';
19912001
if (!hasTemplateHoles(text)) return text;
2002+
return fillTemplateHoles(text, this.recordCopyRoots(action), this.displayLocale?.(), this.tenantCurrency?.());
2003+
}
2004+
2005+
/**
2006+
* The roots a dispatch's pre-run copy fills its `{{ }}` holes over —
2007+
* `confirmText`, and the param dialog's `description` / `helpText`: `record`,
2008+
* the record the action runs against (`dispatchRecord`), and `params`, the
2009+
* action's static params object when it has one, without the row stash (the
2010+
* dialog's collected values do not exist yet).
2011+
*/
2012+
private recordCopyRoots(action: ActionDef): Record<string, unknown> {
19922013
const params = action.params;
19932014
const staticParams = params && typeof params === 'object' && !Array.isArray(params)
19942015
? Object.fromEntries(Object.entries(params).filter(([key]) => key !== '_rowRecord'))
19952016
: undefined;
1996-
return fillTemplateHoles(
2017+
return { record: this.dispatchRecord(action), params: staticParams };
2018+
}
2019+
2020+
/**
2021+
* The `interpolate` a param-collection handler receives: it fills the
2022+
* dialog's `description` and each param's `helpText`, on the text the user
2023+
* reads (the handler localizes first). Both slots are in transition to the
2024+
* `template` dialect (objectstack#27948, ruling A, step 1), one dialect per
2025+
* sentence (`fillTransitionalCopy`): a sentence with a `{{ }}` hole is
2026+
* filled by the template engine over `recordCopyRoots`, exactly as
2027+
* `confirmText` is — so the confirm question an author moves from
2028+
* `confirmText` to `description` reads the same — and one with none keeps
2029+
* its `${…}` reading through `templateEvaluatorFor` (objectui#12967).
2030+
*/
2031+
private dialogCopyFiller(action: ActionDef): (text: string) => string {
2032+
const templates = this.templateEvaluatorFor(action);
2033+
return (text: string) => fillTransitionalCopy(
19972034
text,
1998-
{ record: this.dispatchRecord(action), params: staticParams },
1999-
this.displayLocale?.(),
2000-
this.tenantCurrency?.(),
2035+
(source) => fillTemplateHoles(source, this.recordCopyRoots(action), this.displayLocale?.(), this.tenantCurrency?.()),
2036+
(source) => String(templates.evaluate(source) ?? ''),
20012037
);
20022038
}
20032039

@@ -2996,8 +3032,9 @@ export class ActionRunner {
29963032
// there would widen the authorable surface with nothing behind it and
29973033
// silently blank the token instead of leaving the author's mistake visible.
29983034
//
2999-
// The success toast's `outcomeMessages` copy is the one other caller of the
3000-
// grammar, through `substituteScopeTokens` directly (`composeSuccessMessage`):
3035+
// The success toast's holeless `outcomeMessages` copy is the one other
3036+
// caller of the grammar, through `substituteScopeTokens` directly
3037+
// (`composeSuccessMessage`, until objectstack#27948's step 2 retires it):
30013038
// `result` only, because that is the one scope the contract declares for the
30023039
// copy, and no encoding, because a toast is text.
30033040
const scopes: Record<string, unknown> = { param: params, ctx: this.buildInterpolationContext() };
@@ -3047,10 +3084,11 @@ export class ActionRunner {
30473084
}
30483085

30493086
/**
3050-
* The evaluator a dispatch's authored copy is read through: the param
3051-
* dialog's `description` / `helpText`, via the handler's `interpolate`
3052-
* argument. (`confirmText` reads `{{ }}` holes only, over `dispatchRecord`,
3053-
* the same record this binds — see `confirmMessage`.)
3087+
* The evaluator a dispatch's authored `${…}` copy is read through: the
3088+
* param dialog's `description` / `helpText` in a sentence with no `{{ }}`
3089+
* hole, via the handler's `interpolate` argument (`dialogCopyFiller`).
3090+
* (`confirmText` reads `{{ }}` holes only, over `dispatchRecord`, the same
3091+
* record this binds — see `confirmMessage`.)
30543092
*
30553093
* One rule for every door (objectui#12967): the record the action runs
30563094
* against is `record`. The record header binds it in the runner's context
@@ -3199,7 +3237,8 @@ export function readOnSuccessNavigation(value: unknown): OnSuccessNavigation | n
31993237
/**
32003238
* The runner's ONE `${scope.path}` token grammar — the substitution behind
32013239
* `interpolateTarget` (url / api targets and the `onSuccess.navigate` hop) and
3202-
* behind the success toast's `outcomeMessages` copy (`composeSuccessMessage`).
3240+
* behind the success toast's holeless `outcomeMessages` copy
3241+
* (`composeSuccessMessage`).
32033242
*
32043243
* The scope MAP defines the vocabulary: the pattern is built from its keys, so
32053244
* a token naming a scope the caller did not pass is left in the text exactly as

0 commit comments

Comments
 (0)