Skip to content

Commit 6243bf8

Browse files
committed
fix(ui): a footer pick saves only the column's calculation, and is taken back when not saved
L1 7048239634 on #35919. The pick no longer materialises the reader's drawn columns into the view or appends a column the reader added: the stored view's own columns are the base, and the menu is offered on the columns the view declares only (`summaryPickFields`). A personal view writes from its stored row, so unsaved hides and order never ride along. A save the host refuses (answer false, a promise of false, or a rejection) takes the pick back; the shared save also restores the prior view draft. A shared view the console saves is named `object.key` too (`showcase_product.team_products` in the custom package), so the gate stays the overlay read's list rather than the name's shape; a view a read-only package ships is refused by the door and the pick is taken back with the refusal said, as measured in the browser. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01L6bhgVb7fsaFeMStucvNWA
1 parent cf1927d commit 6243bf8

10 files changed

Lines changed: 199 additions & 72 deletions

File tree

‎.changeset/35702-footer-calculation-row.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ Metadata-protocol: none
1212

1313
A list's table view now always ends in one footer row, aligned with the columns and held at the bottom of the table: the record count in its first cell, and under each column its calculation, if any, written as the calculation's name in the secondary text colour and the figure in the normal one, with a space and no colon (`Sum ¥1,234,500`). A `min` / `max` over a date reads Earliest / Latest. The list's own "N records" line at the foot of the page is gone from a table that draws this row; the data-cap notice stays there. A grouped table, the phone's card list and every other view type are unchanged.
1414

15-
A reader who may change the open view clicks a cell to pick the column's calculation from one menu that lists what the field type allows (sum and average on numbers and amounts, earliest and latest on dates, the counts on any field), the current one ticked and None last. The pick shows at once. The console saves it as the column's `summary` on the view: a personal view at once; a shared view, for a reader who may edit it, as a draft through the view settings' own save, which other readers see once it is published. A reader who may not change the view sees the figures and no menu.
15+
A reader who may change the open view clicks a cell to pick the column's calculation from one menu that lists what the field type allows (sum and average on numbers and amounts, earliest and latest on dates, the counts on any field), the current one ticked and None last. The pick shows at once. The console saves it as the column's `summary` on the view, and nothing else of the reader's layout: a personal view at once; a shared view the console saved, for a reader who may edit it, as a draft through the view settings' own save, which other readers see once it is published. The menu is offered on the columns the view itself declares; a column the reader added for themselves and a view that declares no columns draw the figures with no menu. A pick that is not saved is taken back, with the refusal said (a view a read-only package ships is refused this way: its changes go to the package's customization). A reader who may not change the view sees the figures and no menu.
1616

17-
New host props, all optional and never authored metadata: `ObjectGrid` takes `residentSummaryRow`, `onColumnSummaryPick(field, summary, drawnFields)` and `onResidentSummaryRowChange(drawn)`; `ListView` takes `onColumnSummaryPick`. `ColumnSummaryResult` gains `name` and `text`, the two halves of its `label`. `@object-ui/i18n` adds the `grid.summary` keys `earliest`, `latest`, `pageName`, `calculate`, `none`, `menuPercentEmpty` and `menuPercentFilled` in every pack.
17+
New host props, all optional and never authored metadata: `ObjectGrid` takes `residentSummaryRow`, `onColumnSummaryPick(field, summary)` (answer `false` to have the pick taken back), `summaryPickFields` and `onResidentSummaryRowChange(drawn)`; `ListView` takes `onColumnSummaryPick` and `columnSummaryPickFields`. `ColumnSummaryResult` gains `name` and `text`, the two halves of its `label`. `@object-ui/i18n` adds the `grid.summary` keys `earliest`, `latest`, `pageName`, `calculate`, `none`, `menuPercentEmpty` and `menuPercentFilled` in every pack.

‎content/docs/frontend/plugins/plugin-grid.mdx‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -404,9 +404,11 @@ even when nothing is declared, led by the record count. With
404404
`onColumnSummaryPick` as well (wired only for a reader who may change the view),
405405
clicking a cell opens one menu of the calculations its field type allows, the
406406
current one ticked and None last; the grid draws the pick at once and the host
407-
saves it as the column's `summary`. The console's list saves it on a personal
408-
view at once, and on a shared view as a draft that others see once it is
409-
published.
407+
saves it as the column's `summary` (an answer of `false` takes the pick back).
408+
`summaryPickFields` limits the menu to the columns the host can save. The
409+
console's list offers it on the columns the view declares and saves only the
410+
calculation: on a personal view at once, and on a shared view as a draft that
411+
others see once it is published.
410412

411413
### Keyboard navigation
412414

‎ui/packages/app-shell/src/views/ObjectView.tsx‎

Lines changed: 40 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
import type { ColumnSummary } from '@objectstack/spec/ui';
1313
import type { ListColumn } from '@object-ui/types';
14-
import { columnsWithSummary } from './columnSummaryWrite.js';
14+
import { columnsWithSummary, declaredColumnFields } from './columnSummaryWrite.js';
1515
import { useMemo, useState, useCallback, useEffect, useRef, lazy, Suspense } from 'react';
1616
import { useParams, useSearchParams, useNavigate, useLocation, useHref, createSearchParams } from 'react-router-dom';
1717
import { resolveAffordance, type FilterTokenScope, type SchemaLike } from '@object-ui/core';
@@ -824,20 +824,35 @@ function ObjectViewInner({ dataSource, objects, onEdit, externalRefreshKey }: Co
824824
activeViewId,
825825
baseView,
826826
});
827-
const handlePickPersonalViewSummary = (field: string, summary: ColumnSummary | null, drawnFields: readonly string[]) => {
828-
if (!activeView) return;
829-
const row = personalViews.views.find((v) => v.id === activeView.id);
830-
if (!row) return;
831-
const columns = columnsWithSummary(row.config.columns as ListColumn[] | string[] | undefined, field, summary, drawnFields);
832-
personalViews.update(row.id, { ...row.config, columns }).catch((err) => {
827+
// objectstack#35702 — a footer pick saves the column's calculation and
828+
// nothing else (L1 7048239634): the stored view's own columns are the
829+
// base, so the reader's unsaved hides, order or added columns never ride
830+
// along, and a column the view does not declare is not offered. Each
831+
// resolves whether the pick was saved; on `false` the grid takes it back.
832+
const personalViewRow = activeView ? personalViews.views.find((v) => v.id === activeView.id) : undefined;
833+
const handlePickPersonalViewSummary = async (field: string, summary: ColumnSummary | null): Promise<boolean> => {
834+
if (!personalViewRow) return false;
835+
const columns = columnsWithSummary(personalViewRow.config.columns as ListColumn[] | string[] | undefined, field, summary);
836+
if (!columns) return false;
837+
try {
838+
await personalViews.update(personalViewRow.id, { ...personalViewRow.config, columns });
839+
return true;
840+
} catch (err) {
833841
console.error('[ObjectView] Failed to save a footer calculation:', err);
834842
toast.error(t('form.saveError'), { description: err instanceof Error ? err.message : String(err) });
835-
});
843+
return false;
844+
}
836845
};
837-
const handlePickSharedViewSummary = (field: string, summary: ColumnSummary | null, drawnFields: readonly string[]) => {
838-
if (!activeView) return;
839-
const columns = columnsWithSummary(activeView.columns as ListColumn[] | string[] | undefined, field, summary, drawnFields);
840-
void handleViewConfigSave({ ...activeView, columns });
846+
const handlePickSharedViewSummary = async (field: string, summary: ColumnSummary | null): Promise<boolean> => {
847+
if (!activeView) return false;
848+
const columns = columnsWithSummary(activeView.columns as ListColumn[] | string[] | undefined, field, summary);
849+
if (!columns) return false;
850+
const priorDraft = viewDraft;
851+
const saved = await handleViewConfigSave({ ...activeView, columns });
852+
// The panel's save keeps a refused draft on screen (the panel stays
853+
// dirty); a refused pick is taken back instead.
854+
if (!saved) setViewDraft(priorDraft);
855+
return saved;
841856
};
842857

843858
// objectstack#29635 — creating one of the reader's own views, and Rename
@@ -1119,13 +1134,21 @@ function ObjectViewInner({ dataSource, objects, onEdit, externalRefreshKey }: Co
11191134
pickSummary: isEnvironmentList || !activeView
11201135
? undefined
11211136
: activeIsPersonal
1122-
? (canUpdatePersonalView ? handlePickPersonalViewSummary : undefined)
1123-
// Only a view the metadata door stores: a package view
1124-
// (a qualified, dotted name) or a saved one, never the
1125-
// fallback tab an object with no views is drawn with.
1126-
: isAdmin && (String(activeView.id).includes('.') || isSavedViewId(savedViews, String(activeView.id)))
1137+
? (canUpdatePersonalView && personalViewRow ? handlePickPersonalViewSummary : undefined)
1138+
// Only a view the metadata door stores (one the overlay
1139+
// read lists), never the fallback tab an object with no
1140+
// views is drawn with. Every stored view has a qualified,
1141+
// dotted name, the console's own saved views included
1142+
// (`object.key` in the custom package), so the name cannot
1143+
// tell a view a read-only package ships; the door refuses
1144+
// that save by design (it goes to the custom package) and
1145+
// the refused pick is taken back, as the panel's save is.
1146+
: isAdmin && isSavedViewId(savedViews, String(activeView.id))
11271147
? handlePickSharedViewSummary
11281148
: undefined,
1149+
summaryPickFields: declaredColumnFields(
1150+
(activeIsPersonal ? personalViewRow?.config.columns : activeView?.columns) as ListColumn[] | string[] | undefined,
1151+
),
11291152
},
11301153
});
11311154

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,35 @@
11
/** objectstack#35702 — the view's `columns` the footer menu saves. */
22
import { describe, it, expect } from 'vitest';
3-
import { columnsWithSummary } from '../columnSummaryWrite';
3+
import { columnsWithSummary, declaredColumnFields } from '../columnSummaryWrite';
44

55
describe('columnsWithSummary (objectstack#35702)', () => {
66
it('sets the calculation on the view\'s own column, in the object form', () => {
7-
expect(columnsWithSummary(['name', 'amount'], 'amount', 'sum', [])).toEqual([
7+
expect(columnsWithSummary(['name', 'amount'], 'amount', 'sum')).toEqual([
88
{ field: 'name' }, { field: 'amount', summary: 'sum' },
99
]);
1010
});
1111
it('keeps the object form\'s field override and moves only the calculation', () => {
12-
expect(columnsWithSummary([{ field: 'amount', summary: { type: 'sum', field: 'amount_base' } }], 'amount', 'avg', []))
12+
expect(columnsWithSummary([{ field: 'amount', summary: { type: 'sum', field: 'amount_base' } }], 'amount', 'avg'))
1313
.toEqual([{ field: 'amount', summary: { type: 'avg', field: 'amount_base' } }]);
1414
});
1515
it('takes the calculation off for None', () => {
16-
expect(columnsWithSummary([{ field: 'amount', label: 'Amount', summary: 'sum' }], 'amount', null, []))
16+
expect(columnsWithSummary([{ field: 'amount', label: 'Amount', summary: 'sum' }], 'amount', null))
1717
.toEqual([{ field: 'amount', label: 'Amount' }]);
1818
});
19-
it('writes the drawn columns for a view that declares none, so it keeps drawing them', () => {
20-
expect(columnsWithSummary(undefined, 'amount', 'max', ['name', 'amount'])).toEqual([
21-
{ field: 'name' }, { field: 'amount', summary: 'max' },
22-
]);
19+
// L1 7048239634: the pick writes the calculation, never the reader's layout.
20+
it('writes only the calculation: the view\'s columns stay, whatever the reader hid or added', () => {
21+
// The view declares [a, b]; the reader hid b and added c for themselves.
22+
expect(columnsWithSummary(['a', 'b'], 'a', 'sum')).toEqual([{ field: 'a', summary: 'sum' }, { field: 'b' }]);
2323
});
24-
it('appends a column the view does not list', () => {
25-
expect(columnsWithSummary(['name'], 'amount', 'sum', ['name', 'amount'])).toEqual([
26-
{ field: 'name' }, { field: 'amount', summary: 'sum' },
27-
]);
24+
it('saves nothing for a column the view does not declare', () => {
25+
expect(columnsWithSummary(['a', 'b'], 'c', 'sum')).toBeNull();
26+
});
27+
it('saves nothing on a view that declares no columns', () => {
28+
expect(columnsWithSummary(undefined, 'amount', 'max')).toBeNull();
29+
expect(columnsWithSummary([], 'amount', 'max')).toBeNull();
30+
});
31+
it('names the declared fields, in the view\'s order, for the menu offer', () => {
32+
expect(declaredColumnFields(['b', { field: 'a', summary: 'sum' }])).toEqual(['b', 'a']);
33+
expect(declaredColumnFields(undefined)).toEqual([]);
2834
});
2935
});
Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,36 @@
11
/**
22
* objectstack#35702 — a view's `columns` with one column's footer calculation
3-
* set (`null` = None), as the list's footer menu saves it on the view. The
4-
* view's own columns are the base; a view that declares none takes the columns
5-
* the grid draws, so the saved view keeps drawing them. A field the view does
6-
* not list (a column the reader added) is appended. Every entry comes back in
7-
* the object form, the one that carries `summary`.
3+
* set (`null` = None), as the list's footer menu saves it on the view. Only the
4+
* calculation moves: the view's own columns are kept, in their order, each in
5+
* the object form (`columns` is all names or all objects, never a mix, and only
6+
* the object form carries `summary`). A column the view does not declare — a column the reader
7+
* added for themselves, or any column of a view that declares none — is not
8+
* the view's to change (L1 7048239634): the answer is `null` and nothing is
9+
* saved, which is why the menu is offered on the declared columns only
10+
* ({@link declaredColumnFields}).
811
*/
912

1013
import type { ListColumn } from '@object-ui/types';
1114
import type { ColumnSummary } from '@objectstack/spec/ui';
1215

16+
type AuthoredColumns = ReadonlyArray<string | ListColumn> | undefined;
17+
18+
/** The fields of the columns a view declares, in its order. */
19+
export function declaredColumnFields(authored: AuthoredColumns): string[] {
20+
return (authored ?? [])
21+
.map((entry) => (typeof entry === 'string' ? entry : entry?.field))
22+
.filter((field): field is string => typeof field === 'string' && field.length > 0);
23+
}
24+
1325
export function columnsWithSummary(
14-
authored: ReadonlyArray<string | ListColumn> | undefined,
26+
authored: AuthoredColumns,
1527
field: string,
1628
summary: ColumnSummary | null,
17-
drawnFields: readonly string[],
18-
): ListColumn[] {
19-
const base: ReadonlyArray<string | ListColumn> = authored && authored.length > 0 ? authored : drawnFields;
20-
let found = false;
21-
const columns = base.map((entry): ListColumn => {
29+
): ListColumn[] | null {
30+
if (!declaredColumnFields(authored).includes(field)) return null;
31+
return (authored ?? []).map((entry): ListColumn => {
2232
const column: ListColumn = typeof entry === 'string' ? { field: entry } : { ...entry };
2333
if (column.field !== field) return column;
24-
found = true;
2534
if (summary === null) {
2635
delete column.summary;
2736
return column;
@@ -32,6 +41,4 @@ export function columnsWithSummary(
3241
: summary;
3342
return column;
3443
});
35-
if (!found && summary !== null) columns.push({ field, summary });
36-
return columns;
3744
}

‎ui/packages/app-shell/src/views/objectViewListRenderer.tsx‎

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,13 @@ export function useObjectViewListRenderer({
170170
rename?: (label: string) => boolean | Promise<boolean>;
171171
save?: () => void;
172172
reset?: () => void;
173-
/** objectstack#35702 — save a footer calculation on the open view (wired only for a reader who may change it). */
174-
pickSummary?: (field: string, summary: ColumnSummary | null, drawnFields: readonly string[]) => void;
173+
/**
174+
* objectstack#35702 — save a footer calculation on the open view (wired
175+
* only for a reader who may change it); resolves whether it was saved.
176+
*/
177+
pickSummary?: (field: string, summary: ColumnSummary | null) => boolean | Promise<boolean>;
178+
/** objectstack#35702 — the columns the view declares: the only ones a pick may change. */
179+
summaryPickFields?: readonly string[];
175180
};
176181
}) {
177182
// objectstack#35551 — the host hands fresh closures every render; the list
@@ -182,6 +187,8 @@ export function useObjectViewListRenderer({
182187
const offersSave = !!listViewActions?.save;
183188
const offersReset = !!listViewActions?.reset;
184189
const offersSummaryPick = !!listViewActions?.pickSummary;
190+
// Keyed on content, never the array's identity (a fresh one every render).
191+
const summaryPickKey = (listViewActions?.summaryPickFields ?? []).join('\n');
185192
// objectstack#27058 — below `sm` the title switcher is the phone's one
186193
// view control, so the list offers no layout switcher of its own there.
187194
const wideViewport = useViewTabsFit();
@@ -1048,8 +1055,9 @@ export function useObjectViewListRenderer({
10481055
onSaveView={offersSave ? () => listViewActionsRef.current?.save?.() : undefined}
10491056
onResetView={offersReset ? () => listViewActionsRef.current?.reset?.() : undefined}
10501057
onColumnSummaryPick={offersSummaryPick
1051-
? (field: string, summary: ColumnSummary | null, drawnFields: readonly string[]) => listViewActionsRef.current?.pickSummary?.(field, summary, drawnFields)
1058+
? (field: string, summary: ColumnSummary | null) => listViewActionsRef.current?.pickSummary?.(field, summary) ?? false
10521059
: undefined}
1060+
columnSummaryPickFields={offersSummaryPick ? summaryPickKey.split('\n').filter(Boolean) : undefined}
10531061
className={className}
10541062
onEdit={editHandler}
10551063
// objectui#13089 — the view's Add button is the header New:
@@ -1150,7 +1158,7 @@ export function useObjectViewListRenderer({
11501158
dataSource={ds}
11511159
/>
11521160
);
1153-
}, [activeView, activeViewDeclaresColumns, activeViewIsSaved, objectDef, objectName, refreshKey, createRecord, urlFilters, initialUfSelections, handleUserFilterSelectionsChange, writeListUrlState, listPage, user?.id, pageOffersCreate, listAddRecordOpensCreate, listIdentityKey, listPrefs.ready, listPrefs.preference, listPrefs.patchView, managedUsers, managedUserMarker, recordOpen, openAsPage, rowOpensRecord, handleListRowsChange, hasPhoneTitle, leadStore, wideViewport, handleListPersonalizationChange, workspaceTimeZone, viewPanelFilters, offersRename, offersSave, offersReset, offersSummaryPick, previewDrafts, previewDataSource, unpublishedObjects]);
1161+
}, [activeView, activeViewDeclaresColumns, activeViewIsSaved, objectDef, objectName, refreshKey, createRecord, urlFilters, initialUfSelections, handleUserFilterSelectionsChange, writeListUrlState, listPage, user?.id, pageOffersCreate, listAddRecordOpensCreate, listIdentityKey, listPrefs.ready, listPrefs.preference, listPrefs.patchView, managedUsers, managedUserMarker, recordOpen, openAsPage, rowOpensRecord, handleListRowsChange, hasPhoneTitle, leadStore, wideViewport, handleListPersonalizationChange, workspaceTimeZone, viewPanelFilters, offersRename, offersSave, offersReset, offersSummaryPick, summaryPickKey, previewDrafts, previewDataSource, unpublishedObjects]);
11541162

11551163
return { renderListView };
11561164
}

‎ui/packages/plugin-grid/README.md‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -365,13 +365,16 @@ the secondary text colour and the figure in the normal one (`Sum 1,234.00`).
365365
A grouped grid and the phone's card list draw no such row; the grid reports
366366
whether it drew one through `onResidentSummaryRowChange`.
367367

368-
A host that also passes `onColumnSummaryPick(field, summary, drawnFields)`
368+
A host that also passes `onColumnSummaryPick(field, summary)`
369369
(wire it only for a reader who may change the view) turns each cell into a
370370
menu of the calculations the column's field type allows — `sum`/`avg` on
371371
numbers and amounts, `min`/`max` on numbers and dates (named Earliest and
372372
Latest on a date), the count family on any field, the current one ticked and
373-
None last. The grid draws a pick at once; the host saves it as the column's
374-
`summary` and hands the view back.
373+
None last. `summaryPickFields` limits the menu to the columns the host can
374+
save (the console passes the columns the view itself declares); the other cells
375+
draw their figure only. The grid draws a pick at once; the host saves it as the
376+
column's `summary` and hands the view back, or answers `false` (or a promise of
377+
it) when it did not, and the grid takes the pick back.
375378

376379
A cell counts as empty when it is `null`, `undefined`, `""` or an empty array,
377380
so an unset multi-select or lookup reads as empty rather than as a filled `[]`.

0 commit comments

Comments
 (0)