From e2288d21e3a7851232dede102d65e96243762f29 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 25 Nov 2026 23:57:30 +0000 Subject: [PATCH] fix(app-shell): record-tabs rename gate reads the served sourceLocale The design-mode record-tabs rename decided "source language" by comparing the reader's language with the deployment's default locale. It now takes the source-locale reader the menu rename uses (fetchDeploymentLocales + labelLanguageOf), which falls back to the default locale when the server serves no sourceLocale. Co-authored-by: Claude Claude-Session: https://claude.ai/code/session_01Utp6Ca6EBDpTBZk8v46Jjv --- .changeset/36875-record-tabs-source-locale.md | 10 + .../__tests__/RecordTabsConfig-36875.test.tsx | 214 ++++++++++++++++++ .../src/views/recordTabsConfigIo.tsx | 17 +- 3 files changed, 234 insertions(+), 7 deletions(-) create mode 100644 .changeset/36875-record-tabs-source-locale.md create mode 100644 ui/packages/app-shell/src/views/__tests__/RecordTabsConfig-36875.test.tsx diff --git a/.changeset/36875-record-tabs-source-locale.md b/.changeset/36875-record-tabs-source-locale.md new file mode 100644 index 00000000000..2fa78f1556a --- /dev/null +++ b/.changeset/36875-record-tabs-source-locale.md @@ -0,0 +1,10 @@ +--- +'@object-ui/app-shell': patch +--- + +fix(app-shell): the record-tabs rename in the design mode decides "source language" from the served `sourceLocale`, not the default locale + +Clause-②: no +Metadata-protocol: none + +「Configure tabs」 lets a tab be renamed only in the app's source language, where the name written is the source label. It used to decide that by comparing the reader's language with the deployment's default locale. It now reads the source language `GET /i18n/locales` serves (`sourceLocale`, the default locale where none is served), the same reading the app menu's rename takes. On a deployment whose default locale differs from its source language, a reader in the default locale no longer writes a tab name as the source label, and a reader in the source language can rename again. diff --git a/ui/packages/app-shell/src/views/__tests__/RecordTabsConfig-36875.test.tsx b/ui/packages/app-shell/src/views/__tests__/RecordTabsConfig-36875.test.tsx new file mode 100644 index 00000000000..0d7b805ea92 --- /dev/null +++ b/ui/packages/app-shell/src/views/__tests__/RecordTabsConfig-36875.test.tsx @@ -0,0 +1,214 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +/** + * The record-tabs rename gate reads the app's source language, not the + * deployment's default locale (objectstack#36875): `GET /i18n/locales` serves + * `sourceLocale`, and a reader in the default locale where that differs from + * the source cannot rename a tab (a rename there would be written as the + * source label), while a reader in the source language can. A server that + * serves no `sourceLocale` keeps the default locale as the source. + * + * Real subjects: `useRecordTabsConfig`, `RecordTabsEditor`, + * `recordTabsConfigIo.tsx`, `fetchDeploymentLocales`, `labelLanguageOf`, + * `saveRecordTabs`, the design mode and its bar. Fakes: the design gate's + * answer, the metadata client (it records what is written), the package + * list and the deployment's languages. + */ + +import '@testing-library/jest-dom/vitest'; +import * as React from 'react'; +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; +import { act, cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react'; +import { MemoryRouter } from 'react-router-dom'; + +const session = vi.hoisted(() => ({ language: 'en', defaultLocale: 'en', sourceLocale: null as string | null, gate: true as boolean })); +vi.mock('@object-ui/i18n', async (importOriginal) => ({ + ...(await importOriginal>()), + useObjectTranslation: () => ({ + t: (k: string, o?: Record) => + String(o?.defaultValue ?? k).replace(/\{\{(\w+)\}\}/g, (_hole, name: string) => String(o?.[name] ?? '')), + language: session.language, + }), +})); + +vi.mock('sonner', async (importOriginal) => ({ + ...(await importOriginal>()), + toast: { error: vi.fn(), success: vi.fn() }, +})); + +vi.mock('../../hooks/useStudioDesignGate', async (importOriginal) => ({ + ...(await importOriginal>()), + useStudioDesignGate: (path: string | null) => (session.gate ? path : null), +})); + +const written = vi.hoisted(() => [] as Array<[string, ...unknown[]]>); +const stored = vi.hoisted(() => ({ relatedLists: undefined as unknown[] | undefined })); +const client = vi.hoisted(() => ({ + layered: async () => { + const code = { name: 'account', label: 'Account', ...(stored.relatedLists ? { relatedLists: stored.relatedLists } : {}) }; + return { code, effective: code }; + }, + save: async (...args: unknown[]) => { + written.push(['save', ...args]); + return {}; + }, + publish: async (...args: unknown[]) => { + written.push(['publish', ...args]); + return {}; + }, + reset: async () => ({}), +})); +vi.mock('../metadata-admin/useMetadata', async (importOriginal) => ({ + ...(await importOriginal>()), + useMetadataClient: () => client, +})); +vi.mock('../studio-design/packages-io', async (importOriginal) => ({ + ...(await importOriginal>()), + fetchListedPackageManifests: async () => new Map([['app.crm', { id: 'app.crm', name: 'CRM', writable: true, manifest: {} }]]), +})); + +import { useRecordTabsConfig } from '../RecordTabsConfig'; +import { __resetDefaultLocale } from '../../layout/designModeMenuSave'; +import { DesignModeProvider, useDesignModeController } from '../../layout/designMode'; +import { DesignModeBar } from '../../layout/DesignModeBar'; + +const lookup = { type: 'lookup', reference: 'account' }; +const OBJECTS = [ + { name: 'account', label: 'Account', _packageId: 'app.crm', relatedLists: [{ list: 'contact', label: 'People' }, 'task'] }, + { name: 'contact', label: 'Contact', _packageId: 'app.crm', fields: { account: lookup } }, + { name: 'task', label: 'Task', _packageId: 'app.crm', fields: { account: lookup } }, + { name: 'case', label: 'Case', _packageId: 'app.crm', fields: { account: lookup } }, +]; + +/** The shell's hold on the design mode, its bar while it is on, and the page under it. */ +function Shell({ children }: { children?: React.ReactNode }) { + const mode = useDesignModeController({ appName: 'crm', appBasePath: '/apps/crm', enabled: true }); + return ( + + {mode.active ? : } + {children} + + ); +} + +function Page({ + objectDef = OBJECTS[0] as Record, + objects = OBJECTS, +}: { + objectDef?: Record; + objects?: Record[]; +}) { + const config = useRecordTabsConfig({ + objectDef, + objects, + enabled: true, + titleOf: (list) => list.title || `${list.childLabel}s`, + }); + return ( + <> + {String(config.active)} + {config.editor} + {JSON.stringify(config.previewObject?.relatedLists ?? null)} + + ); +} + +function Harness({ objects, page = true, extra }: { objects?: Record[]; page?: boolean; extra?: React.ReactNode }) { + return ( + + + {page && } + {extra} + + + ); +} + +const flush = () => act(async () => { + await new Promise((r) => setTimeout(r, 0)); +}); + +beforeEach(() => { + written.length = 0; + stored.relatedLists = [{ list: 'contact', label: 'People' }, 'task']; + session.language = 'en'; + session.defaultLocale = 'en'; + session.sourceLocale = null; + session.gate = true; + __resetDefaultLocale(); + vi.stubGlobal( + 'fetch', + vi.fn(async () => ({ + headers: new Headers(), + ok: true, + json: async () => ({ + data: { + locales: [ + { code: 'en', isDefault: session.defaultLocale === 'en' }, + { code: 'zh-CN', isDefault: session.defaultLocale === 'zh-CN' }, + ], + ...(session.sourceLocale ? { sourceLocale: session.sourceLocale } : {}), + }, + }), + })), + ); +}); +afterEach(() => { + cleanup(); + vi.unstubAllGlobals(); +}); + +async function open() { + render(); + fireEvent.click(screen.getByText('design')); + await waitFor(() => expect(screen.getByRole('button', { name: 'Hide Tasks' })).toBeEnabled()); + await flush(); +} + +const save = () => screen.getByTestId('design-mode-save'); + +describe('the record-tabs rename gate reads the served source language (objectstack#36875)', () => { + it('default locale zh-CN, source en: a reader in zh-CN cannot rename, so nothing is written as the source label', async () => { + session.defaultLocale = 'zh-CN'; + session.sourceLocale = 'en'; + session.language = 'zh-CN'; + await open(); + const rename = screen.getByRole('button', { name: 'Rename People' }); + expect(rename).toBeDisabled(); + expect(rename).toHaveAttribute('title', "Tab names are changed in the app's source language"); + expect(save()).toBeDisabled(); + expect(written).toEqual([]); + }); + + it('default locale zh-CN, source en: a reader in en renames, and the save writes the source label', async () => { + session.defaultLocale = 'zh-CN'; + session.sourceLocale = 'en'; + session.language = 'en'; + await open(); + const rename = screen.getByRole('button', { name: 'Rename People' }); + expect(rename).toBeEnabled(); + fireEvent.click(rename); + const input = screen.getByLabelText('Tab name'); + fireEvent.change(input, { target: { value: 'Contacts we know' } }); + fireEvent.keyDown(input, { key: 'Enter' }); + expect(save()).toBeEnabled(); + fireEvent.click(save()); + await flush(); + await flush(); + expect(written.map(([door]) => door)).toEqual(['save', 'publish']); + expect(written[0].slice(1, 3)).toEqual(['object', 'account']); + expect((written[0][3] as { relatedLists: unknown }).relatedLists).toEqual([{ list: 'contact', label: 'Contacts we know' }, 'task']); + }); + + it('no sourceLocale served: the default locale is the source, as before', async () => { + session.defaultLocale = 'zh-CN'; + session.language = 'zh-CN'; + await open(); + expect(screen.getByRole('button', { name: 'Rename People' })).toBeEnabled(); + cleanup(); + __resetDefaultLocale(); + session.language = 'en'; + await open(); + expect(screen.getByRole('button', { name: 'Rename People' })).toBeDisabled(); + }); +}); diff --git a/ui/packages/app-shell/src/views/recordTabsConfigIo.tsx b/ui/packages/app-shell/src/views/recordTabsConfigIo.tsx index 9162c4ca887..2967c318cd8 100644 --- a/ui/packages/app-shell/src/views/recordTabsConfigIo.tsx +++ b/ui/packages/app-shell/src/views/recordTabsConfigIo.tsx @@ -7,7 +7,10 @@ * `relatedLists` (on an installed object whose tabs the paired `.custom` * package arranges, its extension's entries first), the listed packages' * names (a tab's source, card item 7), and whether the reader's language is - * the deployment's default (the rename gate's precedent). + * the app's source language: the `sourceLocale` the deployment serves on + * `GET /i18n/locales`, its default locale where it serves none + * (`fetchDeploymentLocales`, `labelLanguageOf`, objectstack#36875), the same + * reading the menu's rename gate takes (objectstack#36504). * * It sits behind `React.lazy` so the record page's own module graph does not * gain the metadata client's module (it mints its authenticated fetch when it @@ -18,7 +21,7 @@ */ import * as React from 'react'; -import { fetchDefaultLocale, isSameLanguage } from '../layout/designModeMenuSave.js'; +import { fetchDeploymentLocales, labelLanguageOf, type DeploymentLocales } from '../layout/designModeMenuSave.js'; import { useMetadataClient } from './metadata-admin/useMetadata.js'; import { fetchListedPackageManifests } from './studio-design/packages-io.js'; import { readStoredTabEntries, type RecordTabsSaveDoors } from './recordTabsConfigSave.js'; @@ -27,7 +30,7 @@ export interface RecordTabsIo { readonly client: RecordTabsSaveDoors['client']; /** The object's stored `relatedLists`, once read for `objectName` (`null` when the read failed). */ readonly stored: { readonly objectName: string; readonly lists: unknown[] | null } | null; - /** The reader's language is the deployment's default. */ + /** The reader's language is the app's source language (`sourceLocale`, else the default locale). */ readonly sourceLanguage: boolean; /** The listed packages' names, by id (empty until read, or when the read failed). */ readonly packageNames: ReadonlyMap; @@ -47,7 +50,7 @@ const NO_NAMES: ReadonlyMap = new Map(); export default function RecordTabsConfigIo({ objectName, packageId, pairId, language, onIo }: RecordTabsConfigIoProps) { const client = useMetadataClient() as unknown as RecordTabsSaveDoors['client']; const [stored, setStored] = React.useState(null); - const [defaultLocale, setDefaultLocale] = React.useState(null); + const [locales, setLocales] = React.useState(null); const [packageNames, setPackageNames] = React.useState>(NO_NAMES); React.useEffect(() => { @@ -61,15 +64,15 @@ export default function RecordTabsConfigIo({ objectName, packageId, pairId, lang }, () => undefined, ); - void fetchDefaultLocale().then((code) => { - if (!cancelled) setDefaultLocale(code); + void fetchDeploymentLocales().then((read) => { + if (!cancelled) setLocales(read); }); return () => { cancelled = true; }; }, [objectName, packageId, pairId, client]); - const sourceLanguage = !!defaultLocale && isSameLanguage(language, defaultLocale); + const sourceLanguage = labelLanguageOf(language, locales).source; React.useEffect(() => { onIo({ client, stored, sourceLanguage, packageNames }); }, [onIo, client, stored, sourceLanguage, packageNames]);