Skip to content

Commit 8061d83

Browse files
fix(app-shell): record-tabs rename gate reads the served sourceLocale (#37381)
Fixes #36875 Clause-②: no Metadata-protocol: none ## 维护者速读 用户能看到什么变化:搭建者在设计模式里给记录页签改名时,「能不能改名」改按应用的源语言判断,不再按部署的默认语言判断;默认语言与源语言相同的部署用户无感。 为什么做:接着菜单改名已改用源语言的那项工作,把记录页签改名补齐到同一种判断。 出错会怎样:默认语言与源语言不同的部署上,页签名可能被当成源文字写入或该能改时改不了;本改动只换判断依据,可直接撤回。 要你做什么:无 ## What changes `ui/packages/app-shell/src/views/recordTabsConfigIo.tsx` decided "source language" with `fetchDefaultLocale()` + `isSameLanguage(language, defaultLocale)`. It now reads the deployment's languages through the reader PR #36858 added, `fetchDeploymentLocales()`, and asks `labelLanguageOf(language, locales).source`, the exact gate the menu rename uses. That reader takes the served `sourceLocale` and falls back to the default locale when the server serves none, so the fallback is the reader's own. No second fetch: the reader is cached per page load and shared with the menu. What the editor does with the answer is unchanged: in the source language a rename opens and writes the stored label; in any other language the rename button is disabled with the hint "Tab names are changed in the app's source language". ## Tests New file `ui/packages/app-shell/src/views/__tests__/RecordTabsConfig-36875.test.tsx`, same harness as the #36499 suite, the `GET /i18n/locales` fake now serving `sourceLocale`: 1. default locale zh-CN, source en, reader in zh-CN: rename disabled with the source-only hint, Save disabled, nothing written. 2. default locale zh-CN, source en, reader in en: rename opens, Save writes `relatedLists` `[{ list: 'contact', label: 'Contacts we know' }, 'task']` through the draft save, then publish. 3. no `sourceLocale` served: the default locale is the source, as before (zh-CN reader renames, en reader cannot). Reverse check (one-off, no file kept): with the fix committed (`e2288d21`), `recordTabsConfigIo.tsx` was put back to `origin/main` and the new file run. Cases 1 and 2 turned red (`Tests 2 failed | 1 passed (3)`), case 3 stayed green as expected (fallback behaviour is unchanged). Restored with `git checkout HEAD -- PATH`; HEAD blob hash matched, `git diff HEAD` empty. ## Acceptance notes - Acceptance item 2 says the test "stores a tab rename as a translation". The record-tabs editor has no translation write path: outside the source language its rename is closed by design (#36499, ruling (4) precedent), it never writes a translation. The test therefore proves the side the fix controls: a reader in a default locale that is not the source language cannot write the tab name as the source label, and a reader in the source language can. Adding a translation write to record tabs would be a new capability, not this card. - `fetchDefaultLocale` in `layout/designModeMenuSave.ts` has no caller after this change (it was the only one). Left in place: that file is the #36858 reader's and outside this card's file surface. - The lazy-import comment in `RecordTabsConfig.tsx` (~L95) still says "the default language"; comment only, outside the file surface. - No other design-mode rename path gates on the default locale: `git grep` for `fetchDefaultLocale` / `isSameLanguage(` under `ui/` finds only the reader itself. ## Verification Two-minute check: `cd ui && pnpm exec vitest run packages/app-shell/src/views/__tests__/RecordTabsConfig-36875.test.tsx` → 3 passed. Read first: `ui/packages/app-shell/src/views/recordTabsConfigIo.tsx` (the whole change is the gate line and the fetch it reads). <details><summary>Local readings at e2288d2</summary> - `pnpm --filter '@object-ui/app-shell^...' build` → VERDICT command-exit 0 - `cd ui && pnpm exec vitest run --maxWorkers=2` the three RecordTabsConfig suites + `packages/app-shell/src/layout/` → Test Files 167 passed (167), Tests 1467 passed (1467) - `pnpm --filter @object-ui/app-shell run type-check` → exit 0 - `node scripts/pm/dispatch-gates.mjs --commands`: 38 derived commands, all exit 0; `--ran` reconciliation: 38 derived, 38 run, 0 NOT-MEASURED, 0 UNRUN (a derived zero). `pnpm --dir ui exec vitest run scripts/` was OOM-killed on the first unlocked run on the shared box, rerun under the verify lock with `--maxWorkers=2`: 172 passed, 2 skipped files. - `node scripts/pm/overlap-check.mjs --branch=HEAD` → VERDICT clean exit 0 </details> --- _Generated by [Claude Code](https://claude.ai/code/session_01Utp6Ca6EBDpTBZk8v46Jjv)_ Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: objectstack-fleet[bot] <332303061+objectstack-fleet[bot]@users.noreply.github.com>
1 parent ecbe854 commit 8061d83

3 files changed

Lines changed: 234 additions & 7 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 record-tabs rename in the design mode decides "source language" from the served `sourceLocale`, not the default locale
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
「Configure tabs」 lets a tab be renamed only in the app's source language, where the name written is the source label. It used to decide that by comparing the reader's language with the deployment's default locale. It now reads the source language `GET /i18n/locales` serves (`sourceLocale`, the default locale where none is served), the same reading the app menu's rename takes. On a deployment whose default locale differs from its source language, a reader in the default locale no longer writes a tab name as the source label, and a reader in the source language can rename again.
Lines changed: 214 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,214 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* The record-tabs rename gate reads the app's source language, not the
5+
* deployment's default locale (objectstack#36875): `GET /i18n/locales` serves
6+
* `sourceLocale`, and a reader in the default locale where that differs from
7+
* the source cannot rename a tab (a rename there would be written as the
8+
* source label), while a reader in the source language can. A server that
9+
* serves no `sourceLocale` keeps the default locale as the source.
10+
*
11+
* Real subjects: `useRecordTabsConfig`, `RecordTabsEditor`,
12+
* `recordTabsConfigIo.tsx`, `fetchDeploymentLocales`, `labelLanguageOf`,
13+
* `saveRecordTabs`, the design mode and its bar. Fakes: the design gate's
14+
* answer, the metadata client (it records what is written), the package
15+
* list and the deployment's languages.
16+
*/
17+
18+
import '@testing-library/jest-dom/vitest';
19+
import * as React from 'react';
20+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
21+
import { act, cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react';
22+
import { MemoryRouter } from 'react-router-dom';
23+
24+
const session = vi.hoisted(() => ({ language: 'en', defaultLocale: 'en', sourceLocale: null as string | null, gate: true as boolean }));
25+
vi.mock('@object-ui/i18n', async (importOriginal) => ({
26+
...(await importOriginal<Record<string, unknown>>()),
27+
useObjectTranslation: () => ({
28+
t: (k: string, o?: Record<string, unknown>) =>
29+
String(o?.defaultValue ?? k).replace(/\{\{(\w+)\}\}/g, (_hole, name: string) => String(o?.[name] ?? '')),
30+
language: session.language,
31+
}),
32+
}));
33+
34+
vi.mock('sonner', async (importOriginal) => ({
35+
...(await importOriginal<Record<string, unknown>>()),
36+
toast: { error: vi.fn(), success: vi.fn() },
37+
}));
38+
39+
vi.mock('../../hooks/useStudioDesignGate', async (importOriginal) => ({
40+
...(await importOriginal<Record<string, unknown>>()),
41+
useStudioDesignGate: (path: string | null) => (session.gate ? path : null),
42+
}));
43+
44+
const written = vi.hoisted(() => [] as Array<[string, ...unknown[]]>);
45+
const stored = vi.hoisted(() => ({ relatedLists: undefined as unknown[] | undefined }));
46+
const client = vi.hoisted(() => ({
47+
layered: async () => {
48+
const code = { name: 'account', label: 'Account', ...(stored.relatedLists ? { relatedLists: stored.relatedLists } : {}) };
49+
return { code, effective: code };
50+
},
51+
save: async (...args: unknown[]) => {
52+
written.push(['save', ...args]);
53+
return {};
54+
},
55+
publish: async (...args: unknown[]) => {
56+
written.push(['publish', ...args]);
57+
return {};
58+
},
59+
reset: async () => ({}),
60+
}));
61+
vi.mock('../metadata-admin/useMetadata', async (importOriginal) => ({
62+
...(await importOriginal<Record<string, unknown>>()),
63+
useMetadataClient: () => client,
64+
}));
65+
vi.mock('../studio-design/packages-io', async (importOriginal) => ({
66+
...(await importOriginal<Record<string, unknown>>()),
67+
fetchListedPackageManifests: async () => new Map([['app.crm', { id: 'app.crm', name: 'CRM', writable: true, manifest: {} }]]),
68+
}));
69+
70+
import { useRecordTabsConfig } from '../RecordTabsConfig';
71+
import { __resetDefaultLocale } from '../../layout/designModeMenuSave';
72+
import { DesignModeProvider, useDesignModeController } from '../../layout/designMode';
73+
import { DesignModeBar } from '../../layout/DesignModeBar';
74+
75+
const lookup = { type: 'lookup', reference: 'account' };
76+
const OBJECTS = [
77+
{ name: 'account', label: 'Account', _packageId: 'app.crm', relatedLists: [{ list: 'contact', label: 'People' }, 'task'] },
78+
{ name: 'contact', label: 'Contact', _packageId: 'app.crm', fields: { account: lookup } },
79+
{ name: 'task', label: 'Task', _packageId: 'app.crm', fields: { account: lookup } },
80+
{ name: 'case', label: 'Case', _packageId: 'app.crm', fields: { account: lookup } },
81+
];
82+
83+
/** The shell's hold on the design mode, its bar while it is on, and the page under it. */
84+
function Shell({ children }: { children?: React.ReactNode }) {
85+
const mode = useDesignModeController({ appName: 'crm', appBasePath: '/apps/crm', enabled: true });
86+
return (
87+
<DesignModeProvider value={mode}>
88+
{mode.active ? <DesignModeBar mode={mode} /> : <button type="button" onClick={mode.enter}>design</button>}
89+
{children}
90+
</DesignModeProvider>
91+
);
92+
}
93+
94+
function Page({
95+
objectDef = OBJECTS[0] as Record<string, unknown>,
96+
objects = OBJECTS,
97+
}: {
98+
objectDef?: Record<string, unknown>;
99+
objects?: Record<string, unknown>[];
100+
}) {
101+
const config = useRecordTabsConfig({
102+
objectDef,
103+
objects,
104+
enabled: true,
105+
titleOf: (list) => list.title || `${list.childLabel}s`,
106+
});
107+
return (
108+
<>
109+
<span data-testid="active">{String(config.active)}</span>
110+
{config.editor}
111+
<span data-testid="preview">{JSON.stringify(config.previewObject?.relatedLists ?? null)}</span>
112+
</>
113+
);
114+
}
115+
116+
function Harness({ objects, page = true, extra }: { objects?: Record<string, unknown>[]; page?: boolean; extra?: React.ReactNode }) {
117+
return (
118+
<MemoryRouter>
119+
<Shell>
120+
{page && <Page objects={objects} />}
121+
{extra}
122+
</Shell>
123+
</MemoryRouter>
124+
);
125+
}
126+
127+
const flush = () => act(async () => {
128+
await new Promise((r) => setTimeout(r, 0));
129+
});
130+
131+
beforeEach(() => {
132+
written.length = 0;
133+
stored.relatedLists = [{ list: 'contact', label: 'People' }, 'task'];
134+
session.language = 'en';
135+
session.defaultLocale = 'en';
136+
session.sourceLocale = null;
137+
session.gate = true;
138+
__resetDefaultLocale();
139+
vi.stubGlobal(
140+
'fetch',
141+
vi.fn(async () => ({
142+
headers: new Headers(),
143+
ok: true,
144+
json: async () => ({
145+
data: {
146+
locales: [
147+
{ code: 'en', isDefault: session.defaultLocale === 'en' },
148+
{ code: 'zh-CN', isDefault: session.defaultLocale === 'zh-CN' },
149+
],
150+
...(session.sourceLocale ? { sourceLocale: session.sourceLocale } : {}),
151+
},
152+
}),
153+
})),
154+
);
155+
});
156+
afterEach(() => {
157+
cleanup();
158+
vi.unstubAllGlobals();
159+
});
160+
161+
async function open() {
162+
render(<Harness />);
163+
fireEvent.click(screen.getByText('design'));
164+
await waitFor(() => expect(screen.getByRole('button', { name: 'Hide Tasks' })).toBeEnabled());
165+
await flush();
166+
}
167+
168+
const save = () => screen.getByTestId('design-mode-save');
169+
170+
describe('the record-tabs rename gate reads the served source language (objectstack#36875)', () => {
171+
it('default locale zh-CN, source en: a reader in zh-CN cannot rename, so nothing is written as the source label', async () => {
172+
session.defaultLocale = 'zh-CN';
173+
session.sourceLocale = 'en';
174+
session.language = 'zh-CN';
175+
await open();
176+
const rename = screen.getByRole('button', { name: 'Rename People' });
177+
expect(rename).toBeDisabled();
178+
expect(rename).toHaveAttribute('title', "Tab names are changed in the app's source language");
179+
expect(save()).toBeDisabled();
180+
expect(written).toEqual([]);
181+
});
182+
183+
it('default locale zh-CN, source en: a reader in en renames, and the save writes the source label', async () => {
184+
session.defaultLocale = 'zh-CN';
185+
session.sourceLocale = 'en';
186+
session.language = 'en';
187+
await open();
188+
const rename = screen.getByRole('button', { name: 'Rename People' });
189+
expect(rename).toBeEnabled();
190+
fireEvent.click(rename);
191+
const input = screen.getByLabelText('Tab name');
192+
fireEvent.change(input, { target: { value: 'Contacts we know' } });
193+
fireEvent.keyDown(input, { key: 'Enter' });
194+
expect(save()).toBeEnabled();
195+
fireEvent.click(save());
196+
await flush();
197+
await flush();
198+
expect(written.map(([door]) => door)).toEqual(['save', 'publish']);
199+
expect(written[0].slice(1, 3)).toEqual(['object', 'account']);
200+
expect((written[0][3] as { relatedLists: unknown }).relatedLists).toEqual([{ list: 'contact', label: 'Contacts we know' }, 'task']);
201+
});
202+
203+
it('no sourceLocale served: the default locale is the source, as before', async () => {
204+
session.defaultLocale = 'zh-CN';
205+
session.language = 'zh-CN';
206+
await open();
207+
expect(screen.getByRole('button', { name: 'Rename People' })).toBeEnabled();
208+
cleanup();
209+
__resetDefaultLocale();
210+
session.language = 'en';
211+
await open();
212+
expect(screen.getByRole('button', { name: 'Rename People' })).toBeDisabled();
213+
});
214+
});

‎ui/packages/app-shell/src/views/recordTabsConfigIo.tsx‎

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
* `relatedLists` (on an installed object whose tabs the paired `.custom`
88
* package arranges, its extension's entries first), the listed packages'
99
* names (a tab's source, card item 7), and whether the reader's language is
10-
* the deployment's default (the rename gate's precedent).
10+
* the app's source language: the `sourceLocale` the deployment serves on
11+
* `GET /i18n/locales`, its default locale where it serves none
12+
* (`fetchDeploymentLocales`, `labelLanguageOf`, objectstack#36875), the same
13+
* reading the menu's rename gate takes (objectstack#36504).
1114
*
1215
* It sits behind `React.lazy` so the record page's own module graph does not
1316
* gain the metadata client's module (it mints its authenticated fetch when it
@@ -18,7 +21,7 @@
1821
*/
1922

2023
import * as React from 'react';
21-
import { fetchDefaultLocale, isSameLanguage } from '../layout/designModeMenuSave.js';
24+
import { fetchDeploymentLocales, labelLanguageOf, type DeploymentLocales } from '../layout/designModeMenuSave.js';
2225
import { useMetadataClient } from './metadata-admin/useMetadata.js';
2326
import { fetchListedPackageManifests } from './studio-design/packages-io.js';
2427
import { readStoredTabEntries, type RecordTabsSaveDoors } from './recordTabsConfigSave.js';
@@ -27,7 +30,7 @@ export interface RecordTabsIo {
2730
readonly client: RecordTabsSaveDoors['client'];
2831
/** The object's stored `relatedLists`, once read for `objectName` (`null` when the read failed). */
2932
readonly stored: { readonly objectName: string; readonly lists: unknown[] | null } | null;
30-
/** The reader's language is the deployment's default. */
33+
/** The reader's language is the app's source language (`sourceLocale`, else the default locale). */
3134
readonly sourceLanguage: boolean;
3235
/** The listed packages' names, by id (empty until read, or when the read failed). */
3336
readonly packageNames: ReadonlyMap<string, string>;
@@ -47,7 +50,7 @@ const NO_NAMES: ReadonlyMap<string, string> = new Map();
4750
export default function RecordTabsConfigIo({ objectName, packageId, pairId, language, onIo }: RecordTabsConfigIoProps) {
4851
const client = useMetadataClient() as unknown as RecordTabsSaveDoors['client'];
4952
const [stored, setStored] = React.useState<RecordTabsIo['stored']>(null);
50-
const [defaultLocale, setDefaultLocale] = React.useState<string | null>(null);
53+
const [locales, setLocales] = React.useState<DeploymentLocales | null>(null);
5154
const [packageNames, setPackageNames] = React.useState<ReadonlyMap<string, string>>(NO_NAMES);
5255

5356
React.useEffect(() => {
@@ -61,15 +64,15 @@ export default function RecordTabsConfigIo({ objectName, packageId, pairId, lang
6164
},
6265
() => undefined,
6366
);
64-
void fetchDefaultLocale().then((code) => {
65-
if (!cancelled) setDefaultLocale(code);
67+
void fetchDeploymentLocales().then((read) => {
68+
if (!cancelled) setLocales(read);
6669
});
6770
return () => {
6871
cancelled = true;
6972
};
7073
}, [objectName, packageId, pairId, client]);
7174

72-
const sourceLanguage = !!defaultLocale && isSameLanguage(language, defaultLocale);
75+
const sourceLanguage = labelLanguageOf(language, locales).source;
7376
React.useEffect(() => {
7477
onIo({ client, stored, sourceLanguage, packageNames });
7578
}, [onIo, client, stored, sourceLanguage, packageNames]);

0 commit comments

Comments
 (0)