Repository navigation
feat(core): add useTableGroupedRows plugin - #3763
Conversation
Groups a flat data array into collapsible section rows. Each distinct
groupBy value becomes a full-width section-header row with a chevron
toggle, group label, and member count; collapsing hides that group's rows
while keeping the header visible.
- Mirrors useTableRowExpansionState: consumer owns the collapsedGroups set;
the hook returns {data, plugin, getRowKey} — pass to Table data/plugins/idKey.
- Supports renderGroupHeader (custom header content) and groupOrder.
- Synthetic header rows are Proxy-wrapped so user cell renderers can't throw
on them before transformBodyRow replaces the row with a full-width cell.
- Storybook stories (default, initially-collapsed, custom order/header),
docsite hook doc + example block, unit tests, and a Table Lab toggle.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
It generally is looking really good. Just a few small details:
1. Can we use the chevron icon standalone and not in a button so the icon aligns with the start of the table
2. Add a divider line below the grouped row.
3. Grouped row label should use emphasized body and not a larger text size.
A reference for visual can be found here: https://astryx.atmeta.com/templates?preview=table-grouped |
| collapsedGroups, | ||
| onToggleGroup, | ||
| renderGroupHeader, | ||
| getRowKey: getRowKeyProp, |
There was a problem hiding this comment.
I've been trying avoid needing to create too many callbacks so the table accepts an idKey which can optionally be a getter. Think we could match the shape here?
There was a problem hiding this comment.
Matched the shape — the config still takes getRowKey (a getter), and the result now exposes it as idKey so it lines up with <Table idKey={...}> (see the sibling comment). Kept it a single getter rather than string-or-getter since the plugin injects synthetic header rows that need custom keying, so a plain property key wouldn't cover them.
| return out; | ||
| }, [data, groupBy, collapsedGroups, groupOrder]); | ||
|
|
||
| const getRowKey = useCallback( |
There was a problem hiding this comment.
For parallelism with Table we could name this idKey in the output:
const groupedRows = useTableGroupedRows(...);
<Table idKey={groupedRows.idKey} .../>
// vs
<Table idKey={groupedRows.getRowKey} .../>
There was a problem hiding this comment.
Done — renamed the result field getRowKey → idKey, so it now reads <Table idKey={grouped.idKey} … />. Updated the stories, block template, Table Lab, and docs to match.
Address review feedback (cixzhang, ernestt) and self-review findings:
- Rename result field getRowKey -> idKey for parallelism with the Table prop
(cixzhang): <Table idKey={grouped.idKey} />. Config input stays `getRowKey`.
- Fix O(n^2) row keying (self-review): the positional fallback used
flattened.indexOf(item) per row. Prebuild an item->index Map once per
flattened array so key lookup is O(1) — O(n^2) -> O(n) for the whole table.
- Chevron alignment (ernestt meta#1): the chevron is a standalone, chrome-less
button flush with the table's leading edge (no heavy button background),
still keyboard-operable; the whole header row remains a click convenience.
- Divider (ernestt meta#2): add a bottom border beneath each group header row.
- Typography (ernestt meta#3): the group label uses emphasized body (semibold at
body size), not a larger text size; count is regular weight.
- Tests (10, all green): add renderGroupHeader coverage, empty-data,
collapse-persistence-across-data-change (count updates, stays collapsed),
toggle-and-back, aria-expanded on the header row, and a named keyboard-
operable toggle button.
Tags: ai-generated
This diff was generated with AI assistance (Navi). The implementation and
tests were produced by an AI agent; the human author reviewed and approved
the changes.
|
Thanks Ernest — all three addressed:
Matched against the reference template. Kept in draft for another look. |
PR Analysis ReportNo new or modified components detected. Bundle Size Summary
Accessibility AuditStatus: No accessibility violations detected. Generated by PR Enrichment workflow | View full report |
Resolves the transforms/v0.1.5/index.mjs add/add collision with the Switch labelSpacing codemod (meta#3881). Core 0.1.5 and 0.1.6 have since released, so the tableProps codemod moves to transforms/v0.1.7/ (registry entry, registry test, and doc comments renamed to match) and v0.1.5/ is kept exactly as it shipped on main. Also updates the new useTableGroupedRows plugin (meta#3763, added on main after this branch) to this PR's renamed row-transform contract (styles -> xstyle), fixing its 8 tests against the merged tree.

What
Adds
useTableGroupedRows— groups a flat data array into collapsible section rows.Design
groupByvalue becomes a full-width section-header row with a chevron toggle, the group label, and a member count. Collapsing hides that group's data rows while keeping the header visible.useTableRowExpansionState: the consumer owns thecollapsedGroupsset; the hook returns{data, plugin, getRowKey}— pass to<Table>data/plugins/idKeyrespectively.item.name.toUpperCase()) resolves to''instead of throwing — BaseTable evaluatesrenderCell(item)on every row beforetransformBodyRowcan replace the header's cells with a single full-width cell.renderGroupHeader(groupKey, count, collapsed)for custom header content;groupOrderto pin specific groups first.Includes
Core/TableGroupedRows):Default,InitiallyCollapsed,CustomOrderAndHeader.useTableGroupedRowshook page + a "Collapsible Groups" example block.groupOrder.Validation