Repository navigation
Commit 03cb550
<!-- claude-projects-attribution: {"github_login":"os-warren"} -->
_Requested by **Warren** · [project
thread](https://claude.ai/code/project/chan_01U5RdnAAmkSQmZbqh6FtqZ8?thread=cmsg_01U5RdnAAmkSQmZbqh6FtqZ82pszhcdkA6eY6pSTqYSy4t)_
Fixes #36659
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 `master_detail`
child it took the child's one other required single-valued lookup as the
child's **source catalog**: the picker listed that lookup's object and a
pick created a child row naming it. That is right for a line's product
and wrong for a row's own party: `crm_contract` is `master_detail` to
`crm_account` and requires `crm_contact` (its primary contact,
`dependsOn: ['crm_account']`). So an account's 合同 tab opened a picker of
`crm_contact` with no filter (the reported `GET
/api/v1/data/crm_contact?populate=crm_account&top=10&skip=0`), listing
other accounts' contacts, and a pick would have tried to create a
contract from a contact.
The function's own docblock already stated the condition for a catalog:
"the field every row must name, so a pick is a whole row". This PR
checks both halves of that sentence before returning a catalog picker:
- **The candidates do not depend on the row.** A required lookup with a
`dependsOn` entry, or a `lookupFilters` comparand `{ $record }`, is
scoped by the row; the picker lists the catalog for the whole list and
cannot apply that scope. Such a lookup is a party of the row, not a
catalog (`scopedByRow`).
- **The pick leaves nothing for a person to write.** Every other
required field of the child must be filled by the insert: a non-null
`defaultValue` or a select option marked `default` (the engine's
`applyFieldDefaults`,
`packages/objectql/src/engine-select-option-default.test.ts`),
`readonly`, or a computed type (`isComputedFieldType`: formula, summary,
rollup, autonumber). `required` is the writer's contract, so a contract
that still needs its value and dates is filled in on its form, not
completed by a pick (`insertDefaults`).
When either fails, `derivedAddOf` returns `undefined`, which is the
existing "master_detail with no catalog" path: 「+ 添加」 opens New with the
parent filled in. The `lookup` path (pick unlinked children of the
list's own object) and an authored `add` are untouched.
Measured against HotCRM 6.6.0 metadata (read, not run): `crm_contract`
loses the picker on both counts (contact `dependsOn` the account;
`contract_term_months`, `start_date`, `end_date`, `contract_value`
required with no default). `crm_opportunity_line_item`,
`crm_quote_line_item` keep the product picker (product required, no
`dependsOn`, `quantity` required with `defaultValue: 1`, `unit_price`
deliberately not `required`).
Changeset: `@object-ui/plugin-detail` patch.
## Tests
`ui/packages/plugin-detail/src/__tests__/RelatedList.enlargedToolbar-27524.test.tsx`,
in the existing describe "「+ 添加」 is decided by the relationship":
- a contract-shaped child (master_detail parent, required contact
`dependsOn` the parent, required value and start date, autonumber
number): 「+ 添加」 calls New, opens no picker, and no read of `contact` is
made;
- `derivedAddOf` returns `undefined` for a required lookup scoped by
`dependsOn`, and for one whose `lookupFilters` reads `$record`;
- `derivedAddOf` returns `undefined` when another required field has no
default;
- control: a line whose other required fields default (`defaultValue`,
select option `default`), are `readonly` or computed, and whose product
carries a static `lookupFilters`, keeps `{ picker: { object: 'product'
}, linkField: 'product' }`. The existing catalog test ("master_detail
with a catalog: the picker lists the catalog…") passes unchanged.
Reverse verification: with the fix committed, `RelatedList.tsx` restored
from `origin/main` and the file run, then restored from `HEAD` (`git
diff HEAD` empty): the 4 new defect tests fail, the control and the 17
existing tests pass.
<details><summary>Package run under the verify lock</summary>
```
pnpm --dir ui exec vitest run --maxWorkers=2 packages/plugin-detail/
Test Files 415 passed | 1 skipped (416)
Tests 3898 passed | 18 skipped (3916)
os-verify-lock: VERDICT command-exit 0
pnpm --filter @object-ui/plugin-detail type-check (at 26c5daf)
> tsc --noEmit && tsc -p tsconfig.test.json
os-verify-lock: VERDICT command-exit 0
```
The package run started before the select-option-default arm was added;
the touched test file was re-run at `26c5daf1`: `Tests 21 passed (21)`.
</details>
## Acceptance notes
- Not changed here, noted: the derived catalog picker does not carry the
catalog lookup's own static `lookupFilters` (for example HotCRM's
`crm_product` lookup `is_active = true` on opportunity lines), so it can
offer a retired product. Read from code, not reproduced in a browser.
- Not changed here, noted: the reported empty, English 「NAME」 column
follows from the wrong object (contacts have no `name`); with the
contract tab no longer opening a picker it does not appear there.
- Found while verifying, not changed here (same tab, the `lookup` arm
this PR does not touch): on an opportunity's 合同 tab, 「+ 添加」 lists
unlinked contracts of **every** account (HotCRM 6.6.0, opportunity
"Initech Cloud Migration": the picker offers CTR-0004 of Stark Medical
next to CTR-0003 of Initech Solutions; request `GET
/api/v1/data/crm_contract?populate=crm_account&top=10&skip=0&filter=[["crm_opportunity","is_empty"]]`),
although `crm_contract.crm_opportunity` declares `dependsOn:
['crm_account']`. The same picker's first column is headed 「NAME」 and is
empty, because the derived picker's label field falls back to `name` and
a contract's name field is `contract_number`. Reported to the seat for
filing.
- The HotCRM-side card objectstack-ai/hotcrm#2747 (declare that
master-detail children offer no "link existing") is not needed for the
contract tab after this change; whether it is still wanted is that
card's call.
## Verification
Read first:
1. `ui/packages/plugin-detail/src/RelatedList.tsx`, `derivedAddOf`: the
two new early returns (riskiest hunk: `leftToWrite`, which decides which
existing line tabs keep their picker).
2. `scopedByRow` and `insertDefaults` just below it.
Browser, HotCRM 6.6.0 (`d513851`, `objectstack dev --seed-admin
--fresh`) behind this branch's Console (Vite, `DEV_PROXY_TARGET`),
zh-CN, at `961e6e57`:
- Account "Acme Corporation" → 合同 tab → 「+ 添加」: the 新建合同 form opens with
所属客户 = Acme Corporation filled in and 主要联系人 empty; no picker dialog
(`[data-testid="record-picker-dialog"]` count 0); the requests after the
click are the record page's own reads, no `GET
/api/v1/data/crm_contact`.
- The served schema carries what the rule reads: `GET
/api/v1/meta/objects/crm_contract` → `crm_contact` `required: true`,
`dependsOn: ["crm_account"]`; `contract_value`, `start_date` `required:
true` with no default.
- Before (`origin/main`, the card's own repro on 18.6.0): the same click
opened 「添加」 listing contacts of two accounts.
Screenshots are attached in the project thread (GitHub's image store
takes browser uploads only): the account's 合同 tab; the New contract form
after 「+ 添加」.
Two-minute check: on a HotCRM account, open the 合同 tab and click 「+ 添加」:
the New contract form opens with the account filled in, no picker. On an
opportunity's product lines tab, 「+ 添加」 still opens the product picker.
---
_Generated by [Claude
Code](https://claude.ai/code/session_01JQwxbY1aynwSYJFZFRNKBL)_
<!-- signed: repo:objectstack#1 · os-warren ·
session_01JQwxbZeHNsF3RWcWpj7rGj -->
---------
Co-authored-by: Claude <noreply@anthropic.com>
1 parent 0fc430a commit 03cb550
3 files changed
Lines changed: 129 additions & 2 deletions
File tree
- .changeset
- ui/packages/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 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
92 | 92 | | |
93 | 93 | | |
94 | 94 | | |
95 | | - | |
| 95 | + | |
96 | 96 | | |
97 | 97 | | |
98 | 98 | | |
| |||
1066 | 1066 | | |
1067 | 1067 | | |
1068 | 1068 | | |
| 1069 | + | |
| 1070 | + | |
| 1071 | + | |
| 1072 | + | |
1069 | 1073 | | |
1070 | 1074 | | |
1071 | 1075 | | |
| |||
1093 | 1097 | | |
1094 | 1098 | | |
1095 | 1099 | | |
| 1100 | + | |
| 1101 | + | |
| 1102 | + | |
| 1103 | + | |
| 1104 | + | |
| 1105 | + | |
| 1106 | + | |
| 1107 | + | |
| 1108 | + | |
| 1109 | + | |
| 1110 | + | |
| 1111 | + | |
| 1112 | + | |
| 1113 | + | |
| 1114 | + | |
| 1115 | + | |
1096 | 1116 | | |
1097 | 1117 | | |
1098 | 1118 | | |
| |||
1117 | 1137 | | |
1118 | 1138 | | |
1119 | 1139 | | |
| 1140 | + | |
| 1141 | + | |
| 1142 | + | |
| 1143 | + | |
| 1144 | + | |
| 1145 | + | |
| 1146 | + | |
| 1147 | + | |
| 1148 | + | |
1120 | 1149 | | |
1121 | 1150 | | |
1122 | 1151 | | |
| 1152 | + | |
| 1153 | + | |
| 1154 | + | |
| 1155 | + | |
| 1156 | + | |
| 1157 | + | |
| 1158 | + | |
| 1159 | + | |
| 1160 | + | |
| 1161 | + | |
| 1162 | + | |
| 1163 | + | |
| 1164 | + | |
| 1165 | + | |
| 1166 | + | |
| 1167 | + | |
| 1168 | + | |
| 1169 | + | |
| 1170 | + | |
| 1171 | + | |
| 1172 | + | |
| 1173 | + | |
| 1174 | + | |
| 1175 | + | |
1123 | 1176 | | |
1124 | 1177 | | |
1125 | 1178 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
31 | | - | |
| 31 | + | |
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
| |||
319 | 319 | | |
320 | 320 | | |
321 | 321 | | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
322 | 379 | | |
323 | 380 | | |
324 | 381 | | |
| |||
0 commit comments