Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions .changeset/36530-titled-screen-node-label.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
'@objectstack/spec': minor
'@objectstack/lint': minor
'@object-ui/i18n': minor
'@object-ui/components': minor
---

feat(i18n): a flow screen with its own heading gets a translatable step name, `flows.FLOW.nodes.NODE_ID.label`

Clause-②: yes (widening)
Metadata-protocol: added

A screen node that sets its own `config.title` has a heading and a separate canvas label. Until now only the heading could be translated (`flows.FLOW.screens.NODE_ID.title`), so the label stayed in the authoring language. The docs flow embed and the Studio flow designer both draw that label.

- **New key accepted.** `objectstack validate` now accepts `flows.FLOW.nodes.NODE_ID.label` over a screen whose `config.title` is a non-empty string. A screen with no `config.title` is still refused there and pointed at `screens.NODE_ID.title`, because its heading is its label and one string keeps one key. An `approval` node is still pointed at `approvals.NODE_ID.label`.
- **Docs embed.** The `type: flow` embed (`element:metadata_viewer`) names a titled screen by its heading, translated where the bundle has the heading. When the heading holds a `{{ }}` hole, which a drawing cannot fill, the embed now names the screen by the new key, and falls back to the authored label only if the key is missing.
- **Studio designer.** The canvas draws a titled screen's label from the new key.
- **Untitled screen with a hole.** If a translated `screens.NODE_ID.title` contains a `{{ }}` hole, the embed and the canvas now draw the authored label rather than the raw template.
- **Coverage.** `os lint`'s i18n coverage and `os i18n extract` ask for the new key on a top-level screen whose authored heading holds a `{{ }}` hole. These are the screens the embed draws by their label.
- **One branch rule.** `@objectstack/spec/automation` exports `flowDecisionEdgeBranch`, `FlowDecisionEdgeBranch` and `FLOW_DECISION_DEFAULT_BRANCH_LABEL`. They decide which out-edges of a decision a drawing lists as branches. The docs embed's branch list and the i18n walk's folded branch targets both read them, so the two can no longer disagree.

Nothing to migrate. A bundle that does not use the new key keeps working.
8 changes: 4 additions & 4 deletions content/docs/references/system/translation.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ Translation data for a single object
| **screens** | `Record<string, { title?: string; description?: string; fields?: Record<string, object> }>` | optional | Screen translations keyed by screen node id (`FlowNode.id`, the client's `ScreenSpec.nodeId`) |
| **refusals** | `Record<string, { message?: string }>` | optional | Refusal translations keyed by the node id (`FlowNode.id`) of an `end` node declaring `outcome: 'refused'` |
| **approvals** | `Record<string, { label?: string }>` | optional | Approval-step translations keyed by the node id (`FlowNode.id`) of an `approval` node |
| **nodes** | `Record<string, { label?: string }>` | optional | Node-label translations keyed by node id (`FlowNode.id`) — every node other than a `screen` or an `approval` |
| **nodes** | `Record<string, { label?: string }>` | optional | Node-label translations keyed by node id (`FlowNode.id`) — every node other than an untitled `screen` or an `approval` |
| **notices** | `Record<string, { message?: string }>` | optional | Save-notice translations keyed by the node id (`FlowNode.id`) of a `save_notice` node |
| **records** | `Record<string, { fields?: Record<string, string> }>` | optional | Record-write text translations keyed by the node id (`FlowNode.id`) of a `create_record` / `update_record` node |

Expand Down Expand Up @@ -487,7 +487,7 @@ Translation data for a single object
| **screens** | `Record<string, { title?: string; description?: string; fields?: Record<string, object> }>` | optional | Screen translations keyed by screen node id (`FlowNode.id`, the client's `ScreenSpec.nodeId`) |
| **refusals** | `Record<string, { message?: string }>` | optional | Refusal translations keyed by the node id (`FlowNode.id`) of an `end` node declaring `outcome: 'refused'` |
| **approvals** | `Record<string, { label?: string }>` | optional | Approval-step translations keyed by the node id (`FlowNode.id`) of an `approval` node |
| **nodes** | `Record<string, { label?: string }>` | optional | Node-label translations keyed by node id (`FlowNode.id`) — every node other than a `screen` or an `approval` |
| **nodes** | `Record<string, { label?: string }>` | optional | Node-label translations keyed by node id (`FlowNode.id`) — every node other than an untitled `screen` or an `approval` |
| **notices** | `Record<string, { message?: string }>` | optional | Save-notice translations keyed by the node id (`FlowNode.id`) of a `save_notice` node |
| **records** | `Record<string, { fields?: Record<string, string> }>` | optional | Record-write text translations keyed by the node id (`FlowNode.id`) of a `create_record` / `update_record` node |

Expand Down Expand Up @@ -740,7 +740,7 @@ Translation data for a single object
| **screens** | `Record<string, { title?: string; description?: string; fields?: Record<string, object> }>` | optional | Screen translations keyed by screen node id (`FlowNode.id`, the client's `ScreenSpec.nodeId`) |
| **refusals** | `Record<string, { message?: string }>` | optional | Refusal translations keyed by the node id (`FlowNode.id`) of an `end` node declaring `outcome: 'refused'` |
| **approvals** | `Record<string, { label?: string }>` | optional | Approval-step translations keyed by the node id (`FlowNode.id`) of an `approval` node |
| **nodes** | `Record<string, { label?: string }>` | optional | Node-label translations keyed by node id (`FlowNode.id`) — every node other than a `screen` or an `approval` |
| **nodes** | `Record<string, { label?: string }>` | optional | Node-label translations keyed by node id (`FlowNode.id`) — every node other than an untitled `screen` or an `approval` |
| **notices** | `Record<string, { message?: string }>` | optional | Save-notice translations keyed by the node id (`FlowNode.id`) of a `save_notice` node |
| **records** | `Record<string, { fields?: Record<string, string> }>` | optional | Record-write text translations keyed by the node id (`FlowNode.id`) of a `create_record` / `update_record` node |

Expand Down Expand Up @@ -962,7 +962,7 @@ Translation data for a single object
| **screens** | `Record<string, { title?: string; description?: string; fields?: Record<string, object> }>` | optional | Screen translations keyed by screen node id (`FlowNode.id`, the client's `ScreenSpec.nodeId`) |
| **refusals** | `Record<string, { message?: string }>` | optional | Refusal translations keyed by the node id (`FlowNode.id`) of an `end` node declaring `outcome: 'refused'` |
| **approvals** | `Record<string, { label?: string }>` | optional | Approval-step translations keyed by the node id (`FlowNode.id`) of an `approval` node |
| **nodes** | `Record<string, { label?: string }>` | optional | Node-label translations keyed by node id (`FlowNode.id`) — every node other than a `screen` or an `approval` |
| **nodes** | `Record<string, { label?: string }>` | optional | Node-label translations keyed by node id (`FlowNode.id`) — every node other than an untitled `screen` or an `approval` |
| **notices** | `Record<string, { message?: string }>` | optional | Save-notice translations keyed by the node id (`FlowNode.id`) of a `save_notice` node |
| **records** | `Record<string, { fields?: Record<string, string> }>` | optional | Record-write text translations keyed by the node id (`FlowNode.id`) of a `create_record` / `update_record` node |

Expand Down
28 changes: 28 additions & 0 deletions packages/cli/test/i18n-flow-node-coverage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,34 @@ describe('what the walker harvests for the steps a docs flow embed draws (ruling
).toMatchObject({ sourceValue: 'Compute Next Due Date', source: 'flow' });
});

it('asks for a titled screen\'s label exactly where its heading holds a hole, which the embed then draws it by', () => {
const flow = {
name: 'welcome',
label: 'Welcome',
nodes: [
{ id: 'confirm', type: 'screen', label: 'Confirm' },
{ id: 'plain', type: 'screen', label: 'Plain step', config: { title: 'Welcome aboard' } },
{ id: 'greet', type: 'screen', label: 'Greeting step', config: { title: 'Hello {{ vars.name }}' } },
{
id: 'each',
type: 'loop',
label: 'Each',
config: {
collection: '{rows}',
body: { nodes: [{ id: 'inner', type: 'screen', label: 'Inner', config: { title: 'Row {{ row.name }}' } }] },
},
},
],
edges: [],
};
// An untitled screen is named by `screens.<id>.title`, a plain heading by that same key,
// and a nested screen is not drawn by the embed: only `greet` is asked.
expect(nodeKeys({ flows: [flow] })).toEqual(['flows.welcome.nodes.greet.label', 'flows.welcome.nodes.each.label']);
expect(
collectExpectedEntries({ flows: [flow] }).find((e) => e.path.join('.') === 'flows.welcome.nodes.greet.label'),
).toMatchObject({ sourceValue: 'Greeting step', inline: 'Greeting step', source: 'flow' });
});

it('skips a step with no id: nothing could address it', () => {
const flow = { ...opportunityApproval, nodes: [{ type: 'decision', label: 'Anonymous' }] };
expect(nodeKeys({ flows: [flow] })).toEqual([]);
Expand Down
51 changes: 27 additions & 24 deletions packages/lint/src/i18n-walk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ import {
import { FLOW_REGION_SLOTS_BY_TYPE, flowScreenFieldOptionKey, isFlowTextEnvelopeShaped, templateSlotSource } from '@objectstack/spec/automation';
import { DEFAULT_METADATA_TYPE_REGISTRY } from '@objectstack/spec/kernel';
import { deriveFieldGroupLayout } from '@objectstack/spec/data';
import { APPROVAL_NODE_TYPE, isFlowTechnicalNodeType } from '@objectstack/spec/automation';
import { APPROVAL_NODE_TYPE, flowDecisionEdgeBranch, isFlowTechnicalNodeType } from '@objectstack/spec/automation';
import { expandViewContainer, InlineLocaleMapSchema } from '@objectstack/spec/ui';
import { authorWarnedProperties } from './lint-liveness-properties.js';
import { walkPageComponents } from './page-walk.js';
Expand Down Expand Up @@ -2292,18 +2292,16 @@ function collectFlowNodesDeep(nodes: unknown): any[] {
}


/** The label a decision's fall-through branch carries (`DEFAULT_BRANCH_LABEL` in the engine). */
const DECISION_DEFAULT_BRANCH = 'default';

/**
* The folded technical steps a business-altitude flow drawing still names: the
* top-level `FLOW_TECHNICAL_NODE_TYPES` node a top-level decision's branch
* leads to, in edge order, each once.
*
* Mirrors which out-edges the docs viewer lists as branches
* (`decisionBranches`, `ui/packages/components/src/renderers/basic/flow-branches.ts`):
* every out-edge of a decision with no `config.conditions`; otherwise a
* default edge (`isDefault`, or the `default` label) and an edge whose label a
* Which out-edges are branches is the spec's `flowDecisionEdgeBranch`, the one
* rule the docs viewer lists them by (`decisionBranches`,
* `ui/packages/components/src/renderers/basic/flow-branches.ts`): every
* out-edge of a decision with no `config.conditions`; otherwise a default
* edge (`isDefault`, or the `default` label) and an edge whose label a
* condition claims. The viewer finds the target among the top-level nodes
* only, so a region's nested node is not one.
*/
Expand All @@ -2317,17 +2315,10 @@ function decisionBranchTechnicalTargets(flow: any, topLevel: any[]): { id: strin
const targets: { id: string; label: unknown }[] = [];
for (const node of topLevel) {
if (!node || typeof node !== 'object' || node.type !== 'decision' || typeof node.id !== 'string') continue;
const conditions: any[] = Array.isArray(node.config?.conditions)
? node.config.conditions.filter((c: unknown) => c !== null && typeof c === 'object' && !Array.isArray(c))
: [];
const conditions: unknown = node.config && typeof node.config === 'object' ? node.config.conditions : undefined;
for (const edge of edges) {
if (!edge || typeof edge !== 'object' || edge.source !== node.id || typeof edge.target !== 'string') continue;
const listed =
conditions.length === 0 ||
edge.isDefault === true ||
edge.label === DECISION_DEFAULT_BRANCH ||
conditions.some((c) => typeof edge.label === 'string' && c.label === edge.label);
if (!listed) continue;
if (!flowDecisionEdgeBranch(edge, conditions)) continue;
const target = byId.get(edge.target);
if (!target || !isFlowTechnicalNodeType(target.type) || seen.has(target.id)) continue;
seen.add(target.id);
Expand Down Expand Up @@ -2583,16 +2574,28 @@ function walkScreenFlows(config: any, out: ExpectedEntry[]): void {
// every step the docs viewer's `type: flow` embed draws at its default
// altitude (`detail: business`): a top-level node whose type
// `isFlowTechnicalNodeType` does not fold away, the one table that viewer
// reads. A `screen` and an `approval` are drawn too, but their label is
// keyed already (`screens.<node_id>.title`, `approvals.<node_id>.label`),
// so they are not asked twice. Start and end nodes are asked like any
// other step: the viewer draws the author's words for them, not its own.
// A region's nested nodes (ADR-0031) are not drawn by that embed, so they
// are accepted by `os validate` but not demanded here.
// reads. An `approval` and an untitled `screen` are drawn too, but their
// label is keyed already (`approvals.<node_id>.label`,
// `screens.<node_id>.title`), so they are not asked twice. A screen that
// authors its own `config.title` is drawn by that heading, keyed
// `screens.<node_id>.title` too, unless the heading holds a `{{ }}` hole a
// drawing cannot fill; the embed then draws the screen's label, so that
// screen alone is asked for its `nodes` key (`flowStepName`,
// `metadata-viewer.tsx`). The Studio canvas draws every titled screen by
// that key, but the walk asks only for what the docs embed draws, as it
// does for the technical steps that canvas also draws. Start and end
// nodes are asked like any other step: the viewer draws the author's words
// for them, not its own. A region's nested nodes (ADR-0031) are not drawn
// by that embed, so they are accepted by `os validate` but not demanded
// here.
const topLevel: any[] = Array.isArray(flow.nodes) ? flow.nodes : [];
for (const node of topLevel) {
if (!node || typeof node !== 'object') continue;
if (node.type === SCREEN_NODE_TYPE || node.type === APPROVAL_NODE_TYPE) continue;
if (node.type === APPROVAL_NODE_TYPE) continue;
if (node.type === SCREEN_NODE_TYPE) {
const title: unknown = node.config && typeof node.config === 'object' ? node.config.title : undefined;
if (typeof title !== 'string' || !title.includes('{{')) continue;
}
if (isFlowTechnicalNodeType(node.type)) continue;
const nodeId = typeof node.id === 'string' && node.id.length > 0 ? node.id : undefined;
// No id, no key: nothing could address the step.
Expand Down
31 changes: 25 additions & 6 deletions packages/lint/src/validate-translation-references.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2452,6 +2452,7 @@ describe('validateTranslationReferences — flow node labels (`nodes.<node_id>.l
{ id: 'start', type: 'start', label: 'Start' },
{ id: 'gate', type: 'decision', label: 'High Value (> $500K)?' },
{ id: 'collect', type: 'screen', label: 'Collect', config: { fields: [{ name: 'note' }] } },
{ id: 'greet', type: 'screen', label: 'Greeting', config: { title: 'Hello {{ vars.name }}' } },
{
id: 'manager_review',
type: 'approval',
Expand Down Expand Up @@ -2503,13 +2504,31 @@ describe('validateTranslationReferences — flow node labels (`nodes.<node_id>.l
);
});

it('points a `nodes` key over a `screen` node at its heading', () => {
it('points a `nodes` key over an untitled `screen` node at its heading', () => {
const findings = validateTranslationReferences(bundle({ opportunity_approval: { nodes: { collect: { label: 'x' } } } }));
expect(findings).toHaveLength(1);
expect(findings[0].message).toBe(
'Translations are keyed to node "collect", which flow "opportunity_approval" declares as a `screen` node; ' +
'its heading is keyed `screens.collect.title`.',
);
expect(findings.map((f) => [f.rule, f.severity, f.path])).toEqual([
[TRANSLATION_TARGET_UNKNOWN, 'error', 'translations[0]["zh-CN"].flows.opportunity_approval.nodes.collect'],
]);
expect(findings[0].message).toContain('`screens.collect.title`');
});

it('accepts a `nodes` key over a screen that authors its own `config.title`, beside that screen\'s heading key', () => {
expect(
validateTranslationReferences(
bundle({
opportunity_approval: {
nodes: { greet: { label: '问候' } },
screens: { greet: { title: '你好 {{ vars.name }}' } },
},
}),
),
).toEqual([]);
});

it('offers a titled screen as the nearest node for a misspelt `nodes` key', () => {
const findings = validateTranslationReferences(bundle({ opportunity_approval: { nodes: { gret: { label: 'x' } } } }));
expect(findings.map((f) => f.rule)).toEqual([TRANSLATION_TARGET_UNKNOWN]);
expect(findings[0].message).toContain('Did you mean "greet"?');
});

it('refuses a `nodes` key over an UNKNOWN node, with the nearest labelled node offered', () => {
Expand Down
Loading
Loading