Repository navigation
Commit 2c296cf
feat(fields): lookup picker resolves { $record } lookupFilters values and sends orEmpty (#34253)
<!-- claude-projects-attribution: {"github_login":"os-steve"} -->
_Requested by **Steve** · [project
thread](https://claude.ai/code/project/chan_01FdL1XeUyvVNxLreh3F4Qi9?thread=cmsg_01FdL1XeUyvVNxLreh3F4Qi9Jn5meabiiHHeo8KAjDSYr1)_
Fixes #34197
Clause-②: no
Metadata-protocol: none
## 维护者速读
- **改了什么**:在记录表单里,查找字段的选择器现在会读 `lookupFilters` 里的 `{ $record:
'quote_date' }` / `{ $record: 'account.cb_market'
}`,用正在编辑的那条记录的值替换后再查候选;`orEmpty: true` 发成「比较 或
该列为空」。只有记录表单会给字段打上「正在编辑一条记录」的标记(并写明跳一层的查找指向哪个对象),选择器只在有这个标记时才解析;批量操作、参数对话框等其它宿主一律丢弃这类条目。
- **为什么改**:CRM 报价单的价目表选择器要按报价日期和客户市场筛价目表(#34009 的客户需求,契约已在 PR #34078
落地但标着「计划中、未生效」),这次补上读取端。
- **风险与回滚**:只影响写了 `{ $record }` 或 `orEmpty` 的查找字段;普通字面过滤和 `dependsOn`
的查询逐字节不变(有对照测试)。回滚即还原本 PR。
-
**先看**:`ui/packages/fields/src/widgets/lookupRecordReference.ts`(解析与跳一层读取)、`LookupField.tsx`
中 `queryLookupFilters` 一段、`RecordPickerDialog.tsx` 的
`lookupFiltersToRecord`(orEmpty 与未解析引用的丢弃)。
- **两分钟验证**:`pnpm --dir ui exec vitest run
packages/fields/src/widgets/LookupField.recordReference-34197.test.tsx
packages/plugin-form/src/__tests__/lookupRecordHop-34197.test.tsx`,应见 14
条全部通过。
- **需要你做的**:无,席位落地(spec 描述改动需 review 席位的契约复审记录,由席位转交;r2 已按复审 FAIL 修正描述)。
## What changes
**The resolver** —
`ui/packages/fields/src/widgets/lookupRecordReference.ts` (new, the one
reader of the spec's `LookupFilterRecordReferenceSchema`):
- `resolveLookupFilters(filters, record, hopRows)` puts the value a `{
$record }` path names in place of the reference. A path is a field of
the record being edited, or one lookup hop (`account.cb_market`).
- An entry whose referenced value is empty (null, unset, `''`, an empty
list, an unset hop lookup) is left out, the rule an unset `dependsOn`
parent follows (seat ruling 6900252552 §1).
- An expanded related row is collapsed to its id before it is compared.
- `useRecordHopRows` reads each hop's target row once per id,
`$select`ing only the hop fields, unless the record already holds the
row expanded with that field. It reports `pending` until the read lands.
Answers are keyed by object, id and fields.
- **Opt-in by the host.** `withRecordBeingEdited(def, fields)` stamps,
on a lookup whose filters read `{ $record }`, the host's statement that
a single record is being edited here: `recordBeingEdited: { hopObjects:
{ account: 'account' } }`, naming the object each hop's lookup
references. A hop's object is the spec's `referenceTargetOf` (rework r4,
review#1 M1), the arbiter the object linter's `$record` rule also asks,
so a hop through a `user` field, whose target the type fixes with no
`reference` written, resolves like one through a `lookup`. It is the
same hand-off shape as `followedParentObject` / `formObject`: a widget
receives one field, not the object it is drawn for. Exported from
`@object-ui/fields`. ⛔ A field without the stamp resolves no `{ $record
}`: every such entry is left out, whatever values its host passes.
- A hop the widget cannot read (a bare id whose lookup the stamp names
no object for, or a data source with no `findOne`) is left out, with one
dev-mode `console.warn` per path naming the remedy.
**LookupField** — on a stamped field the edited record is the host's
`dependentValues`; on any other it is an empty record, so every `{
$record }` entry drops. `queryLookupFilters` is the resolved list, keyed
on its JSON so it moves only when a resolved value moves. It feeds the
quick-select popover, the recents rail, the table picker and
PeoplePicker. Filters that read no record pass through as the authored
array, so literal entries keep their exact previous identity and bytes.
While a hop read is pending, the popover query and recents fetch are
held, and the Level-2 pickers are held shut, so the first query goes out
once, with the value in it. The referenced fields are not added to
`dependsOn` and gate nothing.
**`lookupFiltersToRecord`** (RecordPickerDialog):
- `orEmpty: true` on eq/ne/gt/lt/gte/lte becomes `{ $or: [condition, {
column: { $null: true } }] }`, one member of a `$and` list, so several
such entries each keep their alternative.
- An entry still carrying a `{ $record }` is left out: an unresolved
reference never reaches the wire.
- The `lookupFilters` props of RecordPickerDialog and PeoplePicker are
typed by reference to the spec row
(`NonNullable<Field['lookupFilters']>[number]`), which declares
`orEmpty`.
**Record forms** — `ObjectForm` (auto layout) and `buildSectionFields`
(authored sections, used by Modal/Drawer/Tabbed forms) wrap the field
they hand the widget in `withRecordBeingEdited`, beside the existing
`withFollowedParentObject` / `withFormObject` stamps. These are the only
callers: every record form (Modal / Drawer / Tabbed / Wizard and the
auto layout) goes through one of the two builders.
**Action dialogs** — `bulkParamToField` (plugin-grid) never carries
`recordBeingEdited` from a bulk param onto its widget: it used to
forward every unenumerated param key (`...extra`), so a bulk param that
wrote the key itself opted its lookup into resolution against the
sibling params (rework r3). `paramToField` (app-shell), the
single-record dialog's twin, builds the widget field from enumerated
keys and never carried it.
**Field-channel census** —
`ui/examples/schema-catalog/test/form-field-channel-census-12130.test.tsx`
gains one ledger row, `recordBeingEdited`, read by
`fields/src/widgets/lookupRecordReference.ts`. It is RUNTIME-ONLY:
stamped by `ObjectForm` and `buildSectionFields`, and ledgered, not
declared on `FormFieldSchema`. The row names what holds the invariant:
the two builders and the closed spec shapes (the published
`customFields` member and action params refuse the key). objectui's
loose `FormFieldSchema`, which can author it on an inline form field, is
tracked by #34344 (review#1 S1). This fixes the Test UI (13/16) red on
`34d869b8`, where the old key `recordHopObjects` was read and neither
declared nor ledgered.
**Spec** — `packages/spec/src/data/field.zod.ts`, describes only:
- The `value`, `orEmpty` and `lookupFilters` describes lose `[PLANNED —
not enforced]` and say what the picker sends.
- Rework r2 (review#2 M1, remedy a): the `lookupFilters` and `value`
describes and the docblock name where `{ $record }` resolves — record
forms only (the auto layout, modal, drawer, tabbed and wizard forms) —
and say every other picker host leaves the entry out: inline edit on a
record page, a record page's header or related list, an action's
parameter dialog, and a bulk action over selected rows.
- Rework r3 (review#2 delta S1/N1): the forms are named by what they
are, "in a record form, whatever its layout" (which also covers authored
or field-group sections and the master-detail header form), and in the
`lookupFilters` describe the "every other picker host" half follows the
record-form half directly. The changeset's empty-value bullet adds "or
cannot be read" (N2).
- Rework r2 (S1): the empty-value sentence adds "or cannot be read" (the
hop's row or field does not come back, no object is named for the hop,
or the host has no single-row reader).
- N6: the no-record example now reads "a bulk action over selected
rows". "A filter panel" is removed: no list filter panel reads
`lookupFilters` (measured: `ui/packages/plugin-list/src` has no
`lookupFilters` read; its lookup chips use `LookupValuePicker`).
- The same correction is made in the `LookupFilterRecordReferenceSchema`
docblock.
- `content/docs/references/**` regenerated (`check:generated --fix` →
`gen:docs`). The `lookupFilters` row of `liveness/field.json` now cites
the readers in place of the dated "declared ahead" sentence, names the
record forms, says the server's refusal of an unresolved `$record` is
not measured and cites its carrier #34199, and is re-verified
(`verifiedAt` 2026-11-16).
Surfaces that read `lookupFilters`, and what each gets:
| Surface | `{ $record }` | one hop |
|:--|:--|:--|
| Record form, auto layout (`ObjectForm`) — stamped | resolved from the
form values | read by id |
| Record form, authored sections (`ModalForm` / `DrawerForm` /
`TabbedForm` / `WizardForm` and the other section builders, via
`buildSectionFields`) — stamped | resolved | read by id |
| Bulk action dialog (hands the widget its sibling parameter values) —
not stamped | every entry left out | — |
| Detail-page inline edit, header highlight, related-list inline edit,
single-record action dialog — not stamped | every entry left out (see
Acceptance notes) | — |
| A widget with no host record — not stamped | every entry left out | —
|
| `GridField` line-item lookup columns, list filter panel | do not read
`lookupFilters` | — |
## Tests
New pins. Ablation: each was mutated on disk through
`scripts/ablation-replace.mjs`, ran red, and was restored to the HEAD
blob (`git diff HEAD` empty).
| Pin | File | Ablation (what was broken → tests red) |
|:--|:--|:--|
| a `{ $record }` field value is sent in place |
`LookupField.recordReference-34197.test.tsx` | A1 resolver keeps the
reference → 7 red |
| a one-hop value is read off the target row and sent once | same | A2
hop row ignored → 1 red; A6 pending gate removed → 1 red |
| an expanded hop costs no request | same | (A1) |
| an empty referenced value, and no record, drop the entry | same | A3
empty test narrowed to `undefined` → 1 red |
| a referenced field change re-queries once; another field does not |
same | A4 memo keyed off the resolved values → 2 red |
| `orEmpty` sends the `$or` null match | same | A5 flag read inverted →
2 red |
| the table picker gets the resolved values | same | (A1, A5) |
| an unresolved reference never reaches the wire | same | A7 drop
deleted → 1 red |
| a host without the record-being-edited stamp leaves every `{ $record
}` entry out, even when its values hold one of that name (the bulk
action dialog's shape); no hop read | same | A10 LookupField ignores the
stamp → 1 red |
| CONTROL: the same field and values on a stamped host resolve; the
stamp names the hop object | same | A11 `withRecordBeingEdited` stamps
nothing → 9 red (every stamped pin, both form pins) |
| CONTROL: literal entry + `dependsOn` query exactly as before | same |
stays green under every ablation |
| `ObjectForm` stamps the field; the hop value reaches the query |
`plugin-form/.../lookupRecordHop-34197.test.tsx` | A8 stamp removed → 1
red (re-run as A8r on the reworked head) |
| authored sections stamp it too | same | A9 stamp removed → 1 red
(re-run as A9r on the reworked head) |
| a hop through a `user` field held as an id: the form names `sys_user`,
the picker reads the hop (`$select: ['id','region']`) and sends its
value | same | A16 hop object read off `reference` alone → 1 red |
| the same hop held as an expanded row: read off it, no request | same |
(resolves off the held row by design; no ablation of its own) |
| the real `BulkActionDialog`: a lookup param whose filters read `{
$record: 'quote_date' }` beside a sibling `quote_date` param holding a
value leaves the entry out; the literal entry beside it is sent |
`plugin-grid/src/__tests__/bulkActionDialogRecordReference-34197.test.tsx`
| A13 LookupField ignores the stamp → 1 red |
| the real `ActionParamDialog`, same shape |
`app-shell/src/views/ActionParamDialog.recordReference-34197.test.tsx` |
A13 → 1 red |
| a bulk param that writes `recordBeingEdited` itself still leaves the
entry out and sends no sibling value |
`bulkActionDialogRecordReference-34197.test.tsx` | A14
`bulkParamToField` drop removed → 1 red |
| a single-record action param that writes it, same |
`ActionParamDialog.recordReference-34197.test.tsx` | A15 `paramToField`
forwards the key → 1 red |
| the channel reads `recordBeingEdited` and it is ledgered |
`form-field-channel-census-12130.test.tsx` | A12 ledger row renamed → 2
red (`unexpected: recordBeingEdited ← …lookupRecordReference.ts`) |
The first attempt at A7–A9 was a no-op: `ablation-replace` refused it
because the replacement text already occurred in the file. They were
re-run with a delete and a distinct replacement, and those runs are the
ones reported. A1–A9 were measured on `34d869b8`; A10, A11, A8r, A9r and
A12 on the r1 head; A13 on the r2 head; A14 and A15 on the r3 head; A16
on the r4 head, each red and restored to the HEAD blob.
<details><summary>Suite and type-check readings</summary>
- `pnpm --dir ui exec vitest run packages/fields/ packages/plugin-form/`
plus the two dialog pin files and the census on the r2 head: Test Files
543 passed | 1 skipped (544), Tests 7248 passed | 8 skipped (7256).
Earlier rounds: 7211 (r1), 7209 (r0).
- `pnpm --dir ui exec vitest run
examples/schema-catalog/test/form-field-channel-census-12130.test.tsx`:
35 passed.
- `pnpm --filter @object-ui/fields --filter @object-ui/plugin-form run
type-check`: both pass (plugin-form after `pnpm --filter
@object-ui/fields build`).
- `pnpm --filter @objectstack/spec check:generated`: `check:docs` stale
→ `--fix` regenerated `gen:docs`, re-check green. `check:test-typecheck`
passes with `NODE_OPTIONS=--max-old-space-size=4096`; without it, tsc
ran out of heap on this shared box.
</details>
## Acceptance notes
- **Opt-in, seat rework r1.** `{ $record }` resolution is opt-in by the
host. `BulkActionDialog` hands a lookup param the dialog's own parameter
values (`cascadeProps`, objectui#8755) and stamps nothing, so it now
leaves every `{ $record }` entry out, as ruling 6900252552 §1 reads ("a
bulk-action bar … leaves every `{ $record }` entry out").
`ui/packages/plugin-grid/**` is not touched. The signal is the
field-definition stamp `recordBeingEdited` (`withRecordBeingEdited`).
The alternative considered was a `LookupField` prop,
`recordBeingEdited`, passed by the form renderer. It was not taken
because a record form hands the widget a field definition, not props,
and the existing hand-offs (`followedParentObject`, `formObject`) ride
the definition.
- **Single-record hosts that are not record forms.** Detail-page inline
edit, header highlight, related-list inline edit and the single-record
action dialog do not stamp, so they leave every `{ $record }` entry out
too. Since r2 the describes say so in as many words (review#2 M1, remedy
a; the seat ruled no further hosts opt in on this card).
- **An authored stamp on a bulk param (fixed in r3).** objectui's grid
schema for bulk params is a `looseObject` and `bulkParamToField` spread
unenumerated keys, so a bulk param that wrote `recordBeingEdited` opted
itself in (measured before the fix: the query carried the sibling's
value). The spec's `BulkActionParamSchema` is a `strictObject` and
refuses the key at authoring. `bulkParamToField` now drops the key;
`BulkActionDialog.tsx` is not touched.
- **Server refusal by name** of an unresolved `$record` (ruling §3,
review#2 S3) is not built or measured here. Its carrier is #34199, cited
from the liveness note.
- **Hand-written docs.** `content/docs/data-modeling/fields.mdx` and
`relationships.mdx` do not yet teach `{ $record }` / `orEmpty`. The
Skills-docs follow-up the card names carries that teaching.
## Verification
Head `866523ae` (rework r4, with main `35c9a305` merged in). Gates were
derived by `node scripts/pm/dispatch-gates.mjs --commands --repo
objectstack-ai/objectstack` on this head, run locally and reconciled
with `--ran`. Every CI family is read from this PR's check-runs.
- `dispatch-gates --ran`: **115 derived, 115 run, 0 NOT-MEASURED, 0
UNRUN**. Every gate exited 0 on the first pass.
- Prerequisites, all exit 0: `pnpm install --frozen-lockfile --offline`
after the merge; `turbo run build --filter='./packages/**'`; `turbo run
build` of the dependencies of `@object-ui/plugin-grid` and
`@object-ui/plugin-form`.
- Type-check of `@object-ui/fields`, `@object-ui/plugin-form` and
`@object-ui/plugin-grid`: pass.
- Suites: `vitest run packages/fields/ packages/plugin-form/
packages/plugin-grid/`, plus the `ActionParamDialog` pin file and the
field-channel census. Test Files 826 passed | 1 skipped (827), Tests
9721 passed | 8 skipped (9729).
- This round supersedes the earlier rounds (`34d869b8`, `0b8ad7e7`,
`0179f341`, `503e0152`), each of which read 115/115.
- The gate runner exports `NODE_OPTIONS=--max-old-space-size=4096`.
---
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_01ADHkmTKRu1t68jcJGgRYi3
<!-- signed: domain:ui#2 · os-steve · session_01ADHkmTKRu1t68jcJGgRYi3
-->
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 2b267b7 commit 2c296cf
19 files changed
Lines changed: 1246 additions & 72 deletions
File tree
- .changeset
- content/docs/references
- data
- system
- packages/spec
- liveness
- src/data
- ui
- examples/schema-catalog/test
- packages
- app-shell/src/views
- fields/src
- widgets
- plugin-form/src
- __tests__
- plugin-grid/src
- __tests__
- components
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
93 | 93 | | |
94 | 94 | | |
95 | 95 | | |
96 | | - | |
| 96 | + | |
97 | 97 | | |
98 | 98 | | |
99 | 99 | | |
| |||
242 | 242 | | |
243 | 243 | | |
244 | 244 | | |
245 | | - | |
246 | | - | |
| 245 | + | |
| 246 | + | |
247 | 247 | | |
248 | 248 | | |
249 | 249 | | |
| |||
0 commit comments