diff --git a/.changeset/related-tab-create-only-new-label.md b/.changeset/related-tab-create-only-new-label.md new file mode 100644 index 00000000000..2390a35962c --- /dev/null +++ b/.changeset/related-tab-create-only-new-label.md @@ -0,0 +1,8 @@ +--- +'@object-ui/plugin-detail': patch +--- + +Clause-②: no +Metadata-protocol: none + +The related tab's one add entry is named for what it does: where it can only create a row (a master-detail child with no catalog, which opens the create form with the parent filled in) it now reads "New" / 「新建」 instead of "Add" / 「添加」. A tab whose entry opens a picker keeps "Add" / 「添加」, or the authored `add.label`. diff --git a/ui/packages/plugin-detail/src/RelatedList.tsx b/ui/packages/plugin-detail/src/RelatedList.tsx index c199589f7aa..e1f2ad715d0 100644 --- a/ui/packages/plugin-detail/src/RelatedList.tsx +++ b/ui/packages/plugin-detail/src/RelatedList.tsx @@ -2802,18 +2802,22 @@ export const RelatedList: React.FC = ({ * opens it — the picker's first row is 「新建」 when New is offered too — * and with none it creates a new row directly (New). `null` when neither is * offered. + * + * objectstack#37251 — the entry is named for what it does: 「添加」 / Add + * (or the authored `add.label`) only where it opens a picker; where it can + * only create (a `master_detail` child with no catalog, since + * objectstack#36704) it reads 「新建」 / New, the create form's own name. */ const pickerOffered = !!add && !!add.picker?.object && !!dataSource && addGranted && addBatchable; - const addFallbackLabel = t('detail.add', { defaultValue: 'Add' }); const addEntry: { label: string; disabled: boolean; onClick: () => void } | null = pickerOffered ? { - label: add!.label || addFallbackLabel, + label: add!.label || t('detail.add', { defaultValue: 'Add' }), disabled: addBusy, onClick: () => { setAddError(null); setPickerOpen(true); }, } : onNew ? { - label: addFallbackLabel, + label: t('detail.new', { defaultValue: 'New' }), disabled: !!newDisabled, onClick: () => onNew(), } diff --git a/ui/packages/plugin-detail/src/__tests__/RelatedList.enlargedToolbar-27524.test.tsx b/ui/packages/plugin-detail/src/__tests__/RelatedList.enlargedToolbar-27524.test.tsx index 11acc3a2e1b..ef3e22f293c 100644 --- a/ui/packages/plugin-detail/src/__tests__/RelatedList.enlargedToolbar-27524.test.tsx +++ b/ui/packages/plugin-detail/src/__tests__/RelatedList.enlargedToolbar-27524.test.tsx @@ -28,6 +28,7 @@ import '@testing-library/jest-dom'; import React from 'react'; import { FilterScopeProvider, RecordContextProvider, RecordPagePreferencesProvider, type RecordPagePreference } from '@object-ui/react'; import { ComponentRegistry } from '@object-ui/core'; +import { I18nProvider } from '@object-ui/i18n'; import { RelatedList, derivedAddOf } from '../RelatedList'; import { resetRelatedTabConditionsForTests } from '../relatedTabConditions'; @@ -114,15 +115,18 @@ function renderList({ onNew = vi.fn(), onViewAll = vi.fn(), preferences = null, + language, ...harness }: Harness & { + /** Render under an `I18nProvider` in this language; none ⇒ provider-less (the English defaults). */ + language?: string; enlarged?: boolean; onNew?: (() => void) | undefined; onViewAll?: (() => void) | undefined; preferences?: { get: (o: string) => RecordPagePreference; update: (o: string, p: RecordPagePreference) => void } | null; } = {}) { const dataSource = dataSourceFor(harness); - const utils = render( + const tree = ( @@ -141,7 +145,12 @@ function renderList({ /> - , + + ); + const utils = render( + language + ? {tree} + : tree, ); return { ...utils, dataSource }; } @@ -507,3 +516,42 @@ describe('the related tab no longer remembers the reader\'s header sort (objects function RecordContextHarness({ children }: { children: React.ReactNode }) { return {children}; } + +/** + * objectstack#37251 — the add entry is named for what it does. Where it can + * only create (a `master_detail` child with no catalog: no picker since + * objectstack#36704) it reads 新建 / New and opens the create form, whose + * parent the host fills in; where it opens a picker it keeps 添加 / Add. + */ +describe('the add entry reads New where it can only create, Add where it opens a picker (objectstack#37251)', () => { + const MASTER_DETAIL_NO_CATALOG = { + subject: { type: 'text', label: 'Subject' }, + lead: { type: 'master_detail', reference: 'lead', label: 'Lead', required: true }, + }; + + it.each([ + ['en', 'New', 'Add'], + ['zh-CN', '新建', '添加'], + ] as const)('%s: a master_detail child with no picker reads %s and opens the create form', async (language, newLabel, addLabel) => { + const onNew = vi.fn(); + renderList({ language, onNew, fields: MASTER_DETAIL_NO_CATALOG }); + await waitFor(() => expect(screen.getByText('Send quote')).toBeInTheDocument()); + expect(addButton()!.textContent?.trim()).toBe(newLabel); + expect(addButton()!.textContent).not.toContain(addLabel); + fireEvent.click(addButton()!); + expect(onNew).toHaveBeenCalledTimes(1); + expect(screen.queryByTestId('record-picker-dialog')).toBeNull(); + }); + + it.each([ + ['en', 'Add', 'New'], + ['zh-CN', '添加', '新建'], + ] as const)('control, %s: a lookup child whose entry opens a picker still reads %s', async (language, addLabel, newLabel) => { + renderList({ language }); + await waitFor(() => expect(screen.getByText('Send quote')).toBeInTheDocument()); + expect(addButton()!.textContent?.trim()).toBe(addLabel); + expect(addButton()!.textContent).not.toContain(newLabel); + fireEvent.click(addButton()!); + expect(await screen.findByTestId('record-picker-dialog')).toBeInTheDocument(); + }); +});