Repository navigation
fix(plugin-detail): a related tab's 「+ 添加」 picker keeps to the parent's own records and names them by their name field (#36707) - #36729
Merged
Conversation
…'s own records and names them by their name field (#36707) Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JQwxbYmr1N6x5nuafz67fw
Contributor
Author
|
repo:objectstack#1 · os-warren · session_01JQwxbZeHNsF3RWcWpj7rGj 维护者速读在商机的「合同」页签里点「添加」时,以前会列出所有客户还没挂商机的合同,选错就会把别的客户的合同挂到这个商机上。现在只列同一个客户的合同;如果商机还没填客户,就不提供「添加」,只能新建。选择框第一列也从空白的「NAME」改成合同编号这样的真实名称字段。HotCRM 上实测过。 席位核对 — ACCEPT (L1) · repo:objectstack#1 · head
|
This was referenced Nov 23, 2026
Nenzyz
pushed a commit
to Nenzyz/objectstack
that referenced
this pull request
Dec 1, 2026
…he child's relationship lookup declares dependsOn (objectstack-ai#37283) Fixes objectstack-ai#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 (objectstack-ai#35050) and the derived Add picker already scopes by them (objectstack-ai#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** (objectstack-ai#35050) and the Add picker (objectstack-ai#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 objectstack-ai#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 objectstack-ai#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 objectstack-ai#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 objectstack-ai#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 objectstack-ai#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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Requested by Warren · project thread
Fixes #36707
Clause-②: no
Metadata-protocol: none
维护者速读
What changes
The related tab's 「+ 添加」 (objectstack#35601) derives its picker from the relationship when the page authors no
add(derivedAddOf,ui/packages/plugin-detail/src/RelatedList.tsx). For a child linked by a plainlookup, the picker lists the child object's unlinked rows and a pick re-parents them. Two defects, both measured on HotCRM (opportunity "Initech Cloud Migration" → 合同 tab):dependsOnwas ignored.crm_contract.crm_opportunitydeclaresdependsOn: ['crm_account']: on a contract's form the opportunity picker lists only opportunities of the contract's account. The derived picker sent onlycrm_opportunity is_empty, so it listed unlinked contracts of every account, and a pick linked another customer's contract to this opportunity.Now the lookup arm reverses that scope from the parent record (
parentScopeOf): adependsOnentry{ field, param }(a bare string names both) sends the child'sfieldas the parent object'sparam(LookupField'sdependentFilter), so a child can name this parent only when itsfieldequals the parent'sparam. Each entry becomes the rulefield equals PARENT.param, added besideis_empty. The parent record is the record page'sRecordContext(already read by this component for the parent currency); an expanded reference reads as its id.When the scope cannot be resolved, the tab offers no picker and 「+ 添加」 takes the existing no-picker path (New with the parent filled): the parent has no value for a
dependsOnfield (no child could name it), the parent record is not in context, or the lookup'slookupFilterscompare with{ $record }(any operator, which this side does not invert). An unscoped lookup (staticlookupFiltersincluded) keeps today's unlinked-only picker. Themaster_detailcatalog arm and an authoredaddare untouched.name. With noadd.picker.labelField(a derived add never has one),pickerDisplayFieldfell back toname; a contract's name field iscontract_number, so the first column was headed 「NAME」 (the dialog's title-cased fallback for a field the schema does not declare) and was empty. The label column is now the picked object's name field,resolveNameField(pickerSchema)(ADR-0079: declarednameField, else the derived title field), under that field's served label;nameonly until the picker's schema is read. An authoredlabelFieldstill wins. This also names the record in the batch-refusal message, which reads the same field.Changeset:
@object-ui/plugin-detailpatch. No new export, key or route.Tests
New
ui/packages/plugin-detail/src/__tests__/RelatedList.derivedAddScope-36707.test.tsx:derivedAddOf: adependsOnlookup getsaccount equals A-1from the parent, for a string entry and a{ field, param }entry; an expanded parent reference reads as its id; no picker when the parent's value is empty or the parent record is absent; no picker when the relationship'slookupFiltersread$record; control: an unscoped lookup with a staticlookupFilterskeeps[is_empty]alone, parent read or not;account: A-1, a pool with one contract of A-1 and one of A-2): the picker shows only the own contract, every picker read carriesA-1besideis_empty, and the first header is the name field's label 「Contract Number」 with no 「Name」 column; with no parent account, 「+ 添加」 calls New and no picker read is made; with no declarednameField, the derived title field leads and no 「Name」 column appears.RelatedList.enlargedToolbar-27524.test.tsx: its candidate fixture rows (thetaskobject, whose derived title field issubject) now carrysubjectbesidename, so the refusal-message tests keep naming the picked row by the field the picker now shows.Ablation, one leg per behaviour, each with the fix committed (
node scripts/ablation-replace.mjs, mutation landed and restored withgit diff HEADempty):const scope = parentScopeOf(rel, parentRecord)→[]: 7 of 9 new tests fail (every scope test and both rendered scope tests); restored: 9/9.labelField || resolveNameField(pickerSchema) || 'name'→labelField || 'name': the 2 label-column tests fail (["Name","Contract Number","Account","Opportunity"]); restored: 9/9.Package run and gates under the verify lock
Acceptance notes
dependsOnscopes the picker only (as on the form): the server does not refuse a contract whose opportunity belongs to another account. A save-side rule, if wanted, is a separate card.lookupFiltersread{ $record }now offers no picker on its related tab (it used to offer an unscoped one). Inverting those comparisons (eq only, one hop) is possible but is not needed by any measured tab; noted, not done.lookupFilterson the relationship (which parents a child may name, e.g. only open opportunities) is not checked against the parent here; read from code, not reproduced.addnames nolabelFieldand whose object's name field is not literallyname; all of them now lead with the object's name field.Verification
Read first:
ui/packages/plugin-detail/src/RelatedList.tsx,parentScopeOfand the lookup arm ofderivedAddOf(riskiest hunk: an unresolved scope returns no picker, which changes 「+ 添加」 to New on those tabs).pickerDisplayField(one line) and thederivedAddmemo, which now depends on the parent record.Browser, HotCRM
origin/main(e2ee348,objectstack dev --seed-admin --fresh) behind this branch's Console (Vite,DEV_PROXY_TARGET), zh-CN, atd7bceceb:["合同编号","所属客户","状态","开始日期"].GET /api/v1/data/crm_contract?populate=crm_account&top=10&skip=0&filter=[["crm_opportunity","is_empty"],["crm_account","equals","SlX6mEUIGqvFAEbb"]](the opportunity's own account id).origin/main, the card's repro): the same click listed CTR-0004 beside CTR-0003 under an empty 「NAME」 column, with only theis_emptyrule.Screenshots are attached in the project thread (GitHub's image store takes browser uploads only): the opportunity's 合同 tab; the 「添加」 dialog with only the account's own contract.
Two-minute check: on a HotCRM opportunity, open the 合同 tab and click 「+ 添加」: only that account's unlinked contracts appear, led by 合同编号.
Generated by Claude Code