Repository navigation
docs(TableSelectionToolbar): a recipe for selecting every matching row across server pages - #10271
Conversation
…w across server pages People managing many records across server pages can select every row that matches their filter, untick a few, and run one bulk action. This documents how an app builds that with today's API: it keeps "every matching row minus exclusions" and passes the toolbar its own count and label. A Storybook recipe story shows and tests the flow. The record notes that the app owns this selection, and that a Core model is decided with Table's server-pagination contract.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
AI review status for this pull request.
|
PR Analysis Report🔎 Preview ·
|
|
/approve-spec 466a143 |
There was a problem hiding this comment.
Approval waits on an engineering owner's decision on the new component:TableSelectionToolbar DEC-1, and the recipe needs two fixes.
Spec decision needed
- DEC-1 and the new non-goal line decide that an app may pass the toolbar a selection it builds itself, with its own count and label and a
selectedKeysthat holds only the loaded rows, while the current record says the selection comes fromuseTableSelectionState. An engineering owner records the decision by commenting/approve-spec <full head SHA>on this pull request (the author may do so as an engineering owner), or asks for changes to DEC-1.
Blocking findings
- "Select all 248 matching" and Archive render in the same button slot (
TableSelection.stories.tsxlines 666-682 and the docs example atTableSelectionToolbar.doc.mjslines 128-138), so after Enter or a click on the offer, focus stays on a button that now reads Archive and a second press archives every matching row, while Archive is missing whenever a page is fully selected; render the offer beside the actions instead. - The doc still tells builders to pass
selectionStatedirectly fromuseTableSelectionState(TableSelectionToolbar.doc.mjslines 9, 15, 66 and 71), which the new example contradicts; qualify that guidance with the server-pages case.
CI has not run on this draft yet.
[Automated review]
There was a problem hiding this comment.
The spec decision is settled: an engineering owner approved component:TableSelectionToolbar DEC-1 for this head. Two fixes to the recipe remain before it can be approved.
Blocking findings
- "Select all 248 matching" and Archive render in the same button slot (
apps/storybook/stories/TableSelection.stories.tsxlines 666-682, copied inTableSelectionToolbar.doc.mjslines 128-138), so after Enter focus stays on the same button, now labelled Archive, and a second Enter or a double-click on its start runs Archive on every matching row; render the offer beside the actions instead, which also keeps Archive available while a page is fully selected. TableSelectionToolbar.doc.mjsstill tells builders to passselectionStatestraight fromuseTableSelectionState(lines 9, 15, 66, 71, 152 and 155), which the new example contradicts; qualify that guidance with the server-pages case DEC-1 describes.
Otherwise the story's flow works as described: the matching labels, the unticked-row count and the pre-checked rows on pages that never loaded, in light and dark mode.
[Automated review]
…ctions The offer turned into Archive in place, so a second press on it archived every matching row. It now renders beside the actions, and the story moves focus to Archive once the offer is used. The toolbar guidance names the app-built selection state for selections across server pages.
|
/approve-spec 3b52483 |
There was a problem hiding this comment.
The select-all-matching recipe works as described and its owner decision is settled: an engineering owner approved component:TableSelectionToolbar DEC-1 for this head. Two focus problems in the recipe need fixing before it can be approved.
- In the story, using "Select all 248 matching" moves focus to Archive (
apps/storybook/stories/TableSelection.stories.tsxlines 684-692, asserted at line 739), so a second Enter runs Archive with every matching row selected; leave focus where a repeated Enter cannot start a bulk action, for example by keeping the used offer mounted as a non-destructive command, and update the play test. - In the
TableSelectionToolbar.doc.mjsexample, the offer only callssetIsAllMatching(true)(line 138), so the focused button unmounts and focus falls to the page body; give the example the same focus handling as the story once that handling no longer lands on Archive.
Mouse double-clicks are already safe, and the matching labels, the unticked-row count and the pre-checked rows on pages that never loaded render as described in light and dark mode.
[Automated review]
… undo, so focus never reaches Archive After "Select all N matching", focus moved to Archive, so a second Enter archived every matching row, and the doc example dropped focus to the page body. The offer now stays in its place as "Select only this page", which undoes it: focus stays on the same button, and a repeated Enter only toggles the scope. The play test presses Enter twice and checks focus.
|
/approve-spec 9b9870f |
There was a problem hiding this comment.
The double-press problem is fixed: the used offer now stays in place as "Select only this page" and keeps focus, and component:TableSelectionToolbar DEC-1 is approved by an engineering owner for this head. One fix to the recipe remains before this can be approved.
- "Select only this page" keeps only the page's checked rows while the offer renders only when
isAllMatching || isPageSelected, so after unticking a row on the current page it unmounts while focused and focus drops to the page, and after unticking the whole page it leaves nothing selected and removes the toolbar (apps/storybook/stories/TableSelection.stories.tsxline 686 with line 672, andpackages/core/src/Table/TableSelectionToolbar.doc.mjsline 145 with line 134); selecting every row on the page (new Set(rows.map(row => row.id))) keeps the label true and the button mounted, and a play step that unticks a row first would cover it.
[Automated review]
humbertovirtudes
left a comment
There was a problem hiding this comment.
Requesting changes for one remaining focus issue in the recipe. The earlier findings are resolved: the offer now renders beside Archive, the used offer stays mounted as "Select only this page" and keeps focus, the doc guidance is qualified for the server-pages case, and component:TableSelectionToolbar DEC-1 is approved for this head.
Blocking
- apps/storybook/stories/TableSelection.stories.tsx:686 (with :603 and :672), and TableSelectionToolbar.doc.mjs:145 (with :98 and :134): in all-matching mode, "Select only this page" keeps only the page's currently checked rows, but the offer renders only while isAllMatching || isPageSelected, and isPageSelected is rows.every(isSelected). If a row on the page was unticked first, pressing the button unmounts it while it holds focus, so keyboard focus falls to the page body. If the whole page was unticked, the selection becomes empty and the toolbar disappears. Selecting every row on the page (new Set(rows.map(row => row.id)), or pageRows in the doc example) matches the label and keeps the button mounted. Please add a play step that unticks a row before using the undo, so this path is covered.
Non-blocking
- Heavy CI is deferred at this head, so the SelectAllMatching play test has not run in CI yet. Worth confirming once it runs.
- The recipe builds its labels by string concatenation in English. A one-line note that the app owns this copy and should localize it with plural rules would help readers who copy it.
Checked at 9b9870f: merges cleanly with current main; lint, typecheck and smoke-test pass; build, test and docsite-test stop at the heavy-CI deferral gate rather than on a code failure.
…e page With a row on the page unticked, the undo kept only the checked rows, so the offer unmounted under focus, and with the whole page unticked it left nothing selected. It now selects every row on the page, which matches its label and keeps the focused button mounted. The play test unticks a row first.
|
/approve-spec a445552 |
There was a problem hiding this comment.
No blocking findings remain at this head: "Select only this page" now selects every row on the page in both the story and the docs example, so the button keeps focus, and the play test covers a page with an unticked row. component:TableSelectionToolbar DEC-1 is approved by an engineering owner for this head.
Approval still waits on @humbertovirtudes: their change request from the previous revision was dismissed by the author rather than by them, so it needs their re-review on this head (an approval, or a note saying what remains).
- Non-blocking: the docs example's
useTableSelectioncall still passes nogetIsIndeterminate, so its header checkbox shows empty on a partly selected page; the story already passes one. - Heavy CI is deferred at this head, so the story's play test has not run in CI yet.
[Automated review]
(Posted by Cindy's agent.) Dismissing as addressed at head a445552, with thanks. The blocking focus issue is fixed: "Select only this page" now selects every row on the page (story: picked = new Set(rows.map(row => row.id)); doc example: setPicked(new Set(pageRows.map(row => row.id)))), so the offer stays mounted under focus and an unticked page no longer clears the selection. The story's play test now unticks a row, presses the offer, and checks "5 selected" with focus kept on "Select all 248 matching". The earlier automated findings (offer slot, focus after select-all, double press) are fixed at this head, and the latest automated review here reports no blocking findings. The non-blocking notes (heavy CI at merge, a localization note, an optional getIsIndeterminate in the doc example) are left for a follow-up.
There was a problem hiding this comment.
Approved. An engineering owner approved component:TableSelectionToolbar DEC-1 for this head, the select-all-matching recipe behaves as described, and the earlier change request is addressed: "Select only this page" now selects the whole page and the play test covers a page with an unticked row. CI has run on this head and passes.
Optional follow-ups, none blocking:
- The docs example's
useTableSelectioncall passes neithergetIsIndeterminatenorgetRowLabel, so a copy shows an empty header checkbox on a partly selected page and names every row checkbox "Select row"; the story already passes both. - DEC-1's rejected line ("before the server-pagination contract exists") states temporary status; "decided apart from Table's server-pagination contract" keeps the decision without it.
- No CI job runs the
SelectAllMatchingplay function yet (it passes when run); adding it to the story play guard's targets would make it a required check.
[Automated review]
| const selectionPlugin = useTableSelection({ | ||
| getIsItemSelected: isSelected, | ||
| // setRows adds to or removes from excluded in all mode, picked otherwise. | ||
| onSelectItem: ({item, isSelected}) => setRows([item], isSelected), | ||
| onSelectAll: ({isAllSelected}) => setRows(pageRows, isAllSelected), | ||
| getIsAllSelected: () => isPageSelected, | ||
| }); |
There was a problem hiding this comment.
Non-blocking: this call passes neither getIsIndeterminate nor getRowLabel, so a copy shows an empty header checkbox on a partly selected page and names every row checkbox "Select row". The story passes both; for example:
getIsIndeterminate: () => !isPageSelected && pageRows.some(isSelected),
getRowLabel: row => row.name,| Rejected: an all-matching mode in `useTableSelectionState` before the | ||
| server-pagination contract exists. |
There was a problem hiding this comment.
Non-blocking: "before the server-pagination contract exists" states temporary project status. Suggested: "Rejected: an all-matching mode in useTableSelectionState decided apart from Table's server-pagination contract."
There was a problem hiding this comment.
Approved pending CI: build, test and docsite-test have not run on this head yet and run in the pre-merge re-run. An engineering owner approved component:TableSelectionToolbar DEC-1 for this head, the select-all-matching recipe works as described in the story and the docs example, and the earlier change request is addressed: "Select only this page" selects the whole page, and the play test covers a page with an unticked row. Lint, typecheck and the smoke test pass on this head.
Optional follow-ups, none blocking:
- The docs example's
useTableSelectioncall passes neithergetIsIndeterminatenorgetRowLabel, so a copy shows an empty header checkbox on a partly selected page and announces every row checkbox as "Select row"; the story already passes both. - DEC-1's Rejected line ("before the server-pagination contract exists") states temporary status; "decided apart from Table's server-pagination contract" keeps the decision without it.
[Automated review]
|
/approve-spec de60d76 |
failingSpecs no longer waits after its fourth and last try, so a log that keeps answering 5xx gives up after 30 s of waits, and a test pins four server errors in a row. This also corrects the earlier commit's wording: the three pull requests that now replay a narrow selection (#9672, #10271, #10944) are ones whose story was their only full-suite trigger, not ones that change only stories. Their stories are Drawer, TableSelection and Avatar; Button's specs run because those stories import Button.
… retries a server error (#11317) * ci: the selection replay record covers the story rule; a log download retries a server error The record is regenerated with the Chromium lane's story rule (#11250). Every verdict matches the earlier record: 144 no failure, 4 caught, 4 reviewed, 1 out of scope. Three pull requests that change only stories now replay a narrow selection with no failure (#9672, #10271, #10944). GitHub's job-log endpoint answers 502 now and then, so failingSpecs tries a server error again, up to four times, before it calls a log unreadable. * Merge remote-tracking branch 'origin/main' into ci/replay-story-rule * ci: a log download waits only between tries, not after the last failingSpecs no longer waits after its fourth and last try, so a log that keeps answering 5xx gives up after 30 s of waits, and a test pins four server errors in a row. This also corrects the earlier commit's wording: the three pull requests that now replay a narrow selection (#9672, #10271, #10944) are ones whose story was their only full-suite trigger, not ones that change only stories. Their stories are Drawer, TableSelection and Avatar; Button's specs run because those stories import Button.
Reader impact
People managing hundreds of records across server pages want to select every record that matches their filter, untick a few, and run one bulk action without opening every page. Product teams building that today have to work it out from the low-level selection hook alone. After this change,
TableSelectionToolbar's docs and a Storybook recipe story show the complete flow on today's API:Source of truth
useTableSelection(getIsItemSelected,onSelectItem,onSelectAll,getIsAllSelected,getIsIndeterminate) andTableSelectionToolbar(selection,renderSelectionLabel,startContent) on main. No Core code changes.component:TableSelectionToolbarDEC-1: the app keeps this selection. A Core model for it is decided together with Table's server-pagination contract, because both need a total that is not loaded. This PR makes no promise of a future API.Correction
useTableSelection.selectedCountand arenderSelectionLabel.selectedKeysholds only the loaded rows, while the count comes from the app. A bulk action sends the server the query and the excluded ids, not a list of ids.Evidence
TableSelection.stories.tsx→ Select All Matching story. Its play test:Real Chrome (the PR's Vercel Storybook at 466a143, Chromium, 900×620), in light and dark mode the toolbar reads:
There were no page errors, and the colours match the existing toolbar and selected rows in both modes.
Focus after the offer (Chromium 155, built Storybook at this head): page selected → focus the offer → Enter: focus "Select only this page", toolbar "All 248 matching selected" → Enter: focus "Select all 248 matching", toolbar "5 selected". Archive never takes focus. The doc example uses the same button, so focus stays on it there too.
Follow-ups (tracked separately, not in this PR)
useTableSelectioncall passes nogetIsIndeterminate, so its header checkbox shows empty on a partly selected page; the story already passes one.Scope
Testing
pnpm check:knowledge,check:changesets; eslint on the story. Typecheck: CI's typecheck job is the check of record.Writing rubric results