Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .changeset/37607-curated-inspector-option-names.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
'@object-ui/app-shell': patch
---

fix(app-shell): the curated page, report and dashboard inspectors name a select's options in Chinese under zh-CN

Clause-②: no
Metadata-protocol: none

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.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ import { SchemaForm } from '../SchemaForm.js';
import { fallbackFormPatch } from './fallbackFormPatch.js';
import type { FormViewSpec } from '../SchemaForm.js';
import { getDashboardForm, getDashboardSchema } from '../dashboard-schema.js';
import { localizeDefaultPeriods } from '../default-period-labels.js';
import { mergeServerFields } from '../mergeServerFields.js';
import { useObjectTranslation } from '@object-ui/i18n';
import { t, tFormat } from '../i18n.js';
// `DashboardWidget.title` is the spec's `I18nLabel`, which @objectstack/spec
// 17.0.0-rc.6 widened from plain `string` to `string | Record<string, string>`
Expand Down Expand Up @@ -175,7 +173,6 @@ export function DashboardDefaultInspector({

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

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

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

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

/** The console row the period chip reads for a Default Period value. */
const chipKey = (value: string) =>
value === 'custom' ? 'dashboard.filters.custom' : `dashboard.filters.range.${value}`;

/** The Default Period options of the report form as `getReportForm` names them for `locale`. */
function namedOptions(locale: string): Array<{ label: string; value: string }> {
for (const section of getReportForm(locale)?.sections ?? []) {
for (const field of (section.fields ?? []) as any[]) {
if (field?.field !== 'dateRange') continue;
const child = (field.fields ?? []).find((c: any) => c?.field === 'defaultRange');
if (child?.options) return child.options;
}
}
throw new Error('the report form names no dateRange.defaultRange options');
}

const readPack = (pack: unknown, key: string) =>
key.split('.').reduce((node: any, seg) => node?.[seg], pack as Record<string, any>);

describe('#36835 — the Default Period select names its periods', () => {
it('the spec English names are the en locale pack rows the period chip reads', () => {
const pack = en as unknown as Record<string, any>;
const read = (key: string) => key.split('.').reduce((node, seg) => node?.[seg], pack);
for (const { value, label } of specOptions()) {
expect(read(defaultPeriodLabelKey(value)), value).toBe(label);
expect(readPack(en, chipKey(value)), value).toBe(label);
}
});

it('the zh names are the zh locale pack rows the period chip reads', () => {
for (const { value, label } of namedOptions('zh-CN')) {
expect(readPack(zh, chipKey(value)), value).toBe(label);
}
});

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

it('zh: every option reads the locale pack name', async () => {
it('zh: every option reads its Chinese name', async () => {
renderIn('zh', 'zh-CN');
// POSITIVE CONTROL: the row label comes through the zh overlay.
const offered = await openDefaultPeriod('时间段与导出', '默认时间段');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,12 @@ import {
} from '../previews/useDatasetCatalog.js';
import { useStudioDatasetAuthoring } from '../../studio-design/datasetCreate.js';
import { getReportForm, getReportSchema } from '../report-schema.js';
import { localizeDefaultPeriods } from '../default-period-labels.js';
import { mergeServerFields } from '../mergeServerFields.js';
import { t, tFormat } from '../i18n.js';
import { mapLoaded } from '../loadState.js';
import type { WidgetContext } from '../widgets.js';
import { datasetPickerOptions, datasetLabelOptions } from './dataset-picker-options.js';
import { pickLocalized, setLocalized, clearLocalized, useObjectTranslation } from '@object-ui/i18n';
import { pickLocalized, setLocalized, clearLocalized } from '@object-ui/i18n';
import { WIDGET_TYPE_META } from '../previews/widget-types.js';
import { shownLabel, writtenLabel, servedLabelNote, useLabelLanguage } from './servedLabel.js';
import { useServedReportText } from '../../studio-design/servedReportText.js';
Expand Down Expand Up @@ -555,24 +554,20 @@ export function ReportDefaultInspector({

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

return (
<InspectorShell
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* The strings belong to the spec, and the platform already declares how they
* are translated: `metadataForms.<type>.{label,description}`,
* `.sections.<section>.{label,description}`,
* `.fields.<dot.path>.{label,helpText,placeholder}` — resolved by
* `.fields.<dot.path>.{label,helpText,placeholder,options}` — resolved by
* `resolveMetadataFormLabels` from `@objectstack/spec/system`, which the
* framework's own `/meta/types` handler calls to localize the very same forms
* before serving them. This module supplies a bundle to THAT function rather
Expand Down Expand Up @@ -135,7 +135,13 @@ const METADATA_FORM_BUNDLE: TranslationBundle = {
dateRange: { label: '日期范围', helpText: '打开仪表盘时默认的时间段,以及查看者能否自选日期。' },
// All three children of the `dateRange` composite — see the ⛔ note above.
'dateRange.field': { label: '日期字段', helpText: '时间段筛选所依据的日期字段。留空则按创建日期筛选。' },
'dateRange.defaultRange': { label: '默认时间段', helpText: '打开仪表盘时显示的时间段。' },
'dateRange.defaultRange': {
label: '默认时间段',
helpText: '打开仪表盘时显示的时间段。',
// Option names: the platform pack's map, pinned byte-equal by
// `metadata-form-option-names.test.ts`.
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: '自定义…' },
},
'dateRange.allowCustomRange': { label: '允许自定义范围', helpText: '允许查看者自己选择开始和结束日期。' },
globalFilters: { label: '全局筛选', helpText: '查看者可用来一次筛选全部组件,或只筛选你指定组件的筛选条件。' },
},
Expand Down
Loading
Loading