Skip to content

feat: Add shared Shift+Click range-selection engine and unify Table onto it (1/3)#95647

Open
TaduJR wants to merge 3 commits into
Expensify:mainfrom
TaduJR:feat/90539-shift-range-engine
Open

feat: Add shared Shift+Click range-selection engine and unify Table onto it (1/3)#95647
TaduJR wants to merge 3 commits into
Expensify:mainfrom
TaduJR:feat/90539-shift-range-engine

Conversation

@TaduJR

@TaduJR TaduJR commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Explanation of Change

This is part 1 of 3 for #90539, split out of #92155 per the review feedback on size. It adds the shared range-selection engine and moves Table onto it. No new surface gains shift+click here (Table already had its own implementation on main the other surfaces come in the follow-up PRs), but Table's existing behavior changes in four ways:

  1. Shift+click now always selects. On main, unchecking a row made the next shift+click deselect the range, which could leave Shift looking unresponsive; removing that mode was suggested in the original PR's review (link).
  2. A first-ever shift+click selects from the top of the list instead of toggling a single row.
  3. A second shift+click moves the endpoint of the range instead of layering a new one on top.
  4. Select All then shift+click narrows the selection to the clicked range (on main it just unchecks the clicked row).

The useShiftRangeSelection hook is surface-agnostic: consumers tell it about plain clicks and bulk toggles, and on shift+click it emits a {toSelect, toDeselect} batch the consumer applies to its own selection store. It holds no selection state, just the session in a ref (the anchor plus the keys its ranges painted), touched only from event handlers. The anchor is the last row the user interacted with; if it disappears mid-session the hook falls back to the first selected row, then the first selectable one (this anchor model is the one flagged for internal-team confirmation on the original PR, unchanged here). The session tracks what it painted by key, so re-sorts and data refreshes can't misattribute a collapse, and a shrink only ever unchecks rows the shift-range itself checked, never rows the user picked individually. Disabled rows and group headers are excluded from ranges, anchors, and targets.

libs/shiftRangeSelection holds the shared event and batch helpers; selectability is decided once by the hook when it builds the batch, so appliers don't filter again. Two engine methods have no caller yet: seedRangeFromSelection and clearAnchor are consumed by the Search provider in part 2.

For Table, the middleware's own anchor refs and range walk are replaced by the shared hook, leaving one implementation for every Table-backed list (workspace Tags, Members, Cards, Categories, Distance rates, Per diem and so on). SelectionButton gains a small shift+mousedown handler: preventDefault stops the browser's text selection from swallowing consecutive shift+clicks, with focus restored afterwards unless another element holds it. TransactionItemRow's checkbox forwards the Shift modifier as an optional argument; nothing reads it yet, existing callers are unaffected, and part 2 consumes it.

Fixed Issues

$ #90539
PROPOSAL: #90539 (comment)

Tests

Scope note for QA: In this PR, Shift+click range selection only applies to the workspace table lists Categories, Tags, Members, Taxes, Distance rates, Per diem, Expensify Cards, and the Rules tabs (any workspace list with checkboxes). It is not yet implemented anywhere else the Reports tab (Expenses/Reports/Chats), the money request report view, report fields' List Values, and pickers like "Add existing expense" or "Share bank account" still toggle one row at a time. That is expected and not a bug: those surfaces ship in the two follow-up PRs. Shift+click is Web/Desktop only (there is no Shift key on mobile).

  1. Click the 2nd category's checkbox, then hold Shift and click the 6th.
    Verify: categories 2–6 are all checked.
  2. Still holding Shift, click the 4th.
    Verify: 2–4 stay checked, 5–6 got unchecked.
  3. Uncheck category 4 (no Shift), then hold Shift and click the 7th.
    Verify: 4–7 all become checked 2 and 3 stay checked.
  4. Still holding Shift, click the 5th.
    Verify: 4–5 stay checked and 6–7 got unchecked, while 2 and 3 are still
    checked.
  5. Uncheck the 2nd category, then the 3rd, then hold Shift and click the 6th.
    Verify: 3–6 become checked while 2 stays unchecked (the range starts from
    your last click row 3 so only that row comes back
  6. Refresh, then Shift+click the 5th category as your very first click.
    Verify: 1–5 are checked.
  7. Refresh, click Select All, then Shift+click the 3rd category.
    Verify: only 1–3 remain checked.
  • Verify that no errors appear in the JS console

Offline tests

Same as tests

QA Steps

// TODO: These must be filled out, or the issue title must include "[No QA]."
Same as tests

  • Verify that no errors appear in the JS console

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
    • MacOS: Desktop
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I verified there are no new alerts related to the canBeMissing param for useOnyx
  • I followed proper code patterns (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick)
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
      • If any non-english text was added/modified, I used JaimeGPT to get English > Spanish translation. I then posted it in #expensify-open-source and it was approved by an internal Expensify engineer. Link to Slack message:
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.ts or at the top of the file that uses the constant) are defined as such
  • I verified that if a function's arguments changed that all usages have also been updated correctly
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))
  • If new assets were added or existing ones were modified, I verified that:
    • The assets are optimized and compressed (for SVG files, run npm run compress-svg)
    • The assets load correctly across all supported platforms.
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • I added unit tests for any new feature or bug fix in this PR to help automatically prevent regressions in this user flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.

Screenshots/Videos

Android: Native
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari

@TaduJR TaduJR requested review from a team as code owners July 8, 2026 20:20
@melvin-bot melvin-bot Bot requested review from QichenZhu and removed request for a team July 8, 2026 20:21
@melvin-bot

melvin-bot Bot commented Jul 8, 2026

Copy link
Copy Markdown

@QichenZhu Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button]

@melvin-bot melvin-bot Bot requested review from heyjennahay and removed request for a team July 8, 2026 20:24
@codecov

codecov Bot commented Jul 8, 2026

Copy link
Copy Markdown

Codecov Report

❌ Looks like you've decreased code coverage for some files. Please write tests to increase, or at least maintain, the existing level of code coverage. See our documentation here for how to interpret this table.

Files with missing lines Coverage Δ
src/components/Table/TableRow.tsx 82.66% <100.00%> (+1.33%) ⬆️
src/components/Table/middlewares/selection.ts 87.03% <100.00%> (+27.31%) ⬆️
...ts/TransactionItemRow/TransactionItemRowNarrow.tsx 0.00% <ø> (ø)
...ents/TransactionItemRow/TransactionItemRowWide.tsx 99.13% <ø> (ø)
...hiftRangeSelection/applyShiftRangeBatchToKeySet.ts 100.00% <100.00%> (ø)
...c/libs/shiftRangeSelection/getShiftKeyFromEvent.ts 100.00% <100.00%> (ø)
src/hooks/useShiftRangeSelection.ts 98.42% <98.42%> (ø)
src/components/SelectionButton.tsx 76.19% <0.00%> (-8.03%) ⬇️
... and 7 files with indirect coverage changes

@TaduJR

TaduJR commented Jul 8, 2026

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Hooray!

Reviewed commit: ac868e7d28

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@TaduJR

TaduJR commented Jul 8, 2026

Copy link
Copy Markdown
Contributor Author

Implementation: +368 / −69 (net +299)
Tests: +935 lines

@QichenZhu

QichenZhu commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

@TaduJR thanks for splitting up the PR. This size makes much more sense.

However, this PR covers lists other than Reports/Expenses, but the original issue is mainly about workspace filters and Reports/Expenses (see Slack). So let's focus on those as part 1, and do this part as a follow-up.

cc @stitesExpensify

workspace-filters

@TaduJR

TaduJR commented Jul 11, 2026

Copy link
Copy Markdown
Contributor Author

@QichenZhu

There is a constraint. Reports/Expenses is built on the shared range engine in this PR (and knip fails the engine with no consumer), so part 1 would become engine + Reports/Expenses, which is roughly twice this PR's size.

So lets continue here.

WDYT?

@TaduJR

TaduJR commented Jul 11, 2026

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. What shall we delve into next?

Reviewed commit: 7741424a20

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants