Skip to content

fix(ui): a related-list New runs the parent lookup's lookupAutofill; a picker's + New seeds its dependsOn parent - #35118

Merged
objectstack-fleet[bot] merged 7 commits into
mainfrom
claude/issue-35050-related-new-autofill
Nov 18, 2026
Merged

objectstack-fleet[bot] merged 7 commits into
mainfrom
claude/issue-35050-related-new-autofill

Conversation

@objectstack-fleet

Copy link
Copy Markdown
Contributor

Requested by Warren · project thread

Fixes #35050

Clause-②: no
Metadata-protocol: none

维护者速读

  • 改了什么:从相关列表点「新建」打开的新建表单,预填的查找字段现在会像手动选择一样执行它声明的 lookupAutofill(例如从商机新建报价,客户自动带出);查找选择器里的「+ 新建」会把它按 dependsOn 过滤的父值预填进新记录。
  • 为什么改:HotCRM 用户从商机的报价相关列表新建报价时,客户字段为空需要手填;在报价的商机选择器里新建商机也是空白,新建出来的商机甚至不在这个选择器的过滤结果里。
  • 风险与回滚:只在新建表单、且查找字段带 lookupAutofill 时生效,只填空目标,不覆盖打开时已有的值;编辑表单不受影响。回滚即还原本 PR。
  • 先看:ui/packages/fields/src/widgets/LookupField.tsx(开场填充的 effect 与「+ 新建」的预填);ui/packages/components/src/renderers/form/form.tsx(onAutofill 的 opening 分支改写脏基线);ui/packages/app-shell/src/hooks/useActionModal.tsx(描述符的 initialValues 传给新建表单)。
  • 两分钟验证:cd ui && pnpm exec vitest run --maxWorkers=2 packages/plugin-form/src/ObjectForm.lookupAutofill-28245.test.tsx packages/fields/src/widgets/LookupField.dependsOn.test.tsx,预期全部通过。
  • 需要你做的:无,席位落地。

What changes

Half 1: an opening lookup value runs the same lookupAutofill as a pick. A related list's New opens the child's create form with the relationship pre-linked (formLink becomes initialValues). The value never passed through the pick handler, so the declared targets stayed empty. Now:

  • The form renderer gives a registered lookup on a create form the value it opened with (openingValue; undefined on an edit form).
  • LookupField fills its declared targets from that record once, while the field still holds it. The record is the one hydration already reads for the chip label, so there is no second request. It uses the same declaredLookupAutofillPatch as a pick, with no earlier pick and without overwrite, so only empty targets fill. A value the form opened with is explicit and is never replaced.
  • The opening record is kept as the widget's earlier pick, so a later pick replaces what the opening fill wrote, by the existing pick rule.
  • The form's onAutofill writer takes { opening: true } for this fill. It adds the filled values to the dirty baseline and writes them without shouldDirty. Opening New and closing at once therefore shows no "Discard changes?" prompt.
  • toHostProps forwards openingValue with the other host plumbing keys. Its compile-time partition guard requires that.

Half 2: the picker's "+ New" seeds its dependsOn parent. handleCreateNew sends initialValues equal to the picker's own dependentFilter: the dependsOn values under the remote field name (param) the candidate query filters on. It sends them through the modal descriptor and also in the one-field inline-create fallback. The record the user creates is then one the scoped picker lists. A picker with no dependsOn seeds nothing.

Location outside the claimed file surface: ui/packages/app-shell/src/hooks/useActionModal.tsx. The lookup's create goes through execute({ type: 'modal', modal: { objectName, mode } }), and useActionModal turns that descriptor into the create form. It had no slot for opening values, so the seed would have been dropped there. ModalDescriptor gains initialValues, a descriptor-only key whose only producer is this lookup path, like objectName. It is read on a create only. @object-ui/app-shell is private. No spec key and no related-list prop is added.

Tests

Premise, measured on origin/main (526282e) before any code change. The new pins went red there: the prefill pins read unit_price as '' instead of '100', the modal descriptor had no initialValues, and the inline create sent { name: 'Pia Quill' } with no parent. Both halves reproduced.

New pins:

  • plugin-form/src/ObjectForm.lookupAutofill-28245.test.tsx, new top-level describe:
    • fills the empty targets and saves them;
    • keeps every opening value, overwrite: true included, and fills the rest;
    • a later pick follows the pick rule;
    • the opening fill is not an edit: an untouched ModalForm closes with no discard prompt, and a touched one still asks;
    • controls: an edit form fills nothing; a lookup without the key fills nothing.
  • fields/src/widgets/LookupField.dependsOn.test.tsx, new describe:
    • the modal create carries initialValues under the param name;
    • the inline create carries the parent;
    • control: no dependsOn means no initialValues key.
  • app-shell/src/hooks/__tests__/useActionModal.objectCreateTitle-30126.test.tsx, new describe:
    • a create descriptor's initialValues open the form holding them;
    • control: without them the form opens empty.

Ablations: one per changed behaviour, each through scripts/ablation-replace.mjs with the anchor proven on disk and the blob restored to HEAD. Every mutation turned its pin red:

Ablation Red
A1: opening fill removed 5 of 11 in the 28245 file
A2: modal seed removed the seed pin
A3: inline-create seed removed the inline pin
A4: opening baseline write removed the discard-prompt pin
A5: descriptor initialValues not passed the app-shell seed pin
A6: opening record not kept as earlier pick the later-pick pin

A2, A4, A5 and A6 first ran as --replacement '' or with a replacement already present. The tool refused them as no-ops (replacement count did not rise), so no tests ran. They were re-run with --delete, or with a distinct replacement for A6. Those re-runs are the readings above.

In the A5 run, the file's first test, the title pin, also failed at about 1025 ms. That is a findByRole timeout on a cold first test on a shared box; it passes on the unmutated tree.

Acceptance notes

  • Bound: the opening fill runs once per opening value. If a host later resets the form's defaultValues to new content while the lookup keeps the same opening value, the reset clears the filled targets and they are not filled again. No path in this repo was found that resets a create form's defaults after the lookup's hydration lands.
  • An opening value that is a JSON-encoded reference string is used as its own record. Its source keys count only if it carries them, the same rule as a pick.
  • The line-item grid (onSelectRecord hosts) keeps applying its pairs itself. It gets no opening fill, as before.

Verification

See the report comment on #35050 for the local subset run on the final head: commands, exit codes and the --ran reconciliation.

🤖 Generated with Claude Code

https://claude.ai/code/session_01JQwxbYRqkDAGuse5Wqbohi

@github-actions github-actions Bot added size/m documentation Improvements or additions to documentation tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface labels Nov 18, 2026
@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#1 · os-warren · session_01JQwxbYRqkDAGuse5Wqbohi

Final head for L1 · 2026-11-18T05:29Z

Head-sha: 03c9a2fc84 · all check-runs success or skipped (45 success, 13 skipped, 0 red) · NOT governed, +325 / −9.
Owed: L1 (first read; area o1-B requests it from L1-a). No L2: ui only, Clause-②: no, Metadata-protocol: none; the one new key (ModalDescriptor.initialValues) is a descriptor-only key in the private @object-ui/app-shell. Inputs: claim 6968373693, dev report 6969681794 (two files outside the claimed surface, reasoned there). Landing waits for the release freeze to lift.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#1 · os-warren · session_01JQwxbXKtHccbeakAgquNs9

L1 review (#35050) · 2026-11-18T05:33Z

L1: ACCEPT
Head-sha: 03c9a2f

This is the first L1 on this PR. I read the full diff against the merge-base 0e46840fca: 9 files, +325/−9, all under ui/** plus one root changeset. I also read the claim 6968373693 and the os-dev report 6969681794 on #35050, and declaredLookupAutofillPatch in lookupAutofill.ts at this head.

Half 1, the opening fill (LookupField.tsx, form.tsx).

  • The new effect fills once per opening value (openingFilledRef). It runs only while the field still holds that value, and it takes the row from the expanded value or hydratedRecords, which is the record hydration already reads for the chip label. No second request is made.
  • It calls declaredLookupAutofillPatch with previous = null and with overwrite stripped from each pair. On that function's rule (overwrite === true || isEmptyValue(held) || filledByEarlierPick), only empty targets fill. A value the form opened with is never replaced, overwrite: true included. This matches the claim and the pin "keeps every opening value".
  • The opening row is merged into pickedRecords, so a later pick treats the opening fill as an earlier pick. Pin A6 holds it.
  • form.tsx: openingValue is defaultValues?.[name] on a create form only, and undefined on an edit form. stripRegisteredFieldProps forwards it only to LOOKUP_AUTOFILL_WIDGET_TYPES. onAutofill(patch, { opening: true }) merges the patch into baselineRef.current and writes with shouldDirty: false, so an untouched form closes with no discard prompt. A pick still dirties the form as before.

Half 2, "+ New" seeds the dependsOn parent.

  • The modal descriptor gets initialValues: { ...dependentFilter } only when a dependentFilter exists. The inline create sends { ...dependentFilter, [displayField]: label }. Both use the same param-keyed object the candidate query filters on, so the new record is one the picker lists.
  • useActionModal.tsx passes initialValues only when formMode === 'create'.

Shape and scope.

  • Fixes #35050 is on the first card line, with no closing keyword next to another open card. Clause-②: no and Metadata-protocol: none match the diff: no packages/spec key, no related-list prop, and widgets/types.ts only adds the optional openingValue prop and the options argument to onAutofill.
  • Two paths are outside the listed surface. ui/packages/app-shell/src/hooks/useActionModal.tsx is the descriptor-to-form producer, and the seed would have been dropped there. ui/packages/fields/src/widgets/toHostProps.ts is needed because its compile-time partition guard must list the new prop. Both fall under the claim's own clause "if the reading shows the real producer is elsewhere, fix it at the producer and say where and why in the report and PR body", and the report names both with reasons. I accept them (see N1).
  • No content/docs/releases/ change, no unrelated file. check-governed-merges --pr 35118: not governed (0 of 9 paths), 334 changed lines, below the 3,000-line threshold. With Clause-②: no, no narrowing and no governed text, no L2 contract record is owed.

Changeset. .changeset/35050-related-new-autofill.md is new and edits no changeset on main, so it does not affect the 18.6.0 freeze or Version PR #33849. It bumps @object-ui/fields, components, app-shell and console as patch. app-shell is private; privatePackages.version: true and earlier changesets list it the same way. I checked its sentences against the diff:

  • "A create form can open with a lookup already set: a related list's New links the parent, a URL prefill sets it, or a form view default does." All three reach the form as defaultValues, which is what openingValue reads.
  • "Only empty targets fill. A value the form opened with is explicit, so overwrite: true does not replace it." This matches the stripped overwrite and the pin.
  • "no second request", "closes without the discard prompt", "A later pick replaces what the opening fill wrote" and "An edit form fills nothing" each match the code and a pin.
  • "under the field name the filter uses (param)", "The one-field inline create … sends the same values" and "A picker with no dependsOn seeds nothing" match dependentFilter and the three dependsOn pins.
  • "Hosts" matches openingValue, { opening: true } and the descriptor's initialValues.

Tests and evidence.

  • ObjectForm.lookupAutofill-28245.test.tsx: fill, keep opening values, later pick, discard prompt (untouched and touched), and two controls (edit form, lookup without the key).
  • LookupField.dependsOn.test.tsx: modal seed under param, inline seed, and a no-dependsOn control.
  • useActionModal.objectCreateTitle-30126.test.tsx: descriptor initialValues open the form holding them, plus a control.
  • The premise was measured red on origin/main (526282e) for both halves before any code change.
  • Ablations A1 to A6, one per changed behaviour, each turned its pin red and was restored to blob == HEAD. The PR body records the four no-op refusals by ablation-replace.mjs and their re-runs, which is the honest reading.

CI at this head, read from check-runs (58): 45 success, 13 skipped, none failed, none in progress. The UI lanes (Lint UI, Type Check UI, the Test UI shards and aggregate, Build & E2E UI), Lint & Repo Gates, Check Changeset, the PR-body guards, Governed Surface Queue Guard and Check PR Size are all green. The Core lanes are skipped by path filter.

Must-fix

None.

Should-fix

None.

Notes

  • N1. The PR body's "Location outside the claimed file surface" paragraph names only useActionModal.tsx. toHostProps.ts is explained under "What changes" and named in the report, so nothing is missing, but a one-line mention in that paragraph would make the body complete on its own.
  • N2. dependentFilter keeps a number as a number and turns anything else into String(v). The seed therefore carries what the filter sends, which is right for record ids. A dependsOn on a boolean or multi-value field would seed a string. No such picker is in scope here.
  • N3. The Acceptance notes record two limits, and I take both as accepted: the once-per-opening-value bound (a later reset of defaultValues with the same opening value is not refilled; no path in the repo does that), and the line-item grid getting no opening fill, as before.
  • N4. In the A5 run, the file's first test (the title pin) timed out once at about 1,025 ms on findByRole. It passes on the unmutated tree and in CI. If it fails again cold, a longer findByRole timeout on that pin would be a separate card.
  • Landing. The 18.6.0 freeze holds this PR. Nothing else is owed before landing.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#1 · os-warren · session_01JQwxbYRqkDAGuse5Wqbohi

Landing · 2026-11-18T06:05Z

Probe Reading
check-governed-merges.mjs --pr 35118 NOT governed · +325 / −9, ui-only, Clause-②: no
Head / review 03c9a2fc84 · L1-a ACCEPT 6970078663 at this head (first L1; no must-fix, no should-fix), the review of record; no L2 owed · all check-runs success or skipped (45 success, 13 skipped, 0 red)
Freshness K = 1, merges cleanly into origin/main; overlap-check.mjs clean

Open findings: notes only (N1–N4 in the verdict). Release freeze lifted (seat comment 6970550718).

State: ready + auto-merge armed by area o1-B (lease o1-B, claim 6968373693); Fixes #35050 closes the card on merge.

Dev-effort: high · Rounds: 1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation size/m tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface

Projects

None yet

2 participants