Repository navigation
Commit a5ddeb6
fix(plugin-detail): the record page hides a field whose own visibleWhen is false (#35421)
Fixes #35314
Clause-②: no
Metadata-protocol: none
## 维护者速读
-
改了什么:记录详情页(默认页与自建页的详情块)不再显示「显示条件」对当前记录为假的字段,与编辑表单一致;条件写错时照旧显示该字段并在控制台告警一次,也与表单一致。
-
为什么改:默认记录页把只在特定状态才有意义的字段(如审批不需要时的「申请资格审批」)也画出来,读者看到空的或误导的字段,同一条记录的页面与表单说法不一。
- 风险与回滚:若判错,会把本应显示的字段藏起来(数据仍在、接口仍返回,只是不画);整体回滚一个提交即可,无数据迁移。
- 先看:`ui/packages/plugin-detail/src/renderers/record-details.tsx` 中新增的
`fieldPredicateVisible` 与 `dropPredicateHidden` 两处;其次同目录
`__tests__/record-details.fieldVisibleWhen-35314.test.tsx` 的对照矩阵。
- 两分钟验证:`pnpm --dir ui exec vitest run
packages/plugin-detail/src/renderers/__tests__/record-details.fieldVisibleWhen-35314.test.tsx`,预期
19 项全绿,其中每一行都同时断言表单与详情页的结论。
- 需要你做的:无,席位落地。
## What changes
`record:details` now honours a field's own object-level `visibleWhen`
(`Field.visibleWhen`: "field is shown only when TRUE (else hidden)") on
every field it draws. Before, it evaluated a field GROUP's `visibleWhen`
(the `{ group }` reference) and no field's, so the synthesized default
record page drew a field whose predicate is false for the record, label
and value.
- **Where it was missing.** The section fold in `record:details`
(`fields: dropHidden(normaliseList(filterList(s.fields)))`) and the
flat-body fold (`filteredFields`) applied field security, the label
ladder and the header dedupe, and never read the object's field
`visibleWhen`; `DetailSection` draws whatever it is handed. The group
derivation (`deriveFieldGroupDetailEntries` / `toField`) does not carry
the field predicate either, so neither layer saw it.
- **The fix.** One new fold, `dropPredicateHidden`, applied last to both
lists. It reads the predicate off the object's field declaration by name
and judges it with `fieldPredicateVisible`, which calls
`resolveFieldRuleState` from `@object-ui/core`: the call the form
renderer makes for a field's `visibleWhen`. So the fault direction is
the field rule's (`VISIBLE_WHEN_FAULTED`, ADR-0137 D3): a predicate that
cannot be evaluated SHOWS the field and warns once. That is the opposite
of the group gate (fail-closed), on purpose; each slot keeps the
direction the form gives it.
- **Record context.** The same inputs the existing group gate passes:
`sectionPredicateRecord` (every declared field seeded `null`, relations
collapsed to their stored id) bound as `record` and `previous`, plus
`usePredicateScope()`. The lazily assembled record is now shared by both
gates (`predicateRecord()`), so a body with no predicate does no extra
work.
- **Scope of the guard.** It applies to every body `record:details`
draws, because the renderer cannot tell the default page's enumerated
sections from an authored page's: app-shell's running default page sends
the ungrouped bucket, and the whole body of an object with no
`fieldGroups`, as enumerated sections of the same shape an authored page
writes. One guard closes the class instead of a default-page-only
branch.
## Tests
New
`ui/packages/plugin-detail/src/renderers/__tests__/record-details.fieldVisibleWhen-35314.test.tsx`
(19 tests):
- **Parity matrix (10).** Each case renders the same row through
`record:details` (the synthesized default page) AND through the entry
form renderer with the field carrying the same predicate, and asserts `{
form, detail }` against the expected verdict: envelope and bare-string
spellings, no predicate, three fault shapes (unbound bare identifier,
parse error, unknown field: drawn, fail-open), a declared-but-absent
column (null seed), a relation bound as its id, `previous`, and the host
`current_user` scope.
- **Every body (7).** Synthesized default page (grouped field, ungrouped
bucket); running default page shape app-shell writes (grouped, ungrouped
bucket, object with no `fieldGroups`); authored enumerated sections;
authored flat `fields` list.
- **Controls (2).** A field whose predicate holds and a field with none
are drawn; a section whose every member is hidden draws no heading (and
draws it on the record where they show).
Harness guards: each render first finds an ungated anchor value and
throws `HARNESS DEAD` otherwise, so an empty body cannot pass a hidden
leg.
<details><summary>Reverse verification: the pin against the BASE
renderer (red), then restored</summary>
`record-details.tsx` restored from the base commit with `git restore
--source=BASE`, the pin run, the file restored with `git checkout HEAD
--` in an EXIT trap. Mutation proof: `resolveFieldRuleState` count in
the file = 0.
```
× envelope `record.stage == closed_won` — the card reproduction
× bare-string `record.stage == closed_won` — the same verdict as the envelope
× a declared field the row does not carry compares as null — evaluated, not faulted
× a relation binds as its stored id, expanded or not
× `previous` binds the persisted row, as on the record's edit form
× the host `current_user` scope binds on both surfaces
× synthesized default page — a field in a declared group: hidden on LOST, drawn on WON
× synthesized default page — a field in the ungrouped bucket: hidden on LOST, drawn on WON
× running default page — a field in a declared group: hidden on LOST, drawn on WON
× running default page — a field in the ungrouped bucket: hidden on LOST, drawn on WON
× running default page of an object with no fieldGroups: hidden on LOST, drawn on WON
× authored page — enumerated sections of bare names: hidden on LOST, drawn on WON
× authored page — a flat fields list: hidden on LOST, drawn on WON
× a section every member of which the predicates hide draws no heading
Test Files 1 failed (1)
Tests 14 failed | 5 passed (19)
card reproduction diff: form [false, true], detail [true, true]
```
The 5 that stay green on the base are the controls that must: no
predicate, the three fail-open fault cases (drawn on both rows, which is
also what the base did), and the predicate-holds control. Restore proof:
`git diff HEAD` empty, `git status --porcelain` empty, `git hash-object`
of the file equals the HEAD blob.
</details>
<details><summary>Package suite and type-check at head
43ff1a5</summary>
```
pnpm --dir ui exec vitest run --maxWorkers=2 packages/plugin-detail/
Test Files 387 passed | 1 skipped (388)
Tests 3511 passed | 18 skipped (3529)
pnpm --filter @object-ui/plugin-detail run type-check (tsc --noEmit && tsc -p tsconfig.test.json; the second program includes src/**/*.test.tsx)
TC_EXIT=0
pnpm --dir ui exec vitest run --maxWorkers=2 scripts/
Test Files 171 passed | 2 skipped (173)
Tests 5092 passed | 2 skipped (5094)
```
The group-gate pin `record-details.groupVisibleWhen-11630.test.tsx` (13
tests) is in that suite and stays green: an authored or synthesized `{
group }` section's own gate is unchanged.
</details>
## Acceptance notes
- **Authored pages change too, deliberately.** On the base, an authored
`record:details` section (or flat `fields` list) naming a field whose
`visibleWhen` is false also drew it (measured red above). The guard
closes that in the same fold, under the bounded in-place rule: same
defect class, mechanical, same file, no new gate surface. Nothing
changes for a field with no predicate, a field whose predicate holds, or
a `{ group }` section's own gate.
- **Evaluated against the stored record, not the inline-edit draft**,
like the group gate: editing `stage` inline reveals a gated field after
save, not while typing.
- **Display only.** The record API still returns the field, as with a
form-hidden field.
- **Not covered here:** `record:highlights` (the header strip) and the
`detail-view` node / record drawer do not read a field's `visibleWhen`
either. Not measured as reachable defects in this run; noted, not filed.
- **Real app.** `showcase_invoice.paid_on` (`visibleWhen: record.status
== 'paid'`, object with no `fieldGroups`) is the in-repo fixture of this
shape; its body is the "object with no fieldGroups" leg above. A live
browser run was not made (no built console bundle in this container).
- The registry `inputs` text for `record:details` (and the generated
reference page) says nothing false after this change, so it is not
edited here.
## Verification
Derived local gate families (`node scripts/pm/dispatch-gates.mjs
--commands`, 38 commands) run, each with its exit code captured before
any pipe; all 38 exit 0. Reconciliation with `--ran`: 38 derived, 38
run, 0 NOT-MEASURED, 0 UNRUN. Every other family is CI's; see this PR's
check runs.
---
_Generated by [Claude
Code](https://claude.ai/code/session_01Utp6CZrgaiMgTJCnswR6jQ)_
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent b7d2474 commit a5ddeb6
3 files changed
Lines changed: 455 additions & 9 deletions
File tree
- .changeset
- ui/packages/plugin-detail/src/renderers
- __tests__
| 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 | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 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 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 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 | + | |
| 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 | + | |
| 379 | + | |
| 380 | + | |
0 commit comments