Skip to content

feat: implement useRowRangeSelection() for multi-select Tables - #21964

Closed
jakehwll wants to merge 3 commits into
mainfrom
jakehwll/20870-table-shift-multiple-select
Closed

jakehwll wants to merge 3 commits into
mainfrom
jakehwll/20870-table-shift-multiple-select

Conversation

@jakehwll

@jakehwll jakehwll commented Feb 6, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #20870

This pull-request implements the useRowRangeSelection() function. This allows us to select multiple rows at one time simply by holding the shift key after selecting a row 🙂. This is an improvement to the Tasks and Workspaces tables.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 509d26ea50

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

* ```
*/
export function useRowRangeSelection(): UseRowRangeSelectionReturn {
const lastSelectedIndexRef = useRef<number>(-1);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Reset shift-click anchor when row set changes

lastSelectedIndexRef persists across all re-renders and is only validated against totalItems, so when the table data changes (for example, Workspaces pagination/filter updates and periodic refetches in WorkspacesPage.tsx) a later Shift+click can reuse an anchor index from a different row set and apply range selection to unintended rows. In this flow, users can accidentally include/exclude unrelated workspaces/tasks before running batch actions, so the anchor should be cleared (or keyed by stable row id) whenever the backing list changes.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would have been an improvement in #21963 but I decided against introducing a complex tanstack/react-table dependency. It would be smarter to use this against the workspace.id (or task.id) rather than saving the entire object.

@aslilac aslilac left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am near universally skeptic of hooks like this.

  • Why does it belong in the top-level hooks/ folder? Is the problem that it solves so pervasive that it deserves to be that front and center? If the problem is narrower in scope, why not place it next to the part of the code base it is most relevant to? In this case, likely the Table components
  • Why does it need to be a hook? It contains a single call to a hook that I might argue is being misused in this context. It otherwise just contains a function that captures that one hooks return value, and then returns the function. Could this just be a normal function where you call the hook yourself and pass the values to the function? Maybe the state could be better managed by a Context/Provider? React 19 gives us use, which doesn't need to follow hook rules for reading contexts. Maybe rather than a duck-tape hook, this behavior could be built in to the Table components directly, providing a clearer implementation, a more consistent user experience, and a better dev experience.

* ```
*/
export function useRowRangeSelection(): UseRowRangeSelectionReturn {
const lastSelectedIndexRef = useRef<number>(-1);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this isn't a ref, this is state

@github-actions github-actions Bot added the stale This issue is like stale bread. label Feb 14, 2026
@github-actions github-actions Bot closed this Feb 17, 2026
@github-actions
github-actions Bot deleted the jakehwll/20870-table-shift-multiple-select branch August 7, 2026 01:09
jakehwll added a commit that referenced this pull request Nov 24, 2026
…30008)

> 🤖 This PR was modified by Coder Agents on behalf of Jake Howell.

Support both **Shift-click** and **Shift-held dragging** to select
workspace ranges. Click a checkbox, then Shift-click another to apply
the anchor's checked state across the range; **Shift+Space** provides
the keyboard equivalent. Shift-dragging selects or deselects from the
starting checkbox, and reversing the drag restores selection outside the
range.

Both gestures skip pending and deleting workspaces and stay on the
displayed page. Ordinary checkbox clicks and workspace navigation retain
their existing behavior. Related: #21964.

<details>
<summary>Design decisions</summary>

- **Table-owned, opt-in behavior.** `SelectableTable`,
`SelectableTableRow`, `SelectableTableCheckbox`, and
`SelectableTableSelectAll` compose the existing Table and Checkbox
primitives rather than a standalone gesture hook. Each table owns its
gesture state; ordinary tables are unchanged. Native refs and consumer
event handlers are retained, with no new dependency or data-grid
framework.
- **Stable anchors and controlled selection.** Ranges use endpoint IDs
and the current display order, so refetch reordering does not change the
anchor's identity. Missing or disabled anchors and external selection
resets stop active drags without restoring stale selections. Batched
pointer events are distinguished from external resets. Select-all clears
the Shift-click anchor.
- **Workspace policy stays in Workspaces.** `WorkspacesTable.tsx`
supplies eligibility and maps selected IDs back to current workspace
objects. The reusable components do not depend on workspace API types or
statuses.
- **Gesture safeguards stay encapsulated.** Dragging requires Shift and
the primary mouse button, starting from an eligible checkbox. Pointer
release, cancellation, and window blur clean up the gesture. A completed
range drag suppresses its terminal click without swallowing the next
ordinary click. Touch and pen do not start drag selection; viewport-edge
autoscrolling is not added.

</details>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stale This issue is like stale bread.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bulk-selection interface: Shift-click doesn't select multiple checkboxes

2 participants