Skip to content

Commit 5315599

Browse files
fix(ui): the related tab's create-only add entry reads New, not Add (#37293)
Fixes #37251 Clause-②: no Metadata-protocol: none ## 维护者速读 - 用户能看到什么变化:记录页上主从子对象页签(如客户 → 合同)里那个只能新建的按钮,从「添加」改为「新建」;会弹出选择已有记录的页签仍叫「添加」。 - 为什么做:主从子对象页签的按钮早已直接打开新建表单,却还叫「添加」,用户以为能关联已有记录(客户 CRM 产品负责人报告的问题)。 - 出错会怎样:只影响按钮文字,不影响数据;改坏了直接撤回即可。 - 要你做什么:无。 ## What changes `ui/packages/plugin-detail/src/RelatedList.tsx`, `addEntry`: the branch with no picker (a `master_detail` child with no catalog, so `derivedAddOf` answers nothing and the entry calls `onNew`) is now labelled `t('detail.new')` (New / 新建) instead of `t('detail.add')` (Add / 添加). The picker branch is unchanged: the authored `add.label` wins, else `detail.add`. The `addFallbackLabel` local is gone, since only the picker branch reads `detail.add` now. `detail.new` already exists in the `en` pack (`New`), `zh-Hans` (`新建`) and `DETAIL_DEFAULT_TRANSLATIONS` (`New`), so no locale key is added. Changeset: `@object-ui/plugin-detail` patch. ## Tests New top-level `describe` in the existing addEntry harness, `RelatedList.enlargedToolbar-27524.test.tsx` (`renderList` gains an optional `language` that wraps the tree in `I18nProvider`): - en and zh-CN: a `master_detail` child with no catalog reads `New` / `新建`, clicking it calls `onNew` once, and no picker opens. - control, en and zh-CN: a `lookup` child (entry opens a picker) reads `Add` / `添加` and opens the picker. Ablation (one-off, not kept): with the no-picker label put back to `detail.add` via `scripts/ablation-replace.mjs`, the two New pins failed and the two Add controls passed (`Tests 2 failed | 2 passed | 21 skipped`). The file was then restored, and the blob matched HEAD (`e1f2ad715d08`, `git diff HEAD` empty). ## Acceptance notes - "An explicit `add.label` still wins" is read as the picker branch, where it applies today. The no-picker branch never read `add.label` before, and still does not: an authored `add` label names the pick-existing action, and putting it on a create-only entry would bring back the same mislabel. - The card face's (non-enlarged) header already used `detail.new` for its New button, so after this change both faces name the create-only action the same way. - Serial constraints: this change stays clear of #37246 (imports and `derivedAddOf`) and #37220 (the count badge). `overlap-check` merges cleanly against origin/main, #37283, #37220 and #37215. ## Verification Two-minute check: in `ui/`, run `pnpm exec vitest run packages/plugin-detail/src/__tests__/RelatedList.enlargedToolbar-27524.test.tsx -t 37251`. Expected result: 4 passed. Files to read first: 1. `ui/packages/plugin-detail/src/RelatedList.tsx`, the `addEntry` hunk (the only runtime change). 2. The new `describe` at the end of `RelatedList.enlargedToolbar-27524.test.tsx`. All readings below were taken at head 9d9bce7. <details><summary>Package tests and type-check</summary> - `pnpm --filter @object-ui/plugin-detail type-check && pnpm --filter @object-ui/plugin-detail test` under the verify lock: `VERDICT command-exit 0`, `Test Files 418 passed | 1 skipped (419)`, `Tests 3953 passed | 18 skipped (3971)`. - Harness plus sibling `RelatedList.derivedAddScope-36707.test.tsx`: `Test Files 2 passed (2)`, `Tests 34 passed (34)`. </details> <details><summary>Derived gates</summary> - `node scripts/pm/dispatch-gates.mjs --commands` derived 38 commands. All 38 ran and every one exited 0. `check:changeset-fixed` also ran (exit 0). - `--ran` reconciliation: `38 derived famil(ies) accounted for, 38 run, 0 NOT-MEASURED (a DERIVED zero, all 38 recorded an exit code)`. - CI owns the full farm, including `test:repo` and the UI lanes. </details> --- _Generated by [Claude Code](https://claude.ai/code/session_01QSeKYmRepQK9DkZeU7F53D)_ Co-authored-by: Claude <noreply@anthropic.com>
1 parent 08bf7d2 commit 5315599

3 files changed

Lines changed: 65 additions & 5 deletions

File tree

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
'@object-ui/plugin-detail': patch
3+
---
4+
5+
Clause-②: no
6+
Metadata-protocol: none
7+
8+
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`.

‎ui/packages/plugin-detail/src/RelatedList.tsx‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2827,18 +2827,22 @@ export const RelatedList: React.FC<RelatedListProps> = ({
28272827
* opens it — the picker's first row is 「新建」 when New is offered too —
28282828
* and with none it creates a new row directly (New). `null` when neither is
28292829
* offered.
2830+
*
2831+
* objectstack#37251 — the entry is named for what it does: 「添加」 / Add
2832+
* (or the authored `add.label`) only where it opens a picker; where it can
2833+
* only create (a `master_detail` child with no catalog, since
2834+
* objectstack#36704) it reads 「新建」 / New, the create form's own name.
28302835
*/
28312836
const pickerOffered = !!add && !!add.picker?.object && !!dataSource && addGranted && addBatchable;
2832-
const addFallbackLabel = t('detail.add', { defaultValue: 'Add' });
28332837
const addEntry: { label: string; disabled: boolean; onClick: () => void } | null = pickerOffered
28342838
? {
2835-
label: add!.label || addFallbackLabel,
2839+
label: add!.label || t('detail.add', { defaultValue: 'Add' }),
28362840
disabled: addBusy,
28372841
onClick: () => { setAddError(null); setPickerOpen(true); },
28382842
}
28392843
: onNew
28402844
? {
2841-
label: addFallbackLabel,
2845+
label: t('detail.new', { defaultValue: 'New' }),
28422846
disabled: !!newDisabled,
28432847
onClick: () => onNew(),
28442848
}

‎ui/packages/plugin-detail/src/__tests__/RelatedList.enlargedToolbar-27524.test.tsx‎

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import '@testing-library/jest-dom';
2828
import React from 'react';
2929
import { FilterScopeProvider, RecordContextProvider, RecordPagePreferencesProvider, type RecordPagePreference } from '@object-ui/react';
3030
import { ComponentRegistry } from '@object-ui/core';
31+
import { I18nProvider } from '@object-ui/i18n';
3132
import { RelatedList, derivedAddOf } from '../RelatedList';
3233
import { resetRelatedTabConditionsForTests } from '../relatedTabConditions';
3334

@@ -114,15 +115,18 @@ function renderList({
114115
onNew = vi.fn(),
115116
onViewAll = vi.fn(),
116117
preferences = null,
118+
language,
117119
...harness
118120
}: Harness & {
121+
/** Render under an `I18nProvider` in this language; none ⇒ provider-less (the English defaults). */
122+
language?: string;
119123
enlarged?: boolean;
120124
onNew?: (() => void) | undefined;
121125
onViewAll?: (() => void) | undefined;
122126
preferences?: { get: (o: string) => RecordPagePreference; update: (o: string, p: RecordPagePreference) => void } | null;
123127
} = {}) {
124128
const dataSource = dataSourceFor(harness);
125-
const utils = render(
129+
const tree = (
126130
<FilterScopeProvider currentUserId="u-1">
127131
<RecordPagePreferencesProvider value={preferences}>
128132
<RelatedListEnlargedContext.Provider value={enlarged}>
@@ -141,7 +145,12 @@ function renderList({
141145
/>
142146
</RelatedListEnlargedContext.Provider>
143147
</RecordPagePreferencesProvider>
144-
</FilterScopeProvider>,
148+
</FilterScopeProvider>
149+
);
150+
const utils = render(
151+
language
152+
? <I18nProvider config={{ defaultLanguage: language, detectBrowserLanguage: false }}>{tree}</I18nProvider>
153+
: tree,
145154
);
146155
return { ...utils, dataSource };
147156
}
@@ -507,3 +516,42 @@ describe('the related tab no longer remembers the reader\'s header sort (objects
507516
function RecordContextHarness({ children }: { children: React.ReactNode }) {
508517
return <RecordContextProvider objectName="lead" recordId="L-1" data={{ id: 'L-1' }}>{children}</RecordContextProvider>;
509518
}
519+
520+
/**
521+
* objectstack#37251 — the add entry is named for what it does. Where it can
522+
* only create (a `master_detail` child with no catalog: no picker since
523+
* objectstack#36704) it reads 新建 / New and opens the create form, whose
524+
* parent the host fills in; where it opens a picker it keeps 添加 / Add.
525+
*/
526+
describe('the add entry reads New where it can only create, Add where it opens a picker (objectstack#37251)', () => {
527+
const MASTER_DETAIL_NO_CATALOG = {
528+
subject: { type: 'text', label: 'Subject' },
529+
lead: { type: 'master_detail', reference: 'lead', label: 'Lead', required: true },
530+
};
531+
532+
it.each([
533+
['en', 'New', 'Add'],
534+
['zh-CN', '新建', '添加'],
535+
] as const)('%s: a master_detail child with no picker reads %s and opens the create form', async (language, newLabel, addLabel) => {
536+
const onNew = vi.fn();
537+
renderList({ language, onNew, fields: MASTER_DETAIL_NO_CATALOG });
538+
await waitFor(() => expect(screen.getByText('Send quote')).toBeInTheDocument());
539+
expect(addButton()!.textContent?.trim()).toBe(newLabel);
540+
expect(addButton()!.textContent).not.toContain(addLabel);
541+
fireEvent.click(addButton()!);
542+
expect(onNew).toHaveBeenCalledTimes(1);
543+
expect(screen.queryByTestId('record-picker-dialog')).toBeNull();
544+
});
545+
546+
it.each([
547+
['en', 'Add', 'New'],
548+
['zh-CN', '添加', '新建'],
549+
] as const)('control, %s: a lookup child whose entry opens a picker still reads %s', async (language, addLabel, newLabel) => {
550+
renderList({ language });
551+
await waitFor(() => expect(screen.getByText('Send quote')).toBeInTheDocument());
552+
expect(addButton()!.textContent?.trim()).toBe(addLabel);
553+
expect(addButton()!.textContent).not.toContain(newLabel);
554+
fireEvent.click(addButton()!);
555+
expect(await screen.findByTestId('record-picker-dialog')).toBeInTheDocument();
556+
});
557+
});

0 commit comments

Comments
 (0)