Skip to content

Commit 17ceb2d

Browse files
fix(plugin-designer): decide a generated nav entry's plural label from the authored object, not the served translation (#35299)
Fixes #35101 Clause-②: yes (widening) Metadata-protocol: none ## 维护者速读 - 改了什么:新建/编辑应用向导离开「对象」步骤时,为新选对象生成的导航项,其复数标签改为读对象的原文定义(authored layers)来判断和存储,不再用界面语言翻译后的对象列表。 - 为什么改:中文界面下会把翻译后的复数名称(如「项目列表」)当原文存进应用定义,其他语言的读者也被迫看到它;按裁定 A(「35101 A」)改为读原文,原文读取失败则不写标签(导航项继承对象标签),绝不回退到翻译文本。 - 风险与回滚:只影响新生成的导航项,已存的导航项不改写;读取期间「下一步/上一步/步骤」与对象选择被禁用,读完后自动进入导航步骤;回滚即 revert 本 PR。 - 先看:`ui/packages/plugin-designer/src/AppCreationWizard.tsx`(`enterNavigationStep` 与 `readAuthoredEntryLabels`)、`ui/packages/plugin-designer/src/pages/authoredObjectReader.ts`(按对象所属包读取)、`ui/packages/plugin-designer/src/__tests__/AppWizard.standardNavEntries-11201.test.tsx`。 - 两分钟验证:`pnpm --dir ui exec vitest run packages/plugin-designer/src/__tests__/AppWizard.standardNavEntries-11201.test.tsx`,预期 10 个用例全部通过。 - 需要你做的:无,席位落地。 ## What changes The app wizard (Create app and Edit app) generates one navigation entry per newly selected object when it leaves the Objects step. Under ruling B (objectui#11201) the entry stored the object's plural label when it differed from the label and the name, and both the decision and the stored text came from the served object list, which is translated for the console's locale. Under ruling A (comment 6996384871, the maintainer's 「35101 A」): - `AppCreationWizardProps` gains an optional `readAuthoredObject(objectName)`. When the wizard leaves the Objects step, it reads every object that needs a generated entry, in parallel, and decides each entry's label from the authored answer alone: the authored `pluralLabel`, stored only when it spells neither the authored `label` nor the object name. - A refused, failed or empty read writes NO label; the entry inherits the object's label at render time. There is no fallback to served text anywhere on this path (the maintainer's in-session instruction). - `pages/authoredObjectReader.ts` holds `owningPackage` (moved out of `EditAppPage`, unchanged) and `useAuthoredObjectReader`, which reads `ObjectStackAdapter.getAuthoredItem('object', name, { packageId })` at the package the served object came from. `CreateAppPage` and `EditAppPage` pass it. - While the reads run, Next, Back, the step header and the object selection (cards, select-all, search) are disabled, so neither the step nor the selection can move under the reads. Next carries `aria-busy`. An unmount during the reads drops the result. - Entries already stored are not rewritten; existing object entries in an edited app are not re-read. ## Tests - `AppWizard.standardNavEntries-11201.test.tsx`: the served list is now a zh-CN list (every label translated) and the authored layers are English. The four ruling-B cases now run against authored data. A new describe for 35101 pins: the authored plural is stored, not the translation (`project`); a translated plural equal to the translated label does not suppress the authored plural (`task`); no stored label carries Han text; a packaged object is read at its package and a package-less one with no package; a refused read (403) writes no label. A second new describe pins that, while a read is held open, Next, Back and the object cards are disabled and the navigation step is not shown, and that the step advances once the read settles. - `AppWizard.specDocument-10867.test.tsx` and `EditAppPage.keepsNavigation-10894.test.tsx`: their adapter mocks answer `getAuthoredItem('object', …)`, and they await the navigation step after leaving Objects. ## Acceptance notes - Comparison basis: the reading on the card says "only when the authored plural differs from the name". The card's option A text (「只在原文的复数名称和名称不同时才存」) uses 名称 as ruling B did, where B compared against both the label and the machine name. This PR keeps both comparisons, against the authored values. If the ruling meant the machine name only, the change is one line in `generatedEntryLabel`. - A host that renders the exported `AppCreationWizard` without `readAuthoredObject` now gets generated entries with no label at all (they inherit). Before, it got the served plural. This follows the ruling's "read fails ⇒ no label" and is stated in the changeset. - A read that never settles leaves Next disabled. Cancel still works. The adapter's own request handling bounds this; the wizard adds no timer of its own. - Declared deviations: the branch is `claude/cool-bardeen-unawl1`, not `claude/issue-35101-*`, because this session may push only that branch. The first three commits (up to `fc64ae98`) were written in the PM session before dispatch. The dev reviewed every line from that sha and owns the result. The dev's changes on top are: freezing the object selection during the reads (Zone 3: the PM's guard disabled the step buttons but left the object cards clickable, so an object toggled mid-read got an entry nobody had read for); a test pinning that freeze; and the changeset's `Clause-②:` line corrected from `no` to the measured `yes (widening)`. - Clause-② measurement: after `pnpm --filter @object-ui/plugin-designer build`, `dist/index.d.ts` carries `export type { AppCreationWizardProps } from './AppCreationWizard.js'`, and `dist/AppCreationWizard.d.ts` line 31 carries `readAuthoredObject?: (objectName: string) => Promise...`. On origin/main the source has zero `readAuthoredObject`. `pages/authoredObjectReader.d.ts` is emitted but nothing in the index closure reaches it (`CreateAppPage.d.ts` does not reference it). An optional prop on an exported type widens the public surface. ## Verification <details><summary>Scoped tests, type-check, lint (head a82d33f, after merging origin/main)</summary> - `pnpm --dir ui exec vitest run --maxWorkers=2 packages/plugin-designer/` (under `os-verify-lock`): `Test Files 52 passed (52)`, `Tests 477 passed (477)`, `VERDICT command-exit 0`. - `pnpm run type-check` in `ui/packages/plugin-designer` (`tsc --noEmit && tsc -p tsconfig.test.json`): clean, same lock run, `VERDICT command-exit 0`. - eslint on the 7 changed source and test files: exit 0, 0 errors, 10 warnings, all on lines this diff does not add (`any` in the pages' object mapping, plus two older warnings in the wizard). - The dependency closure was rebuilt after the merge: `pnpm --workspace-concurrency=2 --filter '@object-ui/plugin-designer^...' build`, `VERDICT command-exit 0`. </details> <details><summary>Ablations (one per tested behaviour, each through scripts/ablation-replace.mjs, restore proven by blob == HEAD and an empty git diff HEAD)</summary> The tests import the wizard and pages by relative path from `src/`, so no `dist` is involved. - M1, a refused read falls back to the served plural: 2 failed / 8 passed ("no stored label carries served text", "a refused authored read writes no label"). - M2, the label is decided from the served object instead of the authored read: 5 failed / 5 passed (the ruling-B CONTROL, the project and task cases, the Han check, the freeze test's final label). - M3, the package is dropped from the read: 1 failed ("a packaged object is read at the package the served object came from"). The first attempt replaced the anchor with text that was already in the file, so the tool refused it (replacement count 1 to 1) and nothing ran. It was re-run with a distinct replacement. - M4, the object selection is not frozen during the reads: 1 failed (the freeze test). This answers the PM's reverse-check gap: each label assertion now fails on its own mutation, not only on the helper's call count. </details> <details><summary>Derived gate families</summary> `node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstack` at a82d33f: 38 families, all run locally, each with exit 0. `--ran`: "38 derived famil(ies) accounted for — 38 run, 0 NOT-MEASURED (a DERIVED zero — all 38 recorded an exit code and none of them is 3)". The full farm, `Lint UI`, `Type Check UI`, `Test UI` and `Build & E2E UI` are CI's. </details> --- _Generated by [Claude Code](https://claude.ai/code/session_01L6bhgUAofPTcVEUbSPa79e)_ --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent a998964 commit 17ceb2d

8 files changed

Lines changed: 299 additions & 52 deletions
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
'@object-ui/plugin-designer': patch
3+
'@object-ui/console': patch
4+
---
5+
6+
fix(plugin-designer): the app wizard decides a generated navigation entry's plural label from the object as authored, not as the console's locale serves it
7+
8+
Clause-②: yes (widening)
9+
Metadata-protocol: none
10+
11+
When the Create app or Edit app wizard leaves the Objects step, it generates one navigation entry for each newly selected object. The entry carries no label unless the object declares a plural label that differs from its label and its name. That decision, and the text it stored, came from the served object list, which is translated for the reader's locale. So a zh-CN session stored the translated plural, such as `项目列表`, as the app's source text, readers in every other locale were served it, and whether a label was stored at all depended on the editor's language. The wizard now reads each newly selected object from the untranslated layers through `ObjectStackAdapter.getAuthoredItem('object', name, { packageId })`, at the package the served object came from, and decides and stores the authored plural label (`Projects`). The Next button waits for these reads, and the step buttons and the object selection are disabled until they settle, so the selection cannot change under them. If an object's stored definition cannot be read, its entry carries no label and inherits the object's label at render time; it never falls back to the served text. To show the plural in another locale, translate the entry under `apps.<app>.navigation.<object>.label`. Entries already stored are not rewritten.
12+
13+
`AppCreationWizardProps` gains the optional `readAuthoredObject(objectName)` prop, which `CreateAppPage` and `EditAppPage` now pass. A host that renders `AppCreationWizard` without it gets entries with no label: they inherit the object's label at render time.

‎ui/packages/plugin-designer/src/AppCreationWizard.tsx‎

Lines changed: 112 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* 4. Branding (logo, primary color, favicon)
1818
*/
1919

20-
import React, { useState, useCallback, useMemo } from 'react';
20+
import React, { useState, useCallback, useMemo, useEffect, useRef } from 'react';
2121
import type {
2222
AppWizardDraft,
2323
AppWizardStep,
@@ -74,8 +74,19 @@ export interface AppCreationWizardProps {
7474
readOnly?: boolean;
7575
/** CSS class */
7676
className?: string;
77+
/**
78+
* Reads an object's definition as its author stored it: the untranslated
79+
* layers, never the served object, which is translated for the console's
80+
* locale (objectstack#35101). The plural label of each generated object
81+
* entry is decided from this answer alone. Absent, refused or empty ⇒ the
82+
* entry carries no label and inherits the object's label at render time.
83+
*/
84+
readAuthoredObject?: (objectName: string) => Promise<Record<string, unknown> | null>;
7785
}
7886

87+
/** The authored text a generated entry's label is decided from, per object name. */
88+
type AuthoredEntryLabels = ReadonlyMap<string, string | undefined>;
89+
7990
// ============================================================================
8091
// Constants
8192
// ============================================================================
@@ -113,19 +124,31 @@ const DEFAULT_DRAFT: AppWizardDraft = {
113124
* `label` is the object's machine name when the object has none
114125
* (`CreateAppPage` / `EditAppPage`), so an unlabelled object's entry stored its
115126
* machine name.
127+
*
128+
* objectstack#35101 — the comparison and the stored text are the object's
129+
* AUTHORED definition, never the served one. The served object is translated
130+
* for the console's locale, so deciding from it stored a translation as the
131+
* app's source text (a zh-CN session wrote '项目列表'), and whether anything
132+
* was stored at all depended on the editor's language. An authored definition
133+
* the host could not read decides nothing: the entry inherits.
116134
*/
117-
function generatedEntryLabel(o: ObjectSelection): string | undefined {
118-
const plural = o.pluralLabel?.trim().toLowerCase();
135+
function generatedEntryLabel(
136+
objectName: string,
137+
authored: Record<string, unknown> | null | undefined,
138+
): string | undefined {
139+
const pluralLabel = authored?.pluralLabel;
140+
if (typeof pluralLabel !== 'string') return undefined;
141+
const plural = pluralLabel.trim().toLowerCase();
119142
if (!plural) return undefined;
120-
const spells = (text: string | undefined) => typeof text === 'string' && text.trim().toLowerCase() === plural;
121-
return spells(o.label) || spells(o.name) ? undefined : o.pluralLabel;
143+
const spells = (text: unknown) => typeof text === 'string' && text.trim().toLowerCase() === plural;
144+
return spells(authored?.label) || spells(objectName) ? undefined : pluralLabel;
122145
}
123146

124-
function generateNavFromObjects(objects: ObjectSelection[]): NavigationItem[] {
147+
function generateNavFromObjects(objects: ObjectSelection[], labels: AuthoredEntryLabels): NavigationItem[] {
125148
return objects
126149
.filter((o) => o.selected)
127150
.map((o) => {
128-
const label = generatedEntryLabel(o);
151+
const label = labels.get(o.name);
129152
return {
130153
id: o.name,
131154
type: 'object' as const,
@@ -200,14 +223,47 @@ function dropDeselectedObjectEntries(
200223
function mergeNavWithObjects(
201224
navigation: NavigationItem[],
202225
objects: ObjectSelection[],
226+
labels: AuthoredEntryLabels,
203227
): NavigationItem[] {
204228
const deselected = new Set(objects.filter((o) => !o.selected).map((o) => o.name));
205229
const kept = dropDeselectedObjectEntries(navigation, deselected);
206230
const present = navObjectNames(kept);
207-
const added = generateNavFromObjects(objects.filter((o) => !present.has(o.name)));
231+
const added = generateNavFromObjects(objects.filter((o) => !present.has(o.name)), labels);
208232
return added.length === 0 ? kept : [...kept, ...added];
209233
}
210234

235+
/**
236+
* The selected objects {@link mergeNavWithObjects} generates an entry for: the
237+
* ones with no object entry left in the tree. Only these need an authored read.
238+
*/
239+
function objectsNeedingEntries(navigation: NavigationItem[], objects: ObjectSelection[]): ObjectSelection[] {
240+
const deselected = new Set(objects.filter((o) => !o.selected).map((o) => o.name));
241+
const present = navObjectNames(dropDeselectedObjectEntries(navigation, deselected));
242+
return objects.filter((o) => o.selected && !present.has(o.name));
243+
}
244+
245+
/**
246+
* The authored label of each object's generated entry (objectstack#35101).
247+
* One read per object; a read that is refused or finds nothing maps to
248+
* `undefined`, so that entry inherits. ⛔ Never falls back to the served
249+
* object's text: that is the translation the read exists to keep out.
250+
*/
251+
async function readAuthoredEntryLabels(
252+
objects: ObjectSelection[],
253+
readAuthoredObject: (objectName: string) => Promise<Record<string, unknown> | null>,
254+
): Promise<AuthoredEntryLabels> {
255+
const entries = await Promise.all(
256+
objects.map(async (o): Promise<[string, string | undefined]> => {
257+
try {
258+
return [o.name, generatedEntryLabel(o.name, await readAuthoredObject(o.name))];
259+
} catch {
260+
return [o.name, undefined];
261+
}
262+
}),
263+
);
264+
return new Map(entries);
265+
}
266+
211267
let navItemCounter = 0;
212268

213269
function createNavId(prefix: string): string {
@@ -847,6 +903,7 @@ export function AppCreationWizard({
847903
onSaveDraft,
848904
readOnly = false,
849905
className,
906+
readAuthoredObject,
850907
}: AppCreationWizardProps) {
851908
// ---- i18n ----
852909
const { t } = useDesignerTranslation();
@@ -857,6 +914,13 @@ export function AppCreationWizard({
857914
// ---- State ----
858915
const [currentStep, setCurrentStep] = useState(0);
859916
const [objectSearch, setObjectSearch] = useState('');
917+
// objectstack#35101 — the authored reads for the generated entries are in flight.
918+
const [generatingNav, setGeneratingNav] = useState(false);
919+
const mountedRef = useRef(true);
920+
useEffect(() => {
921+
mountedRef.current = true;
922+
return () => { mountedRef.current = false; };
923+
}, []);
860924

861925
const [draft, setDraft] = useState<AppWizardDraft>(() => ({
862926
...DEFAULT_DRAFT,
@@ -948,23 +1012,43 @@ export function AppCreationWizard({
9481012
});
9491013
}, []);
9501014

1015+
// Leaving objects → navigation: fill an empty navigation from the selected
1016+
// objects, or merge the selection into the one the draft holds. The new
1017+
// entries' labels are decided from the objects' AUTHORED definitions
1018+
// (objectstack#35101), so the step waits for those reads; the step buttons
1019+
// and the object selection are disabled meanwhile, so neither the step nor
1020+
// the selection can move under them.
1021+
const enterNavigationStep = useCallback(() => {
1022+
const pending = readAuthoredObject ? objectsNeedingEntries(draft.navigation, draft.objects) : [];
1023+
const advance = (labels: AuthoredEntryLabels) => {
1024+
setDraft((prev) => ({ ...prev, navigation: mergeNavWithObjects(prev.navigation, prev.objects, labels) }));
1025+
setCurrentStep(2);
1026+
};
1027+
if (!readAuthoredObject || pending.length === 0) {
1028+
advance(new Map());
1029+
return;
1030+
}
1031+
setGeneratingNav(true);
1032+
void readAuthoredEntryLabels(pending, readAuthoredObject).then((labels) => {
1033+
if (!mountedRef.current) return;
1034+
setGeneratingNav(false);
1035+
advance(labels);
1036+
});
1037+
}, [draft.navigation, draft.objects, readAuthoredObject]);
1038+
9511039
const handleNext = useCallback(() => {
952-
if (isLastStep) return;
953-
// Leaving objects → navigation: fill an empty navigation from the selected
954-
// objects, or merge the selection into the one the draft holds.
1040+
if (isLastStep || generatingNav) return;
9551041
if (currentStep === 1) {
956-
setDraft((prev) => ({
957-
...prev,
958-
navigation: mergeNavWithObjects(prev.navigation, prev.objects),
959-
}));
1042+
enterNavigationStep();
1043+
return;
9601044
}
9611045
setCurrentStep((s) => s + 1);
962-
}, [currentStep, isLastStep]);
1046+
}, [currentStep, isLastStep, generatingNav, enterNavigationStep]);
9631047

9641048
const handleBack = useCallback(() => {
965-
if (isFirstStep) return;
1049+
if (isFirstStep || generatingNav) return;
9661050
setCurrentStep((s) => s - 1);
967-
}, [isFirstStep]);
1051+
}, [isFirstStep, generatingNav]);
9681052

9691053
const handleComplete = useCallback(() => {
9701054
onComplete?.(draft);
@@ -990,21 +1074,20 @@ export function AppCreationWizard({
9901074

9911075
const handleStepClick = useCallback(
9921076
(index: number) => {
1077+
if (generatingNav) return;
9931078
// Only allow navigating to completed steps or the next valid step
9941079
if (index <= currentStep) {
9951080
setCurrentStep(index);
9961081
} else if (index === currentStep + 1 && canProceed) {
9971082
// Jumping objects → navigation: the same fill-or-merge as `handleNext`.
9981083
if (currentStep === 1 && index === 2) {
999-
setDraft((prev) => ({
1000-
...prev,
1001-
navigation: mergeNavWithObjects(prev.navigation, prev.objects),
1002-
}));
1084+
enterNavigationStep();
1085+
return;
10031086
}
10041087
setCurrentStep(index);
10051088
}
10061089
},
1007-
[currentStep, canProceed]
1090+
[currentStep, canProceed, generatingNav, enterNavigationStep]
10081091
);
10091092

10101093
// ---- Render ----
@@ -1076,7 +1159,9 @@ export function AppCreationWizard({
10761159
{currentStep === 1 && (
10771160
<ObjectSelectionStep
10781161
objects={draft.objects}
1079-
readOnly={readOnly}
1162+
// The selection is frozen while its entries' authored reads run:
1163+
// an object toggled mid-read would get an entry nobody read for.
1164+
readOnly={readOnly || generatingNav}
10801165
onToggle={toggleObject}
10811166
onToggleAll={toggleAllObjects}
10821167
search={objectSearch}
@@ -1136,7 +1221,7 @@ export function AppCreationWizard({
11361221
type="button"
11371222
data-testid="wizard-back"
11381223
onClick={handleBack}
1139-
disabled={readOnly}
1224+
disabled={readOnly || generatingNav}
11401225
className="inline-flex items-center gap-1 rounded-md border border-gray-300 px-4 py-2 text-sm font-medium text-gray-700 transition-colors hover:bg-gray-50 disabled:cursor-not-allowed disabled:opacity-50"
11411226
>
11421227
<ChevronLeft className="h-4 w-4" />
@@ -1159,7 +1244,8 @@ export function AppCreationWizard({
11591244
type="button"
11601245
data-testid="wizard-next"
11611246
onClick={handleNext}
1162-
disabled={readOnly || !canProceed}
1247+
disabled={readOnly || !canProceed || generatingNav}
1248+
aria-busy={generatingNav || undefined}
11631249
className="inline-flex items-center gap-1 rounded-md bg-blue-600 px-4 py-2 text-sm font-medium text-white transition-colors hover:bg-blue-700 disabled:cursor-not-allowed disabled:opacity-50"
11641250
>
11651251
{t('common.next')}

‎ui/packages/plugin-designer/src/__tests__/AppWizard.specDocument-10867.test.tsx‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ vi.mock('@object-ui/react', async (importOriginal) => {
5252
getClient: () => ({ meta: { saveItem } }),
5353
// objectstack#35054 — the page edits the app as stored (the layers read):
5454
// the served app minus its read decorations, which no layer carries.
55-
getAuthoredItem: async (_type: string, name: string) => {
55+
// objectstack#35101 — and reads each newly selected object as stored.
56+
getAuthoredItem: async (type: string, name: string) => {
57+
if (type === 'object') return OBJECTS.find((o) => o.name === name) ?? null;
5658
const served = apps.find((a) => a.name === name);
5759
return served ? Object.fromEntries(Object.entries(served).filter(([k]) => !k.startsWith('_'))) : null;
5860
},
@@ -101,6 +103,7 @@ describe('objectui#10867 — member 1: a wizard app with a separator saves a doc
101103
next(); // → objects
102104
fireEvent.click(screen.getByTestId('object-card-account'));
103105
next(); // → navigation, generated from the selected object
106+
await screen.findByTestId('wizard-step-navigation-content'); // the authored object reads settle
104107
fireEvent.click(screen.getByTestId('add-separator-btn'));
105108
next(); // → branding
106109
fireEvent.click(screen.getByTestId('wizard-complete'));
@@ -142,6 +145,7 @@ describe('objectui#10867 — member 2: an edit keeps every stored `branding` key
142145
await screen.findByTestId('edit-app-page');
143146
next(); // → objects
144147
next(); // → navigation
148+
await screen.findByTestId('wizard-step-navigation-content'); // the authored object reads settle
145149
next(); // → branding
146150
onBranding?.();
147151
fireEvent.click(screen.getByTestId('wizard-complete'));

0 commit comments

Comments
 (0)