Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .changeset/35437-field-visiblewhen-highlights-drawer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
'@object-ui/plugin-detail': patch
---

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

Clause-②: no
Metadata-protocol: none

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.

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.
72 changes: 53 additions & 19 deletions ui/packages/plugin-detail/src/DetailView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ import { ActivityTimeline } from './ActivityTimeline';
import { HistoryTimeline } from './HistoryTimeline';
import { RecordMetaFooter } from './RecordMetaFooter';
import { RecordPageProvenanceContext } from './recordPageProvenance';
import { SchemaRenderer, SchemaErrorBoundary, toRenderableSchema, useSafeFieldLabel, useDataInvalidation, useInlineEdit, useRowPredicate, resolveApprovalLock, usePrintPage, useRecordContext } from '@object-ui/react';
import { SchemaRenderer, SchemaErrorBoundary, toRenderableSchema, useSafeFieldLabel, useDataInvalidation, useInlineEdit, useRowPredicate, resolveApprovalLock, usePrintPage, useRecordContext, usePredicateScope } from '@object-ui/react';
import { buildExpandFields, declaredNameField, getRecordDisplayName, formatTitleTemplate, recordDelete, recordDisplayValueAt, resolveAffordance, toDisplayDate, userActionPredicates, withoutDeniedFields } from '@object-ui/core';
import { usePermissions } from '@object-ui/permissions';
import { useLocalization, useDisplayLocale, resolveFieldCurrency, recordCurrencyPath } from '@object-ui/i18n';
Expand All @@ -56,6 +56,7 @@ import { useRecordEditable } from './useRecordEditable';
import { getCellRenderer, resolveCellRendererType, coerceToSafeValue, formatPercent, percentCellScale } from '@object-ui/fields';
import { resolveFieldScale } from '@objectstack/spec/data';
import { hasCellValue } from './emptiness';
import { dropFieldPredicateHidden, lazyPredicateRecord, type FieldPredicateGate } from './fieldPredicateVisibility';
import { enrichDetailField } from './fieldEnrichment';
import { chipTakesCellRenderer } from './summaryChipRenderers';
import { summaryChipPercentPoints } from './summaryChipPercent';
Expand Down Expand Up @@ -587,6 +588,39 @@ export const DetailView: React.FC<DetailViewProps> = ({
);


/**
* The field lists this view DRAWS: `schema`'s, less every field whose own
* `visibleWhen` is false for this record — judged by
* `dropFieldPredicateHidden` (`./fieldPredicateVisibility`), the one
* implementation the details body and the highlights strip call too, so the
* drawer and the `detail-view` node hide what the form hides (fail-open on a
* predicate that cannot be evaluated). The predicate is the object's
* declaration, so nothing is hidden before the object schema is known.
*
* Render-only: the record read above keeps `schema`'s lists (a `$expand`
* built from what is drawn would refetch whenever the verdict moved), and
* the verdict is the SAVED record's, as on the details body.
*/
const predicateScope = usePredicateScope();
const drawn = React.useMemo(() => {
const gate: FieldPredicateGate = {
objectFields,
record: lazyPredicateRecord(data, objectFields),
scope: predicateScope,
where: (n) => `field '${n}' of detail-view on object '${schema.objectName ?? ''}'`,
};
const dropSection = <S extends { fields: unknown[] }>(section: S): S => ({
...section,
fields: dropFieldPredicateHidden(section.fields, gate),
});
return {
fields: dropFieldPredicateHidden(schema.fields, gate),
sections: schema.sections?.map(dropSection),
sectionGroups: schema.sectionGroups?.map((group) => ({ ...group, sections: group.sections.map(dropSection) })),
shows: (name: string) => dropFieldPredicateHidden([name], gate).length === 1,
};
}, [schema.fields, schema.sections, schema.sectionGroups, schema.objectName, objectFields, data, predicateScope]);

// Fire onDataLoaded whenever the record changes so hosts can publish it
// (e.g. to the navigation breadcrumb or document title).
React.useEffect(() => {
Expand Down Expand Up @@ -1168,9 +1202,9 @@ export const DetailView: React.FC<DetailViewProps> = ({
// for the whole body (`EmptySectionsFold`). Only when the sections ARE the
// body: section groups draw fields of their own beside them.
const foldEmptySections = (rendered: React.ReactNode) =>
schema.sectionGroups?.length ? rendered : (
drawn.sectionGroups?.length ? rendered : (
<EmptySectionsFold
sections={schema.sections ?? []}
sections={drawn.sections ?? []}
data={{ ...data, ...editedValues }}
isEditing={isInlineEditing}
>
Expand Down Expand Up @@ -1230,7 +1264,7 @@ export const DetailView: React.FC<DetailViewProps> = ({
<h1 className="text-xl sm:text-2xl font-bold truncate">
{resolveDisplayTitle(titleRow, schema, objectSchema, t('detail.details'))}
</h1>
{effectiveSummaryFields.map((fieldName) => {
{effectiveSummaryFields.filter(drawn.shows).map((fieldName) => {
const val = data?.[fieldName];
// Same definition as `has` above and as every other band of
// the page (`./emptiness`, objectui#8376/#8394). A raw test
Expand Down Expand Up @@ -1971,8 +2005,8 @@ export const DetailView: React.FC<DetailViewProps> = ({
const detailsContent = (
<div className="space-y-3 sm:space-y-4">
{/* Section Groups */}
{schema.sectionGroups && schema.sectionGroups.length > 0 && (
schema.sectionGroups.map((group, index) => (
{drawn.sectionGroups && drawn.sectionGroups.length > 0 && (
drawn.sectionGroups.map((group, index) => (
<SectionGroup
key={index}
group={group}
Expand All @@ -1987,8 +2021,8 @@ export const DetailView: React.FC<DetailViewProps> = ({
/>
))
)}
{schema.sections && schema.sections.length > 0 && foldEmptySections(
schema.sections.map((section, index) => (
{drawn.sections && drawn.sections.length > 0 && foldEmptySections(
drawn.sections.map((section, index) => (
<SectionBoundary key={index} section={section} index={index}>
<DetailSection
section={section}
Expand All @@ -2004,10 +2038,10 @@ export const DetailView: React.FC<DetailViewProps> = ({
</SectionBoundary>
))
)}
{schema.fields && schema.fields.length > 0 && !schema.sections?.length && (
{drawn.fields && drawn.fields.length > 0 && !drawn.sections?.length && (
<DetailSection
section={{
fields: schema.fields,
fields: drawn.fields,
columns: schema.columns,
}}
data={{ ...data, ...editedValues }}
Expand Down Expand Up @@ -2114,9 +2148,9 @@ export const DetailView: React.FC<DetailViewProps> = ({
})() : (
<>
{/* Section Groups */}
{schema.sectionGroups && schema.sectionGroups.length > 0 && (
{drawn.sectionGroups && drawn.sectionGroups.length > 0 && (
<div className="space-y-3 sm:space-y-4">
{schema.sectionGroups.map((group, index) => (
{drawn.sectionGroups.map((group, index) => (
<SectionGroup
key={index}
group={group}
Expand All @@ -2134,10 +2168,10 @@ export const DetailView: React.FC<DetailViewProps> = ({
)}

{/* Sections */}
{schema.sections && schema.sections.length > 0 && (
{drawn.sections && drawn.sections.length > 0 && (
<div className="space-y-3 sm:space-y-4">
{(() => {
const renderSectionAt = (section: NonNullable<typeof schema.sections>[number], index: number) => (
const renderSectionAt = (section: NonNullable<typeof drawn.sections>[number], index: number) => (
<SectionBoundary key={index} section={section} index={index}>
<DetailSection
section={section}
Expand All @@ -2152,24 +2186,24 @@ export const DetailView: React.FC<DetailViewProps> = ({
/>
</SectionBoundary>
);
return emptySectionsAsLine && !schema.sectionGroups?.length ? (
return emptySectionsAsLine && !drawn.sectionGroups?.length ? (
<EmptySectionsLine
sections={schema.sections ?? []}
sections={drawn.sections ?? []}
data={{ ...data, ...editedValues }}
isEditing={isInlineEditing}
objectName={schema.objectName}
renderSection={renderSectionAt}
/>
) : foldEmptySections(schema.sections!.map(renderSectionAt));
) : foldEmptySections(drawn.sections!.map(renderSectionAt));
})()}
</div>
)}

{/* Direct Fields (if no sections) */}
{schema.fields && schema.fields.length > 0 && !schema.sections?.length && (
{drawn.fields && drawn.fields.length > 0 && !drawn.sections?.length && (
<DetailSection
section={{
fields: schema.fields,
fields: drawn.fields,
columns: schema.columns,
}}
data={{ ...data, ...editedValues }}
Expand Down
15 changes: 14 additions & 1 deletion ui/packages/plugin-detail/src/HeaderHighlight.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import { NON_EDITABLE_SYSTEM_FIELDS } from './systemFields';
import { useDetailTranslation } from './useDetailTranslation';
import { hasCellValue } from './emptiness';
import { useDefaultRecordPage } from './defaultRecordPage';
import { dropFieldPredicateHidden, lazyPredicateRecord } from './fieldPredicateVisibility';

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

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

// A highlight whose field's own `visibleWhen` is false for this record is
// not drawn, in either mode: the strip judges it as the form and the details
// body do (`../fieldPredicateVisibility`, fail-open), against the SAVED
// record, as the details body does, so a draft edit reveals a gated field
// after save, not while typing.
const drawnFields = dropFieldPredicateHidden(fields, {
objectFields: objectSchema?.fields,
record: lazyPredicateRecord(data, objectSchema?.fields),
scope: predicateScope,
where: (n) => `field '${n}' of the highlights strip on object '${objectName ?? ''}'`,
});

// In read mode we hide value-less fields to keep the strip dense; WHILE
// EDITING we keep them so the user can fill an empty highlight in place.
const hasValue = (f: HighlightField) => {
const val = data?.[f.name];
return val !== null && val !== undefined && val !== '';
};
const visibleFields = editing ? fields : fields.filter(hasValue);
const visibleFields = editing ? drawnFields : drawnFields.filter(hasValue);

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

Expand Down
Loading
Loading