Skip to content

Commit 343c49c

Browse files
fix(app-shell): Studio flow designer shows the package's translated flow and approval-step labels (#34947)
<!-- claude-projects-attribution: {"github_login":"os-support-ai"} --> _Requested by **Yibo Wang** · [project thread](https://claude.ai/code/project/chan_01BVUyyPie8gHwoPM18iABwB?thread=cmsg_01BVUyyPie8gHwoPM18iABwBXim82sEGBUBXqH4hkWyBJX)_ Fixes #34903 repo:objectstack#3 · os-support-ai · session_01WGufzi3ezPzTysQPDEjmVz Clause-②: yes Metadata-protocol: none ## 维护者速读 - 改了什么:Studio 流程设计器现在读取包自带的流程标签翻译(`flows.<flow>.label`)和审批步骤标签翻译(`flows.<flow>.approvals.<step>.label`),按查看者的语言显示;检查器标题下另起一行显示原文标签。 - 为什么改:zh-CN 管理员打开 HotCRM 的 opportunity_approval,看到的仍是英文流程名和英文审批步骤名,尽管包里已带中文翻译。 - 风险与回滚:只改显示,草稿本身从不写入翻译;没有翻译时一切与之前相同。回滚即 revert 本 PR。 - 先看:`previews/flow-label-translations.tsx`(读取逻辑)、`FlowPreview.tsx` 中 `flowSelectionHeading` 的 hunk、`StudioDesignSurface.tsx` 的三处调用点。 - 两分钟验证:`cd ui && pnpm exec vitest run packages/app-shell/src/views/metadata-admin/previews/FlowCanvas.test.tsx`,预期新增的 6 个用例全部通过。 - 需要你做的:无,席位落地。 ## What changes - **One reader, reused.** A new `previews/flow-label-translations.tsx` reads the bundle `FlowRunner` already reads: `activeFlowsBundle` over the loaded i18next resource tree. The flow label goes through the spec's `translateFlow`, the runner's path. The approval-step label is the spec-typed address `flows.<flow>.approvals.<node_id>.label`, and only `approval` nodes read it. There is no third translation client and no new loader. It is display only: the draft never carries a translation, so editing, renaming and saving still work on the authored label. - **Canvas.** `FlowPreview` hands those translations to the canvas through a context. An approval node card shows its translated step label. Nested approval cards in an expanded region also show it (`flow-region-view.tsx`). - **Inspector header.** `flowSelectionHeading` takes the translations as an optional argument. An approval step is titled by its translation and returns the authored label as `source`. `FlowSelectionTitle` draws that label under the title: "Authored label: “…”" / 原文标签:“…”. Studio is the authoring surface, so the author still sees the text they edit. - **Flow label.** The Automations header caption names the flow by `flows.<flow>.label` when the bundle has it, and falls back to the authored label, then the name. - **Decision/other node labels and edge labels stay authored text: the spec has no keys for them; the filer files that card if wanted.** - **Key added: yes, one.** `engine.inspector.flowNode.sourceLabel` is in the lazy `studio` namespace (`en.ts`, `zh.ts`). The eager `locales/en.ts` is unchanged: `git diff 189358f -- ui/packages/i18n/src/locales/` is empty. No budget ceiling was touched. - **Surface growth (claim amendment 6954477935).** `StudioDesignSurface.tsx` gets only call-site lines: the hook call, the caption title, the heading argument and the title render. `flow-region-view.tsx` gets the nested-approval label line. This is not a deviation. ## Tests <details><summary>Pins, in the existing FlowCanvas harness (one new top-level describe)</summary> `FlowCanvas.test.tsx`, under the describe "Flow designer — package label translations (flows.FLOW.label, approvals.STEP.label)": - the helper resolves the flow label and both step labels from a real `createI18n` resource tree loaded with a zh-CN `TranslationData`; a decision node gets nothing, and an unknown flow gets no bundle; - `useFlowLabelTranslations` reads the `I18nProvider`'s active language; - the canvas draws 经理审核 and, after expanding the region, the nested 总监签批; the decision label and the edge label stay authored; - with no provider the canvas draws the authored labels, as before; - `FlowPreview`, rendered inside `I18nProvider`, hands the bundle to the canvas (the end-to-end fixture reading); - the inspector heading is `{ title: '经理审核', source: 'Manager review' }`, and `FlowSelectionTitle` renders the source line; a decision has no `source`; with no translations the heading is byte-identical to before. `flowNodeLabels.sites-13200.test.ts`: the four ledgered `own-title` sites are re-keyed to their new source lines. The verdicts, the site count and the floors are unchanged. </details> <details><summary>Runs (head 4972af6)</summary> - `vitest run` FlowCanvas.test.tsx, flowNodeLabels-13143, flowNodeLabels.sites-13200, `packages/i18n/`, `scripts/` → `Test Files 276 passed | 2 skipped (278)`, `Tests 7041 passed | 15 skipped`, lock `VERDICT command-exit 0`. - An earlier wider run over `previews/`, `studio-design/` and `packages/i18n/` (602 files) found the 13200 ledger red, its only failure, and that is fixed above. - `pnpm --filter @object-ui/app-shell run type-check` → `VERDICT command-exit 0` (both `tsc` programs; the test program compiles `FlowCanvas.test.tsx`, which it caught once). `@object-ui/i18n` type-check → Done. - Ablation (committed fix, then `ablation-replace.mjs`): the FlowCanvas call site reverted to `label={node.label || node.id}` → 2 failed (the canvas pin and the FlowPreview pin), then restored with `blob == HEAD` and an empty `git diff HEAD`. </details> ## Acceptance notes - **i18n-locale-en reading:** `locales/en.ts` has an empty diff, so the eager catalogue is unchanged. The budget gate (`check-eager-locale-catalogues.mjs`) was NOT MEASURED locally, reason: `PREREQUISITE NOT MET`, because it weighs a built `apps/console/dist/eager-closure.json`. CI's UI build carries it. - **Live readings** (comment 6958860242): real console over bf090e8, zh-CN. Showcase (real pack): caption 项目预算审批; approval cards 经理审核 and 高管审核; inspector 经理审核 / 原文标签:“Manager Review”. Fixture package mirroring opportunity_approval: caption 大额商机审批; cards 经理审核 and 总监签批; after Customize, the Label field edits the authored text while the card keeps the translation. en, and a zh flow with no entry: authored labels, no source line. A nested approval card is not producible, because the spec refuses approval in region bodies (ruling 5724940095 D). Studio already loads the package's flows group: `loadLanguage` fetches the server's merged `GET /api/v1/i18n/translations/LOCALE` tree. Screenshots, readings.txt and scripts: /mnt/project-files/objectstack-seat3/34903-live/. - **Fix round (L1 6956195648 M1), head f5c62bd:** bf090e8 merges main forward (#34932 landed), and f5c62bd is test-only. #34932 draws an approval's approve out-edge as a localized outcome pill, so the authored-edge assertion moved to a decision branch edge. No product code changed. Runs: app-shell studio-design/ + previews/ + i18n/ → `Test Files 605 passed (605)`, `Tests 6315 passed | 13 skipped`; `ui scripts/` → `171 passed | 2 skipped`; dispatch-gates 38/38 run, 0 UNRUN; check:eager-closure exit 0, `i18n-locale-en 60.4 KB / 60.5 KB ceiling`. - The Automations header caption has no pin of its own. It is one expression over the same helper the pins cover. The rail row that lists flows still shows the authored label, which is outside this card's surface. - The docblock of `utils/flowsBundle.ts` still lists three reader surfaces; the designer is now a fourth. That file is outside the surface, so it is left unedited. ## Verification <details><summary>Gates</summary> - `node scripts/pm/dispatch-gates.mjs --commands`: 38 families. All ran, and `--ran` reconciliation shows 38 derived / 38 run / 0 UNRUN. Each exited 0, except `check:test-source-alias`, which went red on the new FlowPreview import in the test. That was fixed with the module-top `import '@objectstack/lint'` the gate prescribes, and the rerun printed `check-test-source-alias OK`. - `pnpm check:new-line-citations` (ui): `0 new citation(s)`. `check-nul-bytes`: OK. `check-i18n-call-site-keys`: exit 0. - `node scripts/pm/overlap-check.mjs --branch=HEAD` before each push: `VERDICT clean`. It merges cleanly with #34932, #34926, #34925, #34914 and #34799. Landing order: #34932 first, then this PR merges main forward. </details> --- _Generated by [Claude Code](https://claude.ai/code/session_01WGufzi3ezPzTysQPDEjmVz)_ 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- signed: repo:objectstack#3 · os-support-ai · session_01WGufzi3ezPzTysQPDEjmVz --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 02a290f commit 343c49c

10 files changed

Lines changed: 285 additions & 13 deletions

File tree

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
'@object-ui/app-shell': patch
3+
'@object-ui/i18n': patch
4+
---
5+
6+
fix(app-shell): the Studio flow designer shows a package's translated flow label and approval-step labels
7+
8+
Clause-②: yes
9+
Metadata-protocol: none
10+
11+
A package can translate a flow's label (`flows.<flow>.label`) and an approval step's label (`flows.<flow>.approvals.<node_id>.label`). The flow runner already used both. The Studio flow designer ignored them, so a zh-CN admin saw the authored English flow name and step names. The designer now reads the same bundle the runner reads, through the spec's `translateFlow`, in the viewer's language. The automation header names the flow by its translation. Approval nodes show their translated step label on the canvas (nested ones included) and in the inspector header. The inspector also shows the authored label on a second line ("Authored label: …"), because Studio is where that label is edited. With no translation, every label shows as authored, as before. The draft is never rewritten with a translation.
12+
13+
The spec has no key for a decision or other node's label, or for an edge label, so those still show the authored text.
14+
15+
`@object-ui/i18n` gains one lazy `studio`-namespace key, `engine.inspector.flowNode.sourceLabel` (en and zh). The eager `locales/en.ts` pack is unchanged.

‎ui/packages/app-shell/src/views/metadata-admin/previews/FlowCanvas.test.tsx‎

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,18 @@ import { extractRegions, NODE_H } from './flow-canvas-layout';
88
import { predictExpandedNodeHeight } from './flow-region-metrics';
99
import type { FlowProblem } from './flow-problems';
1010
import { browserClick, browserDrag } from './__tests__/browserClick';
11+
// FlowPreview reaches a dynamic `import('@objectstack/lint')`; pay its load at collection, not in a test's clock.
12+
import '@objectstack/lint';
13+
import { createI18n, I18nProvider, transformSpecTranslations } from '@object-ui/i18n';
14+
import type { TranslationData } from '@objectstack/spec/system';
15+
import { FlowPreview, FlowSelectionTitle, flowSelectionHeading } from './FlowPreview';
16+
import {
17+
FlowLabelTranslationsProvider,
18+
flowLabelTranslations,
19+
useFlowLabelTranslations,
20+
type FlowLabelTranslations,
21+
} from './flow-label-translations';
22+
import { activeFlowsBundle } from '../../../utils/flowsBundle';
1123

1224
afterEach(cleanup);
1325

@@ -596,3 +608,128 @@ describe('FlowCanvas — a node press on a read-only design canvas selects, and
596608
expect(onPatch).not.toHaveBeenCalled();
597609
});
598610
});
611+
612+
613+
/**
614+
* The flow designer reads a package's `flows` translations: the flow's label
615+
* (`flows.<flow>.label`) and an approval node's step label
616+
* (`flows.<flow>.approvals.<node_id>.label`), in the viewer's language, from
617+
* the bundle `FlowRunner` reads. A decision node and an edge have no key, so
618+
* they stay authored; with no translation everything is authored, as before.
619+
*/
620+
describe('Flow designer — package label translations (flows.<flow>.label, approvals.<step>.label)', () => {
621+
const ZH_CN: TranslationData = {
622+
flows: {
623+
opportunity_approval: {
624+
label: '大额商机审批',
625+
approvals: { manager_review: { label: '经理审核' }, director_signoff: { label: '总监签批' } },
626+
},
627+
},
628+
};
629+
const NODES = [
630+
{ id: 'start', type: 'start', label: 'Start' },
631+
{ id: 'manager_review', type: 'approval', label: 'Manager review' },
632+
{ id: 'big', type: 'decision', label: 'Over 1M?' },
633+
{
634+
id: 'each',
635+
type: 'loop',
636+
label: 'For each signer',
637+
config: { body: { nodes: [{ id: 'director_signoff', type: 'approval', label: 'Director sign-off' }], edges: [] } },
638+
},
639+
];
640+
const EDGES = [
641+
{ source: 'start', target: 'manager_review' },
642+
{ source: 'manager_review', target: 'big', label: 'approve' },
643+
{ source: 'big', target: 'each', label: 'Yes, over 1M' },
644+
];
645+
const DRAFT = { name: 'opportunity_approval', label: 'Large Deal Approval', nodes: NODES, edges: EDGES };
646+
647+
function zhInstance() {
648+
const instance = createI18n({ defaultLanguage: 'zh-CN', detectBrowserLanguage: false });
649+
instance.addResourceBundle('zh-CN', 'translation', transformSpecTranslations(ZH_CN as Record<string, unknown>), true, true);
650+
return instance;
651+
}
652+
const zh = (): FlowLabelTranslations => {
653+
const t = flowLabelTranslations(activeFlowsBundle(zhInstance(), 'zh-CN', 'opportunity_approval'), 'opportunity_approval', 'zh-CN');
654+
expect(t).toBeDefined();
655+
return t!;
656+
};
657+
658+
it('resolves the flow label and approval-step labels out of the loaded resource tree, and nothing else', () => {
659+
const t = zh();
660+
expect(t.flowLabel).toBe('大额商机审批');
661+
expect(t.stepLabel({ id: 'manager_review', type: 'approval' })).toBe('经理审核');
662+
expect(t.stepLabel({ id: 'director_signoff', type: 'approval' })).toBe('总监签批');
663+
// No key for any other node type, even under an approval's id.
664+
expect(t.stepLabel({ id: 'manager_review', type: 'decision' })).toBeUndefined();
665+
expect(t.stepLabel({ id: 'unknown_step', type: 'approval' })).toBeUndefined();
666+
// No bundle for the flow: nothing to translate with.
667+
expect(flowLabelTranslations(activeFlowsBundle(zhInstance(), 'zh-CN', 'other_flow'), 'other_flow', 'zh-CN')).toBeUndefined();
668+
});
669+
670+
it('useFlowLabelTranslations reads the console provider’s active language', () => {
671+
let seen: FlowLabelTranslations | undefined;
672+
function Probe() {
673+
seen = useFlowLabelTranslations('opportunity_approval');
674+
return null;
675+
}
676+
render(
677+
<I18nProvider instance={zhInstance()} persistLanguage={false}>
678+
<Probe />
679+
</I18nProvider>,
680+
);
681+
expect(seen?.flowLabel).toBe('大额商机审批');
682+
expect(seen?.stepLabel({ id: 'manager_review', type: 'approval' })).toBe('经理审核');
683+
});
684+
685+
it('draws the translated approval-step labels on the canvas, nested ones included; decision and branch-edge labels stay authored', () => {
686+
const { container } = render(
687+
<FlowLabelTranslationsProvider value={zh()}>
688+
<FlowCanvas nodes={NODES} edges={EDGES} editable={false} designMode={false} selectedId={null} onSelect={() => {}} />
689+
</FlowLabelTranslationsProvider>,
690+
);
691+
const card = (id: string) => container.querySelector(`[data-node-id="${id}"]`) as HTMLElement;
692+
expect(card('manager_review').textContent).toContain('经理审核');
693+
expect(card('manager_review').textContent).not.toContain('Manager review');
694+
expect(card('big').textContent).toContain('Over 1M?');
695+
// A decision branch's authored edge label has no package key, so it stays as written. (An approval's
696+
// `approve` / `reject` outcome pills are the designer's own vocabulary, not the package bundle's.)
697+
expect(screen.getByText('Yes, over 1M')).toBeInTheDocument();
698+
fireEvent.click(screen.getByRole('button', { name: 'Expand nested regions' }));
699+
expect(card('each').textContent).toContain('总监签批');
700+
expect(card('each').textContent).not.toContain('Director sign-off');
701+
});
702+
703+
it('with no translation the canvas draws the authored labels, as before', () => {
704+
const { container } = render(
705+
<FlowCanvas nodes={NODES} edges={EDGES} editable={false} designMode={false} selectedId={null} onSelect={() => {}} />,
706+
);
707+
expect((container.querySelector('[data-node-id="manager_review"]') as HTMLElement).textContent).toContain('Manager review');
708+
});
709+
710+
it('FlowPreview hands the bundle in from the console provider', () => {
711+
vi.stubGlobal('fetch', vi.fn(async () => new Response('not found', { status: 404 })));
712+
const { container } = render(
713+
<I18nProvider instance={zhInstance()} persistLanguage={false}>
714+
<FlowPreview type="flow" name="opportunity_approval" draft={DRAFT} selection={null} onSelectionChange={() => {}} />
715+
</I18nProvider>,
716+
);
717+
expect((container.querySelector('[data-node-id="manager_review"]') as HTMLElement).textContent).toContain('经理审核');
718+
});
719+
720+
it('the inspector header titles an approval step by its translation and shows the authored label beside it', () => {
721+
const t = zh();
722+
const top = flowSelectionHeading(DRAFT, { kind: 'node', id: 'manager_review' }, undefined, t);
723+
expect(top).toMatchObject({ title: '经理审核', source: 'Manager review' });
724+
render(<FlowSelectionTitle heading={top} />);
725+
expect(screen.getByText('经理审核')).toBeInTheDocument();
726+
expect(screen.getByTestId('flow-selection-source').textContent).toContain('Manager review');
727+
// A decision node has no key: authored title, no source line.
728+
const decision = flowSelectionHeading(DRAFT, { kind: 'node', id: 'big' }, undefined, t);
729+
expect(decision.title).toBe('Over 1M?');
730+
expect(decision).not.toHaveProperty('source');
731+
// No translations: exactly as before.
732+
expect(flowSelectionHeading(DRAFT, { kind: 'node', id: 'manager_review' })).not.toHaveProperty('source');
733+
expect(flowSelectionHeading(DRAFT, { kind: 'node', id: 'manager_review' }).title).toBe('Manager review');
734+
});
735+
});

‎ui/packages/app-shell/src/views/metadata-admin/previews/FlowCanvas.tsx‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import { AlertCircle, AlertTriangle, Maximize2, Plus, ZoomIn, ZoomOut } from 'lu
3838
import { cn } from '@object-ui/components';
3939
import { uniqueId, appendArray, spliceArray } from '../inspectors/_shared.js';
4040
import { t as tr, tFormat } from '../i18n.js';
41+
import { useFlowLabelTranslationsContext } from './flow-label-translations.js';
4142
import {
4243
computeLayoutWithGeometry,
4344
NODE_W,
@@ -218,6 +219,8 @@ export function FlowCanvas({
218219
// has an index signature). Same reference when nothing needed migrating, so
219220
// the memos keyed on `nodes` are unaffected.
220221
const nodes = React.useMemo(() => withCanonicalGeometry(storedNodes), [storedNodes]);
222+
// An approval step's label in the viewer's language, where the package translates it.
223+
const labelTranslations = useFlowLabelTranslationsContext();
221224

222225
const viewportRef = React.useRef<HTMLDivElement>(null);
223226
// objectui#11795 — the viewport width the diagram was last framed at (the
@@ -1294,7 +1297,7 @@ export function FlowCanvas({
12941297
id={node.id}
12951298
locale={locale}
12961299
type={node.type}
1297-
label={node.label || node.id}
1300+
label={labelTranslations?.stepLabel(node) ?? (node.label || node.id)}
12981301
summary={nodeSummary(node, locale, objectLabels)}
12991302
position={pos}
13001303
selected={selectedId === node.id}

‎ui/packages/app-shell/src/views/metadata-admin/previews/FlowPreview.tsx‎

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,9 @@ import type { MetadataPreviewProps, MetadataSelection } from '../preview-registr
3939
import { PreviewShell, PreviewMessage, PreviewErrorBoundary } from './PreviewShell.js';
4040
import { appendArray } from '../inspectors/_shared.js';
4141
import { useObjectCatalog, type ObjectCatalogEntry } from '../inspectors/ObjectPicker.js';
42-
import { t as tr, translateFlowMeta } from '../i18n.js';
42+
import { t as tr, tFormat, translateFlowMeta } from '../i18n.js';
4343
import { FlowCanvas } from './FlowCanvas.js';
44+
import { FlowLabelTranslationsProvider, useFlowLabelTranslations, type FlowLabelTranslations } from './flow-label-translations.js';
4445
import { defaultNodeLabel, flowEdgeDisplayName, flowNodeDisplayName } from './flow-canvas-parts.js';
4546
import { edgeKey, type FlowDesignerEdge, type FlowDesignerNode } from './flow-canvas-layout.js';
4647
import { NESTED_NODE_KIND, parseNestedNodeId, encodeNestedNodeId, locateFlowNode } from '../inspectors/flow-nested-selection.js';
@@ -125,12 +126,18 @@ export function FlowPreviewChromeProvider({ value, children }: { value: FlowPrev
125126
* node with its type's display name ("Node · Decision"), or a connection — and
126127
* the title is the one the inspector's own header would show (the node's label
127128
* or id; the connection's `source → target`, each end by its node's name).
129+
*
130+
* An `approval` node's title is its step label in the viewer's language when
131+
* the package bundle carries one (`translations`, see
132+
* `flow-label-translations.tsx`); `source` is then the authored label, which
133+
* the header shows beside it, since Studio is where that label is authored.
128134
*/
129135
export function flowSelectionHeading(
130136
draft: Record<string, unknown>,
131137
selection: MetadataSelection,
132138
locale?: string,
133-
): { eyebrow: string; title: string } {
139+
translations?: FlowLabelTranslations,
140+
): { eyebrow: string; title: string; source?: string } {
134141
if (selection.kind === 'edge') {
135142
const edges = Array.isArray(draft.edges) ? (draft.edges as FlowDesignerEdge[]) : [];
136143
const edge = edges.find((e, i) => edgeKey(e, i) === selection.id);
@@ -150,12 +157,32 @@ export function flowSelectionHeading(
150157
return { eyebrow: kind, title: selection.label ?? nested?.nodeId ?? selection.id };
151158
}
152159
const type = typeof node.type === 'string' ? node.type : '';
160+
const authored = (typeof node.label === 'string' && node.label) || node.id;
161+
const translated = translations?.stepLabel(node);
153162
return {
154163
eyebrow: type ? `${kind} · ${defaultNodeLabel(type, locale)}` : kind,
155-
title: (typeof node.label === 'string' && node.label) || node.id,
164+
title: translated ?? authored,
165+
...(translated !== undefined && translated !== authored ? { source: authored } : {}),
156166
};
157167
}
158168

169+
/**
170+
* A {@link flowSelectionHeading}'s title as a host's inspector header draws
171+
* it: the title, and under it the authored label when a translation stands in
172+
* for it.
173+
*/
174+
export function FlowSelectionTitle({ heading, locale }: { heading: { title: string; source?: string }; locale?: string }) {
175+
if (heading.source === undefined) return <>{heading.title}</>;
176+
return (
177+
<>
178+
{heading.title}
179+
<span data-testid="flow-selection-source" className="block truncate text-xs font-normal text-muted-foreground">
180+
{tFormat('engine.inspector.flowNode.sourceLabel', locale, { label: heading.source })}
181+
</span>
182+
</>
183+
);
184+
}
185+
159186
/**
160187
* The header's Trigger pill (objectui#11779): the trigger the engine arms this
161188
* flow on, read from its Start node by the spec's own resolver
@@ -465,6 +492,7 @@ export function FlowPreview({ draft, editing, selection, onSelectionChange, onPa
465492

466493
// Run history needs the published flow name (the engine keys runs by it).
467494
const flowName = typeof d.name === 'string' && d.name ? d.name : '';
495+
const labelTranslations = useFlowLabelTranslations(flowName);
468496

469497
const empty = canEdit ? (
470498
<div className="p-3">
@@ -490,6 +518,8 @@ export function FlowPreview({ draft, editing, selection, onSelectionChange, onPa
490518
const canvasEl = nodes.length === 0 ? (
491519
<div className="h-full">{empty}</div>
492520
) : (
521+
// The approval steps' labels in the viewer's language (flow-label-translations.tsx).
522+
<FlowLabelTranslationsProvider value={labelTranslations}>
493523
<FlowCanvas
494524
nodes={nodes}
495525
edges={edges}
@@ -530,6 +560,7 @@ export function FlowPreview({ draft, editing, selection, onSelectionChange, onPa
530560
onPatch={onPatch}
531561
mintNodeId={mintNodeId}
532562
/>
563+
</FlowLabelTranslationsProvider>
533564
);
534565

535566
// The bar's four panel toggles, as the designer has them: one panel at a time beside the canvas.
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* The flow designer's reading of a package's `flows` translations: the flow's
5+
* own label (`flows.<flow>.label`) and an `approval` node's step label
6+
* (`flows.<flow>.approvals.<node_id>.label`), in the viewer's language.
7+
*
8+
* The bundle is the one `FlowRunner` reads, `activeFlowsBundle` over the
9+
* i18next resource tree the console already loaded, and the flow label goes
10+
* through the spec's `translateFlow`, the runner's resolution path. So the
11+
* designer and the runner cannot disagree about a flow's name, and there is no
12+
* second loader.
13+
*
14+
* Only those two keys exist in the spec's `flows` group for a label the
15+
* designer draws. A decision or other node's label and an edge label have no
16+
* key, so they stay the authored text.
17+
*
18+
* Display only: the draft is never rewritten with a translation, so an edit,
19+
* a rename or a save keeps working on the authored label. Studio is the
20+
* authoring surface, so the inspector also shows the authored label beside a
21+
* translation (`flowSelectionHeading`'s `source`).
22+
*/
23+
24+
import * as React from 'react';
25+
import { useObjectTranslation } from '@object-ui/react';
26+
import { translateFlow, type TranslationBundle } from '@objectstack/spec/system';
27+
import { activeFlowsBundle } from '../../../utils/flowsBundle.js';
28+
29+
/** A flow's translated labels in one language. Every member answers `undefined` where the bundle carries nothing. */
30+
export interface FlowLabelTranslations {
31+
/** `flows.<flow>.label`. */
32+
flowLabel?: string;
33+
/** `flows.<flow>.approvals.<node_id>.label`, for an `approval` node only. */
34+
stepLabel: (node: { id?: unknown; type?: unknown }) => string | undefined;
35+
}
36+
37+
/**
38+
* The translated labels for `flowName` out of `bundle` in `language`, or
39+
* `undefined` when there is no bundle (nothing to translate with).
40+
*/
41+
export function flowLabelTranslations(
42+
bundle: TranslationBundle | undefined,
43+
flowName: string,
44+
language: string,
45+
): FlowLabelTranslations | undefined {
46+
if (!bundle || !flowName) return undefined;
47+
const flowLabel = translateFlow<{ name: string; label?: string }>({ name: flowName }, bundle, { locale: language }).label;
48+
const approvals = bundle[language]?.flows?.[flowName]?.approvals;
49+
return {
50+
flowLabel: typeof flowLabel === 'string' && flowLabel ? flowLabel : undefined,
51+
stepLabel: (node) => {
52+
if (node.type !== 'approval' || typeof node.id !== 'string' || !node.id) return undefined;
53+
const label = approvals?.[node.id]?.label;
54+
return typeof label === 'string' && label ? label : undefined;
55+
},
56+
};
57+
}
58+
59+
/**
60+
* {@link flowLabelTranslations} for `flowName` in the console's active
61+
* language. Recomputed on every render: a handful of property reads that
62+
* follow the live resource tree and a language switch.
63+
*/
64+
export function useFlowLabelTranslations(flowName: string): FlowLabelTranslations | undefined {
65+
const { i18n, language } = useObjectTranslation();
66+
return flowLabelTranslations(activeFlowsBundle(i18n, language, flowName), flowName, language);
67+
}
68+
69+
const FlowLabelTranslationsContext = React.createContext<FlowLabelTranslations | undefined>(undefined);
70+
71+
/** Hands {@link FlowLabelTranslations} to the canvas below it. */
72+
export const FlowLabelTranslationsProvider = FlowLabelTranslationsContext.Provider;
73+
74+
/** The translations the nearest provider hands in, or `undefined` outside one. */
75+
export function useFlowLabelTranslationsContext(): FlowLabelTranslations | undefined {
76+
return React.useContext(FlowLabelTranslationsContext);
77+
}

‎ui/packages/app-shell/src/views/metadata-admin/previews/flow-region-view.tsx‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import { REGION_BLOCK_PAD, REGION_GAP, REGION_LABEL_H } from './flow-region-metr
3737
// stable region `key`. It lives in its own module so the nested-node inspector
3838
// breadcrumb reads the same rows (objectui#10696).
3939
import { displayRegionLabel } from './flow-region-label.js';
40+
import { useFlowLabelTranslationsContext } from './flow-label-translations.js';
4041

4142
/**
4243
* Node box inside a region — a compact echo of `NodeCard`. Read-only by default
@@ -60,6 +61,8 @@ function RegionNode({
6061
}) {
6162
const tone = nodeTone(node.type);
6263
const interactive = !!onSelect;
64+
// An approval step's label in the viewer's language, where the package translates it.
65+
const labelTranslations = useFlowLabelTranslationsContext();
6366
return (
6467
<div
6568
data-region-node-id={node.id}
@@ -96,8 +99,8 @@ function RegionNode({
9699
<NodeTypeIcon type={node.type} className={cn('h-4 w-4', tone.icon)} />
97100
</div>
98101
<div className="min-w-0 flex-1">
99-
<div className="truncate text-[12px] font-semibold leading-tight text-foreground" title={node.label || node.id}>
100-
{node.label || node.id}
102+
<div className="truncate text-[12px] font-semibold leading-tight text-foreground" title={labelTranslations?.stepLabel(node) ?? (node.label || node.id)}>
103+
{labelTranslations?.stepLabel(node) ?? (node.label || node.id)}
101104
</div>
102105
<div className={cn('text-[10px] font-semibold uppercase tracking-[0.08em]', tone.label)}>{node.type}</div>
103106
</div>

0 commit comments

Comments
 (0)