Skip to content

Commit e491fce

Browse files
fix(app-shell): the curated page, report and dashboard inspectors name a select's options in Chinese under zh-CN (objectstack-ai#37698)
<!-- claude-projects-attribution: {"github_login":"os-sales"} --> _Requested by **Sales** · [project thread](https://claude.ai/code/project/chan_01D5bWFY3rFzgJcytD5gD4Uu?thread=cmsg_01D5bWFY3rFzgJcytD5gD4UuPE7uyDAJyqjwwMzomWv5ff)_ Fixes objectstack-ai#37607 Clause-②: no Metadata-protocol: none Skills-docs: none (no page under `skills/**` names the console's curated inspector overlay) ## 维护者速读 - 用户能看到什么变化:中文界面下,Studio 里页面检查器的「类型」「记录操作」下拉,和报表、仪表盘检查器的「默认时间段」下拉,选项现在显示中文(例如「记录页」「抽屉(右侧预览)」「本季度」),不再是英文选项配中文标签。用词和平台中文翻译包、服务器下发的表单完全一致,也和报表/仪表盘页面上时间段筛选按钮的用词一致。英文界面不变。 - 为什么做:objectstack-ai#37569 给平台翻译包加了选项名的位置,但这几个检查器读的是控制台自己的翻译表,没读到。 - 出错会怎样:只影响下拉选项的显示文字,存进去的值不变,不影响数据。 - 要你做什么:无。 ## What changes - **`ui/packages/app-shell/src/views/metadata-admin/metadata-form-zh-cn.ts`**: the `page` rows `type` and `interfaceConfig.recordAction` and the `report` row `dateRange.defaultRange` gain `options: { <value>: … }`, the slot `resolveMetadataFormLabels` reads since objectstack-ai#37569. Each map is the platform pack's map (`packages/platform-objects/src/apps/translations/zh-CN.metadata-forms.generated.ts`), copied as is. The header now lists option names among the strings the table carries. - **`metadata-form-i18n.ts`**: the `dashboard` row `dateRange.defaultRange` gains the same map. - **`default-period-labels.ts` retired**, with its calls in `ReportDefaultInspector.tsx` and `DashboardDefaultInspector.tsx` (and their now-unused `useObjectTranslation`). It renamed the Default Period options from the console's `dashboard.filters.range.*` rows for zh only; the overlay names them now, and the platform words equal those rows (pinned below). - **New pin `metadata-form-option-names.test.ts`**: - each option map in `ZH_CN_SPEC_FORMS` equals the platform pack's map, byte for byte (`JSON.stringify`), and the table names exactly the three expected rows; - the platform pack names options on no other row of the `page` / `report` / `dashboard` / `view` forms, so a new one is copied rather than missed; - for each of the four selects, every option `getPageForm` / `getReportForm` / `getDashboardForm` renders under `zh-CN` reads the pack's name (this is what pins the dashboard map, which lives in `metadata-form-i18n.ts`); - one named zh option per form (记录页, 抽屉(右侧预览), 本季度, 近 30 天), and an `en-US` control keeping the spec's English. The pack is read from the checkout's source with a run-time `import()` (a data-only module whose one import is type-only). - **`ReportDefaultInspector.defaultPeriodLabels-36835.test.tsx`**: no longer imports the retired helper. A new case pins the zh names `getReportForm('zh-CN')` gives to the zh pack's `dashboard.filters.range.*` / `dashboard.filters.custom` rows the period chip reads, beside the existing en case; the rendered zh case is unchanged and passes through the new route. - **Changeset**: `@object-ui/app-shell` patch. Small calls made here (no card): - The card prefers reading the names from a served or bundled form's slot. The curated inspectors render the console's own copy of the spec form, and this table's documented posture is data-only with no runtime import (it sits on the Pending changes sheet's eager graph), so the route is the card's second one: copy, plus a byte-equality pin against the pack. - `default-period-labels.ts` is retired in full rather than reduced: the slot now covers everything it did (it was zh-only), and the period-chip parity it guarded is kept by the objectstack-ai#36835 test. ## Why Out-of-diff note 1 of the Contract review record 7195508409 on PR objectstack-ai#37569: under zh-CN the curated page, report and dashboard inspectors showed English select options beside Chinese labels, and objectstack-ai#36950's slot did not reach them. ## Verification Head `8df05bb67`: - `pnpm --dir ui exec vitest run` on `metadata-form-option-names.test.ts`, `metadata-form-i18n.test.ts`, `page-schema.test.ts`, `report-schema.test.ts`, `dashboard-schema.test.ts`, `ReportDefaultInspector.test.tsx`, `ReportDefaultInspector.i18nTitle.test.tsx`, `ReportDefaultInspector.defaultPeriodLabels-36835.test.tsx`, `DashboardDefaultInspector.test.tsx`, `DashboardDefaultInspector.layoutColumns-11796.test.tsx`: 10 files, 96 tests passed. - `eslint` on the 6 touched source and test files: 0 errors. - `check:test-source-alias`, `check:changeset-fixed`, `ui` `check:changeset-claims`: exit 0. - `node scripts/pm/overlap-check.mjs`: clean (shares `metadata-form-zh-cn.ts` with objectstack-ai#37366, merges cleanly). ## Human Minimum - [x] 1. Schemas start as Zod; `packages/spec` holds no runtime logic (not touched). - [x] 2. Every name I added uses the casing for its kind. - [x] 3. No formatter ran; lint passes. - [x] 4. One issue, one branch off an up-to-date `main`, one pull request. - [x] 5. A change that publishes carries a changeset, and both declaration lines are filled in here and in the changeset. - [x] 6. `packages/spec` not touched. - [x] 7. No hand edits to `content/docs/references/`, `packages/*/CHANGELOG.md` or `content/docs/releases/`. - [x] 8. Title, body and comments are in English. - [x] The *Before Submitting* list in CONTRIBUTING.md is done. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01L6bhgUpnvPnJ1hR74pUrVj --- _Generated by [Claude Code](https://claude.ai/code/session_01L6bhgUpnvPnJ1hR74pUrVj)_ <!-- signed: repo:objectstack#2 · os-sales · session_01L6bhgUpnvPnJ1hR74pUrVj --> Co-authored-by: Claude <noreply@anthropic.com>
1 parent 4111380 commit e491fce

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)