Repository navigation
Commit 3110de5
fix(fields): line-item grid stores an emptied multi-record lookup cell as null, reads names once per object, mutes an empty list (#36616)
Fixes #36552
Clause-②: no
Metadata-protocol: none
## 维护者速读
-
编辑带明细行表格的记录时(控制台里人员列、多选查找列),清空多选查找格现在存为空值而不是空列表;二十行的人员列从二十次读取变成一次;列表模式下空列表的破折号变灰。
- 属于明细行表格(多选、标签、人员单元格)那一批工作的收尾,替上次评审留下的四个非阻塞项收口。
- 若出错,碰到的是明细行表格里人员和查找列的名字显示或清空后的存值;改动只在表格组件内,可直接撤回这一个合并。
- 无。
Opened for `repo:objectstack#2 · os-steve ·
session_01ADHkmNmMEXS4EzeVz9RjvD` (area s2-A).
## What changes
The editable line-item grid (`@object-ui/fields`, `GridFieldWidget`),
the four items of #36552:
1. **An emptied multi-record lookup cell writes `null`.** The lookup
cell's `onChange` now goes through `emptyListAsNull`, the helper the
multi-select, tags and people cells already use. Measured on
`origin/main` at `e7399fcdb` before the change: un-picking the last
record of a `lookup` column with `multiple: true` wrote
`[{"products":[]}]`.
2. **Names are read once per referenced object, not once per line.**
Measured on `origin/main` at `e7399fcdb`: twenty lines with a `user`
column and a `lookup` column (naming two products) made **20 `findOne`
on `sys_user` and 20 on `product`**, 0 `find`. Each cell is its own
`LookupField`, whose hydration reads its one bare id with `findOne`.
The grid now hands every people and lookup cell it draws (editable cell,
the people cell's resting face and panel, the read-only table, list
mode) a data source from the new `grid-field/lineReferenceReads.ts`: the
page's source, with the plain by-id read (`findOne(object, id)`, no
options) gathered per tick into one `find(object, { $filter: { id: {
$in: ids } } })` per object, ids de-duplicated, at most 50 ids per read
(`LookupField`'s own `$in` page size). Every other member, and a by-id
read carrying options, passes to the page's source unchanged (bound to
it). Same grid after the change: **1 `$in` read of `sys_user` (20 ids),
1 of `product` (2 ids), 0 `findOne`**, in editable, read-only and list
mode.
**Why not `$expand` on the child read (Prime Directive 5, SQL first):**
the grid does not make that read. Its rows arrive as a value: from
`MasterDetailForm`'s and `LineItemsPanel`'s reads of the child object
(both in `@object-ui/plugin-form`, outside this card's file surface), or
stored inline as the `grid` field's JSON, where no `$expand` reaches the
ids inside. An expanded reference in a row is also what the save diff
and the blank-line check would read and send back. One `$in` read per
object is one SQL `IN` query, at the one place every host's rows pass
through.
3. **The multi-person cell's `null` on Clear is pinned** (it was right
by reading).
4. **Display leftovers.** `cellDisplayText`'s `multiselect` arm loses
its unreachable empty-list return (the guard at the top already answers
an empty list with the em dash). In list mode the muted class reads
`isEmptyCell`, so a stored `[]` draws the em dash muted, as `null` and
`''` did.
Changeset: `.changeset/36552-line-item-grid-followups.md`, patch for
`@object-ui/fields`.
### Read first (by risk)
1. `ui/packages/fields/src/widgets/grid-field/lineReferenceReads.ts`:
the `Proxy` around the page data source, and `flush` (chunking,
de-duplication, rows keyed by `id` else `_id` as `LookupField`'s own
`$in` read keys them, `null` for an id the read did not return,
rejection fan-out).
2. `ui/packages/fields/src/widgets/grid-field/GridFieldWidget.tsx`: the
`cellSource` line and the `dataSource={cellSource}` props on the five
cell sites; the lookup `onChange` hunk.
3. `ui/packages/fields/src/widgets/GridField.test.tsx`: the pins, one
top-level describe at the end of the file (`line-item grid follow-ups:
... (objectstack#36552)`).
## Tests
Seven pins in one top-level describe at the end of `GridField.test.tsx`
(moved there from a separate file once #36607 landed, per ruling record
6583487846; names and assertions unchanged): multi-record lookup un-pick
writes `null`; multi-person Clear writes `null`; one `$in` read per
object and zero `findOne` with all 20 names drawn, in editable,
read-only and list mode; a backend answering with `_id` only still draws
each name from the one read; list-mode `[]` multi-select and tags cells
draw the muted em dash.
<details><summary>Package runs at head fbdfc7d (after merging
origin/main at ed0edb1, which brought #36607)</summary>
- `pnpm --filter @object-ui/fields type-check` (`tsc --noEmit && tsc -p
tsconfig.test.json`): clean.
- `GridField.test.tsx` + `GridField.lookupAutofill-28245.test.tsx`:
`Test Files 2 passed (2)`, `Tests 140 passed (140)`; the seven pins
alone (`-t 36552`): `Tests 7 passed`.
- Earlier, at 2431b1b, the whole package: `Test Files 323 passed | 1
skipped (324)`, `Tests 4897 passed | 7 skipped (4904)`.
</details>
<details><summary>Ablation (one leg per pinned behaviour, through
scripts/ablation-replace.mjs, restored and proven)</summary>
The subject is imported by relative path from source, so no `dist/` is
involved. Each leg: anchor x1 to x0, blob changed, run, restore with
blob == HEAD and `git diff HEAD` empty.
- lookup `onChange` without `emptyListAsNull`: the multi-record lookup
pin fails, 1 failed / 5 passed.
- people `onWrite` without `emptyListAsNull`: the multi-person pin
fails, 1 failed / 5 passed.
- `cellSource` forced to `undefined` (cells read the page source
directly): the three one-read pins fail, 3 failed / 3 passed.
- list-mode muted test back to `null`/`''`: the muted pin fails, 1
failed / 5 passed.
- (at fbdfc7d) rows keyed by `id` only: `× a backend that answers with
_id only`, 1 failed / 6 passed.
The first four legs ran while the pins were in their own file; the moved
pins are byte-identical in name and assertion.
</details>
## Acceptance notes
- **Test placement.** The pins first lived in their own file because
open PR #36607 edited `GridField.test.tsx`; #36607 has merged, so they
now sit in `GridField.test.tsx` as one top-level describe (ruling record
6583487846), and the separate file is deleted.
- **Reads that still go per cell.** A by-id read with options, a lookup
column whose `idField` is not `id` (`LookupField` reads those with
`find` on an equality filter, not `findOne`), and an id the batched read
did not return (deleted or unreadable; the cell's own read gets the same
answer). Out of the card's shape; noted, not changed.
- **README / docs.** No sentence in `ui/packages/fields/README.md` or
`content/docs/frontend/` describes the per-line read, the stored `[]` or
the muted class, so none was made false; none edited.
- **Seen while measuring, not changed:** a `lookup` column with
`multiple: true` reads `undefined` in read-only and list mode (the two
read-only `LookupField` sites pass no `multiple`), while the editable
cell reads `2 selected`. Reported to the seat.
## Verification
Two minutes: from `ui/`, run `pnpm --filter @object-ui/fields exec
vitest run --root ../.. -t 36552
packages/fields/src/widgets/GridField.test.tsx`. Expect `Tests 7
passed`, the rest of the file skipped.
Gates: `node scripts/pm/dispatch-gates.mjs --commands --repo
objectstack-ai/objectstack` derived 38 families at 2b1bd44 and the
same 38 at fbdfc7d; all 38 ran locally with exit 0 at each head
(`--ran` reconciliation: 38 derived, 38 run, 0 NOT-MEASURED, all with
exit codes). Everything else is CI's.
---
_Generated by [Claude
Code](https://claude.ai/code/session_01ADHkmNmMEXS4EzeVz9RjvD)_
<!-- signed: repo:objectstack#2 · os-steve ·
session_01ADHkmNmMEXS4EzeVz9RjvD -->
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 4ef1ea9 commit 3110de5
4 files changed
Lines changed: 351 additions & 8 deletions
File tree
- .changeset
- ui/packages/fields/src/widgets
- grid-field
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
| 2 | + | |
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
| |||
1640 | 1641 | | |
1641 | 1642 | | |
1642 | 1643 | | |
| 1644 | + | |
| 1645 | + | |
| 1646 | + | |
| 1647 | + | |
| 1648 | + | |
| 1649 | + | |
| 1650 | + | |
| 1651 | + | |
| 1652 | + | |
| 1653 | + | |
| 1654 | + | |
| 1655 | + | |
| 1656 | + | |
| 1657 | + | |
| 1658 | + | |
| 1659 | + | |
| 1660 | + | |
| 1661 | + | |
| 1662 | + | |
| 1663 | + | |
| 1664 | + | |
| 1665 | + | |
| 1666 | + | |
| 1667 | + | |
| 1668 | + | |
| 1669 | + | |
| 1670 | + | |
| 1671 | + | |
| 1672 | + | |
| 1673 | + | |
| 1674 | + | |
| 1675 | + | |
| 1676 | + | |
| 1677 | + | |
| 1678 | + | |
| 1679 | + | |
| 1680 | + | |
| 1681 | + | |
| 1682 | + | |
| 1683 | + | |
| 1684 | + | |
| 1685 | + | |
| 1686 | + | |
| 1687 | + | |
| 1688 | + | |
| 1689 | + | |
| 1690 | + | |
| 1691 | + | |
| 1692 | + | |
| 1693 | + | |
| 1694 | + | |
| 1695 | + | |
| 1696 | + | |
| 1697 | + | |
| 1698 | + | |
| 1699 | + | |
| 1700 | + | |
| 1701 | + | |
| 1702 | + | |
| 1703 | + | |
| 1704 | + | |
| 1705 | + | |
| 1706 | + | |
| 1707 | + | |
| 1708 | + | |
| 1709 | + | |
| 1710 | + | |
| 1711 | + | |
| 1712 | + | |
| 1713 | + | |
| 1714 | + | |
| 1715 | + | |
| 1716 | + | |
| 1717 | + | |
| 1718 | + | |
| 1719 | + | |
| 1720 | + | |
| 1721 | + | |
| 1722 | + | |
| 1723 | + | |
| 1724 | + | |
| 1725 | + | |
| 1726 | + | |
| 1727 | + | |
| 1728 | + | |
| 1729 | + | |
| 1730 | + | |
| 1731 | + | |
| 1732 | + | |
| 1733 | + | |
| 1734 | + | |
| 1735 | + | |
| 1736 | + | |
| 1737 | + | |
| 1738 | + | |
| 1739 | + | |
| 1740 | + | |
| 1741 | + | |
| 1742 | + | |
| 1743 | + | |
| 1744 | + | |
| 1745 | + | |
| 1746 | + | |
| 1747 | + | |
| 1748 | + | |
| 1749 | + | |
| 1750 | + | |
| 1751 | + | |
| 1752 | + | |
| 1753 | + | |
| 1754 | + | |
| 1755 | + | |
| 1756 | + | |
| 1757 | + | |
| 1758 | + | |
| 1759 | + | |
| 1760 | + | |
| 1761 | + | |
| 1762 | + | |
| 1763 | + | |
| 1764 | + | |
| 1765 | + | |
| 1766 | + | |
| 1767 | + | |
| 1768 | + | |
| 1769 | + | |
| 1770 | + | |
| 1771 | + | |
| 1772 | + | |
| 1773 | + | |
| 1774 | + | |
| 1775 | + | |
| 1776 | + | |
| 1777 | + | |
| 1778 | + | |
| 1779 | + | |
| 1780 | + | |
| 1781 | + | |
| 1782 | + | |
| 1783 | + | |
| 1784 | + | |
| 1785 | + | |
| 1786 | + | |
| 1787 | + | |
| 1788 | + | |
| 1789 | + | |
| 1790 | + | |
| 1791 | + | |
| 1792 | + | |
| 1793 | + | |
| 1794 | + | |
| 1795 | + | |
| 1796 | + | |
| 1797 | + | |
| 1798 | + | |
| 1799 | + | |
| 1800 | + | |
| 1801 | + | |
| 1802 | + | |
| 1803 | + | |
| 1804 | + | |
| 1805 | + | |
| 1806 | + | |
| 1807 | + | |
| 1808 | + | |
| 1809 | + | |
| 1810 | + | |
| 1811 | + | |
| 1812 | + | |
| 1813 | + | |
| 1814 | + | |
| 1815 | + | |
| 1816 | + | |
| 1817 | + | |
| 1818 | + | |
| 1819 | + | |
| 1820 | + | |
| 1821 | + | |
| 1822 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
| 45 | + | |
| 46 | + | |
45 | 47 | | |
46 | 48 | | |
47 | 49 | | |
| |||
138 | 140 | | |
139 | 141 | | |
140 | 142 | | |
141 | | - | |
| 143 | + | |
| 144 | + | |
142 | 145 | | |
143 | 146 | | |
144 | 147 | | |
| |||
351 | 354 | | |
352 | 355 | | |
353 | 356 | | |
354 | | - | |
355 | 357 | | |
356 | 358 | | |
357 | 359 | | |
| |||
757 | 759 | | |
758 | 760 | | |
759 | 761 | | |
| 762 | + | |
| 763 | + | |
| 764 | + | |
| 765 | + | |
| 766 | + | |
| 767 | + | |
| 768 | + | |
| 769 | + | |
760 | 770 | | |
761 | 771 | | |
762 | 772 | | |
| |||
765 | 775 | | |
766 | 776 | | |
767 | 777 | | |
768 | | - | |
| 778 | + | |
769 | 779 | | |
770 | 780 | | |
771 | 781 | | |
| |||
1246 | 1256 | | |
1247 | 1257 | | |
1248 | 1258 | | |
| 1259 | + | |
1249 | 1260 | | |
1250 | 1261 | | |
1251 | 1262 | | |
| |||
1353 | 1364 | | |
1354 | 1365 | | |
1355 | 1366 | | |
1356 | | - | |
| 1367 | + | |
| 1368 | + | |
1357 | 1369 | | |
1358 | 1370 | | |
1359 | 1371 | | |
1360 | 1372 | | |
1361 | 1373 | | |
1362 | | - | |
| 1374 | + | |
| 1375 | + | |
| 1376 | + | |
1363 | 1377 | | |
1364 | 1378 | | |
1365 | 1379 | | |
| |||
1380 | 1394 | | |
1381 | 1395 | | |
1382 | 1396 | | |
1383 | | - | |
| 1397 | + | |
| 1398 | + | |
| 1399 | + | |
| 1400 | + | |
1384 | 1401 | | |
1385 | 1402 | | |
1386 | 1403 | | |
| |||
1475 | 1492 | | |
1476 | 1493 | | |
1477 | 1494 | | |
1478 | | - | |
| 1495 | + | |
1479 | 1496 | | |
1480 | 1497 | | |
1481 | 1498 | | |
| |||
0 commit comments