Repository navigation
Conversation
There was a problem hiding this comment.
💡 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); |
There was a problem hiding this comment.
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 👍 / 👎.
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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
Tablecomponents - 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 ususe, 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 theTablecomponents directly, providing a clearer implementation, a more consistent user experience, and a better dev experience.
| * ``` | ||
| */ | ||
| export function useRowRangeSelection(): UseRowRangeSelectionReturn { | ||
| const lastSelectedIndexRef = useRef<number>(-1); |
…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>
Closes #20870
This pull-request implements the
useRowRangeSelection()function. This allows us to select multiple rows at one time simply by holding theshiftkey after selecting a row 🙂. This is an improvement to the Tasks and Workspaces tables.