Repository navigation
Commit 3c535ee
fix(fields): the grid reads a boolean column as a boolean in its requiredWhen / readonlyWhen rules (#35074)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_01WGufzi3ezPzTysQPDEjmVz
Fixes #34972
repo:objectstack#3 · os-support-ai · session_01WGufzi3ezPzTysQPDEjmVz
Clause-②: no
Metadata-protocol: none
## 维护者速读
- 改了什么:主从表单的行内表格在计算每个单元格的 `requiredWhen` / `readonlyWhen`
时,把布尔列(下拉框里存的字符串 `'true'` / `'false'`)按真正的布尔值来读;单元格显示的内容和保存出去的数据都不变。
- 为什么改:布尔字段在表格里被画成选项值为字符串的下拉框,`record.won == true`
拿字符串去比布尔,必填标记和只读锁显示的状态与服务端相反;服务端(#34965 之后)按布尔判定,于是用户看到表格没提示、保存却被拒。
- 风险与回滚:只改规则求值时看到的那份行数据,读法与服务端写入归一化 `BOOLEAN_READINGS`
一致(`'true'`/`'1'`/`1` 与 `'false'`/`'0'`/`0`)。识别布尔列靠"select 且恰好两个选项
`'true'`/`'false'`"这一形状:若某个真正的 select 字段恰好就用这两个字符串当选项,它在规则里会被读成布尔(见
Acceptance notes)。回滚即撤销本 PR。
-
先看:`ui/packages/fields/src/widgets/GridField.tsx`(`ruleRecordOf`、`isBooleanSelectColumn`
与 `cellRules`
的改动)、`ui/packages/fields/src/widgets/GridField.test.tsx`(末尾新增的
describe)。
- 两分钟验证:`pnpm --dir ui exec vitest run
packages/fields/src/widgets/GridField.test.tsx`(需先构建 fields 的依赖闭包),预期 51
个测试全部通过,其中新增 4 个。
- 需要你做的:无,席位落地。
## What changes
- **`@object-ui/fields` — `GridField` cell rules.** `cellRules` used to
hand the raw row to `resolveFieldRuleState`. A boolean / toggle child
field is derived by `@object-ui/plugin-form` (`fieldTypeToColumnType`,
`optionsFor` in `deriveMasterDetail.ts`) into a `select` column whose
options store the strings `'true'` / `'false'`, and the select cell
writes that string into the row. So `record.won == true` compared a
string, and the required marker / readonly lock showed the opposite of
what the server enforces.
- New `isBooleanSelectColumn`: a `select` column whose exactly two
options are `'true'` and `'false'` (the derived shape; a grid column
carries no field definition, so the option pair is what names the type
here).
- New `ruleRecordOf`: the row the predicate reads as `record`, with each
boolean column's cell read through `BOOLEAN_READINGS`, the same readings
and comparison (SameValueZero, via `Map`) as the engine's write
normalisation from #34965. Every other value is left as is. It copies
only when a cell is actually read, and never mutates the row.
- Boolean columns are taken from **all** columns (shown or
`defaultHidden`), since a predicate may read any cell.
- `readonlyWhen` shares the same path (`cellRules`), so it is covered.
The grid has no `visibleWhen` reader; nothing to change there.
- What the cell displays and what the row saves are unchanged. The save
path does send the string, but since #34965 the engine stores it as a
boolean, so the stored value is already the boolean; this PR does not
touch the save path.
- **Changeset:** `@object-ui/fields` patch, with both declaration lines.
## Tests
New top-level describe in the shared harness `GridField.test.tsx`, "a
boolean column read as a boolean by the cell rules":
- `requiredWhen: record.won == true`: the row holding `'true'` gets the
required marker, the row holding `'false'` gets none.
- A stored boolean `true` reads the same as `'true'`, and the row value
the select wrote stays `'true'` (no `onChange`).
- `readonlyWhen: record.won == true`: `'true'` locks the cell, `'false'`
does not.
- CONTROL: a non-boolean select column (`open` / `closed`) keeps its
string value in the predicate.
<details><summary>Run on 3fd16f3: GridField.test.tsx 51/51, fields
type-check exit 0</summary>
```
pnpm --dir ui exec vitest run --maxWorkers=2 packages/fields/src/widgets/GridField.test.tsx
Test Files 1 passed (1)
Tests 51 passed (51)
os-verify-lock: VERDICT command-exit 0
pnpm --filter @object-ui/fields type-check
os-verify-lock: VERDICT command-exit 0
```
</details>
<details><summary>Ablation: the coercion removed
(scripts/ablation-replace.mjs), 3 pins red, control green, restored blob
== HEAD</summary>
```
ablation-replace: anchor " ruleRecordOf(booleanColumns, row)," x1 (before)
ablation-replace: replace " (row || {}) as Record<string, unknown>," x0 -> x1
ablation-replace: ok mutation landed: anchor 1 -> 0, blob 9d5bd99 -> 49d2eeda9771
× marks the dependent cell required when the select holds 'true', and not when it holds 'false'
× reads a stored boolean the same way, and leaves the row the select wrote unchanged
× locks a readonlyWhen cell over the same reading: 'true' locks, 'false' does not
Test Files 1 failed (1)
Tests 3 failed | 48 passed (51)
ablation-replace: blob after restore 9d5bd99
ablation-replace: blob at HEAD 9d5bd99
git diff HEAD: empty
```
The CONTROL pin stayed green under the ablation, as it should: it does
not depend on the coercion. The test imports `./GridField` from source,
so no build sits between the mutation and the run.
</details>
## Acceptance notes
- **Detection by option shape.** The column carries no field type (the
spec's `InlineGridColumn` has no such key, and adding one is a contract
change), so a boolean column is recognised by its derived option pair. A
genuine `select` child field whose options are exactly `'true'` and
`'false'` would also be read as a boolean in the rules, while the server
keeps it a string. The exact alternative is a host-supplied prop naming
the boolean columns from the child schema (the pattern `lookupAutofill`
/ `columnCurrencies` already follow), which touches
`MasterDetailForm.tsx` and `LineItemsPanel.tsx`, outside this claim's
file surface.
- **Live reading: NOT MEASURED.** Reason: no example app has a child
object whose `requiredWhen` reads a boolean field (the showcase's
`requiredWhen` rules on `invoice` read `status`), so a live reading
needs authoring a new child object in an example plus a Console build
and a browser run. The jsdom pins above render the real `GridField` over
the derived column shape instead.
## Verification
- Derived gate families: `node scripts/pm/dispatch-gates.mjs --commands
--repo objectstack-ai/objectstack` on 3fd16f3 named 38 commands; all
38 ran with exit 0 (plus `pnpm check:changeset-fixed`, exit 0). `--ran`
reconciliation: "38 derived famil(ies) accounted for — 38 run, 0
NOT-MEASURED (a DERIVED zero — all 38 recorded an exit code and none of
them is 3)".
- `node scripts/pm/overlap-check.mjs`: VERDICT clean exit 0 against
origin/main eb7b09d, 0 PR heads.
- CI families (Lint & Repo Gates, Type Check UI, Test UI, …) are left to
this PR's check-runs.
---
_Generated by [Claude
Code](https://claude.ai/code/session_01WGufzi3ezPzTysQPDEjmVz)_
<!-- signed: repo:objectstack#3 · os-support-ai ·
session_01WGufzi3ezPzTysQPDEjmVz -->
Co-authored-by: Claude <noreply@anthropic.com>1 parent 526282e commit 3c535ee
3 files changed
Lines changed: 146 additions & 3 deletions
File tree
- .changeset
- ui/packages/fields/src/widgets
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
703 | 703 | | |
704 | 704 | | |
705 | 705 | | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
| 722 | + | |
| 723 | + | |
| 724 | + | |
| 725 | + | |
| 726 | + | |
| 727 | + | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
| 743 | + | |
| 744 | + | |
| 745 | + | |
| 746 | + | |
| 747 | + | |
| 748 | + | |
| 749 | + | |
| 750 | + | |
| 751 | + | |
| 752 | + | |
| 753 | + | |
| 754 | + | |
| 755 | + | |
| 756 | + | |
| 757 | + | |
| 758 | + | |
| 759 | + | |
| 760 | + | |
| 761 | + | |
| 762 | + | |
| 763 | + | |
| 764 | + | |
| 765 | + | |
| 766 | + | |
| 767 | + | |
| 768 | + | |
| 769 | + | |
| 770 | + | |
| 771 | + | |
| 772 | + | |
| 773 | + | |
| 774 | + | |
| 775 | + | |
| 776 | + | |
| 777 | + | |
| 778 | + | |
| 779 | + | |
| 780 | + | |
| 781 | + | |
| 782 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
583 | 583 | | |
584 | 584 | | |
585 | 585 | | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
586 | 634 | | |
587 | 635 | | |
588 | 636 | | |
| |||
788 | 836 | | |
789 | 837 | | |
790 | 838 | | |
791 | | - | |
| 839 | + | |
| 840 | + | |
| 841 | + | |
| 842 | + | |
| 843 | + | |
| 844 | + | |
| 845 | + | |
792 | 846 | | |
793 | 847 | | |
794 | 848 | | |
795 | 849 | | |
796 | 850 | | |
797 | 851 | | |
798 | 852 | | |
799 | | - | |
| 853 | + | |
800 | 854 | | |
801 | 855 | | |
802 | 856 | | |
803 | 857 | | |
804 | 858 | | |
805 | 859 | | |
806 | | - | |
| 860 | + | |
807 | 861 | | |
808 | 862 | | |
809 | 863 | | |
| |||
0 commit comments