Repository navigation
Commit 9e6533b
fix(console): a related tab's New keeps the parent it prefills when the child's relationship lookup declares dependsOn (#37283)
Fixes #37246
Clause-②: yes (widening) — one new export, `relatedCreateSeedOf`, on the
published `@object-ui/plugin-detail/core` subpath; nothing is removed or
renamed, and the package root exports the same names as before
Metadata-protocol: none
## 维护者速读
- 用户能看到什么变化:在记录页的相关页签点「添加 →
新建」建子记录时,预填的父记录(如订单、商机)不再被藏在「请先选择客户」后面或被清空,客户字段一并带入,保存后子记录正确挂在父记录下。
-
为什么做:子对象的关系字段声明「依赖于客户」后,页签里新建会把预填的父记录藏在「请先选择客户」后面;若该字段还配了自动带出客户,打开表单时父记录会被清空,并且不报错地存成未关联的记录。这也挡住了
HotCRM 让「添加」只列同一客户记录的改动(HotCRM 那张 p1 卡)。
- 出错会怎样:只影响新建表单打开时带入的初始值;没有声明依赖的关系、父记录没有客户值时,行为与今天完全一样;可直接撤回本次改动。
- 要你做什么:无。
## What changes
A record page's related tab, **New** (the header's, or the one inside
the **Add** picker), opened the child's create form with the parent link
alone. When the child's relationship lookup declares `dependsOn` (a
billing milestone's order `dependsOn` the milestone's account), the form
drew the lookup gated ("Select Account first", the parent hidden); with
a `lookupAutofill` that fills the account from the order, the opening
fill wrote the account and the form's dependent-lookup clear then
emptied the order, and Create saved the child with `crm_sales_order:
null`, no error shown.
Root cause: the New path seeded only the parent link (`formLink` = one
`FIELD:ID` pair). The lookup's own **+ New** already seeds its
`dependsOn` values (#35050) and the derived Add picker already scopes by
them (#36729); the tab's New did neither.
Fix (smallest change, one copy of the relation logic):
- `ui/packages/plugin-detail/src/relatedParentScope.ts` (new, pure,
exported on `/core` only, the subpath its one consumer imports):
`dependsOnFromParent` is the `dependsOn` inversion `parentScopeOf` used
to carry inline, moved here unchanged; `relatedCreateSeedOf(childFields,
referenceField, parentRecord)` reads the same pairs as values.
`RelatedList.tsx`'s `parentScopeOf` now calls `dependsOnFromParent`, so
the picker scope and the New seed cannot drift.
- `ui/packages/app-shell/src/views/RelatedRecordActionsBridge.tsx`:
`onCreate` adds the seed to the link; `openChildForm` writes the parent
pair first, then one `formLink` pair per seeded value (refresh-safe,
like the link). A custom page's lists (`parentFromList`) name their own
parents, which this bridge does not hold, so they keep the link alone.
- `ui/packages/app-shell/src/console/AppContent.tsx`: the overlay reads
every `formLink` pair (first pair of a field wins, a malformed pair is
skipped) into the create's opening values. `urlParams.ts` documents the
repeat.
- `ui/apps/console/vite.config.ts`: the new module joins the
`plugin-detail-core` chunk group, as that file requires for every module
in the `/core` closure.
Unblocks objectstack-ai/hotcrm#2753.
Responsibility:
- Whose code: the platform's own console related-record New path
(`@object-ui/app-shell`, `@object-ui/plugin-detail`).
- Existing platform path: the lookup's own **+ New** (#35050) and the
Add picker (#36729) already handle `dependsOn`; the tab's New did not.
- Who reaches it: every app whose child relationship lookup declares
`dependsOn` (HotCRM: order to billing milestone, opportunity to
contract).
Files to read first (by risk):
1. `ui/packages/app-shell/src/console/AppContent.tsx`: the
`formLinkValues` hunk (the URL contract every child create reads).
2. `ui/packages/app-shell/src/views/RelatedRecordActionsBridge.tsx`: the
`onCreate` seed and `openChildForm` hunks.
3. `ui/packages/plugin-detail/src/relatedParentScope.ts`.
Two-minute check: on a record whose related tab lists a child with a
`dependsOn` relationship lookup, click Add, then New: the parent shows
in its lookup (not "Select ... first"), the `dependsOn` field is filled,
the URL carries two `formLink` pairs, and Create saves the parent id.
## Tests
Pins, each a top-level `describe` for #37246 in the existing harness of
the code it covers:
- `RelatedRecordActionsBridge.createPredicates.test.tsx` (the bridge's
"+ New" harness): New writes `formLink` = parent pair then
`crm_account:acc-1`, with and without `lookupAutofill`; a `{ field,
param }` entry and an expanded reference. Controls: no `dependsOn`, a
parent with no account, a custom page's list: the link alone.
- `AppContent.internalFormRetired-36425.test.tsx` (the record-form
overlay harness, real `ModalForm`): billing milestone (with
`lookupAutofill`) and contract (without): the relationship lookup is
drawn ungated, the opening values hold both, Create posts the parent id
and the account. Repeated-pair parse. Control: a lone parent link seeds
the parent alone.
- `RelatedList.derivedAddScope-36707.test.tsx` (the derived Add
harness): `relatedCreateSeedOf` values and its empty cases. Control: the
derived picker keeps its #36707 scope.
<details><summary>Red on main, green after, ablation</summary>
- Red, the three pins against main's code (the fix files reverted, pins
at `5e0a09e127`): Test Files 3 failed, Tests 5 failed / 26 passed; e.g.
`expected [ 'crm_sales_order:so-1' ] to deeply equal [
'crm_sales_order:so-1', …(1) ]`. The reworked overlay pins against
main's `AppContent.tsx`: 3 failed / 7 passed.
- Green at `951db02b5d`: Test Files 3 passed, Tests 49 passed.
- Ablation (`scripts/ablation-replace.mjs`, the bridge's
`relatedCreateSeedOf(...)` call replaced by `undefined`; the test
imports the bridge from source, so no `dist` leg): anchor 1 to 0, 3
failed / 19 passed (the three seed pins; the controls stayed green);
restored, blob after restore == HEAD `672ca81d0086`, `git diff HEAD`
empty.
- Reproduction on main (readings, not committed): with main's URL, the
overlay drew `lookup-trigger-gated` "Select Account first" for both
children. At the form level, `dependsOn: ['account']` plus a
`lookupAutofill` filling `account`, opened with the parent alone:
account filled, the relationship lookup back to "Select…", submit posted
the relationship as `null`. Opened with the seeded account: the
relationship kept its record and the autofill still filled its other
targets.
</details>
## Acceptance notes
- The overlay harness serves its lookups no record read, so it pins the
gate and the saved payload, not the label text; the label and the
autofill interplay were read at the form level (above).
- The form's dependent-lookup clear treats the opening `lookupAutofill`
fill as an edit of the field it writes, which is what emptied the order
in case 1. The seed sets that field before the form opens, so one level
down nothing moves. It does not hold one level further: if the seeded
`dependsOn` field is itself a lookup with a `dependsOn` and a
`lookupAutofill` of its own (account `dependsOn` region, filled from the
account), the opening fill writes region, the clear empties account, and
the emptied account empties the order. The child then saves unlinked,
which main does too. That transitive value cannot be read off the parent
record, so the fix belongs in the form's clear, not in this seed:
tracked as #37289. A create opened another way, with a relationship
value and an empty `dependsOn` field (a URL prefill), meets the same
clear.
- `ObjectDataPage`'s New from a record trail (the "View all" list)
writes `formLink` with the parent pair alone, so a `dependsOn`
relationship lookup there meets the same gate. Not changed here: tracked
as #37290.
## Verification
<details><summary>Local suites and type-check at 47db09e (origin/main
1b91538 merged in)</summary>
- `pnpm --dir ui exec vitest run --maxWorkers=2
packages/plugin-detail/`: Test Files 418 passed, 1 skipped; Tests 3954
passed, 18 skipped; exit 0.
- `pnpm --dir ui exec vitest run --maxWorkers=2 packages/app-shell/`:
Test Files 2438 passed, 1 skipped; Tests 23194 passed, 9 skipped; exit
0.
- `pnpm --filter @object-ui/plugin-detail type-check`: exit 0. `pnpm
--filter @object-ui/app-shell type-check`: exit 0, after rebuilding
`@object-ui/plugin-detail` (its `/core` types are read from `dist`).
- `pnpm check:new-line-citations` (ui): 0 new citations, exit 0.
</details>
<details><summary>Derived gate families (`dispatch-gates.mjs
--commands`, the same list at cbee57c and 47db09e)</summary>
- Exit 0 at cbee57c (the fix commit, before the main merge): every
listed family except the two below. The re-run on 47db09e is cited in
the report comment on #37246.
- NOT MEASURED: `pnpm check:dual-build-cjs-loads`, reason: PREREQUISITE
NOT MET (exit 3), no `dist/` for packages this diff does not touch
(needs a full `pnpm build`). CI carries it.
- NOT MEASURED at cbee57c: `pnpm check:type-check-debt`, reason: its
re-measure queued behind the shared verify lock past its budget (exit
3). The final-head re-run is in the report comment.
- `pnpm --dir ui exec vitest run scripts/`: in the report comment
(queued on the shared lock while this PR opened).
- Repo-wide `pnpm lint` and the full farm: CI.
</details>
<details><summary>Rework round at 8afea3b (L1 REWORK: M1, S1, S2, N2;
main not merged)</summary>
- M1: the package-root re-export of `relatedCreateSeedOf` is dropped
(`src/index.tsx`); the `/core` export stays. `core.ts`'s header no
longer says every `/core` name is also on the root. The changeset
declares `Clause-②: yes (widening)`; the level stays `patch`, and
`Metadata-protocol: none` stays.
- N2: a new pin in `RelatedList.derivedAddScope-36707.test.tsx` covers a
two-entry `dependsOn`. When the parent answers both entries, both fields
are seeded. When it answers only one, neither is seeded, and the derived
picker offers none either.
- Pins plus `pluginCoreSubpaths-33581.test.ts`: Test Files 4 passed,
Tests 53 passed.
- `pnpm --filter @object-ui/plugin-detail type-check`: exit 0. `pnpm
--filter @object-ui/app-shell type-check`: exit 0, after rebuilding
plugin-detail's `dist`.
- Derived families: the same 46 as before. 44 exit 0,
`check:type-check-debt` included. `--ran` reports 45 run and 1 NOT
MEASURED. NOT MEASURED: `check:dual-build-cjs-loads` (needs a full
build, exit 3) and `pnpm --dir ui exec vitest run scripts/` (lock
timeout, exit 99). CI carries both.
- CI at 8afea3b: the 12 required check-runs are `success` (47
success, 11 skipped).
</details>
---
_Generated by [Claude
Code](https://claude.ai/code/session_01QSeKYmRepQK9DkZeU7F53D)_
<!-- signed: repo:objectstack#4 · os-justin ·
session_01QSeKYmRepQK9DkZeU7F53D -->
---------
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: objectstack-fleet[bot] <332303061+objectstack-fleet[bot]@users.noreply.github.com>1 parent 1a62867 commit 9e6533b
11 files changed
Lines changed: 402 additions & 48 deletions
File tree
- .changeset
- ui
- apps/console
- packages
- app-shell/src
- console
- __tests__
- views
- __tests__
- plugin-detail/src
- __tests__
| 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 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1577 | 1577 | | |
1578 | 1578 | | |
1579 | 1579 | | |
1580 | | - | |
| 1580 | + | |
1581 | 1581 | | |
1582 | 1582 | | |
1583 | 1583 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
861 | 861 | | |
862 | 862 | | |
863 | 863 | | |
864 | | - | |
| 864 | + | |
| 865 | + | |
| 866 | + | |
| 867 | + | |
| 868 | + | |
865 | 869 | | |
866 | 870 | | |
867 | 871 | | |
868 | 872 | | |
869 | 873 | | |
870 | | - | |
871 | | - | |
872 | | - | |
873 | | - | |
874 | | - | |
| 874 | + | |
| 875 | + | |
| 876 | + | |
| 877 | + | |
| 878 | + | |
| 879 | + | |
| 880 | + | |
| 881 | + | |
| 882 | + | |
875 | 883 | | |
876 | 884 | | |
877 | 885 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
25 | | - | |
| 25 | + | |
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
| |||
112 | 112 | | |
113 | 113 | | |
114 | 114 | | |
115 | | - | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
116 | 144 | | |
117 | 145 | | |
118 | 146 | | |
| |||
239 | 267 | | |
240 | 268 | | |
241 | 269 | | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
49 | 53 | | |
50 | 54 | | |
51 | 55 | | |
| |||
111 | 115 | | |
112 | 116 | | |
113 | 117 | | |
114 | | - | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
115 | 122 | | |
116 | 123 | | |
117 | 124 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
95 | 95 | | |
96 | 96 | | |
97 | 97 | | |
| 98 | + | |
98 | 99 | | |
99 | 100 | | |
100 | 101 | | |
| |||
460 | 461 | | |
461 | 462 | | |
462 | 463 | | |
463 | | - | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
464 | 469 | | |
465 | 470 | | |
466 | 471 | | |
| |||
475 | 480 | | |
476 | 481 | | |
477 | 482 | | |
478 | | - | |
479 | | - | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
480 | 493 | | |
481 | 494 | | |
482 | 495 | | |
| |||
666 | 679 | | |
667 | 680 | | |
668 | 681 | | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
669 | 692 | | |
670 | 693 | | |
671 | 694 | | |
672 | | - | |
| 695 | + | |
673 | 696 | | |
674 | 697 | | |
675 | 698 | | |
| |||
0 commit comments