Skip to content

Commit d7665a2

Browse files
committed
feat(plugin-grid): phone cards read the object's highlightFields for amount and subtitle
When an object declares highlightFields (ADR-0085), the phone card takes its amount from the first of them that draws as money and its subtitle from the next three, in that order, with number, currency and percent parts under their field label. Fields no column shows are drawn through the synthesized column draft and fetched beside the name field by the grid, ListView and RelatedList. An object without highlightFields keeps the column-order rule. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01L9qibwy7XB37e8e1P6jRJ3
1 parent 4f7aa88 commit d7665a2

5 files changed

Lines changed: 155 additions & 48 deletions

File tree

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2014,6 +2014,21 @@ export const RelatedList: React.FC<RelatedListProps> = ({
20142014
projection.add(declaredName);
20152015
}
20162016
}
2017+
// [objectstack#37891] The child object's `highlightFields` (ADR-0085).
2018+
// On a phone the enlarged tab's grid draws each row as a card whose
2019+
// amount and subtitle are those fields, in that order, whether or not a
2020+
// column shows them. Fetched, never drawn as columns; on every
2021+
// viewport, as the gallery cover above, so crossing the breakpoint never
2022+
// refetches. Through the name field's gates: declared, readable, and not
2023+
// one the block redacts.
2024+
const highlights = (objectSchema as { highlightFields?: unknown } | undefined)?.highlightFields;
2025+
if (Array.isArray(highlights)) {
2026+
for (const field of highlights) {
2027+
if (typeof field !== 'string' || field === '' || redactedFields.has(field)) continue;
2028+
if (parentRelationshipFieldDef(fields, field) === undefined || !readable(field)) continue;
2029+
projection.add(field);
2030+
}
2031+
}
20172032
}
20182033
return Array.from(projection);
20192034
}, [columns, redactedFields, referenceField, objectName, api, perms, expandFields, objectSchema, rowActions]);

‎ui/packages/plugin-grid/src/ObjectGrid.tsx‎

Lines changed: 61 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2112,7 +2112,7 @@ export const ObjectGrid: React.FC<ObjectGridComponentProps> = ({
21122112
useObjectGridDiagnostics(schema);
21132113

21142114
// `generateColumns`, the column generator, in hook order (`./objectGridGenerateColumns`).
2115-
const { generateColumns } = useObjectGridGenerateColumns({
2115+
const { generateColumns, synthesizeFieldColumn } = useObjectGridGenerateColumns({
21162116
schema, dataSource, data, dataConfig, hasInlineData, objectName, objectSchema, objectFields,
21172117
objectTypesPending, schemaFields, schemaColumns, perms, navigation, executeAction, predicateScope,
21182118
resolveFieldLabel, translateOptions, uiLanguage, recordLinkAdornment, rowOpensRecord,
@@ -4414,8 +4414,37 @@ export const ObjectGrid: React.FC<ObjectGridComponentProps> = ({
44144414
// A WITHHELD column (objectui#10657: the object's field types are still
44154415
// unknown, and the column has no type of its own) is handled the same way:
44164416
// its `cell` draws the mask.
4417+
// objectstack#37891 — the card's BODY. When the object declares
4418+
// `highlightFields` (ADR-0085's "which fields matter most", in priority
4419+
// order) the card reads its amount and subtitle from that list, in that
4420+
// order, whether or not the view shows each field as a column: the wide
4421+
// table keeps its own columns and the phone card follows the object. A
4422+
// shown column is drawn through its own draft; a field no column shows is
4423+
// drawn through the draft the synthesized grid would give it
4424+
// (`synthesizeFieldColumn`: the field's renderer, its translated label, and
4425+
// field-level security, so a field the viewer may not read is left out).
4426+
// The fetches that feed this grid ask for those fields beside the name
4427+
// field. An object that declares none keeps the shown columns' order.
4428+
const highlightNames = Array.isArray((objectSchema as any)?.highlightFields)
4429+
? [...new Set(((objectSchema as any).highlightFields as unknown[])
4430+
.filter((n): n is string => typeof n === 'string' && !!objectFields?.[n]))]
4431+
: [];
4432+
const followsHighlights = highlightNames.length > 0;
4433+
const cardColMap = new Map(colMap);
4434+
const highlightColumns = highlightNames
4435+
.filter((n) => n !== titleKey)
4436+
.map((n) => {
4437+
const shown = colMap.get(n);
4438+
if (shown) return shown;
4439+
const drafted = synthesizeFieldColumn(n);
4440+
if (drafted) cardColMap.set(n, drafted);
4441+
return drafted;
4442+
})
4443+
.filter((c): c is ObjectGridColumnDraft => c !== null && c !== undefined);
4444+
const cardBodyColumns = followsHighlights ? highlightColumns : bodyColumns;
4445+
44174446
const isMaskedCardColumn = (key: string) =>
4418-
isMaskedGridColumn(colMap.get(key)?.type, objectFields?.[key]?.type, objectTypesPending);
4447+
isMaskedGridColumn(cardColMap.get(key)?.type, objectFields?.[key]?.type, objectTypesPending);
44194448

44204449
// objectstack#28484 — a phone's card row is the board's list row: the
44214450
// title, ONE subtitle line and ONE status chip at the right, with no
@@ -4450,12 +4479,31 @@ export const ObjectGrid: React.FC<ObjectGridComponentProps> = ({
44504479
const def = objectFields?.[c.accessorKey];
44514480
return def?.type === c.type && resolveFormulaValueType(def, 0) === 'currency';
44524481
};
4453-
const amountCol = bodyColumns.find(
4454-
(c) => c !== statusCol && drawsAsMoney(c) && !isMaskedCardColumn(c.accessorKey),
4482+
// objectstack#37891 — read from the card body above: with `highlightFields`
4483+
// the amount is the first of them that draws as money (an order line
4484+
// declaring `['total_price', 'quantity', 'unit_price', 'discount']` shows
4485+
// its total, not the unit price its table happens to show first), and the
4486+
// subtitle takes the next three, in that order, each number, currency and
4487+
// percent part under its field label, so `2 · 10` reads as quantities.
4488+
const amountCol = cardBodyColumns.find(
4489+
(c) => c.accessorKey !== statusKey && drawsAsMoney(c) && !isMaskedCardColumn(c.accessorKey),
44554490
);
4456-
const subtitleColumns = bodyColumns
4457-
.filter((c) => c !== statusCol && c !== amountCol && !titleReads.has(c.accessorKey))
4458-
.slice(0, 2);
4491+
const subtitleColumns = cardBodyColumns
4492+
.filter((c) => c.accessorKey !== statusKey && c !== amountCol && !titleReads.has(c.accessorKey))
4493+
.slice(0, followsHighlights ? 3 : 2);
4494+
const labelsSubtitlePart = (c: ObjectGridColumnDraft): boolean => {
4495+
if (!followsHighlights) return false;
4496+
if (c.type === 'number' || c.type === 'currency' || c.type === 'percent') return true;
4497+
if (c.type !== 'formula' && c.type !== 'summary') return false;
4498+
const def = objectFields?.[c.accessorKey];
4499+
if (def?.type !== c.type) return false;
4500+
const valueType = resolveFormulaValueType(def, 0);
4501+
return valueType === 'number' || valueType === 'currency' || valueType === 'percent';
4502+
};
4503+
const subtitlePartLabel = (c: ObjectGridColumnDraft): string | undefined => {
4504+
if (!labelsSubtitlePart(c)) return undefined;
4505+
return typeof c.header === 'string' && c.header !== '' ? c.header : undefined;
4506+
};
44594507
const isEmptyCardValue = (value: unknown) => value == null || value === '';
44604508
const cardCell = (col: ObjectGridColumnDraft, row: any): React.ReactNode => {
44614509
const value = row[col.accessorKey];
@@ -4619,7 +4667,12 @@ export const ObjectGrid: React.FC<ObjectGridComponentProps> = ({
46194667
{subtitle.map((col, i) => (
46204668
<React.Fragment key={col.accessorKey}>
46214669
{i > 0 && <span className="shrink-0 whitespace-pre"> · </span>}
4622-
<span data-testid="grid-card-subtitle-part" className="min-w-0 truncate">{cardCell(col, row)}</span>
4670+
<span data-testid="grid-card-subtitle-part" className="min-w-0 truncate">
4671+
{subtitlePartLabel(col) !== undefined && (
4672+
<span data-testid="grid-card-subtitle-label">{subtitlePartLabel(col)} </span>
4673+
)}
4674+
{cardCell(col, row)}
4675+
</span>
46234676
</React.Fragment>
46244677
))}
46254678
</div>

‎ui/packages/plugin-grid/src/objectGridGenerateColumns.tsx‎

Lines changed: 53 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,55 @@ export function useObjectGridGenerateColumns({
7474
/** objectstack#33317 — `false` ⇒ the host's row click opens nothing (`ObjectGrid`'s prop). */
7575
rowOpensRecord?: boolean;
7676
}) {
77+
// One object field's column draft, as the SYNTHESIZED path (no authored
78+
// `columns` / `fields`) draws it: the field's own renderer, its translated
79+
// label, and field-level security (`null` for a field the viewer may not
80+
// read, or one the object does not declare). Shared with the phone card,
81+
// which draws the object's `highlightFields` (ADR-0085) whether or not the
82+
// view shows them as columns (objectstack#37891).
83+
const synthesizeFieldColumn = useCallback((fieldName: string): ObjectGridColumnDraft | null => {
84+
if (!objectSchema) return null;
85+
const settledFor = (field: unknown, row: Record<string, unknown> | undefined): boolean =>
86+
isDeadlineSettled(field as Parameters<typeof isDeadlineSettled>[0], row, { scope: predicateScope, fields: objectFields });
87+
const field = objectSchema.fields?.[fieldName];
88+
if (!field) return null;
89+
90+
// FLS: drop columns the current user cannot read (server-resolved
91+
// /me/permissions via checkField — the schema itself carries no
92+
// per-caller permission bits, objectstack#3661). Same gate ListView
93+
// applies to its auto-derived columns.
94+
if (perms?.isLoaded && schema.objectName
95+
&& !perms.checkField(schema.objectName, fieldName, 'read')) return null;
96+
97+
// Annotated for the same reason as paths A-C (objectui#6004): `field` is
98+
// `any`, so these values have to be named before they reach a spread
99+
// below — the naming now lives on `GridCellRendering`'s `string | null`
100+
// members. `fieldType` is the DECLARED type the emit forwards to the
101+
// inline editor; the renderer comes from the `format`-promoted key, which
102+
// this path used to skip (objectui#8920).
103+
const { declaredType: fieldType, rendererType, Renderer: CellRenderer } = resolveGridCellRendering(field);
104+
const translatedField = field.options
105+
? { ...field, options: translateOptions(schema.objectName, fieldName, field.options) }
106+
: field;
107+
const header = schema.objectName ? resolveFieldLabel(schema.objectName, fieldName, field.label || fieldName) : field.label || fieldName;
108+
// The face is handed the header's label, as paths A-C hand it
109+
// (objectui#11689).
110+
const fieldForCell: any = field.label ? { ...translatedField, label: header } : translatedField;
111+
// A `referenceVia` pointer column (objectui#12608), as path A.
112+
const pointerFace = recordPointerFace(fieldName, fieldType, field, dataSource);
113+
return {
114+
header,
115+
accessorKey: fieldName,
116+
// Forward the field type for the type-aware inline editor.
117+
...(fieldType && { type: fieldType }),
118+
// Aligned on the RENDERER key, like paths A-C: a `text` column with
119+
// `format: 'currency'` renders as currency, so it aligns as currency.
120+
...(alignsAsNumber(rendererType, field.returnType) && { align: 'right' as const }),
121+
cell: (value: any, row: any) => pointerFace?.(row) ?? <CellRenderer value={value} field={fieldForCell} dependentValues={row} deadlineSettled={settledFor(fieldForCell, row)} inGridColumn />,
122+
sortable: field.sortable !== false,
123+
};
124+
}, [objectSchema, objectFields, resolveFieldLabel, translateOptions, schema.objectName, perms, dataSource, predicateScope]);
125+
77126
const generateColumns = useCallback((): ObjectGridColumnDraft[] => {
78127
// objectui#11815 — the host's verdict on a declared deadline's
79128
// `settledWhen` for ONE row, handed to the cell as `deadlineSettled`. The
@@ -965,47 +1014,12 @@ export function useObjectGridGenerateColumns({
9651014
}
9661015

9671016
fieldsToShow.forEach((fieldName) => {
968-
const field = objectSchema.fields?.[fieldName];
969-
if (!field) return;
970-
971-
// FLS: drop columns the current user cannot read (server-resolved
972-
// /me/permissions via checkField — the schema itself carries no
973-
// per-caller permission bits, objectstack#3661). Same gate ListView
974-
// applies to its auto-derived columns.
975-
if (perms?.isLoaded && schema.objectName
976-
&& !perms.checkField(schema.objectName, fieldName, 'read')) return;
977-
978-
// Annotated for the same reason as paths A-C (objectui#6004): `field` is
979-
// `any`, so these values have to be named before they reach a spread
980-
// below — the naming now lives on `GridCellRendering`'s `string | null`
981-
// members. `fieldType` is the DECLARED type the emit forwards to the
982-
// inline editor; the renderer comes from the `format`-promoted key, which
983-
// this path used to skip (objectui#8920).
984-
const { declaredType: fieldType, rendererType, Renderer: CellRenderer } = resolveGridCellRendering(field);
985-
const translatedField = field.options
986-
? { ...field, options: translateOptions(schema.objectName, fieldName, field.options) }
987-
: field;
988-
const header = schema.objectName ? resolveFieldLabel(schema.objectName, fieldName, field.label || fieldName) : field.label || fieldName;
989-
// The face is handed the header's label, as paths A-C hand it
990-
// (objectui#11689).
991-
const fieldForCell: any = field.label ? { ...translatedField, label: header } : translatedField;
992-
// A `referenceVia` pointer column (objectui#12608), as path A.
993-
const pointerFace = recordPointerFace(fieldName, fieldType, field, dataSource);
994-
generatedColumns.push({
995-
header,
996-
accessorKey: fieldName,
997-
// Forward the field type for the type-aware inline editor.
998-
...(fieldType && { type: fieldType }),
999-
// Aligned on the RENDERER key, like paths A-C: a `text` column with
1000-
// `format: 'currency'` renders as currency, so it aligns as currency.
1001-
...(alignsAsNumber(rendererType, field.returnType) && { align: 'right' as const }),
1002-
cell: (value: any, row: any) => pointerFace?.(row) ?? <CellRenderer value={value} field={fieldForCell} dependentValues={row} deadlineSettled={settledFor(fieldForCell, row)} inGridColumn />,
1003-
sortable: field.sortable !== false,
1004-
});
1017+
const column = synthesizeFieldColumn(fieldName);
1018+
if (column) generatedColumns.push(column);
10051019
});
10061020

10071021
return generatedColumns;
1008-
}, [objectSchema, objectFields, objectTypesPending, schemaFields, schemaColumns, dataConfig, hasInlineData, objectName, navigation.handleClick, executeAction, data, resolveFieldLabel, translateOptions, schema.objectName, perms, uiLanguage, dataSource, predicateScope, recordLinkAdornment, rowOpensRecord]);
1022+
}, [objectSchema, objectFields, objectTypesPending, schemaFields, schemaColumns, dataConfig, hasInlineData, objectName, navigation.handleClick, executeAction, data, resolveFieldLabel, translateOptions, schema.objectName, perms, uiLanguage, dataSource, predicateScope, recordLinkAdornment, rowOpensRecord, synthesizeFieldColumn]);
10091023

1010-
return { generateColumns };
1024+
return { generateColumns, synthesizeFieldColumn };
10111025
}

‎ui/packages/plugin-grid/src/objectGridRowLoad.ts‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -541,9 +541,23 @@ export function useObjectGridRowLoad({
541541
.filter((f) => isProjectableField(f, declared as Record<string, unknown>))
542542
.filter((f) => passesProjectionGate(f))
543543
: [];
544+
// objectstack#37891 — the object's `highlightFields` (ADR-0085).
545+
// A phone draws each row as a card whose amount and subtitle are
546+
// those fields, in that order, whether or not a column shows them,
547+
// so a list showing `unit_price` but not `total_price` still has
548+
// the total to put in the amount slot. Asked whatever the viewport,
549+
// like the name field: a width change must not refetch. Fetched,
550+
// never drawn as columns. The same two gates as the name field.
551+
const declaredHighlights = (resolvedSchema as { highlightFields?: unknown } | undefined)?.highlightFields;
552+
const highlightFields = declared && Array.isArray(declaredHighlights)
553+
? declaredHighlights
554+
.filter((f): f is string => typeof f === 'string' && f !== '')
555+
.filter((f) => isProjectableField(f, declared as Record<string, unknown>))
556+
.filter((f) => passesProjectionGate(f))
557+
: [];
544558
// A UNION, never an append: a grouping field that IS also a column
545559
// must not produce a duplicate `$select` entry.
546-
const extraFields = [...predicateFields, ...groupingFields, ...concurrencyFields, ...rowColorFields, ...deadlineFields, ...lockOperandFields, ...referenceViaFields, ...dependsOnFields, ...nameFields, ...recordCurrencyFields, ...quantityUnitFields];
560+
const extraFields = [...predicateFields, ...groupingFields, ...concurrencyFields, ...rowColorFields, ...deadlineFields, ...lockOperandFields, ...referenceViaFields, ...dependsOnFields, ...nameFields, ...highlightFields, ...recordCurrencyFields, ...quantityUnitFields];
547561
const withHarvestedFields = (list: any[]): any[] => {
548562
if (extraFields.length === 0) return list;
549563
const names = new Set(list.map((f: any) => columnIdentity(f)));

‎ui/packages/plugin-list/src/ListView.tsx‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4644,6 +4644,17 @@ export const ListView = React.forwardRef<ListViewHandle, ListViewProps>(({
46444644
// grid owns.
46454645
addSpeculative(declaredNameField(objectDef));
46464646

4647+
// [objectstack#37891] The object's `highlightFields` (ADR-0085). On
4648+
// a phone the grid draws each row this fetch hands it as a card
4649+
// whose amount and subtitle are those fields, in that order, whether
4650+
// or not a column shows them. Fetched, never drawn as columns; asked
4651+
// whatever the viewport, like the name field above. Through
4652+
// `addSpeculative`, like every binding here. `ObjectGrid`'s
4653+
// `getSelectFields` carries the same arm for the fetch a grouped
4654+
// grid owns.
4655+
const highlights = (objectDef as { highlightFields?: unknown } | undefined)?.highlightFields;
4656+
if (Array.isArray(highlights)) for (const f of highlights) addSpeculative(f);
4657+
46474658
for (const f of collectPredicateFieldRefs(listViewPredicates({
46484659
conditionalFormatting: schema.conditionalFormatting as unknown[] | undefined,
46494660
/**

0 commit comments

Comments
 (0)