Skip to content

Commit 6f4d6e7

Browse files
fix(app-shell): Studio Automations list shows each flow by the package's translated label (#35448)
<!-- claude-projects-attribution: {"github_login":"os-bill"} --> _Requested by **Bill** · [project thread](https://claude.ai/code/project/chan_016iMXWSZDzqWRWvWzdNo8wg?thread=cmsg_016iMXWSZDzqWRWvWzdNo8wg6v19uPsX6gX42G8tGcvvzb)_ Fixes #35319 repo:objectstack#5 · os-bill · session_01Utp6CbSphdunq2aJq7ktuY Clause-②: no Metadata-protocol: none ## 维护者速读 - 用户看到的变化:中文界面下,Studio 里一个包的「自动化」列表每一行都显示包自带的中文流程名,和打开后的标题一致;没有翻译的流程仍显示原名。 - 为什么:管理员在列表里找中文流程名却只看到英文名,要点开才知道是哪一个。 - 如果判断错:只影响列表的显示和搜索,流程本身不变;最坏情况是列表回到显示原名。 - 需要您做的:无。 ## What changes - **One rule, reused.** `flow-label-translations.tsx` gains `useFlowLabelOf()`: for any flow name it returns `flowLabelTranslations(activeFlowsBundle(...)).flowLabel` in the console's active language. That is the exact reading the designer header already makes for the open flow (the sibling designer fix), so a rail row and the flow it opens cannot disagree. No second loader, no second copy of the resolution. - **The Automations rail.** In `AutomationsPillar` (`StudioDesignSurface.tsx`, call-site lines only) each row's text and its hover title use the pack's `flows.NAME.label` when the bundle has one, else the authored label, as before. - **Search matches what the row shows.** The rail search now matches the shown (translated) label, the authored label and the machine name. So a zh-CN admin can type the Chinese name, and an author who knows the English label or the API name still finds the row. - **No pack entry, or a language the pack does not speak:** today's label, byte for byte. ## Tests <details><summary>Pins (one new top-level describe in the existing rail harness)</summary> `AutomationsPillar.railSearch-11794.test.tsx`, describe "a rail row names its flow by the package's translated label", the real `AutomationsPillar` under an `I18nProvider` whose resource tree carries a zh-CN pack labelling two of four flows: - zh-CN: rows read `夜间摘要`, `Approve order`, the long authored label, `欢迎新成员`; the row title starts with the translated label. - zh-CN: the search finds the row by `夜间` (shown label), `DIGEST` (authored label) and `welcome_new` (machine name). - en: the zh-CN pack does not speak for English, every row reads as authored, and `夜间` matches nothing. The harness now finds the search box and the last row by test id (the zh placeholder and row name are Chinese); the four existing cases are unchanged and green. The file gains the module-top `import '@objectstack/lint'` that `check:test-source-alias` prescribes. </details> <details><summary>Runs (head c211406 unless noted)</summary> - `cd ui && vitest run` over `app-shell/src/views/studio-design/`, `app-shell/src/views/metadata-admin/previews/` (includes `FlowCanvas.test.tsx` and `flowNodeLabels.sites-13200`), `plugin-form/src/affordanceGrantMap-12082`, `components/.../clickableNonControlCensus-13461`, `homeRecoveryRedirectsFollowDeclaration-7373`, `openPathObjectReaders-12811` → `Test Files 516 passed (516)`, `Tests 4615 passed (4615)`, lock `VERDICT command-exit 0`. - Earlier targeted run (a508a9f) adding `ui/scripts/__tests__/spec-symbol-ledger-app-shell-7265` and the two `noSetupMetadataLink`/`noRetiredSetupLink` census files: 25 files, 266 tests green after the test-harness fix. - `pnpm --filter @object-ui/app-shell run type-check` → `VERDICT command-exit 0` (a508a9f; the later commits are a main merge touching no `ui/` file and one test-file import line). - Ablation (fix committed, `scripts/ablation-replace.mjs`): `railLabel` reverted to the authored label → the two zh-CN cases fail, the en case and the four existing cases pass; restored, blob after restore == HEAD blob `138ce670`, `git diff HEAD` empty. </details> ## Acceptance notes - `useFlowLabelOf` follows `useFlowLabelTranslations`: recomputed on every render, reading the live resource tree, so a language switch or a late pack load shows on the next render. - The greyed rows for flows another package ships on this package's objects (`ContributedRailRow`, shared by every pillar) still print the contributor's authored label. They live in a shared component outside this card's surface. Noted, not filed. - `utils/flowsBundle.ts`'s docblock still lists three reader surfaces; the designer and now the rail also read it. The file is outside the surface, so it is left as it is. - The live zh-CN reading (HotCRM Revenue → 定制 → 自动化) is not taken in this run; the pins drive the real pillar against a real `createI18n` tree loaded with a spec `TranslationData` pack, the same fixture shape the designer fix pinned. ## Verification <details><summary>Gates</summary> - `node scripts/pm/dispatch-gates.mjs --commands` (tree 4f9ba32): 38 families, all run, each `exit 0`; `check:test-source-alias` was red once on the new harness import reach and is green after the prescribed module-top import. `--ran` reconciliation: `38 derived famil(ies) accounted for — 38 run, 0 NOT-MEASURED (a DERIVED zero ...)`. - `node scripts/pm/overlap-check.mjs --branch=HEAD` before each push: `VERDICT clean`. - The wider CI run (lint, UI typecheck, full UI test shards, dogfood) is left to CI. </details> 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01Utp6CbSphdunq2aJq7ktuY <!-- signed: repo:objectstack#5 · os-bill · session_01Utp6CbSphdunq2aJq7ktuY --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 35bd360 commit 6f4d6e7

4 files changed

Lines changed: 91 additions & 13 deletions

File tree

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
'@object-ui/app-shell': patch
3+
---
4+
5+
fix(app-shell): the Studio Automations list names each flow by the package's translated label
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
A package can translate a flow's label (`flows.<flow>.label`). The flow designer already showed that translation for the open flow, but the Automations list beside it still showed every flow by its authored English label, so a zh-CN admin looked for a flow under a name the list did not use. Each list row, and its hover title, now shows the same translated label the designer header shows, read through the same helper in the viewer's language. A flow the package does not translate keeps its authored label, as before. The list search matches the label a row shows, and still matches the authored label and the machine name.

‎ui/packages/app-shell/src/views/metadata-admin/previews/flow-label-translations.tsx‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,20 @@ export function useFlowLabelTranslations(flowName: string): FlowLabelTranslation
6666
return flowLabelTranslations(activeFlowsBundle(i18n, language, flowName), flowName, language);
6767
}
6868

69+
/**
70+
* The flow label of any flow, by name, for a surface that lists many: the
71+
* Automations rail names each row by it. Each call is
72+
* {@link flowLabelTranslations}' `flowLabel` in the console's active language,
73+
* the reading the designer header makes for the open flow, so a row and the
74+
* flow it opens cannot disagree. `undefined` where the bundle carries no label
75+
* for that flow, and the caller keeps the authored label. A fresh function on
76+
* every render, for the reason above.
77+
*/
78+
export function useFlowLabelOf(): (flowName: string) => string | undefined {
79+
const { i18n, language } = useObjectTranslation();
80+
return (flowName) => flowLabelTranslations(activeFlowsBundle(i18n, language, flowName), flowName, language)?.flowLabel;
81+
}
82+
6983
const FlowLabelTranslationsContext = React.createContext<FlowLabelTranslations | undefined>(undefined);
7084

7185
/** Hands {@link FlowLabelTranslations} to the canvas below it. */

‎ui/packages/app-shell/src/views/studio-design/AutomationsPillar.railSearch-11794.test.tsx‎

Lines changed: 56 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,13 @@
2222
*/
2323

2424
import '@testing-library/jest-dom/vitest';
25+
import * as React from 'react';
2526
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
2627
import { render, screen, cleanup, fireEvent, waitFor, within } from '@testing-library/react';
2728
import { MemoryRouter } from 'react-router-dom';
29+
import { createI18n, I18nProvider, transformSpecTranslations } from '@object-ui/i18n';
30+
// Pays the dynamic `@objectstack/lint` load the pillar's source reaches at collection, not inside a case (check:test-source-alias).
31+
import '@objectstack/lint';
2832

2933
const PKG = 'com.acme.app';
3034
const LONG_LABEL = 'Escalate overdue high-priority support cases to the regional on-call manager';
@@ -100,16 +104,12 @@ afterEach(() => {
100104
vi.unstubAllGlobals();
101105
});
102106

103-
/** The rail (the `nav` holding the search box) once every row has rendered. */
104-
async function renderRail(): Promise<HTMLElement> {
105-
render(
106-
<MemoryRouter initialEntries={[`/studio/${PKG}/automations`]}>
107-
<AutomationsPillar packageId={PKG} />
108-
</MemoryRouter>,
109-
);
110-
const search = await screen.findByPlaceholderText(t('engine.studio.designer.search', 'en'), undefined, { timeout: 8000 });
107+
/** The rail (the `nav` holding the search box) once every row has rendered; `wrap` puts a provider around the pillar. */
108+
async function renderRail(wrap: (pillar: React.ReactElement) => React.ReactElement = (pillar) => pillar): Promise<HTMLElement> {
109+
render(<MemoryRouter initialEntries={[`/studio/${PKG}/automations`]}>{wrap(<AutomationsPillar packageId={PKG} />)}</MemoryRouter>);
110+
const search = await screen.findByTestId('auto-rail-search', undefined, { timeout: 8000 });
111111
const rail = search.closest('nav') as HTMLElement;
112-
await waitFor(() => expect(within(rail).getByRole('button', { name: /welcome_new_member/ })).toBeInTheDocument(), {
112+
await waitFor(() => expect(rail.querySelector('[data-testid="auto-rail-row-welcome_new_member"]')).toBeInTheDocument(), {
113113
timeout: 8000,
114114
});
115115
return rail;
@@ -173,3 +173,50 @@ describe('a flow’s name in the Automations rail is not cut to a stub (objectui
173173
expect(row.getAttribute('title') ?? '').toMatch(new RegExp(`^${LONG_LABEL} · `));
174174
});
175175
});
176+
177+
describe('a rail row names its flow by the package’s translated label (objectstack#35319)', () => {
178+
// The package's zh-CN pack: a label for two of the four flows. The other two keep their authored copy.
179+
const ZH_CN = {
180+
flows: {
181+
nightly_digest: { label: '夜间摘要' },
182+
welcome_new_member: { label: '欢迎新成员' },
183+
},
184+
};
185+
/** The console's i18n with the pack loaded under zh-CN, speaking `language`. */
186+
const withPack = (language: string) => (pillar: React.ReactElement) => {
187+
const instance = createI18n({ defaultLanguage: language, detectBrowserLanguage: false });
188+
instance.addResourceBundle('zh-CN', 'translation', transformSpecTranslations(ZH_CN), true, true);
189+
return (
190+
<I18nProvider instance={instance} persistLanguage={false}>
191+
{pillar}
192+
</I18nProvider>
193+
);
194+
};
195+
// By its test id: under a zh-CN provider the box's placeholder is the Chinese one.
196+
const search = (rail: HTMLElement, value: string) =>
197+
fireEvent.change(within(rail).getByTestId('auto-rail-search'), { target: { value } });
198+
199+
it('zh-CN: a flow the pack labels reads by that label, on the row and in its title; the rest stay authored', async () => {
200+
const rail = await renderRail(withPack('zh-CN'));
201+
expect(rowNames(rail)).toEqual(['夜间摘要', 'Approve order', LONG_LABEL, '欢迎新成员']);
202+
const row = rail.querySelector('[data-testid="auto-rail-row-nightly_digest"]') as HTMLElement;
203+
expect(row.getAttribute('title') ?? '').toMatch(/^夜间摘要 · /);
204+
});
205+
206+
it('zh-CN: the search matches the label the row shows, and still the authored label and the machine name', async () => {
207+
const rail = await renderRail(withPack('zh-CN'));
208+
search(rail, '夜间');
209+
expect(rowNames(rail)).toEqual(['夜间摘要']);
210+
search(rail, 'DIGEST');
211+
expect(rowNames(rail)).toEqual(['夜间摘要']);
212+
search(rail, 'welcome_new');
213+
expect(rowNames(rail)).toEqual(['欢迎新成员']);
214+
});
215+
216+
it('en: the zh-CN pack does not speak for English, so every row reads as authored', async () => {
217+
const rail = await renderRail(withPack('en'));
218+
expect(rowNames(rail)).toEqual(['Nightly digest', 'Approve order', LONG_LABEL, 'welcome_new_member']);
219+
search(rail, '夜间');
220+
expect(rowNames(rail)).toEqual([]);
221+
});
222+
});

‎ui/packages/app-shell/src/views/studio-design/StudioDesignSurface.tsx‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ import {
396396
type FlowProblemTally,
397397
} from '../metadata-admin/previews/FlowPreview.js';
398398
import { InspectorShellHostProvider } from '../metadata-admin/inspectors/_shared.js';
399-
import { useFlowLabelTranslations } from '../metadata-admin/previews/flow-label-translations.js';
399+
import { useFlowLabelOf, useFlowLabelTranslations } from '../metadata-admin/previews/flow-label-translations.js';
400400
import type { FlowRegistration } from '@objectstack/spec/api';
401401
import {
402402
navEntryLabelText,
@@ -8271,7 +8271,14 @@ export function AutomationsPillar({
82718271
// or the machine name. Ephemeral (AGENTS.md #8): nobody expects it back.
82728272
const [railQuery, setRailQuery] = React.useState('');
82738273
const railNeedle = railQuery.trim().toLowerCase();
8274-
const flowMatches = (f: Surface) => f.label.toLowerCase().includes(railNeedle) || f.name.toLowerCase().includes(railNeedle);
8274+
// objectstack#35319 — a row names its flow as the open flow's header does:
8275+
// the package's `flows.NAME.label` in the console's language, else the
8276+
// authored label. The search matches that name, the authored label and the
8277+
// machine name, so what the row shows is always searchable.
8278+
const flowLabelOf = useFlowLabelOf();
8279+
const railLabel = (f: Surface) => flowLabelOf(f.name) || f.label;
8280+
const flowMatches = (f: Surface) =>
8281+
[railLabel(f), f.label, f.name].some((text) => text.toLowerCase().includes(railNeedle));
82758282
// objectstack#28572 — "only customizations" keeps the marked rows.
82768283
const flowShown = (f: Surface) =>
82778284
(!railNeedle || flowMatches(f)) && (!onlyCustomized || railMarks?.markOf(f) != null);
@@ -9555,7 +9562,7 @@ export function AutomationsPillar({
95559562
active={active}
95569563
data-testid={`auto-rail-row-${f.name}`}
95579564
data-trigger={glyph}
9558-
title={[f.label, t(FLOW_GLYPH_LABEL_KEY[glyph], locale), reading?.view.label].filter(Boolean).join(' · ')}
9565+
title={[railLabel(f), t(FLOW_GLYPH_LABEL_KEY[glyph], locale), reading?.view.label].filter(Boolean).join(' · ')}
95599566
onClick={() => {
95609567
// objectstack#26705 — another flow's load replaces the
95619568
// buffer the held step lives in; the open one keeps it.
@@ -9571,7 +9578,7 @@ export function AutomationsPillar({
95719578
</>
95729579
}
95739580
>
9574-
{f.label}
9581+
{railLabel(f)}
95759582
</StudioRailRow>
95769583
);
95779584
})}

0 commit comments

Comments
 (0)