diff --git a/.changeset/34652-action-table-column-labels.md b/.changeset/34652-action-table-column-labels.md new file mode 100644 index 00000000000..c6f4154cf0c --- /dev/null +++ b/.changeset/34652-action-table-column-labels.md @@ -0,0 +1,24 @@ +--- +'@objectstack/spec': minor +'@objectstack/lint': patch +'@objectstack/platform-objects': patch +'@object-ui/i18n': patch +--- + +feat(spec, lint, i18n): an action answer table's column headers have a translation bundle key + +Clause-②: yes (widening) — `ActionResultDialogTranslationSchema` and the action `preflight` translation node accept a new optional `columns` map, `columns..` (both keys literal, dots included), beside `fields`; every bundle that parsed before parses unchanged and reads the same. +Metadata-protocol: added +Skills-docs: follow-up owed — skills/objectstack-i18n/SKILL.md + +A `format: 'table'` field in an action's `resultDialog.fields` or `preflight.fields` declares `columns: [{ path, label }]`, and each column's `label` is translatable, but no bundle key carried it, so a table's headers stayed in the authored language in every locale. The key is `objects.._actions..resultDialog.columns..` (and `….preflight.columns.…`; `globalActions..…` for an object-less action): + +```ts +resultDialog: { + fields: { rows: '逐行结果' }, + columns: { rows: { email: '邮箱', 'error.message': '未添加的原因' } }, +} +``` + +- `os i18n extract` lists one key per labelled column, `os validate` refuses a column key that names no declared table field or column (`translation-target-unknown`), and `resolveActionResultDialog` / `resolveActionPreflight` (so `translateAction` and the served metadata) and the console's `useObjectLabel` overlay the translated header; a column with no key keeps its authored label. +- The platform bundles carry the nine column headers of `sys_user.import_sso_users`'s result table in every shipped locale. diff --git a/content/docs/protocol/kernel/i18n-standard.mdx b/content/docs/protocol/kernel/i18n-standard.mdx index c947d2fee36..cf706e24f18 100644 --- a/content/docs/protocol/kernel/i18n-standard.mdx +++ b/content/docs/protocol/kernel/i18n-standard.mdx @@ -1155,6 +1155,7 @@ beneath an action entry are judged the same way under either. | `{action}.params.{param}.options.{value}` | an option's stored **`value`** in that param's inline `options` — a warning, as on a field. A param that references a `field` and declares no inline `options` takes the field's list when the dialog renders, so its option keys are not judged | | `{action}.outcomeMessages.{outcome}` | an outcome the action's own `outcomeMessages` declares | | `{action}.resultDialog.fields.{path}` | the literal `path` of a field the action's `resultDialog.fields[]` declares — dots included, so `client.secret` is one key | +| `{action}.resultDialog.columns.{path}.{column}` / `{action}.preflight.columns.{path}.{column}` | a column header of a table: `{path}` the literal `path` of a `format: 'table'` field in that block's `fields[]`, `{column}` the literal `path` of one of its `columns[]` — dots included at both levels, so `columns.rows["error.message"]` is two keys deep, not three | | `{action}.resultDialog.title` / `.description` / `.acknowledge` | an action that declares a `resultDialog`, whether or not the dialog sets that text itself — for an action that declares none, nothing reads the dialog's copy | | `apps.{app}` | an app declared, or one a `navigationContributions` entry anywhere in the artifact contributes into — including an app owned outside the artifact; under an app that is only contributed into, `apps.{app}.label` may be left out (the owning package's label survives the merge) | | `apps.{app}.navigation.{id}` | a navigation item `id` the app declares (nested `children` and `areas[]` included) or one contributed into it; under an app that is only contributed into, the contributed ids alone | diff --git a/content/docs/references/system/translation.mdx b/content/docs/references/system/translation.mdx index 8fa67c8231d..74ea9ae48be 100644 --- a/content/docs/references/system/translation.mdx +++ b/content/docs/references/system/translation.mdx @@ -34,6 +34,7 @@ Translations for an action result dialog | **description** | `string` | optional | Translated result dialog description | | **acknowledge** | `string` | optional | Translated acknowledge button label | | **fields** | `Record` | optional | Result field labels keyed by the literal field path declared in the action metadata (keys may contain dots) | +| **columns** | `Record>` | optional | Table column header labels: keyed by the literal path of a `format: 'table'` field, then by the literal path of one of its `columns[]` (keys may contain dots) | --- @@ -136,8 +137,8 @@ Translation data for a single field | **cancelText** | `string` | optional | Translated label of the dismiss button on the action's confirm or param dialog (the action must declare `confirmText` or `params`) | | **outcomeMessages** | `Record` | optional | Translated success copy per handler outcome, keyed by the snake_case outcome name the action's `outcomeMessages` declares | | **params** | `Record }>` | optional | Action parameter translations keyed by parameter name | -| **resultDialog** | `{ title?: string; description?: string; acknowledge?: string; fields?: Record }` | optional | Translations for the action result dialog | -| **preflight** | `{ fields?: Record }` | optional | Translations for the action preflight panel | +| **resultDialog** | `{ title?: string; description?: string; acknowledge?: string; fields?: Record; … }` | optional | Translations for the action result dialog | +| **preflight** | `{ fields?: Record; columns?: Record> }` | optional | Translations for the action preflight panel | ### Nested Shape: `ObjectTranslationData._sections[string]` @@ -241,8 +242,8 @@ Translation data for a single object | **cancelText** | `string` | optional | Translated label of the dismiss button on the action's confirm or param dialog (the action must declare `confirmText` or `params`) | | **outcomeMessages** | `Record` | optional | Translated success copy per handler outcome, keyed by the snake_case outcome name the action's `outcomeMessages` declares | | **params** | `Record }>` | optional | Action parameter translations keyed by parameter name | -| **resultDialog** | `{ title?: string; description?: string; acknowledge?: string; fields?: Record }` | optional | Translations for the action result dialog | -| **preflight** | `{ fields?: Record }` | optional | Translations for the action preflight panel | +| **resultDialog** | `{ title?: string; description?: string; acknowledge?: string; fields?: Record; … }` | optional | Translations for the action result dialog | +| **preflight** | `{ fields?: Record; columns?: Record> }` | optional | Translations for the action preflight panel | ### Nested Shape: `PlatformTranslationData.dashboards[string]` @@ -421,8 +422,8 @@ Translation data for a single object | **cancelText** | `string` | optional | Translated label of the dismiss button on the action's confirm or param dialog (the action must declare `confirmText` or `params`) | | **outcomeMessages** | `Record` | optional | Translated success copy per handler outcome, keyed by the snake_case outcome name the action's `outcomeMessages` declares | | **params** | `Record }>` | optional | Action parameter translations keyed by parameter name | -| **resultDialog** | `{ title?: string; description?: string; acknowledge?: string; fields?: Record }` | optional | Translations for the action result dialog | -| **preflight** | `{ fields?: Record }` | optional | Translations for the action preflight panel | +| **resultDialog** | `{ title?: string; description?: string; acknowledge?: string; fields?: Record; … }` | optional | Translations for the action result dialog | +| **preflight** | `{ fields?: Record; columns?: Record> }` | optional | Translations for the action preflight panel | ### Nested Shape: `ServedTranslationData.dashboards[string]` @@ -664,8 +665,8 @@ Translation data for a single object | **cancelText** | `string` | optional | Translated label of the dismiss button on the action's confirm or param dialog (the action must declare `confirmText` or `params`) | | **outcomeMessages** | `Record` | optional | Translated success copy per handler outcome, keyed by the snake_case outcome name the action's `outcomeMessages` declares | | **params** | `Record }>` | optional | Action parameter translations keyed by parameter name | -| **resultDialog** | `{ title?: string; description?: string; acknowledge?: string; fields?: Record }` | optional | Translations for the action result dialog | -| **preflight** | `{ fields?: Record }` | optional | Translations for the action preflight panel | +| **resultDialog** | `{ title?: string; description?: string; acknowledge?: string; fields?: Record; … }` | optional | Translations for the action result dialog | +| **preflight** | `{ fields?: Record; columns?: Record> }` | optional | Translations for the action preflight panel | ### Nested Shape: `TranslationData.dashboards[string]` @@ -876,8 +877,8 @@ Translation data for a single object | **cancelText** | `string` | optional | Translated label of the dismiss button on the action's confirm or param dialog (the action must declare `confirmText` or `params`) | | **outcomeMessages** | `Record` | optional | Translated success copy per handler outcome, keyed by the snake_case outcome name the action's `outcomeMessages` declares | | **params** | `Record }>` | optional | Action parameter translations keyed by parameter name | -| **resultDialog** | `{ title?: string; description?: string; acknowledge?: string; fields?: Record }` | optional | Translations for the action result dialog | -| **preflight** | `{ fields?: Record }` | optional | Translations for the action preflight panel | +| **resultDialog** | `{ title?: string; description?: string; acknowledge?: string; fields?: Record; … }` | optional | Translations for the action result dialog | +| **preflight** | `{ fields?: Record; columns?: Record> }` | optional | Translations for the action preflight panel | ### Nested Shape: `TranslationItem.dashboards[string]` diff --git a/content/docs/ui/translations.mdx b/content/docs/ui/translations.mdx index 4d3fc2d0fd9..a155092825f 100644 --- a/content/docs/ui/translations.mdx +++ b/content/docs/ui/translations.mdx @@ -76,6 +76,7 @@ export default defineStack({ | Bulk-action copy on a list view (button, confirm prompt, dialog fields) | `objects.._views..bulkActions..label` / `.confirmText` / `.confirmLabel` / `.params..label` / `.help` / `.placeholder` — a bulk param's hint is `help`, not `helpText` | | Action labels, confirm text, success messages, disabled reasons, param dialog submit labels, confirm and param dialog dismiss labels | `objects.._actions.` | | Action result dialogs (title / description / acknowledge / field labels) | `objects.._actions..resultDialog` | +| Column headers of a table in an action's result dialog or preflight panel | `objects.._actions..resultDialog.columns..` / `.preflight.columns..` — a sibling of `fields`, both paths written literally, dots included | | Form sections | `objects.._sections.
` | | Custom validation-rule messages | `objects.._validations..message` | | App navigation | `apps..navigation..label` | @@ -159,7 +160,9 @@ is resolved by this one rule. `resultDialog` shown by actions like `create_user` (temporary password), 2FA backup codes, and OAuth client-secret rotation carries its own `_actions..resultDialog` slot (`title` / `description` / `acknowledge` -and `fields` keyed by the literal result-field path, e.g. `"user.email"`). +and `fields` keyed by the literal result-field path, e.g. `"user.email"`; a +`format: 'table'` field's column headers sit beside `fields` under +`columns..`). `os i18n extract` emits these keys; the shipped platform dialogs ship en / zh-CN / ja-JP / es-ES copy. Separately, **platform notification and storage strings localize to the recipient's locale** — collaboration diff --git a/packages/lint/src/i18n-walk.test.ts b/packages/lint/src/i18n-walk.test.ts index 4e19a0b2bef..3d474d43049 100644 --- a/packages/lint/src/i18n-walk.test.ts +++ b/packages/lint/src/i18n-walk.test.ts @@ -153,3 +153,72 @@ describe('collectExpectedEntries — preflight field labels', () => { expect(preflightKeys(['objects', 'sys_package', '_actions', 'install_bare'])).toEqual([]); }); }); + +/** + * [#34652] `resultDialog.columns..` and + * `preflight.columns..` — one key per labelled column of a + * `format: 'table'` field, beside the field's own `fields.` key, both + * levels keyed by the literal path (a dotted path stays ONE segment). + */ +describe('collectExpectedEntries — answer table column labels', () => { + const table = { + path: 'rows', + label: 'Result per row', + format: 'table', + columns: [ + { path: 'email', label: 'Email' }, + { path: 'error.message', label: { en: 'Not added because', 'zh-CN': '未添加的原因' } }, + { path: 'row', format: 'json' }, + ], + }; + const stack = { + objects: [ + { + name: 'sys_user', + label: 'User', + fields: {}, + actions: [ + { + name: 'import_users', + label: 'Import', + type: 'api', + params: [{ name: 'csv', type: 'text' }], + resultDialog: { title: 'Done', fields: [{ path: 'summary.added', label: 'Added' }, table] }, + preflight: { read: { url: '/api/v1/x' }, fields: [table] }, + }, + ], + }, + ], + }; + const entries = collectExpectedEntries(stack, { warnedGroups: new Set() }); + const root = ['objects', 'sys_user', '_actions', 'import_users']; + const blockKeys = (block: string) => + entries + .filter((e) => root.every((seg, i) => e.path[i] === seg) && e.path[root.length] === block) + .map((e) => e.path.slice(root.length)); + + it('lists a key per labelled column beside the field key, an unlabelled column none', () => { + expect(blockKeys('resultDialog')).toEqual([ + // The optional prose slots are listed whether authored or not. + ['resultDialog', 'title'], + ['resultDialog', 'description'], + ['resultDialog', 'acknowledge'], + ['resultDialog', 'fields', 'summary.added'], + ['resultDialog', 'fields', 'rows'], + ['resultDialog', 'columns', 'rows', 'email'], + ['resultDialog', 'columns', 'rows', 'error.message'], + ]); + const email = entries.find((e) => e.path.join('\u0000') === [...root, 'resultDialog', 'columns', 'rows', 'email'].join('\u0000')); + expect(email).toMatchObject({ sourceValue: 'Email', inline: 'Email', source: 'action', objectName: 'sys_user' }); + const reason = entries.find((e) => e.path.join('\u0000') === [...root, 'resultDialog', 'columns', 'rows', 'error.message'].join('\u0000')); + expect(reason?.inlineLocales).toEqual({ en: 'Not added because', 'zh-CN': '未添加的原因' }); + }); + + it('lists the same column keys under a preflight table field', () => { + expect(blockKeys('preflight')).toEqual([ + ['preflight', 'fields', 'rows'], + ['preflight', 'columns', 'rows', 'email'], + ['preflight', 'columns', 'rows', 'error.message'], + ]); + }); +}); diff --git a/packages/lint/src/i18n-walk.ts b/packages/lint/src/i18n-walk.ts index 225c5f24cf3..18e669bec75 100644 --- a/packages/lint/src/i18n-walk.ts +++ b/packages/lint/src/i18n-walk.ts @@ -97,12 +97,15 @@ * objects.._actions..params..options. * objects.._actions..resultDialog.title / .description / .acknowledge * objects.._actions..resultDialog.fields. + * objects.._actions..resultDialog.columns.. * objects.._actions..preflight.fields. + * objects.._actions..preflight.columns.. * globalActions..label / .description / .confirmText / .successMessage * / .disabledReason / .submitText (beside a non-empty `params`) * / .cancelText (beside `confirmText` or a non-empty `params`) * globalActions..outcomeMessages. * globalActions..params..* / .resultDialog.* / .preflight.fields. + * / .preflight.columns.. * (same shape as object actions) * apps..label / .description * apps..navigation..label @@ -767,8 +770,9 @@ function pushActionParams( } /** - * Emit `resultDialog.{title,description,acknowledge}` and - * `resultDialog.fields.` entries under an action's translation root. + * Emit `resultDialog.{title,description,acknowledge}`, + * `resultDialog.fields.` and `resultDialog.columns..` + * entries under an action's translation root. * Mirrors `ActionResultDialogTranslationSchema` in @objectstack/spec and the * client-side `actionResultDialog` resolver. Field entries are keyed by the * LITERAL result-field path (`"user.email"`) — the dot stays inside a single @@ -814,10 +818,37 @@ function pushActionResultDialog( if (!field || typeof field !== 'object') continue; if (typeof field.path !== 'string' || field.path.length === 0) continue; pushEntry(out, [...base, 'fields', field.path], field.label, kind, { objectName }); + pushAnswerTableColumns(out, base, field, kind, objectName); } } } +/** + * [#34652] Emit `columns..` entries beside `fields` under an + * answer block's root (`…resultDialog` or `…preflight`) — one per labelled + * column of a `format: 'table'` field. Both levels are keyed by the LITERAL + * path (`"error.message"` is one segment), the address + * `ActionResultDialogTranslationSchema.columns` declares and + * `resolveActionResultDialog` / `resolveActionPreflight` read. A column with + * no `label` draws its `path` as the header and gets no key, as a field row + * with no `label` gets none; the format is not re-judged here — a `columns` + * list beside any other format is refused at parse. + */ +function pushAnswerTableColumns( + out: ExpectedEntry[], + blockRoot: string[], + field: any, + kind: ExpectedEntry['source'], + objectName?: string, +): void { + if (!Array.isArray(field.columns)) return; + for (const column of field.columns) { + if (!column || typeof column !== 'object') continue; + if (typeof column.path !== 'string' || column.path.length === 0) continue; + pushEntry(out, [...blockRoot, 'columns', field.path, column.path], column.label, kind, { objectName }); + } +} + /** * Emit `preflight.fields.` entries under an action's translation root — * one per field the action's `preflight.fields[]` declares, keyed by the @@ -840,6 +871,7 @@ function pushActionPreflight( if (!field || typeof field !== 'object') continue; if (typeof field.path !== 'string' || field.path.length === 0) continue; pushEntry(out, [...actionRoot, 'preflight', 'fields', field.path], field.label, kind, { objectName }); + pushAnswerTableColumns(out, [...actionRoot, 'preflight'], field, kind, objectName); } } diff --git a/packages/lint/src/rule-explanations.ts b/packages/lint/src/rule-explanations.ts index c26e696a936..ba8ec972ca9 100644 --- a/packages/lint/src/rule-explanations.ts +++ b/packages/lint/src/rule-explanations.ts @@ -4314,7 +4314,9 @@ const TRANSLATION_TARGET_UNKNOWN_EXPLANATION: RuleExplanation = { 'outcome the action\'s own `outcomeMessages` declares; `resultDialog.title`, `.description` ' + 'and `.acknowledge` an action that declares a `resultDialog` at all; ' + '`resultDialog.fields.PATH` the literal `path` of a declared dialog field, dots included; ' + - '`preflight.fields.PATH` the literal `path` of a declared preflight field, dots included. A ' + + '`preflight.fields.PATH` the literal `path` of a declared preflight field, dots included; ' + + '`resultDialog.columns.PATH.COLUMN` and `preflight.columns.PATH.COLUMN` a `format: \'table\'` ' + + 'field\'s literal `path`, then the literal `path` of one of its `columns`. A ' + 'bundle translates what the action declares and cannot add an outcome or a dialog.', 'Not judged: a platform object in the registry, an object this stack only extends through ' + '`objectExtensions[]`, and a picklist it only extends through `picklistExtensions[]` — the ' + diff --git a/packages/lint/src/validate-translation-references.test.ts b/packages/lint/src/validate-translation-references.test.ts index 608dfae51fe..b1cbbd157c1 100644 --- a/packages/lint/src/validate-translation-references.test.ts +++ b/packages/lint/src/validate-translation-references.test.ts @@ -3865,7 +3865,15 @@ describe('validateTranslationReferences — keyed children of an action entry (# objectName: 'crm_env', type: 'api', target: '/api/v1/rotate', - resultDialog: { title: 'Secret', fields: [{ path: 'client.secret', label: 'Secret' }, { path: 'token' }] }, + resultDialog: { + title: 'Secret', + fields: [ + { path: 'client.secret', label: 'Secret' }, + { path: 'token' }, + // [#34652] A table field: its columns' headers are keyed under `resultDialog.columns`. + { path: 'rows', format: 'table', columns: [{ path: 'id', label: 'ID' }, { path: 'error.message', label: 'Why' }] }, + ], + }, }, { name: 'plain_env', label: 'Plain', objectName: 'crm_env', type: 'script', target: 'plainEnv' }, { @@ -3880,7 +3888,7 @@ describe('validateTranslationReferences — keyed children of an action entry (# label: 'Mint', type: 'api', target: '/api/v1/mint', - resultDialog: { fields: [{ path: 'token' }] }, + resultDialog: { fields: [{ path: 'token' }, { path: 'rows', format: 'table', columns: [{ path: 'id' }] }] }, }, // [#31885] A preflight panel with declared fields, bound and object-less, // and a bound one that declares none (its panel shows the answer as JSON). @@ -3893,7 +3901,11 @@ describe('validateTranslationReferences — keyed children of an action entry (# params: [{ name: 'version', label: 'Version', type: 'text' }], preflight: { read: { url: '/api/v1/upgrade-plan?version=${param.version}' }, - fields: [{ path: 'verdict.summary', label: 'Verdict' }, { path: 'findings' }], + fields: [ + { path: 'verdict.summary', label: 'Verdict' }, + { path: 'findings' }, + { path: 'steps', format: 'table', columns: [{ path: 'step.name', label: 'Step' }] }, + ], }, }, { @@ -3913,7 +3925,7 @@ describe('validateTranslationReferences — keyed children of an action entry (# params: [{ name: 'version', label: 'Version', type: 'text' }], preflight: { read: { url: '/api/v1/upgrade-plan?version=${param.version}' }, - fields: [{ path: 'findings', label: 'Findings' }], + fields: [{ path: 'findings', label: 'Findings' }, { path: 'steps', format: 'table', columns: [{ path: 'step.name' }] }], }, }, ], @@ -4206,6 +4218,65 @@ describe('validateTranslationReferences — keyed children of an action entry (# }); }); + /** + * [#34652] `resultDialog.columns..` and + * `preflight.columns..` — a table field's column headers, + * read by the resolvers for the declared table fields and their declared + * columns only. + */ + describe('resultDialog.columns / preflight.columns', () => { + it('refuses a column the table field does not list, quoting a dotted path as ONE key', () => { + const findings = validateTranslationReferences( + actionStack( + onEnv({ + rotate_secret: { resultDialog: { columns: { rows: { id: '编号', 'error.message': '原因', 'error.code': '代码' } } } }, + upgrade_env: { preflight: { columns: { steps: { 'step.name': '步骤', 'step.ghost': '幽灵' } } } }, + }), + ), + ); + expect(findings.map((f) => [f.rule, f.severity, f.path])).toEqual([ + [TRANSLATION_TARGET_UNKNOWN, 'error', `${ENV}.rotate_secret.resultDialog.columns.rows["error.code"]`], + [TRANSLATION_TARGET_UNKNOWN, 'error', `${ENV}.upgrade_env.preflight.columns.steps["step.ghost"]`], + ]); + expect(findings[0].message).toContain('does not list'); + }); + + it('refuses headers keyed to a field that is not a table, a field no row declares, or a block the action lacks', () => { + const findings = validateTranslationReferences( + actionStack( + onEnv({ + rotate_secret: { resultDialog: { columns: { 'client.secret': { id: '编号' }, ghost_rows: { id: '编号' } } } }, + plain_env: { preflight: { columns: { steps: { 'step.name': '步骤' } } } }, + }), + ), + ); + expect(findings.map((f) => [f.rule, f.severity, f.path])).toEqual([ + [TRANSLATION_TARGET_UNKNOWN, 'error', `${ENV}.rotate_secret.resultDialog.columns["client.secret"]`], + [TRANSLATION_TARGET_UNKNOWN, 'error', `${ENV}.rotate_secret.resultDialog.columns.ghost_rows`], + [TRANSLATION_TARGET_UNKNOWN, 'error', `${ENV}.plain_env.preflight.columns.steps`], + ]); + expect(findings[0].message).toContain("no `format: 'table'` field at that path"); + expect(findings[2].message).toContain('declares no `preflight`'); + }); + + it('accepts every declared column at both addresses (the control)', () => { + expect( + validateTranslationReferences( + actionStack({ + ...onEnv({ + rotate_secret: { resultDialog: { columns: { rows: { id: '编号', 'error.message': '原因' } } } }, + upgrade_env: { preflight: { columns: { steps: { 'step.name': '步骤' } } } }, + }), + globalActions: { + mint_token: { resultDialog: { columns: { rows: { id: '编号' } } } }, + upgrade_pkg: { preflight: { columns: { steps: { 'step.name': '步骤' } } } }, + }, + }), + ), + ).toEqual([]); + }); + }); + /** * The action-entry twin of the #13835 object-branch pin above: every key the * action translation shape declares — down into `params..*` and @@ -4311,7 +4382,7 @@ describe('validateTranslationReferences — keyed children of an action entry (# }, resultDialog: { kind: 'container', - why: 'a fixed-key node; its leaves and its keyed child `resultDialog.fields` are each judged below', + why: 'a fixed-key node; its leaves and its keyed children `resultDialog.fields` and `resultDialog.columns` are each judged below', }, 'resultDialog.title': { kind: 'reference-checked', @@ -4341,9 +4412,16 @@ describe('validateTranslationReferences — keyed children of an action entry (# suffix: '.resultDialog.fields.ghost_path', rule: TRANSLATION_TARGET_UNKNOWN, }, + 'resultDialog.columns': { + kind: 'reference-checked', + host: 'dialog', + ghost: { resultDialog: { columns: { rows: { ghost_column: 'x' } } } }, + suffix: '.resultDialog.columns.rows.ghost_column', + rule: TRANSLATION_TARGET_UNKNOWN, + }, preflight: { kind: 'container', - why: 'a fixed-key node; its one keyed child `preflight.fields` is judged below', + why: 'a fixed-key node; its keyed children `preflight.fields` and `preflight.columns` are judged below', }, 'preflight.fields': { kind: 'reference-checked', @@ -4352,6 +4430,13 @@ describe('validateTranslationReferences — keyed children of an action entry (# suffix: '.preflight.fields.ghost_path', rule: TRANSLATION_TARGET_UNKNOWN, }, + 'preflight.columns': { + kind: 'reference-checked', + host: 'preflight', + ghost: { preflight: { columns: { ghost_path: { 'step.name': 'x' } } } }, + suffix: '.preflight.columns.ghost_path', + rule: TRANSLATION_TARGET_UNKNOWN, + }, }; // The global action needs a param with inline options for the options ghost. @@ -4403,8 +4488,10 @@ describe('validateTranslationReferences — keyed children of an action entry (# outcomeMessages: address === 'bound' ? { archived: 'x' } : { up_to_date: 'x' }, params: { mode: { label: 'x', helpText: 'x', placeholder: 'x', options: { soft: 'x' } } }, }, - [dialog]: { resultDialog: { title: 'x', description: 'x', acknowledge: 'x', fields: { token: 'x' } } }, - [HOST.preflight[address]]: { preflight: { fields: { findings: 'x' } } }, + [dialog]: { + resultDialog: { title: 'x', description: 'x', acknowledge: 'x', fields: { token: 'x' }, columns: { rows: { id: 'x' } } }, + }, + [HOST.preflight[address]]: { preflight: { fields: { findings: 'x' }, columns: { steps: { 'step.name': 'x' } } } }, }; }; expect( diff --git a/packages/lint/src/validate-translation-references.ts b/packages/lint/src/validate-translation-references.ts index b52150aa1d2..d98ab48bd2f 100644 --- a/packages/lint/src/validate-translation-references.ts +++ b/packages/lint/src/validate-translation-references.ts @@ -2736,6 +2736,7 @@ interface ActionEntryContext { * | `resultDialog.fields.` | `resultDialog.fields[].path` | `resolveActionResultDialog` | * | `resultDialog.title` / `.description` / `.acknowledge` | the action's `resultDialog`, present at all | `resolveActionResultDialog` | * | `preflight.fields.` | `preflight.fields[].path` | `resolveActionPreflight` | + * | `resultDialog.columns..` / `preflight.columns..` | that field's `columns[].path` | `resolveActionResultDialog` / `resolveActionPreflight` | * | `submitText` | a non-empty `params` (the param dialog) | `translateAction` | * | `cancelText` | `confirmText` or a non-empty `params` (either dialog) | `translateAction` | * @@ -2765,6 +2766,8 @@ function checkActionEntry(findings: TranslationRefFinding[], ctx: ActionEntryCon checkActionResultDialogLeaves(findings, ctx); checkActionResultDialogFields(findings, ctx); checkActionPreflightFields(findings, ctx); + checkActionAnswerTableColumns(findings, ctx, 'resultDialog'); + checkActionAnswerTableColumns(findings, ctx, 'preflight'); checkActionSubmitText(findings, ctx); checkActionCancelText(findings, ctx); } @@ -3202,6 +3205,78 @@ function checkActionPreflightFields(findings: TranslationRefFinding[], ctx: Acti } } +/** + * [#34652] `resultDialog.columns..` and + * `preflight.columns..` — a table field's column header + * labels, keyed by the LITERAL `path` of a field the block's `fields[]` + * declares and then the LITERAL `path` of one of that field's `columns[]` + * (dots included at both levels). + * + * The resolvers map over the declared fields and, inside a field, over its + * declared `columns[]`, looking each header up by those two paths; a field + * path no row declares, a field that declares no `columns` (any format but + * `table`), or a column path the field's `columns[]` does not list is never + * read. + */ +function checkActionAnswerTableColumns( + findings: TranslationRefFinding[], + ctx: ActionEntryContext, + block: 'resultDialog' | 'preflight', +): void { + const rawBlock = isRec(ctx.rawAction) ? ctx.rawAction[block] : undefined; + const rawColumns = asRecord(isRec(rawBlock) ? rawBlock.columns : undefined); + const rawFieldPaths = Object.keys(rawColumns); + if (rawFieldPaths.length === 0) return; + + const declaredBlock = isRec(ctx.action[block]) ? ctx.action[block] : undefined; + const tables = new Map>(); + for (const field of declaredBlock && Array.isArray(declaredBlock.fields) ? declaredBlock.fields : []) { + if (!isRec(field) || typeof field.path !== 'string' || !Array.isArray(field.columns)) continue; + const columnPaths = new Set(); + for (const column of field.columns) { + if (isRec(column) && typeof column.path === 'string') columnPaths.add(column.path); + } + tables.set(field.path, columnPaths); + } + + const noun = block === 'resultDialog' ? 'result' : 'preflight'; + for (const fieldPath of rawFieldPaths) { + const fieldMember = `${ctx.path}.${block}.columns${memberPath(fieldPath)}`; + const columns = tables.get(fieldPath); + if (!columns) { + findings.push({ + severity: TRANSLATION_TARGET_UNKNOWN_SEVERITY, + rule: TRANSLATION_TARGET_UNKNOWN, + where: `${ctx.where} · ${noun} table "${fieldPath}"`, + path: fieldMember, + message: !declaredBlock + ? `Headers are keyed to ${noun} field "${fieldPath}", but ${ctx.subject} declares no ` + + `\`${block}\`, so nothing reads them.` + : `Headers are keyed to ${noun} field "${fieldPath}", but ${ctx.subject}'s \`${block}.fields\` ` + + `has no \`format: 'table'\` field at that path, so they are never shown.` + + suggest(fieldPath, tables.keys()), + hint: + `Key the headers by the literal \`path\` of a table field (dots included), or drop them.`, + }); + continue; + } + for (const columnPath of Object.keys(asRecord(rawColumns[fieldPath]))) { + if (columns.has(columnPath)) continue; + findings.push({ + severity: TRANSLATION_TARGET_UNKNOWN_SEVERITY, + rule: TRANSLATION_TARGET_UNKNOWN, + where: `${ctx.where} · ${noun} table "${fieldPath}" · column "${columnPath}"`, + path: `${fieldMember}${memberPath(columnPath)}`, + message: + `A header is keyed to column "${columnPath}" of ${noun} table "${fieldPath}", which its ` + + `\`columns\` does not list, so it is never shown.` + + suggest(columnPath, columns), + hint: `Match the key to a declared column's literal \`path\` (dots included), or drop it.`, + }); + } + } +} + /** A record key as a config-path member — bracketed when it is not an identifier. */ function memberPath(key: string): string { return /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(key) ? `.${key}` : `["${key}"]`; diff --git a/packages/platform-objects/src/apps/translations/ar.objects.generated.ts b/packages/platform-objects/src/apps/translations/ar.objects.generated.ts index 55e6d0fcdcf..3ceb1ff25ab 100644 --- a/packages/platform-objects/src/apps/translations/ar.objects.generated.ts +++ b/packages/platform-objects/src/apps/translations/ar.objects.generated.ts @@ -263,6 +263,19 @@ export const arObjects: NonNullable = { "summary.alreadyPending": "معلّق بالفعل، أُبلغ مجددًا", "summary.failed": "لم تتم الإضافة", rows: "النتيجة لكل صف" + }, + columns: { + rows: { + row: "الصف", + email: "البريد الإلكتروني", + ok: "نجح", + alreadyPending: "معلّق بالفعل، أُبلغ مجددًا", + "host.notified": "أُبلغت المؤسسة المستضيفة", + "host.reason": "سبب عدم الإبلاغ", + "error.message": "لم تتم الإضافة بسبب", + notApplied: "لم يُطبَّق (اضبطه في السجل)", + managerError: "المدير" + } } } }, diff --git a/packages/platform-objects/src/apps/translations/de.objects.generated.ts b/packages/platform-objects/src/apps/translations/de.objects.generated.ts index ff148fd61b1..d806c925f67 100644 --- a/packages/platform-objects/src/apps/translations/de.objects.generated.ts +++ b/packages/platform-objects/src/apps/translations/de.objects.generated.ts @@ -263,6 +263,19 @@ export const deObjects: NonNullable = { "summary.alreadyPending": "Bereits ausstehend, erneut benachrichtigt", "summary.failed": "Nicht hinzugefügt", rows: "Ergebnis pro Zeile" + }, + columns: { + rows: { + row: "Zeile", + email: "E-Mail", + ok: "Erfolgreich", + alreadyPending: "Bereits ausstehend, erneut benachrichtigt", + "host.notified": "Hosting-Organisation benachrichtigt", + "host.reason": "Warum nicht benachrichtigt", + "error.message": "Nicht hinzugefügt, weil", + notApplied: "Nicht übernommen (am Datensatz festlegen)", + managerError: "Vorgesetzte(r)" + } } } }, diff --git a/packages/platform-objects/src/apps/translations/en.objects.generated.ts b/packages/platform-objects/src/apps/translations/en.objects.generated.ts index 01dacfa65d8..6694705d4d7 100644 --- a/packages/platform-objects/src/apps/translations/en.objects.generated.ts +++ b/packages/platform-objects/src/apps/translations/en.objects.generated.ts @@ -263,6 +263,19 @@ export const enObjects: NonNullable = { "summary.alreadyPending": "Already pending, told again", "summary.failed": "Not added", rows: "Result per row" + }, + columns: { + rows: { + row: "Row", + email: "Email", + ok: "Succeeded", + alreadyPending: "Already pending, told again", + "host.notified": "Hosting organization told", + "host.reason": "Why not told", + "error.message": "Not added because", + notApplied: "Not applied (set these on the record)", + managerError: "Manager" + } } } }, diff --git a/packages/platform-objects/src/apps/translations/es-ES.objects.generated.ts b/packages/platform-objects/src/apps/translations/es-ES.objects.generated.ts index d3aaa149e99..b804e60dd5e 100644 --- a/packages/platform-objects/src/apps/translations/es-ES.objects.generated.ts +++ b/packages/platform-objects/src/apps/translations/es-ES.objects.generated.ts @@ -263,6 +263,19 @@ export const esESObjects: NonNullable = { "summary.alreadyPending": "Ya pendientes, avisados de nuevo", "summary.failed": "No añadidos", rows: "Resultado por fila" + }, + columns: { + rows: { + row: "Fila", + email: "Correo electrónico", + ok: "Correcto", + alreadyPending: "Ya pendiente, avisado de nuevo", + "host.notified": "Organización de alojamiento avisada", + "host.reason": "Por qué no se avisó", + "error.message": "No añadido porque", + notApplied: "No aplicado (configúralo en el registro)", + managerError: "Responsable" + } } } }, diff --git a/packages/platform-objects/src/apps/translations/fr.objects.generated.ts b/packages/platform-objects/src/apps/translations/fr.objects.generated.ts index 06778c96beb..1892d5a90fd 100644 --- a/packages/platform-objects/src/apps/translations/fr.objects.generated.ts +++ b/packages/platform-objects/src/apps/translations/fr.objects.generated.ts @@ -263,6 +263,19 @@ export const frObjects: NonNullable = { "summary.alreadyPending": "Déjà en attente, prévenus à nouveau", "summary.failed": "Non ajoutés", rows: "Résultat par ligne" + }, + columns: { + rows: { + row: "Ligne", + email: "E-mail", + ok: "Réussi", + alreadyPending: "Déjà en attente, prévenu à nouveau", + "host.notified": "Organisation d’hébergement prévenue", + "host.reason": "Pourquoi non prévenue", + "error.message": "Non ajouté car", + notApplied: "Non appliqué (à définir sur la fiche)", + managerError: "Responsable" + } } } }, diff --git a/packages/platform-objects/src/apps/translations/ja-JP.objects.generated.ts b/packages/platform-objects/src/apps/translations/ja-JP.objects.generated.ts index bc466437933..61e43042933 100644 --- a/packages/platform-objects/src/apps/translations/ja-JP.objects.generated.ts +++ b/packages/platform-objects/src/apps/translations/ja-JP.objects.generated.ts @@ -263,6 +263,19 @@ export const jaJPObjects: NonNullable = { "summary.alreadyPending": "保留中のため再通知", "summary.failed": "未追加", rows: "行ごとの結果" + }, + columns: { + rows: { + row: "行", + email: "メール", + ok: "成功", + alreadyPending: "保留中のため再通知", + "host.notified": "ホスティング組織に通知済み", + "host.reason": "通知しなかった理由", + "error.message": "追加されなかった理由", + notApplied: "未適用(レコードで設定してください)", + managerError: "上長" + } } } }, diff --git a/packages/platform-objects/src/apps/translations/ko.objects.generated.ts b/packages/platform-objects/src/apps/translations/ko.objects.generated.ts index 44d1c702a5f..ab25aae74b7 100644 --- a/packages/platform-objects/src/apps/translations/ko.objects.generated.ts +++ b/packages/platform-objects/src/apps/translations/ko.objects.generated.ts @@ -263,6 +263,19 @@ export const koObjects: NonNullable = { "summary.alreadyPending": "이미 대기 중, 다시 알림", "summary.failed": "추가되지 않음", rows: "행별 결과" + }, + columns: { + rows: { + row: "행", + email: "이메일", + ok: "성공", + alreadyPending: "이미 대기 중, 다시 알림", + "host.notified": "호스팅 조직에 알림", + "host.reason": "알리지 않은 이유", + "error.message": "추가되지 않은 이유", + notApplied: "적용되지 않음(레코드에서 설정)", + managerError: "관리자" + } } } }, diff --git a/packages/platform-objects/src/apps/translations/pt-BR.objects.generated.ts b/packages/platform-objects/src/apps/translations/pt-BR.objects.generated.ts index 954330ca772..8d40a6ab5af 100644 --- a/packages/platform-objects/src/apps/translations/pt-BR.objects.generated.ts +++ b/packages/platform-objects/src/apps/translations/pt-BR.objects.generated.ts @@ -263,6 +263,19 @@ export const ptBRObjects: NonNullable = { "summary.alreadyPending": "Já pendentes, avisados novamente", "summary.failed": "Não adicionados", rows: "Resultado por linha" + }, + columns: { + rows: { + row: "Linha", + email: "E-mail", + ok: "Sucesso", + alreadyPending: "Já pendente, avisado novamente", + "host.notified": "Organização de hospedagem avisada", + "host.reason": "Por que não foi avisada", + "error.message": "Não adicionado porque", + notApplied: "Não aplicado (defina no registro)", + managerError: "Gestor" + } } } }, diff --git a/packages/platform-objects/src/apps/translations/ru.objects.generated.ts b/packages/platform-objects/src/apps/translations/ru.objects.generated.ts index 95f841a0f57..f61e6c80a08 100644 --- a/packages/platform-objects/src/apps/translations/ru.objects.generated.ts +++ b/packages/platform-objects/src/apps/translations/ru.objects.generated.ts @@ -263,6 +263,19 @@ export const ruObjects: NonNullable = { "summary.alreadyPending": "Уже ожидают, уведомлены повторно", "summary.failed": "Не добавлено", rows: "Результат по строкам" + }, + columns: { + rows: { + row: "Строка", + email: "Эл. почта", + ok: "Успешно", + alreadyPending: "Уже ожидает, уведомлён повторно", + "host.notified": "Хостинг-организация уведомлена", + "host.reason": "Почему не уведомлена", + "error.message": "Не добавлен, потому что", + notApplied: "Не применено (задайте в записи)", + managerError: "Руководитель" + } } } }, diff --git a/packages/platform-objects/src/apps/translations/zh-CN.objects.generated.ts b/packages/platform-objects/src/apps/translations/zh-CN.objects.generated.ts index 713e40bab25..9d2792d9751 100644 --- a/packages/platform-objects/src/apps/translations/zh-CN.objects.generated.ts +++ b/packages/platform-objects/src/apps/translations/zh-CN.objects.generated.ts @@ -263,6 +263,19 @@ export const zhCNObjects: NonNullable = { "summary.alreadyPending": "已在待激活中,已再次通知", "summary.failed": "未添加", rows: "逐行结果" + }, + columns: { + rows: { + row: "行", + email: "邮箱", + ok: "成功", + alreadyPending: "已在待激活中,已再次通知", + "host.notified": "已通知托管组织", + "host.reason": "未通知的原因", + "error.message": "未添加的原因", + notApplied: "未应用(请在记录上设置)", + managerError: "上级" + } } } }, diff --git a/packages/platform-objects/src/apps/translations/zh-Hant.objects.generated.ts b/packages/platform-objects/src/apps/translations/zh-Hant.objects.generated.ts index b1b707dea97..dfba232d497 100644 --- a/packages/platform-objects/src/apps/translations/zh-Hant.objects.generated.ts +++ b/packages/platform-objects/src/apps/translations/zh-Hant.objects.generated.ts @@ -263,6 +263,19 @@ export const zhHantObjects: NonNullable = { "summary.alreadyPending": "已在待啟用中,已再次通知", "summary.failed": "未新增", rows: "逐列結果" + }, + columns: { + rows: { + row: "列", + email: "電子郵件", + ok: "成功", + alreadyPending: "已在待啟用中,已再次通知", + "host.notified": "已通知託管組織", + "host.reason": "未通知的原因", + "error.message": "未新增的原因", + notApplied: "未套用(請在記錄上設定)", + managerError: "上級" + } } } }, diff --git a/packages/spec/authorable-surface/system.json b/packages/spec/authorable-surface/system.json index 2652b2b5414..af65c7d8aec 100644 --- a/packages/spec/authorable-surface/system.json +++ b/packages/spec/authorable-surface/system.json @@ -14,6 +14,7 @@ "system/AccessControlConfig:maxAgeSeconds", "system/AccessControlConfig:publicAccess", "system/ActionResultDialogTranslation:acknowledge", + "system/ActionResultDialogTranslation:columns", "system/ActionResultDialogTranslation:description", "system/ActionResultDialogTranslation:fields", "system/ActionResultDialogTranslation:title", diff --git a/packages/spec/src/system/i18n-resolver.test.ts b/packages/spec/src/system/i18n-resolver.test.ts index 1c930bf44e2..217bdc8bd07 100644 --- a/packages/spec/src/system/i18n-resolver.test.ts +++ b/packages/spec/src/system/i18n-resolver.test.ts @@ -570,6 +570,134 @@ describe('resolveActionPreflight + translateAction', () => { }); }); +/** + * [#34652] `resultDialog.columns..` and + * `preflight.columns..` — the header labels of a + * `format: 'table'` field's `columns[]`, a SIBLING of `fields` keyed by the + * field's literal path and then the column's literal path (dots inside one + * key at both levels). A bundle with no column key answers as it did before. + */ +describe('answer table column labels (resultDialog.columns / preflight.columns)', () => { + const importUsers = { + name: 'import_users', + objectName: 'sys_user', + resultDialog: { + title: 'Import finished', + fields: [ + { path: 'summary.added', label: 'Added', format: 'text' }, + { + path: 'rows', + label: 'Result per row', + format: 'table', + columns: [ + { path: 'email', label: 'Email' }, + { path: 'error.message', label: 'Not added because' }, + { path: 'row', format: 'json' }, + ], + }, + ], + }, + preflight: { + read: { url: '/api/v1/x' }, + fields: [ + { path: 'plan', label: 'Plan', format: 'table', columns: [{ path: 'step.name', label: 'Step' }] }, + ], + }, + }; + + const bundle: TranslationBundle = { + en: { + objects: { + sys_user: { + _actions: { + import_users: { + resultDialog: { columns: { rows: { email: 'Email address' } } }, + }, + }, + }, + }, + }, + 'zh-CN': { + objects: { + sys_user: { + _actions: { + import_users: { + resultDialog: { + title: '导入完成', + fields: { rows: '逐行结果' }, + columns: { + rows: { email: '邮箱', 'error.message': '未添加的原因', row: '行' }, + // A field path the dialog does not declare: read by nothing. + ghost: { email: '幽灵' }, + }, + }, + preflight: { columns: { plan: { 'step.name': '步骤' } } }, + }, + }, + }, + }, + }, + }; + + it('overlays each declared column header in zh-CN, a dotted column path as ONE key', () => { + const out = resolveActionResultDialog(bundle, importUsers, { locale: 'zh-CN' }); + expect(out?.fields?.[1]).toEqual({ + path: 'rows', + label: '逐行结果', + format: 'table', + columns: [ + { path: 'email', label: '邮箱' }, + { path: 'error.message', label: '未添加的原因' }, + // A column with no authored label gains the translated one. + { path: 'row', label: '行', format: 'json' }, + ], + }); + // A field that declares no columns is untouched by the columns map. + expect(out?.fields?.[0]).toEqual({ path: 'summary.added', label: 'Added', format: 'text' }); + // Source spec is not mutated. + expect(importUsers.resultDialog.fields[1].columns?.[0].label).toBe('Email'); + }); + + it('reads the en bundle in en, and keeps the authored header where en carries no key', () => { + const out = resolveActionResultDialog(bundle, importUsers, { locale: 'en' }); + expect(out?.fields?.[1].columns?.map((c) => c.label)).toEqual(['Email address', 'Not added because', undefined]); + }); + + it('a bundle without any column key answers exactly as before (authored headers)', () => { + const noColumns: TranslationBundle = { + 'zh-CN': { objects: { sys_user: { _actions: { import_users: { resultDialog: { fields: { rows: '逐行结果' } } } } } } }, + }; + const out = resolveActionResultDialog(noColumns, importUsers, { locale: 'zh-CN' }); + expect(out?.fields?.[1]).toEqual({ ...importUsers.resultDialog.fields[1], label: '逐行结果' }); + expect(TranslationDataSchema.safeParse(noColumns['zh-CN']).success).toBe(true); + }); + + it('walks the fallback chain per column', () => { + const out = resolveActionResultDialog(bundle, importUsers, { locale: 'ja-JP', fallbackChain: ['zh-CN'] }); + expect(out?.fields?.[1].columns?.[1].label).toBe('未添加的原因'); + }); + + it('overlays a preflight table field\'s column headers the same way', () => { + const out = resolveActionPreflight(bundle, importUsers, { locale: 'zh-CN' }); + expect(out?.fields?.[0].columns).toEqual([{ path: 'step.name', label: '步骤' }]); + }); + + it('translateAction carries the translated column headers on both blocks', () => { + const out = translateAction(importUsers, bundle, { locale: 'zh-CN' }); + expect(out.resultDialog?.fields?.[1].columns?.[0].label).toBe('邮箱'); + expect(out.preflight?.fields?.[0].columns?.[0].label).toBe('步骤'); + }); + + it('the columns shape parses through TranslationDataSchema; a non-string header is refused', () => { + expect(TranslationDataSchema.safeParse(bundle['zh-CN']).success).toBe(true); + const flat = TranslationDataSchema.safeParse({ globalActions: { x: { resultDialog: { columns: { rows: '邮箱' } } } } }); + expect(flat.success).toBe(false); + expect(flat.error?.issues.map((i) => [i.code, i.path.join('.')])).toEqual([ + ['invalid_type', 'globalActions.x.resultDialog.columns.rows'], + ]); + }); +}); + describe('translateAction — description + params (the declared-and-linted keys)', () => { // The card's own zh-CN fixture: `TranslationItemSchema` declares every key // below and the translation linter validates them, so this bundle is what an diff --git a/packages/spec/src/system/i18n-resolver.ts b/packages/spec/src/system/i18n-resolver.ts index 1b76faae1a6..3cda2b6912e 100644 --- a/packages/spec/src/system/i18n-resolver.ts +++ b/packages/spec/src/system/i18n-resolver.ts @@ -51,7 +51,7 @@ * globalActions..label / .description / .confirmText / * .successMessage / .disabledReason / .submitText / .cancelText / * .outcomeMessages. / .params..* / .resultDialog.* / - * .preflight.fields. + * .preflight.fields. / .preflight.columns.. * * That is the declaration `TranslationDataSchema.globalActions` makes: global * translations are for object-less actions. A `globalActions` entry that names @@ -293,21 +293,35 @@ export interface ActionParamLike { [key: string]: unknown; } +/** + * One row of the fields an action shows from a server answer — the + * `{ path, label?, columns? }` row `resultDialog.fields` and + * `preflight.fields` share. `columns` is a `format: 'table'` field's cells, + * each with its own header `label` (#34652). + */ +interface AnswerFieldLike { + path: string; + label?: string; + columns?: Array<{ path: string; label?: string; [key: string]: unknown }>; + [key: string]: unknown; +} + /** Minimal result-dialog shape consumed by `resolveActionResultDialog`. */ export interface ResultDialogLike { title?: string; description?: string; acknowledge?: string; - fields?: Array<{ path: string; label?: string; [key: string]: unknown }>; + fields?: AnswerFieldLike[]; [key: string]: unknown; } /** * Minimal preflight shape consumed by `resolveActionPreflight` — the panel's - * `fields` rows, the same `{ path, label? }` row `resultDialog.fields` carries. + * `fields` rows, the same `{ path, label?, columns? }` row `resultDialog.fields` + * carries. */ export interface PreflightLike { - fields?: Array<{ path: string; label?: string; [key: string]: unknown }>; + fields?: AnswerFieldLike[]; [key: string]: unknown; } @@ -915,15 +929,44 @@ export function resolveActionConfirm( * Look up the translated `resultDialog` node for an action in a single * locale's data, at the action's one address ({@link actionTranslationNode}). * The node's `fields` record is keyed by the LITERAL result-field path - * (`"user.email"`), so it is indexed directly — never split on `.`. + * (`"user.email"`), and its `columns` record by that path and then the + * column's literal path, so both are indexed directly — never split on `.`. */ function lookupActionResultDialogNode( data: TranslationData | undefined, action: ActionLike, -): { title?: string; description?: string; acknowledge?: string; fields?: Record } | undefined { +): + | { + title?: string; + description?: string; + acknowledge?: string; + fields?: Record; + columns?: Record>; + } + | undefined { return actionTranslationNode(data, action)?.resultDialog; } +/** + * [#34652] Overlay a `format: 'table'` field's column header labels, each + * looked up by the column's literal `path` through `lookup` (which walks the + * locale chain). A column with no translated string keeps its authored + * `label` — an inline per-locale map included — and a field that declares no + * `columns` is answered as the same reference. + */ +function overlayAnswerColumnLabels( + field: F, + lookup: (columnPath: string) => string | undefined, +): F { + if (!Array.isArray(field.columns)) return field; + const columns = field.columns.map((column) => { + if (!column || typeof column.path !== 'string') return column; + const label = lookup(column.path); + return label !== undefined ? { ...column, label } : column; + }); + return { ...field, columns }; +} + function lookupActionResultDialogText( bundle: TranslationBundle | undefined, action: ActionLike, @@ -942,10 +985,12 @@ function lookupActionResultDialogText( /** * Resolve a translated copy of an action's `resultDialog`, overlaying - * `title` / `description` / `acknowledge` and per-field `label`s (keyed by - * the literal field path) when translations exist. Returns the original - * spec untouched (same reference) when the action has no `resultDialog`; - * otherwise a shallow copy with translated strings merged in. + * `title` / `description` / `acknowledge`, per-field `label`s (keyed by + * the literal field path) and a table field's column header `label`s (from + * `resultDialog.columns..`, #34652) when translations + * exist. Returns the original spec untouched (same reference) when the action + * has no `resultDialog`; otherwise a shallow copy with translated strings + * merged in. */ export function resolveActionResultDialog( bundle: TranslationBundle | undefined, @@ -965,7 +1010,10 @@ export function resolveActionResultDialog( const label = lookupActionResultDialogText(bundle, action, (n) => n.fields?.[field.path], opts) ?? field.label; - return label !== undefined ? { ...field, label } : field; + const withColumns = overlayAnswerColumnLabels(field, (columnPath) => + lookupActionResultDialogText(bundle, action, (n) => n.columns?.[field.path]?.[columnPath], opts), + ); + return label !== undefined ? { ...withColumns, label } : withColumns; }) : spec.fields; return { @@ -980,8 +1028,10 @@ export function resolveActionResultDialog( /** * Resolve a translated copy of an action's `preflight`, overlaying each * declared field's `label` from `…preflight.fields.` (keyed by the - * literal field path, indexed directly and never split on `.`), exactly as - * {@link resolveActionResultDialog} overlays `resultDialog.fields`. Returns the + * literal field path, indexed directly and never split on `.`) and a table + * field's column header labels from `…preflight.columns..`, + * exactly as {@link resolveActionResultDialog} overlays `resultDialog.fields` + * and `resultDialog.columns`. Returns the * original spec untouched (same reference) when the action has no `preflight` * or it declares no `fields` — the panel then shows the answer as JSON and * reads no label; otherwise a shallow copy with translated labels merged in. @@ -995,21 +1045,27 @@ export function resolveActionPreflight( if (!spec || !Array.isArray(spec.fields)) return spec; const fields = spec.fields.map((field) => { if (!field || typeof field.path !== 'string') return field; - const label = lookupActionPreflightFieldLabel(bundle, action, field.path, opts) ?? field.label; - return label !== undefined ? { ...field, label } : field; + const label = + lookupActionPreflightText(bundle, action, (n) => n.fields?.[field.path], opts) ?? field.label; + const withColumns = overlayAnswerColumnLabels(field, (columnPath) => + lookupActionPreflightText(bundle, action, (n) => n.columns?.[field.path]?.[columnPath], opts), + ); + return label !== undefined ? { ...withColumns, label } : withColumns; }); return { ...spec, fields }; } -function lookupActionPreflightFieldLabel( +function lookupActionPreflightText( bundle: TranslationBundle | undefined, action: ActionLike, - path: string, + pick: (node: NonNullable>['preflight']>) => string | undefined, opts?: ResolveOptions, ): string | undefined { if (!bundle) return undefined; for (const code of localeChain(opts)) { - const value = actionTranslationNode(pickData(bundle, code), action)?.preflight?.fields?.[path]; + const node = actionTranslationNode(pickData(bundle, code), action)?.preflight; + if (!node) continue; + const value = pick(node); if (typeof value === 'string' && value.length > 0) return value; } return undefined; diff --git a/packages/spec/src/system/translation.zod.ts b/packages/spec/src/system/translation.zod.ts index bf3c2385df4..33b6bcbd203 100644 --- a/packages/spec/src/system/translation.zod.ts +++ b/packages/spec/src/system/translation.zod.ts @@ -265,6 +265,20 @@ export const FieldTranslationSchema = lazySchema(() => strictObject({ export type FieldTranslation = z.input; +/** + * The header labels of an answer table's columns, shared by an action's + * `resultDialog` and `preflight` translation nodes: field path → column path + * → translated label. A field in either block whose `format` is `'table'` + * declares `columns: [{ path, label? }]` (`ui/action.zod.ts`), and each + * column's `label` is an `I18nLabel`; this map is its bundle key. Both levels + * are keyed by the LITERAL path from the action metadata — `"host.reason"` is + * one key, never two — so resolvers index each record directly. + * + * Module-local, like `ActionPreflightTranslationSchema`: a new named export + * would rewrite the published skills' reference indexes. + */ +const ActionAnswerColumnLabelsSchema = lazySchema(() => z.record(z.string(), z.record(z.string(), z.string()))); + /** * Action Result-Dialog Translation Schema * @@ -277,10 +291,18 @@ export type FieldTranslation = z.input; * …_actions..resultDialog.description * …_actions..resultDialog.acknowledge * …_actions..resultDialog.fields. + * …_actions..resultDialog.columns.. * * `fields` is keyed by the **literal** `resultDialog.fields[].path` from the * action metadata (e.g. `"user.email"`, `"temporaryPassword"`). Keys may * contain dots — resolvers must index the record directly, not split on `.`. + * + * `columns` carries the header labels of a `format: 'table'` field's + * `columns[]`: keyed first by the field's literal `path`, then by the + * column's literal `path` (`columns.rows["error.message"]`), both indexed + * directly. It is a SIBLING of `fields`, not a child of a field entry, so a + * `fields.` value stays the field's label string and every bundle that + * carries no column key reads exactly as before. */ export const ActionResultDialogTranslationSchema = lazySchema(() => strictObject({ surface: 'this action result dialog translation', @@ -292,6 +314,8 @@ export const ActionResultDialogTranslationSchema = lazySchema(() => strictObject acknowledge: z.string().optional().describe('Translated acknowledge button label'), fields: z.record(z.string(), z.string()).optional() .describe('Result field labels keyed by the literal field path declared in the action metadata (keys may contain dots)'), + columns: ActionAnswerColumnLabelsSchema.optional() + .describe("Table column header labels: keyed by the literal path of a `format: 'table'` field, then by the literal path of one of its `columns[]` (keys may contain dots)"), }).describe('Translations for an action result dialog')); export type ActionResultDialogTranslation = z.input; @@ -305,6 +329,7 @@ export type ActionResultDialogTranslation = z.input.preflight.fields. + * …_actions..preflight.columns.. * * `fields` is keyed exactly as `resultDialog.fields` is: by the **literal** * `preflight.fields[].path` from the action metadata (e.g. `"findings"`, @@ -327,6 +352,8 @@ const ActionPreflightTranslationSchema = lazySchema(() => strictObject({ }, { fields: z.record(z.string(), z.string()).optional() .describe('Preflight panel field labels keyed by the literal field path declared in the action metadata (keys may contain dots)'), + columns: ActionAnswerColumnLabelsSchema.optional() + .describe("Table column header labels, keyed as `resultDialog.columns` is: by the literal path of a `format: 'table'` field, then by the literal path of one of its `columns[]` (keys may contain dots)"), }).describe('Translations for an action preflight panel')); /** @@ -400,8 +427,9 @@ const actionTranslationSchema = (surface: string) => strictObject({ .describe('Translations for the action result dialog'), // `ActionSchema.preflight` (#31840) — the panel's field labels, keyed by // the literal `preflight.fields[].path` exactly as `resultDialog.fields` - // is; overlaid by `translateAction` (`resolveActionPreflight`) for the - // fields the action declares. + // is, and its table column headers under `columns` (#34652); overlaid by + // `translateAction` (`resolveActionPreflight`) for the fields and columns + // the action declares. preflight: ActionPreflightTranslationSchema.optional() .describe('Translations for the action preflight panel'), }); @@ -680,6 +708,7 @@ export const ObjectTranslationDataSchema = lazySchema(() => strictObject({ * objects.._actions..params..options. * objects.._actions..resultDialog.* * objects.._actions..preflight.fields. + * objects.._actions..preflight.columns.. */ _actions: z.record(z.string(), actionTranslationSchema('this object action translation')) .optional().describe('Action translations keyed by action name'), @@ -1209,6 +1238,7 @@ const appTranslationDataShape = () => ({ * globalActions..params..options. * globalActions..resultDialog.* * globalActions..preflight.fields. + * globalActions..preflight.columns.. */ globalActions: z.record(z.string(), actionTranslationSchema('this global action translation')) .optional().describe('Global action translations keyed by action name'), diff --git a/ui/packages/i18n/src/__tests__/useObjectLabel-actionResultDialog.test.tsx b/ui/packages/i18n/src/__tests__/useObjectLabel-actionResultDialog.test.tsx index 69b9bb731e9..4a08cf18c45 100644 --- a/ui/packages/i18n/src/__tests__/useObjectLabel-actionResultDialog.test.tsx +++ b/ui/packages/i18n/src/__tests__/useObjectLabel-actionResultDialog.test.tsx @@ -84,3 +84,97 @@ describe('useObjectLabel().actionResultDialog', () => { expect(result.current.actionResultDialog('sys_user', 'create_user', undefined)).toBeUndefined(); }); }); + +/** + * [objectstack#34652] A `format: 'table'` field's column headers, keyed + * `resultDialog.columns..` (and `preflight.columns…`) — + * a sibling of `fields`, both levels literal keys, the address the spec's + * `resolveActionResultDialog` / `resolveActionPreflight` read. + */ +describe('useObjectLabel() — answer table column headers', () => { + const tableSpec = { + title: 'Import finished', + fields: [ + { path: 'summary.added', label: 'Added', format: 'text' }, + { + path: 'rows', + label: 'Result per row', + format: 'table', + columns: [ + { path: 'email', label: 'Email' }, + { path: 'error.message', label: 'Not added because' }, + { path: 'row', format: 'json' }, + ], + }, + ], + }; + const node = (columns: Record | undefined) => ({ + setup: { + objects: { + sys_user: { + _actions: { + import_users: { + resultDialog: { fields: { rows: '逐行结果' }, ...(columns ? { columns } : {}) }, + ...(columns ? { preflight: { columns } } : {}), + }, + }, + }, + }, + }, + }); + + it('draws each declared column header from the zh-CN bundle, and the en bundle in en', async () => { + const { result } = renderHook( + () => ({ labels: useObjectLabel(), i18n: useObjectTranslation().i18n }), + { wrapper }, + ); + const { i18n } = result.current; + i18n.addResourceBundle( + 'zh-CN', + 'translation', + node({ rows: { email: '邮箱', 'error.message': '未添加的原因', row: '行', ghost: '幽灵' } }), + true, + true, + ); + i18n.addResourceBundle('en', 'translation', node({ rows: { email: 'Email address' } }), true, true); + + await i18n.changeLanguage('zh-CN'); + const zh = result.current.labels.actionResultDialog('sys_user', 'import_users', tableSpec); + expect(zh?.fields?.[1]).toEqual({ + path: 'rows', + label: '逐行结果', + format: 'table', + columns: [ + { path: 'email', label: '邮箱' }, + // A dotted column path is ONE literal key. + { path: 'error.message', label: '未添加的原因' }, + { path: 'row', label: '行', format: 'json' }, + ], + }); + // A row with no columns is untouched by the columns node. + expect(zh?.fields?.[0]).toEqual({ path: 'summary.added', label: 'Added', format: 'text' }); + const zhPreflight = result.current.labels.actionPreflight('sys_user', 'import_users', { fields: tableSpec.fields }); + expect(zhPreflight?.fields?.[1].columns).toEqual(zh?.fields?.[1].columns); + + await i18n.changeLanguage('en'); + const en = result.current.labels.actionResultDialog('sys_user', 'import_users', tableSpec); + expect(en?.fields?.[1].columns?.map((c: { label?: string }) => c.label)).toEqual([ + 'Email address', + 'Not added because', + undefined, + ]); + // Source spec is not mutated. + expect(tableSpec.fields[1].columns?.[0].label).toBe('Email'); + }); + + it('keeps every authored header when the bundle carries no column key', async () => { + const { result } = renderHook( + () => ({ labels: useObjectLabel(), i18n: useObjectTranslation().i18n }), + { wrapper }, + ); + result.current.i18n.addResourceBundle('zh-CN', 'translation', node(undefined), true, true); + await result.current.i18n.changeLanguage('zh-CN'); + const out = result.current.labels.actionResultDialog('sys_user', 'import_users', tableSpec); + expect(out?.fields?.[1]).toEqual({ ...tableSpec.fields[1], label: '逐行结果' }); + }); +}); diff --git a/ui/packages/i18n/src/useObjectLabel.ts b/ui/packages/i18n/src/useObjectLabel.ts index 47dcf10a7dc..0a5b1544d54 100644 --- a/ui/packages/i18n/src/useObjectLabel.ts +++ b/ui/packages/i18n/src/useObjectLabel.ts @@ -222,20 +222,23 @@ export function useObjectLabel() { : [`globalActions.${actionName}.${tail}`]; /** - * Fetch the `fields` node of an action's answer-showing block - * (`resultDialog` or `preflight`) WHOLE, with `returnObjects`. The node is - * keyed by the LITERAL field path from the action metadata, which may contain - * dots (`"user.email"`), so it is indexed directly and never resolved through - * a dotted i18next key. Undefined when no namespace carries an object node. + * Fetch the `fields` (or `columns`) node of an action's answer-showing block + * (`resultDialog` or `preflight`) WHOLE, with `returnObjects`. The `fields` + * node is keyed by the LITERAL field path from the action metadata, which + * may contain dots (`"user.email"`); the `columns` node by that path and then + * a table column's literal path (#34652). Both are indexed directly and never + * resolved through a dotted i18next key. Undefined when no namespace carries + * an object node. */ const readActionFieldsNode = ( objectName: string | undefined, actionName: string, block: 'resultDialog' | 'preflight', + member: 'fields' | 'columns' = 'fields', ): Record | undefined => { try { for (const ns of getAppNamespaces()) { - for (const suffix of actionSuffixes(objectName, actionName, `${block}.fields`)) { + for (const suffix of actionSuffixes(objectName, actionName, `${block}.${member}`)) { const node = t(`${ns}.${suffix}`, { returnObjects: true, defaultValue: null, @@ -257,19 +260,41 @@ export function useObjectLabel() { * literal `path`: a non-empty string replaces that row's `label`, a row with * none keeps its authored label (an inline per-locale map included), and a * node entry naming no declared row adds nothing. + * + * [#34652] A `format: 'table'` row's `columns[]` headers are overlaid the + * same way from the `columns` node (`columns..`), the key + * `@objectstack/spec`'s `resolveActionResultDialog` / `resolveActionPreflight` + * read: only declared columns, a non-empty string replacing that column's + * `label`, a column with none keeping its authored label. A row with no + * `columns` is the same reference. */ - const overlayActionFieldLabels = ( + const overlayActionFieldLabels = ( fields: F[] | undefined, labels: Record | undefined, + columnLabels?: Record, ): F[] | undefined => Array.isArray(fields) ? fields.map((field) => { if (!field || typeof field.path !== 'string') return field; const label = labels?.[field.path]; - return typeof label === 'string' && label.length > 0 ? { ...field, label } : field; + const withColumns = overlayColumnLabels(field, columnLabels?.[field.path]); + return typeof label === 'string' && label.length > 0 ? { ...withColumns, label } : withColumns; }) : fields; + const overlayColumnLabels = (field: F, labels: unknown): F => { + if (!Array.isArray(field.columns) || !labels || typeof labels !== 'object' || Array.isArray(labels)) return field; + const byPath = labels as Record; + const columns = field.columns.map((column: unknown) => { + if (!column || typeof column !== 'object') return column; + const path = (column as { path?: unknown }).path; + if (typeof path !== 'string') return column; + const label = byPath[path]; + return typeof label === 'string' && label.length > 0 ? { ...(column as object), label } : column; + }); + return { ...field, columns }; + }; + const fieldSuffixes = (objectName: string, fieldName: string): string[] => { const base = stripNamespace(objectName); return base !== objectName @@ -730,7 +755,8 @@ export function useObjectLabel() { /** * Resolve a translated copy of an action's post-success RESULT DIALOG - * (`title` / `description` / `acknowledge` + per-field labels). + * (`title` / `description` / `acknowledge` + per-field labels + a table + * field's column headers from `resultDialog.columns`). * Convention: `{ns}.objects.{objectName}._actions.{actionName}.resultDialog.*`; * with no key object, `{ns}.globalActions.{actionName}.resultDialog.*`. * Falls back to the metadata's literal strings. @@ -760,6 +786,7 @@ export function useObjectLabel() { const fields = overlayActionFieldLabels( spec.fields, readActionFieldsNode(objectName, actionName, 'resultDialog'), + readActionFieldsNode(objectName, actionName, 'resultDialog', 'columns'), ); return { ...spec, @@ -799,6 +826,7 @@ export function useObjectLabel() { fields: overlayActionFieldLabels( spec.fields, readActionFieldsNode(objectName, actionName, 'preflight'), + readActionFieldsNode(objectName, actionName, 'preflight', 'columns'), ), }; },