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
17 changes: 17 additions & 0 deletions .changeset/35702-footer-calculation-row.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
'@object-ui/plugin-grid': patch
'@object-ui/plugin-list': patch
'@object-ui/app-shell': patch
'@object-ui/i18n': patch
---

feat(ui): a resident footer row on list tables, where a reader who may change the view picks each column's calculation

Clause-②: yes (widening)
Metadata-protocol: none

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.

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 console saves it as the column's `summary` on the view, and nothing else of the reader's layout. On a personal view it is saved at once and stays drawn. On a shared view the console saved, a reader who may edit it saves it as a draft through the view settings' own save: the draft save reloads the list, which then draws the published view again, so the pick shows for a moment and is drawn again, for every reader, once the draft is published. Until #35932, each pick's draft is built on the published view, so a second pick before Publish replaces the first in the draft: only the latest pick 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.

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.
14 changes: 14 additions & 0 deletions content/docs/frontend/plugins/plugin-grid.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,20 @@ row whose new value would sort it elsewhere stays in place until the next load
an open editor Ctrl+Z stays the editor's own text undo. A save of a field the
row did not read offers no Undo.

### Footer calculations

A column's `summary` draws its calculation in the table's last row, under the
column. A host that passes `residentSummaryRow` draws that row on a flat table
even when nothing is declared, led by the record count. With
`onColumnSummaryPick` as well (wired only for a reader who may change the view),
clicking a cell opens one menu of the calculations its field type allows, the
current one ticked and None last; the grid draws the pick at once and the host
saves it as the column's `summary` (an answer of `false` takes the pick back).
`summaryPickFields` limits the menu to the columns the host can save. The
console's list offers it on the columns the view declares and saves only the
calculation: on a personal view at once, and on a shared view as a draft, which
the list draws, for the editor and everyone else, once it is published.

### Keyboard navigation

`keyboardNavigation` turns the grid's data cells into one roving Tab stop, on the
Expand Down
8 changes: 4 additions & 4 deletions ui/e2e/list-condition-row-35549.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import { uiRoot } from '../scripts/ui-root.mjs';
*
* - The data source is in memory: one object definition and twelve records.
* It records every `find` it is asked, and answers the stage filter
* (`in`) and the sort the list sends, so the count bar and the row order
* (`in`) and the sort the list sends, so the footer row's count and the row order
* move as they do against a server.
* - The translator is the English defaults table (no provider).
* - Animations are off, so a closed popover leaves the page at once rather
Expand Down Expand Up @@ -256,7 +256,7 @@ async function mount(page: Page): Promise<void> {
await page.goto('http://localhost/list-condition-row');
await page.addScriptTag({ content: bundle, type: 'module' });
await page.getByTestId('toolbar-filter-trigger').waitFor({ state: 'attached', timeout: 30_000 });
await page.getByTestId('record-count-bar').waitFor({ state: 'attached', timeout: 30_000 });
await page.getByTestId('data-table-summary-lead').waitFor({ state: 'attached', timeout: 30_000 });
await style(page);
}

Expand All @@ -268,8 +268,8 @@ async function click(page: Page, testId: string): Promise<void> {

const slot = (page: Page) => page.getByTestId('list-condition-row');
const slotHeight = (page: Page) => slot(page).evaluate((el) => el.getBoundingClientRect().height);
/** The number the count bar reads, once the list has answered. */
const count = async (page: Page) => (await page.getByTestId('record-count-bar').textContent())?.match(/\d+/)?.[0];
/** The number the grid's footer row leads with (objectstack#35702), once the list has answered. */
const count = async (page: Page) => (await page.getByTestId('data-table-summary-lead').textContent())?.match(/\d+/)?.[0];
const sortNow = (page: Page) =>
page.evaluate(() => (window as unknown as { __sort: Array<{ field: string; order: string }> }).__sort.map((s) => `${s.field}:${s.order}`));

Expand Down
4 changes: 2 additions & 2 deletions ui/e2e/live/saved-view-filter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { test, expect } from '@playwright/test';
* `showcase_task.in_progress` is a SHIPPED saved view whose stored filter is
* exactly that rule array (`src/ui/views/task.view.ts`), so no fixture setup is
* needed — opening it is the reproduction. Before the fix the list renders no
* rows at all (the request 400s, so `record-count-bar` never mounts); after it,
* rows at all (the request 400s, so the footer row's count never mounts); after it,
* the 2 in-progress tasks out of 10.
*
* Prereqs: the usual live-e2e pair (see playwright.live.config.ts). Run:
Expand Down Expand Up @@ -60,7 +60,7 @@ test('a saved view filter reaches $filter as AST, and the server answers 200', a
await page.goto(`/apps/${APP}/showcase_task/view/showcase_task.in_progress`);

// The filter applied: 2 of the 10 seeded tasks are in_progress.
await expect(page.getByTestId('record-count-bar')).toContainText(/^2 /, { timeout: 20000 });
await expect(page.getByTestId('data-table-summary-lead')).toContainText(/^2 /, { timeout: 20000 });

// And it applied by being ACCEPTED, not by some later rescue.
expect(refused, `data requests the backend refused:\n${refused.join('\n')}`).toEqual([]);
Expand Down
8 changes: 4 additions & 4 deletions ui/e2e/live/user-filters.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ test.describe('ADR-0053 interface mode — Task Triage tabs element', () => {
// Picking a tab filters the grid and mirrors into the URL.
await urgentTab.click();
await expect(page).toHaveURL(/uf__tab=urgent/);
await expect(page.getByTestId('record-count-bar')).toContainText(/^2 /, { timeout: 15000 });
await expect(page.getByTestId('data-table-summary-lead')).toContainText(/^2 /, { timeout: 15000 });

// Reload: the tab selection and its filter survive.
await page.reload();
await expect(page).toHaveURL(/uf__tab=urgent/);
await expect(page.getByTestId('record-count-bar')).toContainText(/^2 /, { timeout: 15000 });
await expect(page.getByTestId('data-table-summary-lead')).toContainText(/^2 /, { timeout: 15000 });
});
});

Expand Down Expand Up @@ -105,7 +105,7 @@ test.describe('ADR-0047 interface mode — Task Workbench', () => {
// Select Urgent: the grid narrows and the URL picks up the selection.
await options.getByText('Urgent').click();
await expect(page).toHaveURL(/uf_priority=urgent/);
await expect(page.getByTestId('record-count-bar')).toContainText(/^2 /, { timeout: 15000 });
await expect(page.getByTestId('data-table-summary-lead')).toContainText(/^2 /, { timeout: 15000 });

// Counts snapshot: with Urgent active the OTHER options keep their
// pre-selection counts instead of collapsing to 0 (the server already
Expand All @@ -123,6 +123,6 @@ test.describe('ADR-0047 interface mode — Task Workbench', () => {
await page.reload();
await expect(page).toHaveURL(/uf_priority=urgent/);
await expect(page.getByTestId('filter-badge-priority')).toContainText('1');
await expect(page.getByTestId('record-count-bar')).toContainText(/^2 /, { timeout: 15000 });
await expect(page.getByTestId('data-table-summary-lead')).toContainText(/^2 /, { timeout: 15000 });
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,12 @@ async function footer(lang: Lang, count: number): Promise<string> {
</I18nProvider>,
);
await screen.findByRole('dialog', undefined, { timeout: 5000 });
const bar = await screen.findByTestId('record-count-bar', undefined, { timeout: 5000 });
// The split pane's footer is gone: the bar is the one count on the page.
// objectstack#35702 — the grid's footer row leads with the count, the one
// count at the foot of the page: no split-pane footer, no count bar.
const lead = await screen.findByTestId('data-table-summary-lead', undefined, { timeout: 5000 });
expect(screen.queryByTestId('record-count-footer')).toBeNull();
const text = bar.querySelector('span')?.textContent ?? '';
expect(screen.queryByTestId('record-count-bar')).toBeNull();
const text = lead.textContent ?? '';
cleanup();
return text;
}
Expand Down Expand Up @@ -335,8 +337,8 @@ describe('a list page load reads its object once, and the bar counts that answer
render(<Harness />);
const reads = () => find.mock.calls.filter(([object]) => object === OBJECT_NAME);
const barCount = async () =>
(await screen.findByTestId('record-count-bar', undefined, { timeout: 5000 })).querySelector('span')
?.textContent ?? '';
// objectstack#35702 — the count leads the grid's footer row.
(await screen.findByTestId('data-table-summary-lead', undefined, { timeout: 5000 })).textContent ?? '';
return { reads, barCount, bump: () => act(async () => { bump(); }) };
}

Expand Down
57 changes: 56 additions & 1 deletion ui/packages/app-shell/src/views/ObjectView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
* - ListView delegation for non-grid view types (kanban, calendar, chart, etc.)
*/

import type { ColumnSummary } from '@objectstack/spec/ui';
import type { ListColumn } from '@object-ui/types';
import { columnsWithSummary, declaredColumnFields } from './columnSummaryWrite.js';
import { useMemo, useState, useCallback, useEffect, useRef, lazy, Suspense } from 'react';
import { useParams, useSearchParams, useNavigate, useLocation, useHref, createSearchParams } from 'react-router-dom';
import { resolveAffordance, type FilterTokenScope, type SchemaLike } from '@object-ui/core';
Expand Down Expand Up @@ -56,7 +59,7 @@ import { useRecordOpenPreference } from '../utils/recordOpenPreference.js';
import { usePhoneViewport } from '../hooks/usePhoneViewport.js';
import { LIST_PINNED_VIEW_PREFERENCE, objectPreferenceScope, useWorkspacePreference } from '../utils/workspacePreference.js';
import type { ListViewProps } from '@object-ui/plugin-list';
import { defaultListViewId, viewRowId } from '../utils/viewIdentity.js';
import { defaultListViewId, isSavedViewId, viewRowId } from '../utils/viewIdentity.js';
import { useObjectActions } from '../hooks/useObjectActions.js';
import { useObjectTranslation, useObjectLabel } from '@object-ui/i18n';
import { usePermissions } from '@object-ui/permissions';
Expand Down Expand Up @@ -821,6 +824,36 @@ function ObjectViewInner({ dataSource, objects, onEdit, externalRefreshKey }: Co
activeViewId,
baseView,
});
// objectstack#35702 — a footer pick saves the column's calculation and
// nothing else (L1 7048239634): the stored view's own columns are the
// base, so the reader's unsaved hides, order or added columns never ride
// along, and a column the view does not declare is not offered. Each
// resolves whether the pick was saved; on `false` the grid takes it back.
const personalViewRow = activeView ? personalViews.views.find((v) => v.id === activeView.id) : undefined;
const handlePickPersonalViewSummary = async (field: string, summary: ColumnSummary | null): Promise<boolean> => {
if (!personalViewRow) return false;
const columns = columnsWithSummary(personalViewRow.config.columns as ListColumn[] | string[] | undefined, field, summary);
if (!columns) return false;
try {
await personalViews.update(personalViewRow.id, { ...personalViewRow.config, columns });
return true;
} catch (err) {
console.error('[ObjectView] Failed to save a footer calculation:', err);
toast.error(t('form.saveError'), { description: err instanceof Error ? err.message : String(err) });
return false;
}
};
const handlePickSharedViewSummary = async (field: string, summary: ColumnSummary | null): Promise<boolean> => {
if (!activeView) return false;
const columns = columnsWithSummary(activeView.columns as ListColumn[] | string[] | undefined, field, summary);
if (!columns) return false;
const priorDraft = viewDraft;
const saved = await handleViewConfigSave({ ...activeView, columns });
// The panel's save keeps a refused draft on screen (the panel stays
// dirty); a refused pick is taken back instead.
if (!saved) setViewDraft(priorDraft);
return saved;
};

// objectstack#29635 — creating one of the reader's own views, and Rename
// and Delete on them. Creating is offered to any reader the server lets
Expand Down Expand Up @@ -1094,6 +1127,28 @@ function ObjectViewInner({ dataSource, objects, onEdit, externalRefreshKey }: Co
: undefined,
save: !isEnvironmentList && canUpdatePersonalView && listPersonalizedParts.length > 0 ? () => { void handleSaveToPersonalView(); } : undefined,
reset: !isEnvironmentList && listPersonalizedParts.length > 0 ? handleResetView : undefined,
// objectstack#35702 — the footer's calculation, saved on the open
// view (ruling 7045525672): a personal view at once; a shared one,
// by a reader who may edit it, as a draft through the view panel's
// save, which others see once published.
pickSummary: isEnvironmentList || !activeView
? undefined
: activeIsPersonal
? (canUpdatePersonalView && personalViewRow ? handlePickPersonalViewSummary : undefined)
// Only a view the metadata door stores (one the overlay
// read lists), never the fallback tab an object with no
// views is drawn with. Every stored view has a qualified,
// dotted name, the console's own saved views included
// (`object.key` in the custom package), so the name cannot
// tell a view a read-only package ships; the door refuses
// that save by design (it goes to the custom package) and
// the refused pick is taken back, as the panel's save is.
: isAdmin && isSavedViewId(savedViews, String(activeView.id))
? handlePickSharedViewSummary
: undefined,
summaryPickFields: declaredColumnFields(
(activeIsPersonal ? personalViewRow?.config.columns : activeView?.columns) as ListColumn[] | string[] | undefined,
),
},
});

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/** objectstack#35702 — the view's `columns` the footer menu saves. */
import { describe, it, expect } from 'vitest';
import { columnsWithSummary, declaredColumnFields } from '../columnSummaryWrite';

describe('columnsWithSummary (objectstack#35702)', () => {
it('sets the calculation on the view\'s own column, in the object form', () => {
expect(columnsWithSummary(['name', 'amount'], 'amount', 'sum')).toEqual([
{ field: 'name' }, { field: 'amount', summary: 'sum' },
]);
});
it('keeps the object form\'s field override and moves only the calculation', () => {
expect(columnsWithSummary([{ field: 'amount', summary: { type: 'sum', field: 'amount_base' } }], 'amount', 'avg'))
.toEqual([{ field: 'amount', summary: { type: 'avg', field: 'amount_base' } }]);
});
it('takes the calculation off for None', () => {
expect(columnsWithSummary([{ field: 'amount', label: 'Amount', summary: 'sum' }], 'amount', null))
.toEqual([{ field: 'amount', label: 'Amount' }]);
});
// L1 7048239634: the pick writes the calculation, never the reader's layout.
it('writes only the calculation: the view\'s columns stay, whatever the reader hid or added', () => {
// The view declares [a, b]; the reader hid b and added c for themselves.
expect(columnsWithSummary(['a', 'b'], 'a', 'sum')).toEqual([{ field: 'a', summary: 'sum' }, { field: 'b' }]);
});
it('saves nothing for a column the view does not declare', () => {
expect(columnsWithSummary(['a', 'b'], 'c', 'sum')).toBeNull();
});
it('saves nothing on a view that declares no columns', () => {
expect(columnsWithSummary(undefined, 'amount', 'max')).toBeNull();
expect(columnsWithSummary([], 'amount', 'max')).toBeNull();
});
it('names the declared fields, in the view\'s order, for the menu offer', () => {
expect(declaredColumnFields(['b', { field: 'a', summary: 'sum' }])).toEqual(['b', 'a']);
expect(declaredColumnFields(undefined)).toEqual([]);
});
});
44 changes: 44 additions & 0 deletions ui/packages/app-shell/src/views/columnSummaryWrite.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**
* objectstack#35702 — a view's `columns` with one column's footer calculation
* set (`null` = None), as the list's footer menu saves it on the view. Only the
* calculation moves: the view's own columns are kept, in their order, each in
* the object form (`columns` is all names or all objects, never a mix, and only
* the object form carries `summary`). A column the view does not declare — a column the reader
* added for themselves, or any column of a view that declares none — is not
* the view's to change (L1 7048239634): the answer is `null` and nothing is
* saved, which is why the menu is offered on the declared columns only
* ({@link declaredColumnFields}).
*/

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

type AuthoredColumns = ReadonlyArray<string | ListColumn> | undefined;

/** The fields of the columns a view declares, in its order. */
export function declaredColumnFields(authored: AuthoredColumns): string[] {
return (authored ?? [])
.map((entry) => (typeof entry === 'string' ? entry : entry?.field))
.filter((field): field is string => typeof field === 'string' && field.length > 0);
}

export function columnsWithSummary(
authored: AuthoredColumns,
field: string,
summary: ColumnSummary | null,
): ListColumn[] | null {
if (!declaredColumnFields(authored).includes(field)) return null;
return (authored ?? []).map((entry): ListColumn => {
const column: ListColumn = typeof entry === 'string' ? { field: entry } : { ...entry };
if (column.field !== field) return column;
if (summary === null) {
delete column.summary;
return column;
}
// The object form keeps its `field` override; only the calculation moves.
column.summary = typeof column.summary === 'object' && column.summary !== null
? { ...column.summary, type: summary }
: summary;
return column;
});
}
Loading
Loading