Skip to content

Commit fa23941

Browse files
fix(plugin-detail): a related tab's 「+ 添加」 picker keeps to the parent's own records and names them by their name field (#36707) (#36729)
<!-- claude-projects-attribution: {"github_login":"os-warren"} --> _Requested by **Warren** · [project thread](https://claude.ai/code/project/chan_01U5RdnAAmkSQmZbqh6FtqZ8?thread=cmsg_01U5RdnAAmkSQmZbqh6FtqZ8TsQcYbERTSLy2YcnwnC3Mn)_ Fixes #36707 Clause-②: no Metadata-protocol: none ## 维护者速读 - 在商机的「合同」页签点「添加」,选择框只列出这个商机所属客户自己的、尚未关联商机的合同,不再混进别的客户的合同;第一列显示合同编号(列名「合同编号」),不再是一列空白的英文「NAME」。 - 属于记录详情页重做专题,补的是上一张修合同页签「添加」时顺路发现的问题:一键就能把别的客户的合同挂到这个商机上。 - 出错的话只是某些页签的「添加」选择框里少列或多列了几条候选、或改成直接新建,不改任何已有数据,可直接撤回。 - 无。 ## What changes The related tab's 「+ 添加」 (objectstack#35601) derives its picker from the relationship when the page authors no `add` (`derivedAddOf`, `ui/packages/plugin-detail/src/RelatedList.tsx`). For a child linked by a plain `lookup`, the picker lists the child object's **unlinked** rows and a pick re-parents them. Two defects, both measured on HotCRM (opportunity "Initech Cloud Migration" → 合同 tab): 1. **The relationship lookup's `dependsOn` was ignored.** `crm_contract.crm_opportunity` declares `dependsOn: ['crm_account']`: on a contract's form the opportunity picker lists only opportunities of the contract's account. The derived picker sent only `crm_opportunity is_empty`, so it listed unlinked contracts of every account, and a pick linked another customer's contract to this opportunity. Now the lookup arm reverses that scope from the parent record (`parentScopeOf`): a `dependsOn` entry `{ field, param }` (a bare string names both) sends the child's `field` as the parent object's `param` (`LookupField`'s `dependentFilter`), so a child can name this parent only when its `field` equals the parent's `param`. Each entry becomes the rule `field equals PARENT.param`, added beside `is_empty`. The parent record is the record page's `RecordContext` (already read by this component for the parent currency); an expanded reference reads as its id. When the scope cannot be resolved, the tab offers **no picker** and 「+ 添加」 takes the existing no-picker path (New with the parent filled): the parent has no value for a `dependsOn` field (no child could name it), the parent record is not in context, or the lookup's `lookupFilters` compare with `{ $record }` (any operator, which this side does not invert). An unscoped lookup (static `lookupFilters` included) keeps today's unlinked-only picker. The `master_detail` catalog arm and an authored `add` are untouched. 2. **The picker's label column was a hard-coded `name`.** With no `add.picker.labelField` (a derived add never has one), `pickerDisplayField` fell back to `name`; a contract's name field is `contract_number`, so the first column was headed 「NAME」 (the dialog's title-cased fallback for a field the schema does not declare) and was empty. The label column is now the picked object's name field, `resolveNameField(pickerSchema)` (ADR-0079: declared `nameField`, else the derived title field), under that field's served label; `name` only until the picker's schema is read. An authored `labelField` still wins. This also names the record in the batch-refusal message, which reads the same field. Changeset: `@object-ui/plugin-detail` patch. No new export, key or route. ## Tests New `ui/packages/plugin-detail/src/__tests__/RelatedList.derivedAddScope-36707.test.tsx`: - `derivedAddOf`: a `dependsOn` lookup gets `account equals A-1` from the parent, for a string entry and a `{ field, param }` entry; an expanded parent reference reads as its id; no picker when the parent's value is empty or the parent record is absent; no picker when the relationship's `lookupFilters` read `$record`; control: an unscoped lookup with a static `lookupFilters` keeps `[is_empty]` alone, parent read or not; - rendered opportunity 合同 tab (parent `account: A-1`, a pool with one contract of A-1 and one of A-2): the picker shows only the own contract, every picker read carries `A-1` beside `is_empty`, and the first header is the name field's label 「Contract Number」 with no 「Name」 column; with no parent account, 「+ 添加」 calls New and no picker read is made; with no declared `nameField`, the derived title field leads and no 「Name」 column appears. `RelatedList.enlargedToolbar-27524.test.tsx`: its candidate fixture rows (the `task` object, whose derived title field is `subject`) now carry `subject` beside `name`, so the refusal-message tests keep naming the picked row by the field the picker now shows. Ablation, one leg per behaviour, each with the fix committed (`node scripts/ablation-replace.mjs`, mutation landed and restored with `git diff HEAD` empty): - `const scope = parentScopeOf(rel, parentRecord)` → `[]`: 7 of 9 new tests fail (every scope test and both rendered scope tests); restored: 9/9. - `labelField || resolveNameField(pickerSchema) || 'name'` → `labelField || 'name'`: the 2 label-column tests fail (`["Name","Contract Number","Account","Opportunity"]`); restored: 9/9. <details><summary>Package run and gates under the verify lock</summary> ``` pnpm --filter @object-ui/plugin-detail type-check && pnpm --filter @object-ui/plugin-detail test (at d7bcece's tree) > tsc --noEmit && tsc -p tsconfig.test.json Test Files 416 passed | 1 skipped (417) Tests 3907 passed | 18 skipped (3925) os-verify-lock: VERDICT command-exit 0 node scripts/pm/dispatch-gates.mjs --commands → 38 commands, all exit 0 at d7bcece (incl. pnpm --dir ui exec vitest run scripts/, check:nul-bytes, check:published-files, check:test-source-alias, check:type-check-debt, check:empty-changeset, check:adr-0087-registration) ``` </details> ## Acceptance notes - `dependsOn` scopes the picker only (as on the form): the server does not refuse a contract whose opportunity belongs to another account. A save-side rule, if wanted, is a separate card. - A relationship lookup whose `lookupFilters` read `{ $record }` now offers no picker on its related tab (it used to offer an unscoped one). Inverting those comparisons (eq only, one hop) is possible but is not needed by any measured tab; noted, not done. - A static `lookupFilters` on the relationship (which parents a child may name, e.g. only open opportunities) is not checked against the parent here; read from code, not reproduced. - The empty 「NAME」 column was not contract-specific: it appeared on every picker whose `add` names no `labelField` and whose object's name field is not literally `name`; all of them now lead with the object's name field. ## Verification Read first: 1. `ui/packages/plugin-detail/src/RelatedList.tsx`, `parentScopeOf` and the lookup arm of `derivedAddOf` (riskiest hunk: an unresolved scope returns no picker, which changes 「+ 添加」 to New on those tabs). 2. `pickerDisplayField` (one line) and the `derivedAdd` memo, which now depends on the parent record. Browser, HotCRM `origin/main` (`e2ee348`, `objectstack dev --seed-admin --fresh`) behind this branch's Console (Vite, `DEV_PROXY_TARGET`), zh-CN, at `d7bceceb`: - Opportunity "Initech Cloud Migration" (account Initech Solutions) → 合同 tab → 「+ 添加」: the dialog lists one row, CTR-0003 / Initech Solutions; CTR-0004 (Stark Medical, also unlinked) is not offered. Headers `["合同编号","所属客户","状态","开始日期"]`. - The picker's request: `GET /api/v1/data/crm_contract?populate=crm_account&top=10&skip=0&filter=[["crm_opportunity","is_empty"],["crm_account","equals","SlX6mEUIGqvFAEbb"]]` (the opportunity's own account id). - Before (`origin/main`, the card's repro): the same click listed CTR-0004 beside CTR-0003 under an empty 「NAME」 column, with only the `is_empty` rule. Screenshots are attached in the project thread (GitHub's image store takes browser uploads only): the opportunity's 合同 tab; the 「添加」 dialog with only the account's own contract. Two-minute check: on a HotCRM opportunity, open the 合同 tab and click 「+ 添加」: only that account's unlinked contracts appear, led by 合同编号. --- _Generated by [Claude Code](https://claude.ai/code/session_01JQwxbYmr1N6x5nuafz67fw)_ Co-authored-by: Claude <noreply@anthropic.com>
1 parent 6156fdd commit fa23941

4 files changed

Lines changed: 269 additions & 13 deletions

File tree

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
'@object-ui/plugin-detail': patch
3+
---
4+
5+
fix(plugin-detail): a related tab's 「+ 添加」 picker keeps to the parent's own records and names them by their name field
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
On a record page's related tab whose child is linked by a plain `lookup`, the derived 「+ 添加」 picker listed the unlinked children of every parent's scope. An opportunity's 合同 (contracts) tab listed unlinked contracts of every account, although a contract's opportunity lookup `dependsOn` the contract's account; a pick linked another customer's contract to the opportunity. The picker now applies that lookup's `dependsOn` from the parent record: each named child field must equal the parent's value (here, only contracts of the opportunity's own account). When the parent has no value for it, or the lookup's `lookupFilters` compare with `$record`, the tab offers no picker and 「+ 添加」 creates a record directly.
11+
12+
The picker's label column is the picked object's name field (its declared `nameField`, else the derived title field) when the add names no `labelField`, under that field's label. It was a hard-coded `name`: on contracts, whose name field is `contract_number`, the first column was an empty 「NAME」.

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

Lines changed: 69 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1089,7 +1089,15 @@ function relationFieldEntries(fields: unknown): Array<[string, RelationFieldDef]
10891089
* lists only UNLINKED children (this relationship empty): a row already
10901090
* here would be a no-op pick, and a row under another parent would move
10911091
* silently. Moving a child between parents stays on the child's own
1092-
* form, where the change is visible (seat ruling on L1-a S1, #35725);
1092+
* form, where the change is visible (seat ruling on L1-a S1, #35725).
1093+
* When the relationship lookup is scoped by the child's own fields
1094+
* (`dependsOn`: a contract's opportunity `dependsOn` the contract's
1095+
* account), the picker lists only children that lookup could name this
1096+
* parent from: each `dependsOn` field equal to the parent's value
1097+
* (objectstack#36707 — the opportunity's 合同 tab listed every account's
1098+
* unlinked contracts, and a pick linked another customer's contract).
1099+
* A scope it cannot resolve (the parent's value is empty or not read, or
1100+
* a `lookupFilters` comparand reads `$record`) offers no picker;
10931101
* - `master_detail` with a source catalog: the picker lists the catalog and
10941102
* a pick creates a row of this list naming it (`linkField`). The catalog
10951103
* is the child's one other REQUIRED single-valued `lookup` (a line's
@@ -1120,12 +1128,17 @@ export function derivedAddOf(
11201128
childFields: unknown,
11211129
referenceField: string | undefined,
11221130
childObject: string | undefined,
1131+
parentRecord?: Record<string, unknown>,
11231132
): RelatedListAdd | undefined {
11241133
if (!referenceField || !childObject) return undefined;
11251134
const entries = relationFieldEntries(childFields);
11261135
const rel = entries.find(([name]) => name === referenceField)?.[1];
11271136
if (!rel || rel.multiple === true) return undefined;
1128-
if (rel.type === 'lookup') return { picker: { object: childObject, filter: [{ field: referenceField, operator: 'is_empty' }] } };
1137+
if (rel.type === 'lookup') {
1138+
const scope = parentScopeOf(rel, parentRecord);
1139+
if (!scope) return undefined;
1140+
return { picker: { object: childObject, filter: [{ field: referenceField, operator: 'is_empty' }, ...scope] } };
1141+
}
11291142
if (rel.type !== 'master_detail') return undefined;
11301143
const catalogs = entries.filter(([name, def]) =>
11311144
name !== referenceField
@@ -1149,6 +1162,51 @@ export function derivedAddOf(
11491162
return { picker: { object: catalogDef.reference as string }, linkField: catalogField };
11501163
}
11511164

1165+
/**
1166+
* The candidate rules a `lookup` relationship's own scope adds to the derived
1167+
* picker of children (`derivedAddOf`), seen from the parent: `[]` when the
1168+
* lookup is unscoped, `undefined` when the scope cannot be resolved here.
1169+
*
1170+
* `dependsOn` scopes the lookup's candidates by equality — a `{ field, param }`
1171+
* entry (a bare string names both) sends the child's `field` value as the
1172+
* parent object's `param` (`LookupField`'s `dependentFilter`). Reversed, a
1173+
* child can name this parent only when its `field` equals the parent's
1174+
* `param`, so each entry becomes `field equals <parent's param>`. With the
1175+
* parent's value empty or not read yet no child could name it: no picker,
1176+
* never an unscoped one. A `lookupFilters` comparand reading `$record` relates
1177+
* the parent's columns to the child's by any operator, and this side does not
1178+
* invert it: no picker either.
1179+
*/
1180+
function parentScopeOf(rel: RelationFieldDef, parentRecord: Record<string, unknown> | undefined): ViewFilterElement[] | undefined {
1181+
if (Array.isArray(rel.lookupFilters) && rel.lookupFilters.some(readsRecord)) return undefined;
1182+
if (!Array.isArray(rel.dependsOn) || rel.dependsOn.length === 0) return [];
1183+
const rules: ViewFilterElement[] = [];
1184+
for (const entry of rel.dependsOn) {
1185+
const field = typeof entry === 'string' ? entry : (entry as { field?: unknown } | null)?.field;
1186+
const param = typeof entry === 'string' ? entry : ((entry as { param?: unknown }).param ?? field);
1187+
if (typeof field !== 'string' || field === '' || typeof param !== 'string' || param === '') return undefined;
1188+
const value = referenceValueOf(parentRecord?.[param]);
1189+
if (value === undefined) return undefined;
1190+
rules.push({ field, operator: 'equals', value });
1191+
}
1192+
return rules;
1193+
}
1194+
1195+
/** A record field's value as a filter comparand: an expanded reference reads as its id. */
1196+
function referenceValueOf(raw: unknown): string | number | boolean | undefined {
1197+
const value = raw && typeof raw === 'object' && !Array.isArray(raw)
1198+
? ((raw as { id?: unknown; _id?: unknown }).id ?? (raw as { _id?: unknown })._id)
1199+
: raw;
1200+
if (typeof value === 'number' || typeof value === 'boolean') return value;
1201+
return typeof value === 'string' && value !== '' ? value : undefined;
1202+
}
1203+
1204+
/** Does this `lookupFilters` entry compare with a `{ $record }` value? */
1205+
function readsRecord(entry: unknown): boolean {
1206+
const value = (entry as { value?: unknown } | null)?.value;
1207+
return !!value && typeof value === 'object' && '$record' in (value as object);
1208+
}
1209+
11521210
/**
11531211
* Does the insert fill this field when a create omits it — the engine's
11541212
* `applyFieldDefaults`: a non-null `defaultValue`, else a select option marked
@@ -1166,11 +1224,7 @@ function insertDefaults(def: RelationFieldDef): boolean {
11661224
*/
11671225
function scopedByRow(def: RelationFieldDef): boolean {
11681226
if (Array.isArray(def.dependsOn) && def.dependsOn.length > 0) return true;
1169-
if (!Array.isArray(def.lookupFilters)) return false;
1170-
return def.lookupFilters.some((entry) => {
1171-
const value = (entry as { value?: unknown } | null)?.value;
1172-
return !!value && typeof value === 'object' && '$record' in (value as object);
1173-
});
1227+
return Array.isArray(def.lookupFilters) && def.lookupFilters.some(readsRecord);
11741228
}
11751229

11761230
/** One group of a stateful child list (`statusGroupsOf`). */
@@ -1544,8 +1598,8 @@ export const RelatedList: React.FC<RelatedListProps> = ({
15441598
// when the page authored none (`derivedAddOf`). The rest of this component
15451599
// reads `add` alone, so a derived add takes the authored one's path.
15461600
const derivedAdd = React.useMemo(
1547-
() => (enlargedFace && !authoredAdd && !schema ? derivedAddOf(objectSchema?.fields, referenceField, api) : undefined),
1548-
[enlargedFace, authoredAdd, schema, objectSchema, referenceField, api],
1601+
() => (enlargedFace && !authoredAdd && !schema ? derivedAddOf(objectSchema?.fields, referenceField, api, parentRecord) : undefined),
1602+
[enlargedFace, authoredAdd, schema, objectSchema, referenceField, api, parentRecord],
15491603
);
15501604
const add = authoredAdd ?? derivedAdd;
15511605
// objectstack#27056 — the card's count, asked up front with the column's
@@ -2118,7 +2172,12 @@ export const RelatedList: React.FC<RelatedListProps> = ({
21182172
});
21192173
return () => { cancelled = true; };
21202174
}, [pickerOpen, pickerObject, pickerSchema, dataSource]);
2121-
const pickerDisplayField = add?.picker?.labelField || 'name';
2175+
// The label column is the picked object's name field (ADR-0079: declared
2176+
// `nameField`, else derived) when the add names no `labelField` — a derived
2177+
// add never does (objectstack#36707: a contract's 合同 tab picker led with an
2178+
// empty 「NAME」, the contract's name being `contract_number`). `name` only
2179+
// until the schema is read.
2180+
const pickerDisplayField = add?.picker?.labelField || resolveNameField(pickerSchema) || 'name';
21222181
const pickerColumns = React.useMemo(() => {
21232182
const derived = deriveLookupColumns(pickerSchema, { displayField: pickerDisplayField });
21242183
return derived.length > 0 ? derived : undefined;
Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
/**
2+
* objectstack#36707 — the related tab's derived 「+ 添加」 on a `lookup`
3+
* relationship (`derivedAddOf`, the lookup arm):
4+
*
5+
* 1. the relationship lookup's `dependsOn` scopes the picker from the parent
6+
* record. An opportunity's 合同 tab: `contract.opportunity` `dependsOn`
7+
* the contract's account, so the picker lists only unlinked contracts of
8+
* the opportunity's own account — never another customer's, which a pick
9+
* would have linked here. A scope it cannot resolve offers no picker;
10+
* 2. the picker's label column is the picked object's name field, not a
11+
* hard-coded `name` (an empty 「NAME」 column on contracts, whose name
12+
* field is `contract_number`).
13+
*/
14+
import { describe, it, expect, vi, beforeAll, afterEach } from 'vitest';
15+
import { render, screen, waitFor, fireEvent, within } from '@testing-library/react';
16+
import '@testing-library/jest-dom';
17+
import React from 'react';
18+
import { FilterScopeProvider, RecordContextProvider } from '@object-ui/react';
19+
import { ComponentRegistry } from '@object-ui/core';
20+
import { RelatedList, derivedAddOf } from '../RelatedList';
21+
import { resetRelatedTabConditionsForTests } from '../relatedTabConditions';
22+
import { RelatedListEnlargedContext } from '../relatedListCompact';
23+
24+
afterEach(() => resetRelatedTabConditionsForTests());
25+
26+
/** `object-grid` lives in `plugin-grid`, which this package cannot import. */
27+
function ObjectGridStandIn({ schema }: { schema: any }) {
28+
const rows: any[] = schema?.data?.items ?? [];
29+
return <ul data-object-grid-stand-in="">{rows.map((row) => <li key={row.id}>{String(row.subject ?? row.contract_number ?? row.id)}</li>)}</ul>;
30+
}
31+
32+
beforeAll(() => {
33+
Object.defineProperty(window, 'innerWidth', { configurable: true, value: 1280 });
34+
ComponentRegistry.register('object-grid', ObjectGridStandIn as never);
35+
});
36+
37+
const CONTRACT_FIELDS = {
38+
contract_number: { type: 'autonumber', label: 'Contract Number' },
39+
account: { type: 'master_detail', reference: 'account', label: 'Account', required: true },
40+
opportunity: { type: 'lookup', reference: 'opportunity', label: 'Opportunity', dependsOn: ['account'] },
41+
status: { type: 'text', label: 'Status' },
42+
};
43+
const CONTRACT_SCHEMA = { name: 'contract', nameField: 'contract_number', fields: CONTRACT_FIELDS };
44+
45+
/** The unlinked contracts of two accounts; the stand-in server honours equality on `account`. */
46+
const POOL = [
47+
{ id: 'k-own', contract_number: 'CTR-0003', account: 'A-1', opportunity: null, status: 'Draft' },
48+
{ id: 'k-other', contract_number: 'CTR-0004', account: 'A-2', opportunity: null, status: 'Draft' },
49+
];
50+
const LINKED = [{ id: 'k-here', contract_number: 'CTR-0001', account: 'A-1', opportunity: 'O-1', status: 'Active' }];
51+
52+
function dataSourceFor(schema: Record<string, unknown> = CONTRACT_SCHEMA) {
53+
return {
54+
find: vi.fn(async (resource: string, params?: any) => {
55+
const filter = JSON.stringify(params?.$filter ?? []);
56+
if (resource === 'contract' && JSON.stringify(params ?? {}).includes('O-1')) return { data: LINKED, total: LINKED.length };
57+
const data = POOL.filter((r) => !filter.includes('"account"') || filter.includes(`"${r.account}"`));
58+
return { data, total: data.length };
59+
}),
60+
getObjectSchema: vi.fn(async () => schema),
61+
create: vi.fn(async () => ({})),
62+
update: vi.fn(async () => ({})),
63+
batchTransaction: vi.fn(async (ops: unknown[]) => ({ results: ops.map(() => ({})) })),
64+
};
65+
}
66+
67+
function renderTab(parent: Record<string, unknown>, { onNew = vi.fn(), schema }: { onNew?: () => void; schema?: Record<string, unknown> } = {}) {
68+
const dataSource = dataSourceFor(schema);
69+
render(
70+
<FilterScopeProvider currentUserId="u-1">
71+
<RecordContextProvider objectName="opportunity" recordId="O-1" data={parent} dataSource={dataSource as any}>
72+
<RelatedListEnlargedContext.Provider value>
73+
<RelatedList
74+
title="Contracts"
75+
type="table"
76+
api="contract"
77+
objectName="contract"
78+
referenceField="opportunity"
79+
parentId="O-1"
80+
pageSize={25}
81+
columns={[{ field: 'contract_number', label: 'Contract Number' }]}
82+
onNew={onNew}
83+
dataSource={dataSource as never}
84+
/>
85+
</RelatedListEnlargedContext.Provider>
86+
</RecordContextProvider>
87+
</FilterScopeProvider>,
88+
);
89+
return { dataSource };
90+
}
91+
92+
/** The picker's column headers that carry a name, in order (the select-all column has none). */
93+
const headerTexts = (dialog: HTMLElement) =>
94+
Array.from(within(dialog).getByTestId('record-picker-sticky-header').querySelectorAll('th'))
95+
.map((th) => th.textContent?.trim() ?? '')
96+
.filter((text) => text !== '');
97+
const addButton = () => document.querySelector('[data-related-enlarged-toolbar] [data-related-add]') as HTMLElement;
98+
const pickerReads = (ds: ReturnType<typeof dataSourceFor>) =>
99+
ds.find.mock.calls.filter(([r, p]) => r === 'contract' && !JSON.stringify(p ?? {}).includes('O-1'));
100+
101+
describe('derivedAddOf — a lookup relationship scoped by dependsOn (objectstack#36707)', () => {
102+
const unlinked = { field: 'opportunity', operator: 'is_empty' };
103+
104+
it('each dependsOn field must equal the parent\'s value: string and { field, param } entries', () => {
105+
expect(derivedAddOf(CONTRACT_FIELDS, 'opportunity', 'contract', { id: 'O-1', account: 'A-1' })).toEqual({
106+
picker: { object: 'contract', filter: [unlinked, { field: 'account', operator: 'equals', value: 'A-1' }] },
107+
});
108+
const byParam = { ...CONTRACT_FIELDS, opportunity: { type: 'lookup', reference: 'opportunity', dependsOn: [{ field: 'account', param: 'customer' }] } };
109+
expect(derivedAddOf(byParam, 'opportunity', 'contract', { id: 'O-1', customer: 'A-9', account: 'A-1' })?.picker.filter).toEqual([
110+
unlinked,
111+
{ field: 'account', operator: 'equals', value: 'A-9' },
112+
]);
113+
});
114+
115+
it('an expanded reference on the parent reads as its id', () => {
116+
expect(derivedAddOf(CONTRACT_FIELDS, 'opportunity', 'contract', { id: 'O-1', account: { id: 'A-1', name: 'Initech' } })?.picker.filter).toEqual([
117+
unlinked,
118+
{ field: 'account', operator: 'equals', value: 'A-1' },
119+
]);
120+
});
121+
122+
it.each([
123+
['the parent has no value for it', { id: 'O-1', account: null }],
124+
['the parent record is not read', undefined],
125+
] as const)('no picker when the scope cannot be resolved: %s', (_label, parent) => {
126+
expect(derivedAddOf(CONTRACT_FIELDS, 'opportunity', 'contract', parent as any)).toBeUndefined();
127+
});
128+
129+
it('no picker when a lookupFilters comparand on the relationship reads $record', () => {
130+
const fields = {
131+
...CONTRACT_FIELDS,
132+
opportunity: { type: 'lookup', reference: 'opportunity', lookupFilters: [{ field: 'region', operator: 'eq', value: { $record: 'region' } }] },
133+
};
134+
expect(derivedAddOf(fields, 'opportunity', 'contract', { id: 'O-1', region: 'east' })).toBeUndefined();
135+
});
136+
137+
it('control: an unscoped lookup (static lookupFilters included) keeps the unlinked-only picker, parent read or not', () => {
138+
const fields = {
139+
...CONTRACT_FIELDS,
140+
opportunity: { type: 'lookup', reference: 'opportunity', lookupFilters: [{ field: 'is_active', operator: 'eq', value: true }] },
141+
};
142+
expect(derivedAddOf(fields, 'opportunity', 'contract')).toEqual({ picker: { object: 'contract', filter: [unlinked] } });
143+
});
144+
});
145+
146+
describe('the opportunity\'s 合同 tab picker (objectstack#36707)', () => {
147+
it('lists only the account\'s own unlinked contracts, led by the contract number under its label', async () => {
148+
const { dataSource } = renderTab({ id: 'O-1', name: 'Initech Cloud Migration', account: 'A-1' });
149+
await waitFor(() => expect(screen.getByText('CTR-0001')).toBeInTheDocument());
150+
fireEvent.click(addButton());
151+
const dialog = await screen.findByTestId('record-picker-dialog');
152+
expect(await within(dialog).findByTestId('record-row-k-own')).toHaveTextContent('CTR-0003');
153+
expect(within(dialog).queryByTestId('record-row-k-other')).toBeNull();
154+
const reads = pickerReads(dataSource);
155+
expect(reads.length).toBeGreaterThan(0);
156+
for (const [, params] of reads) {
157+
const filter = JSON.stringify((params as any)?.$filter ?? []);
158+
expect(filter).toContain('"A-1"');
159+
expect(filter).toContain('is_empty');
160+
}
161+
const headers = headerTexts(dialog);
162+
expect(headers[0]).toBe('Contract Number');
163+
expect(headers).not.toContain('Name');
164+
});
165+
166+
it('a parent with no account offers no picker: 「+ 添加」 creates a contract', async () => {
167+
const onNew = vi.fn();
168+
const { dataSource } = renderTab({ id: 'O-1', name: 'Initech Cloud Migration', account: null }, { onNew });
169+
await waitFor(() => expect(screen.getByText('CTR-0001')).toBeInTheDocument());
170+
fireEvent.click(addButton());
171+
expect(onNew).toHaveBeenCalledTimes(1);
172+
expect(screen.queryByTestId('record-picker-dialog')).toBeNull();
173+
expect(pickerReads(dataSource)).toHaveLength(0);
174+
});
175+
176+
it('with no declared nameField the label column is the derived title field, still never an empty 「NAME」', async () => {
177+
const { nameField: _drop, ...undeclared } = CONTRACT_SCHEMA;
178+
renderTab({ id: 'O-1', account: 'A-1' }, { schema: undeclared });
179+
await waitFor(() => expect(screen.getByText('CTR-0001')).toBeInTheDocument());
180+
fireEvent.click(addButton());
181+
const dialog = await screen.findByTestId('record-picker-dialog');
182+
await within(dialog).findByTestId('record-row-k-own');
183+
expect(headerTexts(dialog)).not.toContain('Name');
184+
});
185+
});

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,9 @@ const ROWS = [
7676
{ id: 't2', subject: 'Call back', lead: 'L-1', owner_id: 'u-2', due_date: '2026-11-04' },
7777
];
7878
const CANDIDATES = [
79-
{ id: 'c1', name: 'Alpha' },
80-
{ id: 'c2', name: 'Bravo' },
81-
{ id: 'c3', name: 'Charlie' },
79+
{ id: 'c1', name: 'Alpha', subject: 'Alpha' },
80+
{ id: 'c2', name: 'Bravo', subject: 'Bravo' },
81+
{ id: 'c3', name: 'Charlie', subject: 'Charlie' },
8282
];
8383

8484
interface Harness {

0 commit comments

Comments
 (0)