Skip to content

Commit 9cd4254

Browse files
committed
wip(app-shell): title a served object's list as served in the object page header and the app header
Claude-Session: https://claude.ai/code/session_01Utp6CZywtebM5fE7KZuMEM Co-authored-by: Claude <noreply@anthropic.com>
1 parent 3a0c7bf commit 9cd4254

6 files changed

Lines changed: 67 additions & 20 deletions

File tree

‎ui/packages/app-shell/src/hooks/useNavTargetLabel.ts‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,29 @@ function nonEmpty(text: string | undefined): string | undefined {
9595
return typeof text === 'string' && text.trim() !== '' ? text : undefined;
9696
}
9797

98+
/** `useObjectLabel().objectPluralLabel` — the client bundle's list-title lookup. */
99+
export type ObjectPluralLabelLookup = (objectDef: { name: string; label: string; pluralLabel?: string }) => string;
100+
101+
/**
102+
* What a served object's LIST is called (objectstack#30311): its served
103+
* `pluralLabel`, else its served `label`, drawn as given. The server
104+
* translated both, by its label order for an overridden item, so running the
105+
* bundle over them was a second translation pass in which the base package's
106+
* string won a rename back. The bundle's `objectPluralLabel` under the
107+
* object's name is asked only when the definition carries neither; `''` when
108+
* nothing names it. Shared by every surface that titles an object's list —
109+
* the object page's header, the app header, a recent object row.
110+
*/
111+
export function servedObjectPluralLabel(
112+
objectDef: { name: string; label?: unknown; pluralLabel?: unknown },
113+
language: string | undefined,
114+
objectPluralLabel: ObjectPluralLabelLookup,
115+
): string {
116+
// `pluralLabel` is a plain string in the spec, so only a string is one.
117+
const plural = typeof objectDef.pluralLabel === 'string' ? nonEmpty(objectDef.pluralLabel) : undefined;
118+
return plural ?? metadataText(objectDef.label, language) ?? objectPluralLabel({ name: objectDef.name, label: '' });
119+
}
120+
98121
/** The two members this hook reads off a cached metadata record. */
99122
export interface LabelledRecord {
100123
name?: unknown;

‎ui/packages/app-shell/src/hooks/useRecentItemLabel.ts‎

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,14 @@ import { useObjectLabel, useObjectTranslation } from '@object-ui/i18n';
6565
import type { RecentItem } from '../context/RecentItemsProvider.js';
6666
import { useMetadata } from '../providers/MetadataProvider.js';
6767
import { bundledFirst, useBundledReads } from '../providers/bundledReads.js';
68-
import { findByName, metadataText, useNavTargetLabel, type LabelledRecord, type NavTargetLabelOptions } from './useNavTargetLabel.js';
68+
import {
69+
findByName,
70+
metadataText,
71+
servedObjectPluralLabel,
72+
useNavTargetLabel,
73+
type LabelledRecord,
74+
type NavTargetLabelOptions,
75+
} from './useNavTargetLabel.js';
6976
import { readObjectsByName, useReadItemsByName } from './useObjectPresence.js';
7077

7178
const BY_NAME: NavTargetLabelOptions = { byName: true };
@@ -102,14 +109,8 @@ export function useRecentItemLabel(
102109
const listTitle = (objectName: string): string => {
103110
const def = findByName(readObjectsByName(metadata, [objectName]), objectName) as (LabelledRecord & { pluralLabel?: unknown }) | undefined;
104111
// A served object's labels are already translated (objectstack#30311):
105-
// drawn as given. The singular half is read exactly as
106-
// `useNavTargetLabel` reads it; `pluralLabel` is a plain string in the
107-
// spec, so only a string is one.
108-
const plural = typeof def?.pluralLabel === 'string' ? nonEmpty(def.pluralLabel) : undefined;
109-
return plural
110-
?? metadataText(def?.label, language)
111-
?? nonEmpty(objectPluralLabel({ name: objectName, label: '' }))
112-
?? objectName;
112+
// drawn as given, as the list page the entry opens titles itself.
113+
return nonEmpty(servedObjectPluralLabel({ ...def, name: objectName }, language, objectPluralLabel)) ?? objectName;
113114
};
114115
switch (item.type) {
115116
case 'object':

‎ui/packages/app-shell/src/layout/AppHeader.tsx‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ import { getIcon } from '../utils/getIcon.js';
9696
import { useNavigationContext } from '../context/NavigationContext.js';
9797
import { useCommandPalette, useCommandPaletteProviderMounted } from '../context/CommandPaletteProvider.js';
9898
import { useUrlOverlay } from '../hooks/useUrlOverlay.js';
99-
import { metadataText } from '../hooks/useNavTargetLabel.js';
99+
import { metadataText, servedObjectPluralLabel } from '../hooks/useNavTargetLabel.js';
100100
import { KEYBOARD_SHORTCUTS_PARAM } from '../urlParams.js';
101101
import { useAiSurfaceEnabled } from '../hooks/useAiSurface.js';
102102
import { useStudioEntryGate } from '../hooks/useStudioDesignGate.js';
@@ -765,7 +765,10 @@ export function AppHeader({
765765
} else if (routeType) {
766766
const currentObject = safeObjects.find((o: any) => o.name === routeType);
767767
if (currentObject) {
768-
routeTitle = objectPluralLabel(currentObject);
768+
// A served object's label is already translated (objectstack#30311):
769+
// drawn as given, as the object page's own header draws it.
770+
const listTitle = servedObjectPluralLabel(currentObject, language, objectPluralLabel);
771+
routeTitle = listTitle;
769772
if (pathParts[3] === 'record' && pathParts[4]) {
770773
const shortId = pathParts[4].length > 12 ? `${pathParts[4].slice(0, 8)}…` : pathParts[4];
771774
const trimmedTitle = recordTitle?.trim();
@@ -799,7 +802,7 @@ export function AppHeader({
799802
currentObject.name,
800803
servedViews,
801804
viewLabel,
802-
objectPluralLabel(currentObject),
805+
listTitle,
803806
language,
804807
);
805808
}

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ import {
7878
PREVIEW_QUERY_VALUE,
7979
} from '../preview/PreviewModeContext.js';
8080
import { useTenancyPosture } from '../hooks/useTenancyPosture.js';
81+
import { servedObjectPluralLabel } from '../hooks/useNavTargetLabel.js';
8182
import type { RowCrudPredicates } from '../utils/crudAffordances.js';
8283

8384
/** Field types the auto-derived user-filter bar offers as dropdowns. */
@@ -234,7 +235,7 @@ export function buildSaveAsViewSpec(
234235

235236
export function ObjectDataPage({ dataSource, objects }: any) {
236237
const { appName, objectName } = useParams();
237-
const { t } = useObjectTranslation();
238+
const { t, language } = useObjectTranslation();
238239
const { objectLabel, objectPluralLabel, fieldLabel } = useObjectLabel();
239240
const navigate = useNavigate();
240241
const [searchParams, setSearchParams] = useSearchParams();
@@ -600,7 +601,8 @@ export function ObjectDataPage({ dataSource, objects }: any) {
600601
{/* The page lists the object's records, so it is titled with the
601602
plural, as the object crumb above it is (objectui#11696). The
602603
record drawer below keeps the singular. */}
603-
<span className="truncate">{objectPluralLabel(objectDef)}</span>
604+
{/* A served object's label is already translated (objectstack#30311): drawn as given. */}
605+
<span className="truncate">{servedObjectPluralLabel(objectDef, language, objectPluralLabel)}</span>
604606
<span className="rounded border px-1.5 py-0.5 text-[10px] font-medium uppercase tracking-wide text-muted-foreground">
605607
{t('console.objectData.badge', { defaultValue: 'Data' })}
606608
</span>

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import { useObjectListFavorite } from '../layout/SidebarItemMenu.js';
2525
import { useMetaItemRefusal } from '../hooks/useMetaItemRefusal.js';
2626
import { useTenancyPosture } from '../hooks/useTenancyPosture.js';
2727
import { useServedViewItems } from '../hooks/useServedViewItems.js';
28+
import { servedObjectPluralLabel } from '../hooks/useNavTargetLabel.js';
2829
import type { DataSource } from '@object-ui/types';
2930
import { MetadataPanel, useMetadataInspector } from './MetadataInspector.js';
3031
import { ViewConfigPanel } from './ViewConfigPanel.js';
@@ -256,14 +257,22 @@ function ObjectViewInner({ dataSource, objects, onEdit, externalRefreshKey }: Co
256257
// and keeps an `object:` favorite only for an object the app does not list.
257258
// The entry the list is starred under is named with the plural the title
258259
// reads (objectui#11733).
260+
// What this list is titled: a served object's label is already translated
261+
// (objectstack#30311), so it is drawn as given; the bundle is asked only
262+
// when the definition carries none. The header, the favorite and an
263+
// unlabelled view's tab all read this one function, so they agree.
264+
const listTitleOf = useCallback(
265+
(def: { name: string; label?: unknown; pluralLabel?: unknown }) => servedObjectPluralLabel(def, language, objectPluralLabel),
266+
[language, objectPluralLabel],
267+
);
259268
const listFavorite = useObjectListFavorite({
260269
appSegment: appName,
261270
objectName,
262-
label: objectPluralLabel(objectDef),
271+
label: listTitleOf(objectDef),
263272
});
264273
// A view stored with no `label` is named by the object's plural label, on
265274
// its tab and on the record page's way back alike (objectui#12774).
266-
const unlabelledViewText = objectPluralLabel(objectDef);
275+
const unlabelledViewText = listTitleOf(objectDef);
267276

268277
// Refresh trigger — bumped after view CRUD or this page's own data writes.
269278
const [ownRefreshKey, setRefreshKey] = useState(0);
@@ -1182,7 +1191,7 @@ function ObjectViewInner({ dataSource, objects, onEdit, externalRefreshKey }: Co
11821191
titleSwitcher={pageHeaderShown ? titleSwitcher : null}
11831192
titleLabel={titleLabel}
11841193
objectListHref={appName && objectName ? `/apps/${appName}/${objectName}` : undefined}
1185-
objectPluralLabel={objectPluralLabel}
1194+
objectPluralLabel={listTitleOf}
11861195
objectDesc={objectDesc}
11871196
createButton={createButton}
11881197
importShown={importShown}

‎ui/packages/app-shell/src/views/studio-design/StudioDesignSurface.standardNavEntries-11201.test.tsx‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,19 @@ const OBJECT_DEFS = [{ name: 'account', label: 'Account' }, { name: 'draft_thing
6060

6161
const ZH_CN: TranslationData = { objects: { account: { label: '客户' } } } as TranslationData;
6262

63-
function metadata() {
63+
/**
64+
* The served objects, per language: the server translates what it serves under
65+
* the request's language from the same catalog the console loads, so a zh-CN
66+
* session holds the zh-CN label (objectstack#30311).
67+
*/
68+
function servedObjects(language: string) {
69+
return language === 'zh-CN' ? OBJECT_DEFS.map((o) => (o.name === 'account' ? { ...o, label: '客户' } : o)) : OBJECT_DEFS;
70+
}
71+
72+
function metadata(language: string) {
6473
return {
6574
apps: [],
66-
objects: OBJECT_DEFS,
75+
objects: servedObjects(language),
6776
dashboards: [],
6877
reports: [],
6978
pages: [],
@@ -108,7 +117,7 @@ function renderSidebar(items: Array<Record<string, unknown>>, language: string)
108117
render(
109118
<I18nProvider instance={i18nIn(language)} persistLanguage={false}>
110119
<MemoryRouter initialEntries={['/apps/acme']}>
111-
<MetadataCtx.Provider value={metadata() as never}>
120+
<MetadataCtx.Provider value={metadata(language) as never}>
112121
<Sidebar items={items as unknown as NavigationItem[]} />
113122
</MetadataCtx.Provider>
114123
</MemoryRouter>

0 commit comments

Comments
 (0)