Skip to content

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
objectstack-fleet[bot] merged 1 commit into
mainfrom
claude/project-thread-vudywh
Nov 23, 2026
Merged

objectstack-fleet[bot] merged 1 commit into
mainfrom
claude/project-thread-vudywh

Conversation

@objectstack-fleet

Copy link
Copy Markdown
Contributor

Requested by Warren · project thread

Fixes #36707

Clause-②: no
Metadata-protocol: none

维护者速读

  • 在商机的「合同」页签点「添加」,选择框只列出这个商机所属客户自己的、尚未关联商机的合同,不再混进别的客户的合同;第一列显示合同编号(列名「合同编号」),不再是一列空白的英文「NAME」。
  • 属于记录详情页重做专题,补的是上一张修合同页签「添加」时顺路发现的问题:一键就能把别的客户的合同挂到这个商机上。
  • 出错的话只是某些页签的「添加」选择框里少列或多列了几条候选、或改成直接新建,不改任何已有数据,可直接撤回。
  • 无。

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 plain lookup, 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):

  1. The relationship lookup's dependsOn was ignored. crm_contract.crm_opportunity declares dependsOn: ['crm_account']: on a contract's form the opportunity picker lists only opportunities of the contract's account. The derived picker sent only crm_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): a dependsOn entry { field, param } (a bare string names both) sends the child's field as the parent object's param (LookupField's dependentFilter), so a child can name this parent only when its field equals the parent's param. Each entry becomes the rule field equals PARENT.param, added beside is_empty. The parent record is the record page's RecordContext (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 dependsOn field (no child could name it), the parent record is not in context, or the lookup's lookupFilters compare with { $record } (any operator, which this side does not invert). An unscoped lookup (static lookupFilters included) keeps today's unlinked-only picker. The master_detail catalog arm and an authored add are untouched.
  2. The picker's label column was a hard-coded name. With no add.picker.labelField (a derived add never has one), pickerDisplayField fell back to name; a contract's name field is contract_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: declared nameField, else the derived title field), under that field's served label; name only until the picker's schema is read. An authored labelField still wins. This also names the record in the batch-refusal message, which reads the same field.

Changeset: @object-ui/plugin-detail patch. No new export, key or route.

Tests

New ui/packages/plugin-detail/src/__tests__/RelatedList.derivedAddScope-36707.test.tsx:

  • derivedAddOf: a dependsOn lookup gets account equals A-1 from 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's lookupFilters read $record; control: an unscoped lookup with a static lookupFilters keeps [is_empty] alone, parent read or not;
  • rendered opportunity 合同 tab (parent 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 carries A-1 beside is_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 declared nameField, the derived title field leads and no 「Name」 column appears.

RelatedList.enlargedToolbar-27524.test.tsx: its candidate fixture rows (the task object, whose derived title field is subject) now carry subject beside name, 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 with git diff HEAD empty):

  • 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
pnpm --filter @object-ui/plugin-detail type-check && pnpm --filter @object-ui/plugin-detail test   (at d7bceceb's tree)
> tsc --noEmit && tsc -p tsconfig.test.json
 Test Files  416 passed | 1 skipped (417)
      Tests  3907 passed | 18 skipped (3925)
os-verify-lock: VERDICT command-exit 0

node scripts/pm/dispatch-gates.mjs --commands   → 38 commands, all exit 0 at d7bceceb
(incl. pnpm --dir ui exec vitest run scripts/, check:nul-bytes, check:published-files, check:test-source-alias,
 check:type-check-debt, check:empty-changeset, check:adr-0087-registration)

Acceptance notes

  • dependsOn scopes 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.
  • A relationship lookup whose lookupFilters read { $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.
  • A static lookupFilters on 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.
  • The empty 「NAME」 column was not contract-specific: it appeared on every picker whose add names no labelField and whose object's name field is not literally name; all of them now lead with the object's name field.

Verification

Read first:

  1. ui/packages/plugin-detail/src/RelatedList.tsx, parentScopeOf and the lookup arm of derivedAddOf (riskiest hunk: an unresolved scope returns no picker, which changes 「+ 添加」 to New on those tabs).
  2. pickerDisplayField (one line) and the derivedAdd memo, 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, at d7bceceb:

  • Opportunity "Initech Cloud Migration" (account Initech Solutions) → 合同 tab → 「+ 添加」: the dialog lists one row, CTR-0003 / Initech Solutions; CTR-0004 (Stark Medical, also unlinked) is not offered. Headers ["合同编号","所属客户","状态","开始日期"].
  • The picker's request: 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).
  • Before (origin/main, the card's repro): the same click listed CTR-0004 beside CTR-0003 under an empty 「NAME」 column, with only the is_empty rule.

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

…'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
@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 23, 2026
@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#1 · os-warren · session_01JQwxbZeHNsF3RWcWpj7rGj

维护者速读

在商机的「合同」页签里点「添加」时,以前会列出所有客户还没挂商机的合同,选错就会把别的客户的合同挂到这个商机上。现在只列同一个客户的合同;如果商机还没填客户,就不提供「添加」,只能新建。选择框第一列也从空白的「NAME」改成合同编号这样的真实名称字段。HotCRM 上实测过。
要你做的:无。

席位核对 — ACCEPT (L1) · repo:objectstack#1 · head d7bceceb · 2026-11-23T14:49Z

  • Shape: Fixes #36707. The changes are in ui/packages/plugin-detail/src/RelatedList.tsx (+79/−13), a new test RelatedList.derivedAddScope-36707.test.tsx, a fixture line in RelatedList.enlargedToolbar-27524.test.tsx, and a changeset (plugin-detail patch). Clause-②: no. Metadata-protocol: none. No new export.
  • Read:
    • The derived lookup picker now adds the relationship lookup's own dependsOn scope, reversed onto the parent. Each entry { field, param } becomes field equals <parent[param]>, and an expanded reference reads as its id.
    • When the scope cannot be resolved, there is no picker; New stays. That covers a parent value that is empty or not read, and a lookupFilters comparand that reads $record. The picker is never unscoped.
    • readsRecord is factored out of scopedByRow without a behaviour change.
    • The picker's label column falls back to resolveNameField(pickerSchema) before name.
    • The fixture change adds subject to the candidates. The fixture's object names subject as its name field, so it follows the new label column. This does not weaken the test.
    • parentRecord joins the memo deps. It is the record context's data, which is stable per record load.
  • Evidence (thread): package 3907/3907 and type-check green under lock; 38/38 derived gates exit 0. Ablating each behaviour turns its case red. Live on HotCRM main: opportunity Initech Cloud Migration › 合同 › 添加 lists only CTR-0003, with headers 合同编号/所属客户/状态/开始日期 (screens in issue-36707/).
  • Gates: on d7bceceb: 42 success, 13 skipped (expected roster), 0 failed. The PR is 8 commits behind main (< 15).
  • Landing: ready + auto-merge now. On merge, 记录页相关页签「添加」关联已有记录时不按客户过滤,且首列「NAME」为空(商机 → 合同) #36707 closes and the seat clears its label.
    No must-fix, no should-fix.

@objectstack-fleet
objectstack-fleet Bot marked this pull request as ready for review November 23, 2026 14:49
@objectstack-fleet
objectstack-fleet Bot added this pull request to the merge queue Nov 23, 2026
Merged via the queue into main with commit fa23941 Nov 23, 2026
56 checks passed
@objectstack-fleet
objectstack-fleet Bot deleted the claude/project-thread-vudywh branch November 23, 2026 15:11
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>
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

Development

Successfully merging this pull request may close these issues.

记录页相关页签「添加」关联已有记录时不按客户过滤,且首列「NAME」为空(商机 → 合同)

2 participants