Skip to content

Commit 8df05bb

Browse files
committed
fix(app-shell): the curated page, report and dashboard inspectors name a select's options in Chinese under zh-CN
The console's metadataForms overlay named a select's row but not its options, so under zh-CN the page Type and Record action selects and the report and dashboard Default Period selects listed English choices beside Chinese labels. The overlay now carries those four rows' option names in the options slot resolveMetadataFormLabels reads, copied from the platform's zh-CN pack and pinned byte-equal to it (metadata-form-option-names.test.ts). The console-side Default Period renaming (default-period-labels.ts) is retired; #36835's pin now also holds the zh names to the period chip's rows. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01L6bhgUpnvPnJ1hR74pUrVj
1 parent c2bfa3e commit 8df05bb

8 files changed

Lines changed: 222 additions & 135 deletions
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 curated page, report and dashboard inspectors name a select's options in Chinese under zh-CN
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
Under zh-CN the page Type and Record action selects and the report and dashboard Default Period selects listed English choices beside Chinese labels. The console's `metadataForms` overlay now carries those four rows' option names in the `options` slot `resolveMetadataFormLabels` reads, copied from the platform's zh-CN pack (`zh-CN.metadata-forms.generated.ts`, the one `/api/v1/meta/types` localizes the same forms with) and pinned byte-equal to it. The console-side Default Period renaming (`default-period-labels.ts`) is retired: the overlay names those options now, in the same words the report and dashboard period chip shows. Every other designer locale keeps the spec's English, as before.

‎ui/packages/app-shell/src/views/metadata-admin/default-period-labels.ts‎

Lines changed: 0 additions & 83 deletions
This file was deleted.

‎ui/packages/app-shell/src/views/metadata-admin/inspectors/DashboardDefaultInspector.tsx‎

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,7 @@ import { SchemaForm } from '../SchemaForm.js';
4545
import { fallbackFormPatch } from './fallbackFormPatch.js';
4646
import type { FormViewSpec } from '../SchemaForm.js';
4747
import { getDashboardForm, getDashboardSchema } from '../dashboard-schema.js';
48-
import { localizeDefaultPeriods } from '../default-period-labels.js';
4948
import { mergeServerFields } from '../mergeServerFields.js';
50-
import { useObjectTranslation } from '@object-ui/i18n';
5149
import { t, tFormat } from '../i18n.js';
5250
// `DashboardWidget.title` is the spec's `I18nLabel`, which @objectstack/spec
5351
// 17.0.0-rc.6 widened from plain `string` to `string | Record<string, string>`
@@ -175,7 +173,6 @@ export function DashboardDefaultInspector({
175173

176174
// Graft any server-only top-level dashboard fields onto the bundled-spec
177175
// form so they are editable even when the bundled spec lags the server.
178-
const { t: appT } = useObjectTranslation();
179176
const { schema, form } = React.useMemo(() => {
180177
const merged = mergeServerFields({
181178
bundledSchema: getDashboardSchema(),
@@ -187,16 +184,8 @@ export function DashboardDefaultInspector({
187184
sectionTitle: t('engine.inspector.moreFields', locale),
188185
});
189186
// After the graft, so a server-only section stacks too (objectui#11796).
190-
// The Default Period options are named the way the report inspector names
191-
// them (`localizeDefaultPeriods`): the console's locale packs for a zh
192-
// designer, the producer's English otherwise.
193-
return {
194-
schema: merged.schema,
195-
form: stackSectionsForNarrowPanel(localizeDefaultPeriods(merged.form, locale, (key, options) => appT(key, options))),
196-
};
197-
// `appT` changes with the app's language and when a locale pack lands, so
198-
// the names follow both.
199-
}, [serverSchema, locale, appT]);
187+
return { schema: merged.schema, form: stackSectionsForNarrowPanel(merged.form) };
188+
}, [serverSchema, locale]);
200189

201190
return (
202191
<InspectorShell

‎ui/packages/app-shell/src/views/metadata-admin/inspectors/ReportDefaultInspector.defaultPeriodLabels-36835.test.tsx‎

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,17 @@
55
* (「Period & export」 → Date Range → Default Period) listed each option by its
66
* stored preset, `this_month`, in English and in Chinese alike.
77
*
8-
* The spec form now names the options in English, and a zh designer reads the
9-
* names from the console's locale packs, the rows the report page's period chip
10-
* shows (`dashboard.filters.range.*`, `dashboard.filters.custom`).
8+
* The spec form names the options in English; under zh the metadata-form
9+
* overlay names them with the platform pack's words (objectstack#37607, which
10+
* retired the console-side renaming this file first pinned).
1111
*
1212
* - en: the options read the spec's names, and never a stored preset.
13-
* - zh: the options read the locale pack's names. POSITIVE CONTROL in the same
14-
* run: the row's own zh label (默认时间段, from the metadata-form overlay),
15-
* so a dead locale channel cannot pass for "not relabelled".
16-
* - The spec's English names equal the en pack's rows, so the two surfaces
17-
* that name a period (this select and the period chip) cannot drift apart.
13+
* - zh: the options read Chinese names. POSITIVE CONTROL in the same run: the
14+
* row's own zh label (默认时间段, from the same overlay), so a dead locale
15+
* channel cannot pass for "not relabelled".
16+
* - The select's names equal the rows the report page's period chip reads
17+
* (`dashboard.filters.range.*`, `dashboard.filters.custom`), in en and in zh,
18+
* so the two surfaces that name a period cannot drift apart.
1819
*/
1920

2021
import '@testing-library/jest-dom/vitest';
@@ -25,9 +26,10 @@ import { render, screen, fireEvent, cleanup, waitFor } from '@testing-library/re
2526
import '@objectstack/formula';
2627
import '@objectstack/lint';
2728
import { I18nProvider, en } from '@object-ui/i18n';
29+
import { zh } from '@object-ui/i18n/locales';
2830
import { reportForm } from '@objectstack/spec/ui';
2931
import { ReportDefaultInspector } from './ReportDefaultInspector';
30-
import { defaultPeriodLabelKey } from '../default-period-labels';
32+
import { getReportForm } from '../report-schema';
3133
import type { DatasetCatalogEntry } from '../previews/useDatasetCatalog';
3234
import { loadStudioCatalogue } from '@object-ui/i18n/namespaces/studio';
3335
await loadStudioCatalogue('zh');
@@ -99,12 +101,35 @@ async function openDefaultPeriod(sectionTitle: string, rowLabel: string): Promis
99101

100102
const VALUES = specOptions().map((o) => o.value);
101103

104+
/** The console row the period chip reads for a Default Period value. */
105+
const chipKey = (value: string) =>
106+
value === 'custom' ? 'dashboard.filters.custom' : `dashboard.filters.range.${value}`;
107+
108+
/** The Default Period options of the report form as `getReportForm` names them for `locale`. */
109+
function namedOptions(locale: string): Array<{ label: string; value: string }> {
110+
for (const section of getReportForm(locale)?.sections ?? []) {
111+
for (const field of (section.fields ?? []) as any[]) {
112+
if (field?.field !== 'dateRange') continue;
113+
const child = (field.fields ?? []).find((c: any) => c?.field === 'defaultRange');
114+
if (child?.options) return child.options;
115+
}
116+
}
117+
throw new Error('the report form names no dateRange.defaultRange options');
118+
}
119+
120+
const readPack = (pack: unknown, key: string) =>
121+
key.split('.').reduce((node: any, seg) => node?.[seg], pack as Record<string, any>);
122+
102123
describe('#36835 — the Default Period select names its periods', () => {
103124
it('the spec English names are the en locale pack rows the period chip reads', () => {
104-
const pack = en as unknown as Record<string, any>;
105-
const read = (key: string) => key.split('.').reduce((node, seg) => node?.[seg], pack);
106125
for (const { value, label } of specOptions()) {
107-
expect(read(defaultPeriodLabelKey(value)), value).toBe(label);
126+
expect(readPack(en, chipKey(value)), value).toBe(label);
127+
}
128+
});
129+
130+
it('the zh names are the zh locale pack rows the period chip reads', () => {
131+
for (const { value, label } of namedOptions('zh-CN')) {
132+
expect(readPack(zh, chipKey(value)), value).toBe(label);
108133
}
109134
});
110135

@@ -116,7 +141,7 @@ describe('#36835 — the Default Period select names its periods', () => {
116141
for (const value of VALUES) expect(offered, value).not.toContain(value);
117142
});
118143

119-
it('zh: every option reads the locale pack name', async () => {
144+
it('zh: every option reads its Chinese name', async () => {
120145
renderIn('zh', 'zh-CN');
121146
// POSITIVE CONTROL: the row label comes through the zh overlay.
122147
const offered = await openDefaultPeriod('时间段与导出', '默认时间段');

‎ui/packages/app-shell/src/views/metadata-admin/inspectors/ReportDefaultInspector.tsx‎

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,12 @@ import {
5555
} from '../previews/useDatasetCatalog.js';
5656
import { useStudioDatasetAuthoring } from '../../studio-design/datasetCreate.js';
5757
import { getReportForm, getReportSchema } from '../report-schema.js';
58-
import { localizeDefaultPeriods } from '../default-period-labels.js';
5958
import { mergeServerFields } from '../mergeServerFields.js';
6059
import { t, tFormat } from '../i18n.js';
6160
import { mapLoaded } from '../loadState.js';
6261
import type { WidgetContext } from '../widgets.js';
6362
import { datasetPickerOptions, datasetLabelOptions } from './dataset-picker-options.js';
64-
import { pickLocalized, setLocalized, clearLocalized, useObjectTranslation } from '@object-ui/i18n';
63+
import { pickLocalized, setLocalized, clearLocalized } from '@object-ui/i18n';
6564
import { WIDGET_TYPE_META } from '../previews/widget-types.js';
6665
import { shownLabel, writtenLabel, servedLabelNote, useLabelLanguage } from './servedLabel.js';
6766
import { useServedReportText } from '../../studio-design/servedReportText.js';
@@ -555,24 +554,20 @@ export function ReportDefaultInspector({
555554

556555
// Graft any server-only top-level fields onto the bundled-spec form so they
557556
// are directly editable here even when the bundled `@objectstack/spec` lags
558-
// the running server (skew root-cure).
559-
// The Default Period options carry the spec's English names; a zh designer
560-
// reads them from the console's locale packs, the rows the report page's
561-
// period chip shows (`localizeDefaultPeriods`). Every other designer locale
562-
// keeps the producer's English, like the rest of this panel.
563-
const { t: appT } = useObjectTranslation();
564-
const { schema, form } = React.useMemo(() => {
565-
const merged = mergeServerFields({
566-
bundledSchema: getReportSchema(),
567-
bundledForm: getReportForm(locale),
568-
serverSchema,
569-
excludeFields: REPORT_CURATED_FIELDS,
570-
sectionTitle: t('engine.inspector.moreFields', locale),
571-
});
572-
return { ...merged, form: localizeDefaultPeriods(merged.form, locale, (key, options) => appT(key, options)) };
573-
// `appT` changes with the app's language and when a locale pack lands, so
574-
// the names follow both.
575-
}, [serverSchema, locale, appT]);
557+
// the running server (skew root-cure). `getReportForm(locale)` names the
558+
// options of a select too (the Default Period presets among them), from the
559+
// same overlay that names the rows.
560+
const { schema, form } = React.useMemo(
561+
() =>
562+
mergeServerFields({
563+
bundledSchema: getReportSchema(),
564+
bundledForm: getReportForm(locale),
565+
serverSchema,
566+
excludeFields: REPORT_CURATED_FIELDS,
567+
sectionTitle: t('engine.inspector.moreFields', locale),
568+
}),
569+
[serverSchema, locale],
570+
);
576571

577572
return (
578573
<InspectorShell

‎ui/packages/app-shell/src/views/metadata-admin/metadata-form-i18n.ts‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
* The strings belong to the spec, and the platform already declares how they
2121
* are translated: `metadataForms.<type>.{label,description}`,
2222
* `.sections.<section>.{label,description}`,
23-
* `.fields.<dot.path>.{label,helpText,placeholder}` — resolved by
23+
* `.fields.<dot.path>.{label,helpText,placeholder,options}` — resolved by
2424
* `resolveMetadataFormLabels` from `@objectstack/spec/system`, which the
2525
* framework's own `/meta/types` handler calls to localize the very same forms
2626
* before serving them. This module supplies a bundle to THAT function rather
@@ -135,7 +135,13 @@ const METADATA_FORM_BUNDLE: TranslationBundle = {
135135
dateRange: { label: '日期范围', helpText: '打开仪表盘时默认的时间段,以及查看者能否自选日期。' },
136136
// All three children of the `dateRange` composite — see the ⛔ note above.
137137
'dateRange.field': { label: '日期字段', helpText: '时间段筛选所依据的日期字段。留空则按创建日期筛选。' },
138-
'dateRange.defaultRange': { label: '默认时间段', helpText: '打开仪表盘时显示的时间段。' },
138+
'dateRange.defaultRange': {
139+
label: '默认时间段',
140+
helpText: '打开仪表盘时显示的时间段。',
141+
// Option names: the platform pack's map, pinned byte-equal by
142+
// `metadata-form-option-names.test.ts`.
143+
options: { today: '今天', yesterday: '昨天', this_week: '本周', last_week: '上周', this_month: '本月', last_month: '上月', next_month: '下月', this_quarter: '本季度', last_quarter: '上季度', next_quarter: '下季度', this_year: '今年', last_year: '去年', last_7_days: '近 7 天', last_30_days: '近 30 天', last_90_days: '近 90 天', next_30_days: '未来 30 天', custom: '自定义…' },
144+
},
139145
'dateRange.allowCustomRange': { label: '允许自定义范围', helpText: '允许查看者自己选择开始和结束日期。' },
140146
globalFilters: { label: '全局筛选', helpText: '查看者可用来一次筛选全部组件,或只筛选你指定组件的筛选条件。' },
141147
},

0 commit comments

Comments
 (0)