Skip to content

Commit b65488a

Browse files
fix(plugin-detail): the highlights strip, the detail view and the record drawer hide a field whose own visibleWhen is false (#35545)
Fixes #35437 Clause-②: no Metadata-protocol: none ## 维护者速读 - 用户能看到什么变化:记录页顶部的要点条、详情视图(含页眉小标签)和列表等视图打开的侧边抽屉里,「显示条件」对当前记录不成立的字段不再显示,与编辑表单和详情正文一致。 - 为什么做:上一张卡只修好了详情正文,这三处是同一问题剩下的位置;同一条记录在不同位置显示不一,读者会看到空的或误导的字段。 - 出错会怎样:只影响显示,数据与接口不变;条件写错或算不出来时照常显示该字段;整体撤回一个提交即可。 - 要你做什么:无。 ## What changes A field's own object-level `visibleWhen` (`Field.visibleWhen`: "field is shown only when TRUE (else hidden)") now hides it on every record surface in `plugin-detail` that draws fields, not only on the `record:details` body: - **One implementation, three callers.** The details body's fold is lifted into a new module-internal helper, `ui/packages/plugin-detail/src/fieldPredicateVisibility.ts` (`dropFieldPredicateHidden`, with `assemblePredicateRecord`, `lazyPredicateRecord` and `fieldPredicateVisible` moved there unchanged). It is not exported from the package barrel. Call sites: 1. `record:details` (`renderers/record-details.tsx`): its `dropPredicateHidden` now delegates to the helper; the group gate keeps its own fail-closed judge and reads the same lazily assembled record. 2. `HeaderHighlight`: drops a gated highlight before the read/edit face split. This covers `record:highlights` and the strip a `detail-view` draws from `highlightFields`. 3. `DetailView`: a render-only `drawn` memo filters `fields`, `sections[].fields`, `sectionGroups[].sections[].fields` and the header summary chips. This covers the `detail-view` node and the record drawer (`RecordDetailDrawer` and the views' overlay both render `RecordDetailPanel`, which renders `DetailView`). - **The verdict is the form's (the ruling in the claim).** `resolveFieldRuleState`, the record bound as `record` and `previous`, the host predicate scope. A predicate that cannot be evaluated SHOWS the field and warns once (ADR-0137 D3). A field with no predicate is untouched. - **Evaluated against the saved record**, as on the details body: on the strip, an inline edit reveals a gated field after save, not while typing. - **`DetailView`'s record read is untouched.** The `$expand` read keeps `schema`'s lists. A list derived from the verdict would refetch whenever the verdict moved. ## Tests New `ui/packages/plugin-detail/src/__tests__/fieldVisibleWhen.surfaces-35437.test.tsx` (11 tests). Each test renders the same row on four surface legs: `record:highlights`, the `detail-view` node through `SchemaRenderer`, the node's own `highlightFields` strip, and `RecordDetailDrawer`. It also renders the row through the entry `form` renderer and asserts `{ form, highlights, node, nodeStrip, drawer }` against the expected verdict in one assertion, so a red names the surface: - **Parity matrix (8):** envelope and bare-string predicates, where the WON row is the CONTROL for a predicate that holds. Also: no predicate (CONTROL), a parse error and an unbound bare identifier (both fail-open CONTROLs, drawn), the null seed, a relation bound as its stored id, `previous`, and the host `current_user` scope. - **Controls (1):** beside a hidden field, a field whose predicate holds and a field with none stay drawn on every surface. - **Summary chip (1):** the `detail-view` header draws no chip for a gated field. - Harness guards: each leg first finds an ungated anchor value, and the `DetailView` legs wait for their own object-schema read to land. Otherwise the leg throws `HARNESS DEAD`, so an empty render cannot pass a hidden leg. The details body's own pin, `record-details.fieldVisibleWhen-35314.test.tsx` (19 tests), is unchanged and green. <details><summary>Reproduction on the base renderer: 8 red, the 3 fail-open/no-predicate controls green</summary> `DetailView.tsx`, `HeaderHighlight.tsx` and `record-details.tsx` were restored from the base commit 5756ae0 with `git restore --source`, and the new pin was run. The sources were restored with `git checkout HEAD --` in an EXIT trap. Mutation proof: helper references in the three files = 0/0/0. Restore proof: `git diff HEAD` empty, `git status --porcelain` empty, and the three `git hash-object` values equal the HEAD blobs. ``` x envelope `record.stage == closed_won` — the card reproduction; CONTROL: drawn where it holds x bare-string `record.stage == closed_won` — the same verdict as the envelope x a declared field the row does not carry compares as null — evaluated, not faulted x a relation binds as its stored id, expanded or not x `previous` binds the persisted row, as on the record's edit form x the host `current_user` scope binds on every surface x CONTROL — beside a hidden field, a field whose predicate holds and a field with none stay drawn x a `stage` chip is drawn on WON and not on LOST Tests 8 failed | 3 passed (11) card reproduction diff: form [false, true]; highlights, node, nodeStrip, drawer each [true, true] ``` All four surface legs reproduce red on the base (A1). None already routed through the details body. </details> <details><summary>Ablation of the shared helper: both pins red</summary> `node scripts/ablation-replace.mjs` replaced the helper's `if (visibleWhen == null) return true;` with `return true;`: anchor 1 to 0, blob 627ab41 to 0e66c463. The new pin and the details-body pin were then run together: ``` Test Files 2 failed (2) Tests 22 failed | 8 passed (30) ``` That is 8 red in the new pin and 14 in the `record:details` pin, the same 14 that PR #35421 measured red against its base. So the details body runs through the shared helper too. Restored with `git checkout HEAD --` in an EXIT trap: `git diff HEAD` empty, hash equals the HEAD blob, marker count 0. </details> <details><summary>Package suite and type-check</summary> Taken at head 86c2830, after merging origin/main. The build closure was rebuilt first, and the commands were chained with `&&` under the verify lock, whose verdict was `command-exit 0`: ``` pnpm --workspace-concurrency=2 --filter '@object-ui/plugin-detail^...' build pnpm --dir ui exec vitest run --maxWorkers=2 packages/plugin-detail/ Test Files 388 passed | 1 skipped (389) Tests 3536 passed | 18 skipped (3554) pnpm --filter @object-ui/plugin-detail run type-check (tsc --noEmit && tsc -p tsconfig.test.json; the second program includes src/**/*.test.tsx, so the new pin is compiled) exit 0 ``` The group-gate pin `record-details.groupVisibleWhen-11630.test.tsx` and the details-body pin `record-details.fieldVisibleWhen-35314.test.tsx` are in that suite and unchanged. </details> ## Acceptance notes - **The drawer learns the predicate from `DetailView`'s own object-schema read** (`dataSource.getObjectSchema`). That is the same read that gives it option labels on the record page. `RecordDetailPanel` hands `DetailView` typed field descriptors and no object schema. A host that opens the panel with a data source lacking `getObjectSchema` therefore still draws a gated field, as it also draws no option labels from `DetailView`'s side. Every in-repo caller (grid, list, gallery, kanban, calendar, gantt, map, tree, timeline) passes the view's data source. `RecordDetailPanel.tsx` is outside this claim's file surface, so this is noted here, not changed. - **The header summary chips are included.** They are fields the `detail-view` node draws, and they have the same defect. An auto-picked chip that is hidden is dropped, not replaced by the next candidate. - **`record:highlights` still registers every authored highlight name** for the body's dedupe. A field the predicate hides is dropped by both the strip and the body, so the registration changes nothing visible. - **Display only.** The record API still returns the field, as with a field the form hides. - Line-addressed citations: none added. ## Verification Two-minute check: `pnpm --dir ui exec vitest run packages/plugin-detail/src/__tests__/fieldVisibleWhen.surfaces-35437.test.tsx`. Expect 11 passed, each asserting the form and all four surface legs together. Files to read first: 1. `ui/packages/plugin-detail/src/DetailView.tsx`, the `drawn` memo and the render sites that read it. Risk: a render path still reading `schema.*` (the fetch effect deliberately does). 2. `ui/packages/plugin-detail/src/fieldPredicateVisibility.ts`, the single implementation. 3. `ui/packages/plugin-detail/src/HeaderHighlight.tsx`, the gate before the read/edit split. <details><summary>Derived local gate families</summary> At head 86c2830, `node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstack` derived 38 commands. Each was run with its exit code captured before any pipe, the vitest and type-check families under the verify lock. All 38 exited 0. `--ran` reconciliation: `38 derived, 38 run, 0 NOT-MEASURED, 0 UNRUN`. `pnpm --dir ui exec vitest run scripts/` reported 171 passed and 2 skipped files (5092 passed tests). `pnpm check:new-line-citations` (ui) reported 0 new citations. Every other family belongs to CI; see this PR's check runs. </details> --- _Generated by [Claude Code](https://claude.ai/code/session_01Utp6CZrgaiMgTJCnswR6jQ)_ --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 93fa4f9 commit b65488a

6 files changed

Lines changed: 605 additions & 106 deletions

File tree

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
'@object-ui/plugin-detail': patch
3+
---
4+
5+
fix(plugin-detail): the highlights strip, the detail view and the record drawer no longer draw a field whose own `visibleWhen` is false for the record
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
A field's object-level `visibleWhen` (`Field.visibleWhen`: "field is shown only when TRUE") now hides it on every record surface that draws fields, not only on the `record:details` body: the header highlights strip (`record:highlights`, and the strip a `detail-view` draws from `highlightFields`), the `detail-view` node's body and its header summary chips, and the record drawer that list, kanban, calendar, gantt and the other views open. Before, these surfaces drew such a field, label and value, on every record, so they disagreed with the edit form and the details body about the same record.
11+
12+
Every surface calls the one implementation the details body uses, so the verdict is the form's own (`resolveFieldRuleState`), over the record shown (bound as `record` and as `previous`) and the host predicate scope (`current_user`). A predicate that cannot be evaluated still shows the field and warns once, as on the form (ADR-0137 D3). The verdict is the saved record's: an inline edit reveals a gated field after save. Display only: the record API still returns the field.

‎ui/packages/plugin-detail/src/DetailView.tsx‎

Lines changed: 53 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ import { ActivityTimeline } from './ActivityTimeline';
4646
import { HistoryTimeline } from './HistoryTimeline';
4747
import { RecordMetaFooter } from './RecordMetaFooter';
4848
import { RecordPageProvenanceContext } from './recordPageProvenance';
49-
import { SchemaRenderer, SchemaErrorBoundary, toRenderableSchema, useSafeFieldLabel, useDataInvalidation, useInlineEdit, useRowPredicate, resolveApprovalLock, usePrintPage, useRecordContext } from '@object-ui/react';
49+
import { SchemaRenderer, SchemaErrorBoundary, toRenderableSchema, useSafeFieldLabel, useDataInvalidation, useInlineEdit, useRowPredicate, resolveApprovalLock, usePrintPage, useRecordContext, usePredicateScope } from '@object-ui/react';
5050
import { buildExpandFields, declaredNameField, getRecordDisplayName, formatTitleTemplate, recordDelete, recordDisplayValueAt, resolveAffordance, toDisplayDate, userActionPredicates, withoutDeniedFields } from '@object-ui/core';
5151
import { usePermissions } from '@object-ui/permissions';
5252
import { useLocalization, useDisplayLocale, resolveFieldCurrency, recordCurrencyPath } from '@object-ui/i18n';
@@ -56,6 +56,7 @@ import { useRecordEditable } from './useRecordEditable';
5656
import { getCellRenderer, resolveCellRendererType, coerceToSafeValue, formatPercent, percentCellScale } from '@object-ui/fields';
5757
import { resolveFieldScale } from '@objectstack/spec/data';
5858
import { hasCellValue } from './emptiness';
59+
import { dropFieldPredicateHidden, lazyPredicateRecord, type FieldPredicateGate } from './fieldPredicateVisibility';
5960
import { enrichDetailField } from './fieldEnrichment';
6061
import { chipTakesCellRenderer } from './summaryChipRenderers';
6162
import { summaryChipPercentPoints } from './summaryChipPercent';
@@ -587,6 +588,39 @@ export const DetailView: React.FC<DetailViewProps> = ({
587588
);
588589

589590

591+
/**
592+
* The field lists this view DRAWS: `schema`'s, less every field whose own
593+
* `visibleWhen` is false for this record — judged by
594+
* `dropFieldPredicateHidden` (`./fieldPredicateVisibility`), the one
595+
* implementation the details body and the highlights strip call too, so the
596+
* drawer and the `detail-view` node hide what the form hides (fail-open on a
597+
* predicate that cannot be evaluated). The predicate is the object's
598+
* declaration, so nothing is hidden before the object schema is known.
599+
*
600+
* Render-only: the record read above keeps `schema`'s lists (a `$expand`
601+
* built from what is drawn would refetch whenever the verdict moved), and
602+
* the verdict is the SAVED record's, as on the details body.
603+
*/
604+
const predicateScope = usePredicateScope();
605+
const drawn = React.useMemo(() => {
606+
const gate: FieldPredicateGate = {
607+
objectFields,
608+
record: lazyPredicateRecord(data, objectFields),
609+
scope: predicateScope,
610+
where: (n) => `field '${n}' of detail-view on object '${schema.objectName ?? ''}'`,
611+
};
612+
const dropSection = <S extends { fields: unknown[] }>(section: S): S => ({
613+
...section,
614+
fields: dropFieldPredicateHidden(section.fields, gate),
615+
});
616+
return {
617+
fields: dropFieldPredicateHidden(schema.fields, gate),
618+
sections: schema.sections?.map(dropSection),
619+
sectionGroups: schema.sectionGroups?.map((group) => ({ ...group, sections: group.sections.map(dropSection) })),
620+
shows: (name: string) => dropFieldPredicateHidden([name], gate).length === 1,
621+
};
622+
}, [schema.fields, schema.sections, schema.sectionGroups, schema.objectName, objectFields, data, predicateScope]);
623+
590624
// Fire onDataLoaded whenever the record changes so hosts can publish it
591625
// (e.g. to the navigation breadcrumb or document title).
592626
React.useEffect(() => {
@@ -1168,9 +1202,9 @@ export const DetailView: React.FC<DetailViewProps> = ({
11681202
// for the whole body (`EmptySectionsFold`). Only when the sections ARE the
11691203
// body: section groups draw fields of their own beside them.
11701204
const foldEmptySections = (rendered: React.ReactNode) =>
1171-
schema.sectionGroups?.length ? rendered : (
1205+
drawn.sectionGroups?.length ? rendered : (
11721206
<EmptySectionsFold
1173-
sections={schema.sections ?? []}
1207+
sections={drawn.sections ?? []}
11741208
data={{ ...data, ...editedValues }}
11751209
isEditing={isInlineEditing}
11761210
>
@@ -1230,7 +1264,7 @@ export const DetailView: React.FC<DetailViewProps> = ({
12301264
<h1 className="text-xl sm:text-2xl font-bold truncate">
12311265
{resolveDisplayTitle(titleRow, schema, objectSchema, t('detail.details'))}
12321266
</h1>
1233-
{effectiveSummaryFields.map((fieldName) => {
1267+
{effectiveSummaryFields.filter(drawn.shows).map((fieldName) => {
12341268
const val = data?.[fieldName];
12351269
// Same definition as `has` above and as every other band of
12361270
// the page (`./emptiness`, objectui#8376/#8394). A raw test
@@ -1971,8 +2005,8 @@ export const DetailView: React.FC<DetailViewProps> = ({
19712005
const detailsContent = (
19722006
<div className="space-y-3 sm:space-y-4">
19732007
{/* Section Groups */}
1974-
{schema.sectionGroups && schema.sectionGroups.length > 0 && (
1975-
schema.sectionGroups.map((group, index) => (
2008+
{drawn.sectionGroups && drawn.sectionGroups.length > 0 && (
2009+
drawn.sectionGroups.map((group, index) => (
19762010
<SectionGroup
19772011
key={index}
19782012
group={group}
@@ -1987,8 +2021,8 @@ export const DetailView: React.FC<DetailViewProps> = ({
19872021
/>
19882022
))
19892023
)}
1990-
{schema.sections && schema.sections.length > 0 && foldEmptySections(
1991-
schema.sections.map((section, index) => (
2024+
{drawn.sections && drawn.sections.length > 0 && foldEmptySections(
2025+
drawn.sections.map((section, index) => (
19922026
<SectionBoundary key={index} section={section} index={index}>
19932027
<DetailSection
19942028
section={section}
@@ -2004,10 +2038,10 @@ export const DetailView: React.FC<DetailViewProps> = ({
20042038
</SectionBoundary>
20052039
))
20062040
)}
2007-
{schema.fields && schema.fields.length > 0 && !schema.sections?.length && (
2041+
{drawn.fields && drawn.fields.length > 0 && !drawn.sections?.length && (
20082042
<DetailSection
20092043
section={{
2010-
fields: schema.fields,
2044+
fields: drawn.fields,
20112045
columns: schema.columns,
20122046
}}
20132047
data={{ ...data, ...editedValues }}
@@ -2114,9 +2148,9 @@ export const DetailView: React.FC<DetailViewProps> = ({
21142148
})() : (
21152149
<>
21162150
{/* Section Groups */}
2117-
{schema.sectionGroups && schema.sectionGroups.length > 0 && (
2151+
{drawn.sectionGroups && drawn.sectionGroups.length > 0 && (
21182152
<div className="space-y-3 sm:space-y-4">
2119-
{schema.sectionGroups.map((group, index) => (
2153+
{drawn.sectionGroups.map((group, index) => (
21202154
<SectionGroup
21212155
key={index}
21222156
group={group}
@@ -2134,10 +2168,10 @@ export const DetailView: React.FC<DetailViewProps> = ({
21342168
)}
21352169

21362170
{/* Sections */}
2137-
{schema.sections && schema.sections.length > 0 && (
2171+
{drawn.sections && drawn.sections.length > 0 && (
21382172
<div className="space-y-3 sm:space-y-4">
21392173
{(() => {
2140-
const renderSectionAt = (section: NonNullable<typeof schema.sections>[number], index: number) => (
2174+
const renderSectionAt = (section: NonNullable<typeof drawn.sections>[number], index: number) => (
21412175
<SectionBoundary key={index} section={section} index={index}>
21422176
<DetailSection
21432177
section={section}
@@ -2152,24 +2186,24 @@ export const DetailView: React.FC<DetailViewProps> = ({
21522186
/>
21532187
</SectionBoundary>
21542188
);
2155-
return emptySectionsAsLine && !schema.sectionGroups?.length ? (
2189+
return emptySectionsAsLine && !drawn.sectionGroups?.length ? (
21562190
<EmptySectionsLine
2157-
sections={schema.sections ?? []}
2191+
sections={drawn.sections ?? []}
21582192
data={{ ...data, ...editedValues }}
21592193
isEditing={isInlineEditing}
21602194
objectName={schema.objectName}
21612195
renderSection={renderSectionAt}
21622196
/>
2163-
) : foldEmptySections(schema.sections!.map(renderSectionAt));
2197+
) : foldEmptySections(drawn.sections!.map(renderSectionAt));
21642198
})()}
21652199
</div>
21662200
)}
21672201

21682202
{/* Direct Fields (if no sections) */}
2169-
{schema.fields && schema.fields.length > 0 && !schema.sections?.length && (
2203+
{drawn.fields && drawn.fields.length > 0 && !drawn.sections?.length && (
21702204
<DetailSection
21712205
section={{
2172-
fields: schema.fields,
2206+
fields: drawn.fields,
21732207
columns: schema.columns,
21742208
}}
21752209
data={{ ...data, ...editedValues }}

‎ui/packages/plugin-detail/src/HeaderHighlight.tsx‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import { NON_EDITABLE_SYSTEM_FIELDS } from './systemFields';
3333
import { useDetailTranslation } from './useDetailTranslation';
3434
import { hasCellValue } from './emptiness';
3535
import { useDefaultRecordPage } from './defaultRecordPage';
36+
import { dropFieldPredicateHidden, lazyPredicateRecord } from './fieldPredicateVisibility';
3637

3738
export interface HeaderHighlightProps {
3839
fields: HighlightField[];
@@ -100,13 +101,25 @@ export const HeaderHighlight: React.FC<HeaderHighlightProps> = ({
100101

101102
if (!fields.length || !data) return null;
102103

104+
// A highlight whose field's own `visibleWhen` is false for this record is
105+
// not drawn, in either mode: the strip judges it as the form and the details
106+
// body do (`../fieldPredicateVisibility`, fail-open), against the SAVED
107+
// record, as the details body does, so a draft edit reveals a gated field
108+
// after save, not while typing.
109+
const drawnFields = dropFieldPredicateHidden(fields, {
110+
objectFields: objectSchema?.fields,
111+
record: lazyPredicateRecord(data, objectSchema?.fields),
112+
scope: predicateScope,
113+
where: (n) => `field '${n}' of the highlights strip on object '${objectName ?? ''}'`,
114+
});
115+
103116
// In read mode we hide value-less fields to keep the strip dense; WHILE
104117
// EDITING we keep them so the user can fill an empty highlight in place.
105118
const hasValue = (f: HighlightField) => {
106119
const val = data?.[f.name];
107120
return val !== null && val !== undefined && val !== '';
108121
};
109-
const visibleFields = editing ? fields : fields.filter(hasValue);
122+
const visibleFields = editing ? drawnFields : drawnFields.filter(hasValue);
110123

111124
if (visibleFields.length === 0) return null;
112125

0 commit comments

Comments
 (0)