Skip to content

Commit ad2d94c

Browse files
committed
fix(ui): a pickable footer figure follows its column's alignment
L1 7049007771 on #35919. The picker's trigger is a flex box, which the cell's `text-align` does not move, so a right-aligned amount's figure was drawn at the column's left edge. It is now justified from the column's `align`, and its menu opens from the same edge. The changeset says what a shared view's draft save does to the drawn pick until it is published (#35932). Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01L6bhgVb7fsaFeMStucvNWA
1 parent 6243bf8 commit ad2d94c

5 files changed

Lines changed: 28 additions & 6 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
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, 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.
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 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 comes back once the draft is published, for every reader (#35932). 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

1717
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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -407,8 +407,8 @@ current one ticked and None last; the grid draws the pick at once and the host
407407
saves it as the column's `summary` (an answer of `false` takes the pick back).
408408
`summaryPickFields` limits the menu to the columns the host can save. The
409409
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.
410+
calculation: on a personal view at once, and on a shared view as a draft, which
411+
the list draws, for the editor and everyone else, once it is published.
412412

413413
### Keyboard navigation
414414

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3061,6 +3061,7 @@ export const ObjectGrid: React.FC<ObjectGridComponentProps> = ({
30613061
current={summaryTypes.get(field)}
30623062
offered={offeredColumnSummaries(def)}
30633063
temporal={isTemporalSummaryField(def)}
3064+
align={(col as { align?: 'left' | 'center' | 'right' }).align}
30643065
onPick={onColumnSummaryPick && def && (!pickableSummaryFields || pickableSummaryFields.has(field))
30653066
? pickColumnSummary
30663067
: undefined}

‎ui/packages/plugin-grid/src/__tests__/footerCalculationPicker-35702.test.tsx‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,4 +201,18 @@ describe('the resident footer row (objectstack#35702)', () => {
201201
await new Promise((r) => setTimeout(r, 20));
202202
expect(screen.getByTestId('summary-picker-amount')).toHaveTextContent('Sum 350');
203203
});
204+
205+
// L1 7049007771: the trigger is a flex box, which the cell's text-align does
206+
// not move; a right-aligned amount's figure ends under the amounts.
207+
it('justifies the cell from its column\'s alignment', async () => {
208+
renderGrid({ residentSummaryRow: true, onColumnSummaryPick: vi.fn() }, [
209+
{ field: 'name', label: 'Name' },
210+
{ field: 'amount', label: 'Amount', align: 'right', summary: 'sum' },
211+
{ field: 'due', label: 'Due', align: 'center' },
212+
]);
213+
await screen.findByTestId('data-table-summary-row');
214+
expect(screen.getByTestId('summary-picker-amount')).toHaveClass('justify-end');
215+
expect(screen.getByTestId('summary-picker-due')).toHaveClass('justify-center');
216+
expect(screen.getByTestId('summary-picker-name')).toHaveClass('justify-start');
217+
});
204218
});

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ export interface SummaryCellPickerProps {
3636
offered: ReadonlyArray<ColumnSummaryType>;
3737
/** The column's field is a date or time (its min / max read Earliest / Latest). */
3838
temporal: boolean;
39+
/**
40+
* The column's alignment, as its cells take it. The trigger is a flex box,
41+
* which the cell's `text-align` does not move, so the figure is justified
42+
* from this (a right-aligned amount's sum ends under the amounts).
43+
*/
44+
align?: 'left' | 'center' | 'right';
3945
/** Wired only for a reader who may change the view. `null` = None. */
4046
onPick?: (field: string, summary: ColumnSummaryType | null) => void;
4147
t: SummaryTranslate;
@@ -50,7 +56,7 @@ function Figure({ figure }: { figure: SummaryCellFigure }) {
5056
);
5157
}
5258

53-
export function SummaryCellPicker({ field, figure, current, offered, temporal, onPick, t }: SummaryCellPickerProps) {
59+
export function SummaryCellPicker({ field, figure, current, offered, temporal, align, onPick, t }: SummaryCellPickerProps) {
5460
if (!onPick) return figure ? <Figure figure={figure} /> : null;
5561
const active = current && current !== 'none' ? current : undefined;
5662
return (
@@ -61,7 +67,8 @@ export function SummaryCellPicker({ field, figure, current, offered, temporal, o
6167
data-testid={`summary-picker-${field}`}
6268
aria-label={figure ? figure.label : t('grid.summary.calculate')}
6369
className={cn(
64-
'group/summary flex h-8 w-full min-w-0 items-center gap-1 rounded-sm [text-align:inherit] [justify-content:inherit]',
70+
'group/summary flex h-8 w-full min-w-0 items-center gap-1 rounded-sm [text-align:inherit]',
71+
align === 'right' ? 'justify-end' : align === 'center' ? 'justify-center' : 'justify-start',
6572
'hover:bg-muted/60 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring',
6673
)}
6774
>
@@ -77,7 +84,7 @@ export function SummaryCellPicker({ field, figure, current, offered, temporal, o
7784
)}
7885
</button>
7986
</DropdownMenuTrigger>
80-
<DropdownMenuContent align="start" className="min-w-[10rem]" data-testid={`summary-menu-${field}`}>
87+
<DropdownMenuContent align={align === 'right' ? 'end' : align === 'center' ? 'center' : 'start'} className="min-w-[10rem]" data-testid={`summary-menu-${field}`}>
8188
{offered.map((summary) => (
8289
<DropdownMenuItem
8390
key={summary}

0 commit comments

Comments
 (0)