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
17 changes: 17 additions & 0 deletions .changeset/22536-record-page-header-title.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
'@objectstack/spec': patch
---

A locale pack's page `label` no longer replaces the record-derived heading on a record page whose header authors no title

Clause-②: no

On a record page, a `page:header` with no `title` is the sanctioned spelling for "the renderer derives the heading from the record" (`PageHeaderProps.title`). Studio's record-page seed writes exactly that header. `translatePage` used to fill the absent title with the pack's `pages.<name>.label`, so the record's name was replaced by the page's static label. This happened in every locale whose pack carries the label, including the `en` skeleton that `os i18n extract` writes. Measured at `GET /api/v1/meta/page/:name` before this change: the header gained `title: "客户记录页"` in zh-CN, and `title: "Account Record"` in en with the extracted skeleton.

The label now does not fill an untitled root `page:header` when all three of these hold:

- the page's `type` is `'record'` as served (a document with no `type` is not a record page);
- the page's `object` is a non-empty string;
- the header keeps its record chrome (`properties.recordChrome` is not `false`).

Everywhere else the label still fills an absent header title, as before. An authored header title follows the existing order, including one that restates the page's `label`. A pack's `pages.<name>.title` and `subtitle` apply as before.
4 changes: 4 additions & 0 deletions content/docs/ui/translations.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ When `title` is omitted, the header keeps the title its author wrote, and
title restates the page's `label`. So a page whose header title matches its
nav label needs only `label`, while a header whose title says something else,
such as a dynamic `'{name}'`, keeps it until the bundle supplies a `title`.
One exception: on a page of `type: 'record'` bound to an `object`, a header
that authors no title and keeps its record chrome (`recordChrome` not
`false`) derives its heading from the record, so `label` does not fill it and
the record's own name shows in every locale.
Every root-level `page:header` (a region's entry or a `slots.<slot>` entry)
is resolved by this one rule.
</Callout>
Expand Down
141 changes: 140 additions & 1 deletion packages/spec/src/system/i18n-resolver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2784,7 +2784,10 @@ describe('translatePage — a bundle label never replaces a header title that sa
expect(headerOf(root, out).title).toBe('客户 {name}');
});

it('CONTROL: a header with no authored title still shows the bundle `label`', () => {
// The fixture page carries no `type` and no `object`, so as served it is
// NOT a record page and its untitled header derives nothing from a
// record. On a record page the label does not fill (#22536, below).
it('CONTROL: a header with no authored title on a non-record page still shows the bundle `label`', () => {
for (const header of [{}, { title: '' }, { subtitle: 'Overview' }]) {
const out = translatePage(pageWith(root, header), labelOnly, { locale: 'zh-CN' });
expect({ header, title: headerOf(root, out).title }).toEqual({ header, title: '客户详情' });
Expand Down Expand Up @@ -2813,6 +2816,142 @@ describe('translatePage — a bundle label never replaces a header title that sa
});
});

// #22536: on a record page, a header with no title is the sanctioned spelling
// for "the renderer derives the heading from the record"
// (`PageHeaderProps.title`). Filling it with the bundle's page `label` put the
// page's static name in place of the record's, in every locale whose pack
// carries the label, the en skeleton `os i18n extract` writes included. The
// label now does not fill an untitled header when the page's `type` is
// `'record'` as served, its `object` is a non-empty string, and the header
// keeps its record chrome. Everywhere else it still fills, as before.
describe('translatePage — a bundle label does not fill the untitled header of a record page', () => {
const PAGE = 'account_record';
type Root = 'region' | 'slot';
const ROOTS: readonly Root[] = ['region', 'slot'];

/**
* The Studio seed's shape: objectui's `createSeed` writes `type: 'record'`,
* the chosen `object`, and the synthesized `page:header`, which carries
* `recordChrome: true` and no `title`.
*/
const SEED_PAGE: Record<string, unknown> = { label: 'Account Record', type: 'record', object: 'account' };
const SEED_HEADER = { recordChrome: true };

const pageWith = (
root: Root,
header: Record<string, unknown>,
page: Record<string, unknown> = SEED_PAGE,
): any => {
const component = { type: 'page:header', properties: header };
return root === 'region'
? { name: PAGE, ...page, regions: [{ name: 'main', components: [component] }] }
: { name: PAGE, ...page, kind: 'slotted', regions: [], slots: { header: component } };
};
const headerOf = (root: Root, page: any): Record<string, unknown> =>
root === 'region' ? page.regions[0].components[0].properties : page.slots.header.properties;

/** A zh-CN pack carrying the page label and nothing else. */
const zhLabelOnly: TranslationBundle = {
'zh-CN': { pages: { [PAGE]: { label: '客户记录页' } } },
};
/** The en skeleton `os i18n extract` writes: the authored label, restated. */
const enSkeleton: TranslationBundle = {
en: { pages: { [PAGE]: { label: 'Account Record' } } },
};
const CASES = [
{ pack: 'zh-CN label only', bundle: zhLabelOnly, locale: 'zh-CN', label: '客户记录页' },
{ pack: 'en extract skeleton', bundle: enSkeleton, locale: 'en', label: 'Account Record' },
] as const;

for (const root of ROOTS) {
describe(`at a ${root} root`, () => {
for (const { pack, bundle, locale, label } of CASES) {
it(`keeps the Studio-seeded record header untitled with the ${pack} pack`, () => {
const out = translatePage(pageWith(root, SEED_HEADER), bundle, { locale });
expect(headerOf(root, out)).toEqual({ recordChrome: true });
expect('title' in headerOf(root, out)).toBe(false);
// The page's own label still translates; only the header stays as authored.
expect(out.label).toBe(label);
});
}

it('keeps an untitled header untitled when `recordChrome` is left at its default', () => {
const headers: Array<Record<string, unknown>> = [{}, { title: '' }];
for (const header of headers) {
const out = translatePage(pageWith(root, header), zhLabelOnly, { locale: 'zh-CN' });
expect(headerOf(root, out)).toEqual(header);
}
});

it('still applies the bundle subtitle beside the untitled header', () => {
const subtitled: TranslationBundle = {
'zh-CN': { pages: { [PAGE]: { label: '客户记录页', subtitle: '客户概览' } } },
};
const out = translatePage(pageWith(root, SEED_HEADER), subtitled, { locale: 'zh-CN' });
expect(headerOf(root, out)).toEqual({ recordChrome: true, subtitle: '客户概览' });
});

// One control per condition: drop any one of the three and the header
// derives nothing from a record, so the label fills it as before.
it('CONTROL: a page with no `type` is not a record page as served, and the label fills', () => {
const untyped = { label: SEED_PAGE.label, object: SEED_PAGE.object };
const out = translatePage(pageWith(root, SEED_HEADER, untyped), zhLabelOnly, { locale: 'zh-CN' });
expect(headerOf(root, out).title).toBe('客户记录页');
});

it('CONTROL: a record page with no `object`, or an empty one, has no record to derive from, and the label fills', () => {
const unbound = { label: SEED_PAGE.label, type: SEED_PAGE.type };
const pages: Array<Record<string, unknown>> = [unbound, { ...SEED_PAGE, object: '' }];
for (const page of pages) {
const out = translatePage(pageWith(root, SEED_HEADER, page), zhLabelOnly, { locale: 'zh-CN' });
expect({ object: page.object, title: headerOf(root, out).title })
.toEqual({ object: page.object, title: '客户记录页' });
}
});

it('CONTROL: a record-page header with `recordChrome: false` draws the bare heading, and the label fills', () => {
const out = translatePage(pageWith(root, { recordChrome: false }), zhLabelOnly, { locale: 'zh-CN' });
expect(headerOf(root, out)).toEqual({ recordChrome: false, title: '客户记录页' });
});

it('CONTROL: an object-bound page of another `type` derives nothing from a record, and the label fills', () => {
for (const type of ['list', 'app', 'home', 'utility']) {
const out = translatePage(pageWith(root, SEED_HEADER, { ...SEED_PAGE, type }), zhLabelOnly, { locale: 'zh-CN' });
expect({ type, title: headerOf(root, out).title }).toEqual({ type, title: '客户记录页' });
}
});

// An authored title on a record page follows #22508 unchanged.
it('an authored template title on a record page is kept against a label-only pack', () => {
const out = translatePage(pageWith(root, { ...SEED_HEADER, title: '{name}' }), zhLabelOnly, { locale: 'zh-CN' });
expect(headerOf(root, out).title).toBe('{name}');
});

it('an authored title on a record page that restates the page label takes the label translation', () => {
const out = translatePage(pageWith(root, { ...SEED_HEADER, title: 'Account Record' }), zhLabelOnly, { locale: 'zh-CN' });
expect(headerOf(root, out).title).toBe('客户记录页');
});

it('a pack with `title` replaces an authored title on a record page', () => {
const withTitle: TranslationBundle = {
'zh-CN': { pages: { [PAGE]: { label: '客户记录页', title: '客户 {name}' } } },
};
const out = translatePage(pageWith(root, { ...SEED_HEADER, title: '{name}' }), withTitle, { locale: 'zh-CN' });
expect(headerOf(root, out).title).toBe('客户 {name}');
});
});
}

it('serves the same answer through `translateMetadataDocument`, the function the REST page doors call', () => {
for (const root of ROOTS) {
for (const { bundle, locale } of CASES) {
const out = translateMetadataDocument('page', pageWith(root, SEED_HEADER), bundle, { locale });
expect({ root, locale, header: headerOf(root, out) }).toEqual({ root, locale, header: { recordChrome: true } });
}
}
});
});

describe('translatePage — filter-preset tab bar', () => {
const bundle: TranslationBundle = {
'zh-CN': {
Expand Down
57 changes: 53 additions & 4 deletions packages/spec/src/system/i18n-resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1884,8 +1884,14 @@ function sameAuthoredText(a: string | Record<string, string>, b: unknown): boole
* 2. the header's AUTHORED title, left as written: a template such as
* `'{name}'`, a plain string, or an inline locale map;
* 3. the bundle's `pages.<name>.label`, in two cases only: the header authors
* no title, or its title restates the page's own authored `label`. In the
* second case the label's translation IS a translation of that text, and
* no title AND does not derive its heading from a record
* ({@link headerDerivesFromRecord}), or its title restates the page's own
* authored `label`. In the first case's exception, an absent title IS the
* authored value: `PageHeaderProps.title` makes "omitted" the sanctioned
* spelling for "the renderer derives the heading from the record", so the
* label filling it would put the page's static name in place of the
* record's, and the title stays absent (#22536). In the second case the
* label's translation IS a translation of that text, and
* `os i18n extract` offers no `title` key for such a header (it offers the
* label alone), so reading the label here is what translates it.
*
Expand All @@ -1896,14 +1902,53 @@ function resolvePageHeaderTitle(
bundleLabel: string | undefined,
authoredTitle: unknown,
authoredPageLabel: unknown,
derivesFromRecord: boolean,
): string | undefined {
if (bundleTitle !== undefined) return bundleTitle;
if (bundleLabel === undefined) return undefined;
const own = authoredLabelText(authoredTitle);
if (own === undefined || sameAuthoredText(own, authoredPageLabel)) return bundleLabel;
if (own === undefined) return derivesFromRecord ? undefined : bundleLabel;
if (sameAuthoredText(own, authoredPageLabel)) return bundleLabel;
return undefined;
}

/**
* Does this root-level `page:header` derive its heading from a record? The
* test step 3 of {@link resolvePageHeaderTitle} reads (#22536), and all three
* conditions must hold:
*
* - the page's `type` is `'record'`, read as SERVED. A document with no
* `type` is not a record page to the hosts below, so it is not one here
* either, although `PageSchema` defaults an absent `type` to `'record'`
* at parse;
* - the page's `object` is a non-empty string;
* - the header does not opt out of the record chrome
* (`properties.recordChrome !== false`).
*
* The renderer's own test is runtime, not a property of this document.
* objectui's `PageHeaderRenderer` draws the record-derived heading when a
* record context is mounted (`ctx.data` and `ctx.objectSchema`) and the
* header keeps its record chrome. The first two conditions are when the
* record hosts mount that context: the record route mounts it for the page
* `usePageAssignment` picks (`type === 'record'` and `object` naming the
* route's object), and the Studio preview mounts it for a `type: 'record'`
* page with an `object`. The third is the renderer's own switch, which it
* reads off the header node. Only `properties.recordChrome` is read:
* `PageComponentSchema` is strict and refuses a bare top-level
* `recordChrome` on a component, so a valid document never carries that
* spelling.
*
* One host is not visible from here, and that gap is accepted. A
* `type: 'modal'` action renders the page it targets inside the record
* context of the page it was invoked from, whatever that page's `type` is.
* Such a page keeps the label fill.
*/
function headerDerivesFromRecord(page: PageLike, header: PageComponentLike): boolean {
return page.type === 'record'
&& typeof page.object === 'string' && page.object.length > 0
&& header.properties?.recordChrome !== false;
}

/**
* The copy keys `pages.<name>.components.<id>` carries (#6080). Measured
* against `ComponentPropsMap` — see the schema's own note for which component
Expand Down Expand Up @@ -2265,7 +2310,10 @@ export function walkAddressedPageComponents(
* authors no title or its title restates the page's own `label`, so a
* translator need not repeat a string identical to the page's nav label
* ({@link resolvePageHeaderTitle}). A label never replaces a header title
* that says something else, a dynamic `'{name}'` above all.
* that says something else, a dynamic `'{name}'` above all. Nor does it fill
* the absent title of a header that derives its heading from a record
* ({@link headerDerivesFromRecord}): on a `type: 'record'` page bound to an
* object, "no title" means "the record's own name".
*
* **One component, one address.** A ROOT-LEVEL `page:header` — an entry of a
* region's `components[]`, or of a `slots.<slot>` on a `kind: 'slotted'` page
Expand Down Expand Up @@ -2421,6 +2469,7 @@ export function translatePage<T extends PageLike>(
// `nested: false`, so the fallback order cannot differ between them.
const headerTitle = resolvePageHeaderTitle(
bundleHeaderTitle, bundleLabel, next.properties?.title, doc.label,
headerDerivesFromRecord(doc, next),
);
if (headerTitle === undefined && headerSubtitle === undefined) return next;
return {
Expand Down
Loading