Skip to content

Commit 6156fdd

Browse files
fix(fields): a multi-record lookup column in the line-item grid reads its records, not "undefined", read-only and in list mode (#36728)
<!-- claude-projects-attribution: {"github_login":"os-warren"} --> _Requested by **Warren** · [project thread](https://claude.ai/code/project/chan_01U5RdnAAmkSQmZbqh6FtqZ8?thread=cmsg_01U5RdnAAmkSQmZbqh6FtqZ852pUyi6G1KDP9T8JogHTeb)_ Fixes #36618 Clause-②: no Metadata-protocol: none ## 维护者速读 - 用户在只读的记录页、打印页或卡片式明细里查看明细行时,"可选多条关联记录"的那一列不再显示 undefined,而是逐个显示所关联记录的名称;单选的关联列外观不变。 - 属于体验专题的界面缺陷修复,替查看订单、报价这类带明细行单据的人解决看不懂的问题。 - 出错的话只是这一列显示不对,不影响保存的数据,可直接撤回。 - 无。 ## What changes The line-item grid renders a read-only `LookupField` at two sites: the read-only table (`readonly` grid: read-only record page, print page) and the list form-factor cell (`displayMode="list"`). Both built the lookup's `field` without the column's `multiple`, while the editable cell passes `multiple: c.multiple`. Without it, `LookupField` resolves the stored id list as ONE id (`selectedOptions = [resolveSelectedOption(value)]`) and its single-value read-only face prints that option's missing label, which renders as "undefined". - `ui/packages/fields/src/widgets/grid-field/GridFieldWidget.tsx`: both read-only sites now pass `multiple: c.multiple`, read from the column definition (as the card asks), never inferred from the value's shape. The read-only face then draws one badge per related record. - Changeset: `@object-ui/fields` patch. No new prop, key or export. Single-record lookup columns are unchanged. ## Tests New `ui/packages/fields/src/widgets/GridField.multiLookupReadonly-36618.test.tsx`, one case per site plus a control per site: - read-only table: a cell holding `['p1', 'p2']` draws `Widget` and `Gadget`, and the grid's text has no `undefined`; - list mode: the same; - control, each site: a single-record lookup column still draws its one name. Reverse verification (fix committed first; each site reverted on its own with an anchored replacement whose hit count was checked, test run, then `git checkout HEAD --` and `git diff HEAD` empty): | Site reverted | Result | |---|---| | read-only table | `× read-only: a cell holding two product ids draws both product names`; 3 others pass | | list mode | `× list: a cell holding two product ids draws both product names`; 3 others pass | So each multi-value case pins its own site, and the controls pass both ways. <details><summary>Package runs at 418f177 (merged with main e343ab7; the merge touched nothing under ui/packages/fields)</summary> ``` pnpm exec vitest run --root ../.. --maxWorkers=2 packages/fields/src/widgets/GridField Test Files 21 passed (21) Tests 272 passed (272) os-verify-lock: VERDICT command-exit 0 pnpm --filter @object-ui/fields type-check (tsc --noEmit && tsc -p tsconfig.test.json) exit 0 ``` The dependency closure was built first (`pnpm --filter '@object-ui/fields^...' build`, VERDICT command-exit 0). </details> <details><summary>Derived gate families (dispatch-gates --commands, 38 families, run on the same diff at 974437a3 before the merge with main)</summary> All 38 exited 0. `dispatch-gates --ran`: 38 derived, 38 run, 0 NOT-MEASURED, 0 UNRUN. Every family CI runs is read from this PR's check-runs, not re-run locally. </details> ## Acceptance notes - Not measured in a browser: the showcase app has no line-item grid with a multi-record lookup column to open. The jsdom pins render the real `LookupField` against a data source and read the drawn names. - An empty stored list (`[]`) still reaches the lookup branch in both sites (the guard checks `null` and `''` only); with `multiple` passed it draws the lookup's read-only empty face, not the grid's muted em dash. Not pinned here, and what it drew before was not measured. Left as is: the card asks only for `multiple`. ## Verification Read first: 1. `ui/packages/fields/src/widgets/grid-field/GridFieldWidget.tsx`, the two read-only `LookupField` sites (the only code change). 2. The new test file. Two-minute check: `pnpm --dir ui exec vitest run packages/fields/src/widgets/GridField.multiLookupReadonly-36618.test.tsx` shows 4 passing; revert either `multiple: c.multiple` and its site's multi-value case fails. --- _Generated by [Claude Code](https://claude.ai/code/session_01JQwxbYEoTneL1bdkVJrq2S)_ Co-authored-by: Claude <noreply@anthropic.com>
1 parent d24a502 commit 6156fdd

3 files changed

Lines changed: 97 additions & 2 deletions

File tree

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
'@object-ui/fields': patch
3+
---
4+
5+
fix(fields): a multi-record lookup column in the line-item grid reads its records, not "undefined", in the read-only table and in list mode
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
The line-item grid rendered its read-only lookup cell (the read-only table of a read-only record page or print page, and the list form-factor) without the column's `multiple` flag. A multi-record lookup cell's id list was therefore resolved as one id, and the cell printed "undefined". Both read-only sites now pass `multiple` from the column, as the editable cell already did, so the cell shows one badge per related record. Single-record lookup columns are unchanged.
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/**
2+
* ObjectUI
3+
* Copyright (c) 2024-present ObjectStack Inc.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
/**
10+
* objectstack#36618 — a multi-record lookup column in the line-item grid drew
11+
* "undefined" in the read-only table and in list mode.
12+
*
13+
* Both read-only sites rendered `LookupField` without the column's `multiple`,
14+
* so the stored id list was resolved as ONE id and the single-value face
15+
* printed its missing label. The editable cell always passed `multiple`; the
16+
* two read-only sites now pass it too, from the column, never from the value's
17+
* shape. One case per site; a single-record column is the control.
18+
*/
19+
20+
import { describe, it, expect, vi, afterEach } from 'vitest';
21+
import { render, screen, cleanup, waitFor } from '@testing-library/react';
22+
import * as React from 'react';
23+
import { SchemaRendererContext } from '@object-ui/react';
24+
import { GridFieldWidget as GridField } from './grid-field/GridFieldWidget';
25+
26+
const PRODUCTS = [
27+
{ id: 'p1', name: 'Widget' },
28+
{ id: 'p2', name: 'Gadget' },
29+
];
30+
31+
function makeSource() {
32+
return {
33+
find: vi.fn(async (_object: string, params?: { $filter?: Record<string, any> }) => {
34+
const wanted = params?.$filter?.id?.$in as unknown[] | undefined;
35+
const rows = wanted ? PRODUCTS.filter((r) => wanted.includes(r.id)) : PRODUCTS;
36+
return { data: rows.map((r) => ({ ...r })), total: rows.length };
37+
}),
38+
findOne: vi.fn(async (_object: string, id: string) => {
39+
const row = PRODUCTS.find((r) => r.id === id);
40+
return row ? { ...row } : null;
41+
}),
42+
};
43+
}
44+
45+
const multiColumn = { name: 'products', label: 'Products', type: 'lookup', reference: 'product', multiple: true };
46+
const singleColumn = { name: 'product', label: 'Product', type: 'lookup', reference: 'product' };
47+
48+
function renderGrid(mode: 'read-only' | 'list', rows: any[], columns: any[]) {
49+
return render(
50+
<SchemaRendererContext.Provider value={{ dataSource: makeSource() } as never}>
51+
<GridField
52+
value={rows}
53+
onChange={() => {}}
54+
field={{ columns } as never}
55+
readonly={mode === 'read-only'}
56+
displayMode={mode === 'list' ? 'list' : undefined}
57+
onRowExpand={mode === 'list' ? () => {} : undefined}
58+
/>
59+
</SchemaRendererContext.Provider>,
60+
);
61+
}
62+
63+
afterEach(cleanup);
64+
65+
describe('a multi-record lookup column reads its records, not "undefined" (objectstack#36618)', () => {
66+
for (const mode of ['read-only', 'list'] as const) {
67+
it(`${mode}: a cell holding two product ids draws both product names`, async () => {
68+
const { container } = renderGrid(mode, [{ products: ['p1', 'p2'] }], [multiColumn]);
69+
expect(await screen.findByText('Widget')).toBeTruthy();
70+
expect(await screen.findByText('Gadget')).toBeTruthy();
71+
expect(container.textContent).not.toContain('undefined');
72+
});
73+
74+
it(`${mode}: a single-record column still draws its one name (control)`, async () => {
75+
const { container } = renderGrid(mode, [{ product: 'p2' }], [singleColumn]);
76+
await waitFor(() => expect(screen.getByText('Gadget')).toBeTruthy());
77+
expect(screen.queryByText('Widget')).toBeNull();
78+
expect(container.textContent).not.toContain('undefined');
79+
});
80+
}
81+
});

‎ui/packages/fields/src/widgets/grid-field/GridFieldWidget.tsx‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1280,7 +1280,10 @@ function GridFieldBody({
12801280
value={row[c.name]}
12811281
onChange={() => {}}
12821282
readonly
1283-
field={{ reference: c.reference, displayField: c.displayField, idField: c.idField } as any}
1283+
// `multiple` from the column, as the editable cell passes it:
1284+
// without it a multi-record cell's id list reads as one id
1285+
// and draws "undefined" (objectstack#36618).
1286+
field={{ reference: c.reference, displayField: c.displayField, idField: c.idField, multiple: c.multiple } as any}
12841287
dataSource={cellSource}
12851288
/>
12861289
) : (
@@ -1389,7 +1392,8 @@ function GridFieldBody({
13891392
if (c.type === 'lookup' && val != null && val !== '') {
13901393
return (
13911394
<LookupField value={val} onChange={() => {}} readonly
1392-
field={{ reference: c.reference, displayField: c.displayField, idField: c.idField } as any}
1395+
// `multiple` from the column, as in the read-only table (objectstack#36618).
1396+
field={{ reference: c.reference, displayField: c.displayField, idField: c.idField, multiple: c.multiple } as any}
13931397
dataSource={cellSource} />
13941398
);
13951399
}

0 commit comments

Comments
 (0)