Skip to content

fix: Search selections of partly loaded groups and Select all exclusions - #103617

Open
TaduJR wants to merge 11 commits into
Expensify:mainfrom
TaduJR:fix/90539-selection-exclusions
Open

TaduJR wants to merge 11 commits into
Expensify:mainfrom
TaduJR:fix/90539-selection-exclusions

Conversation

@TaduJR

@TaduJR TaduJR commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Explanation of Change

This is part 4 of #90539 (shift+click range selection). While building ranges in Search, I found that when a group hadn't loaded all of its expenses, its checkbox, the selected count and total, and the bulk actions disagreed about what was selected. This PR makes them agree.

In grouped searches (by category, tag and so on), a group loads its expenses a page at a time. With this change:

  • Checking a group's header selects the whole group, including expenses that haven't loaded yet. The selected count and total include them, as an export already did, and expenses that load later come in checked.
  • While a checked group still has expenses to load, the bulk menu only offers actions that cover the whole group, like Export, as it already does for a checked collapsed group. Actions that work one expense at a time (Hold, Move, Delete, Edit multiple, Merge, Download receipts) come back once the group has fully loaded. Edit multiple, Merge and Download receipts are now also hidden next to a checked collapsed group, where before they acted on the other expenses and left the group out.
  • A group shows as fully checked only when every expense in it is selected, loaded or not. Otherwise it shows as partly checked.
  • A new expense added to a fully checked group stays unchecked, so a bulk action can't include an expense nobody selected.
  • If a group reloads and only its first page comes back, for example when you return from an expense, the expenses you checked on later pages stay checked. Unchecking the group's header clears them too. If one of them was deleted on another device in the meantime, a fully checked group stays fully checked, so new expenses still come in unchecked.
  • An expense that moves to another group, for example after its category changes, counts as part of its new group.
  • Rejecting or moving an expense from its details makes the rest of its group a partial selection, the same as unchecking its row. Deleting one keeps the rest of the group selected.

With Select all on:

  • Unchecking a group's header takes out the whole group. Before, only its loaded expenses were taken out, and the rest stayed in exports and bulk actions.
  • An expense you check again inside a group you took out is counted in the selected count and total.
  • The page's select-all checkbox now checks rows you had unchecked, instead of leaving them excluded.
  • In an expense search, Pay is hidden once anything is unchecked, since paying a report would also pay the expenses you unchecked. In the Reports view, Mark as exported now leaves out the reports you unchecked.

Fixed Issues

$ #90539
PROPOSAL:

Tests

Prerequisites: use a workspace with its default categories and add these expenses:

  • Travel: more than 50 expenses (the steps assume 60, so swap in your own number).
  • Car: exactly 3 expenses, at least one with a receipt.
  • Fees: at least 2 expenses.

Test 1. Checking a group that hasn't fully loaded selects all of it

  1. Go to Spend > Expenses, then Display > Group by > Category.
  2. Click the Travel row to open it. Verify it shows 50 expenses and a "Show more" link under them.
  3. Check Travel's checkbox.
  4. Verify the selection button says "60 selected", not 50.
  5. Verify the footer shows Expenses: 60, and a Total spend that matches Travel's total.
  6. Open the "60 selected" menu. Verify Export is there, and Hold, Delete, Move to report, Edit multiple and Merge are not.
  7. Open Car and check the expense that has a receipt. Verify the button says "61 selected" and the menu has no "Download receipt" option. Then uncheck that Car expense again.

Test 2. A group shows partly checked when only some of it is selected

  1. Continue from test 1. Uncheck one expense in Travel, then check it again.
  2. Verify Travel's checkbox shows a dash (partly checked) and the button says "50 selected".
  3. Click Travel's checkbox. Verify nothing is selected anymore.

Test 3. Expenses that load later come in checked

  1. With Travel open, check Travel's checkbox. Verify "60 selected".
  2. Click "Show more" under Travel. Verify the expenses that just loaded are checked.
  3. Open the "60 selected" menu. Verify actions like Hold or Delete are back (whichever your expenses allow).

Test 4. Expenses checked lower down stay checked after you open an expense

  1. With all 60 of Travel's expenses showing, check the last two expenses in Travel. Verify "2 selected".
  2. Click any expense in Travel to open its details, then close the details.
  3. Verify the button still says "2 selected". If Travel shows "Show more" again, click it and verify the two expenses are still checked.
  4. Click Travel's checkbox. Verify nothing is selected anymore.

Test 5. Checking every expense of a group one by one shows a full check

  1. Open Car and check each of its 3 expenses one by one.
  2. Verify Car's checkbox shows a full check, not a dash, and the button says "3 selected".

Test 6. A new expense added to a fully checked group stays unchecked

  1. Open Car and check Car's checkbox. Verify "3 selected".
  2. Without leaving Spend, create a new expense in the Car category.
  3. Verify the new expense shows under Car unchecked, Car's checkbox shows a dash, and the button still says "3 selected".

Test 7. Deleting an expense keeps its group checked

  1. Open Fees and check Fees's checkbox. Note the count on the button.
  2. Open one of Fees's expenses and delete it.
  3. Verify Fees's checkbox still shows a full check and the count went down by 1.

Test 8. An expense moved to another category goes with it

  1. Open Car and Fees. Check Car's checkbox. Note the count on the button.
  2. Open one of Car's expenses, change its category to Fees, and close the details.
  3. Verify the expense now shows under Fees, still checked, and the count hasn't changed.
  4. Uncheck Car's checkbox. Verify the moved expense under Fees stays checked and the button says "1 selected".
  5. Wait a few seconds. Verify Car doesn't become checked again.

Test 9. Select all: unchecking a group that hasn't fully loaded

This needs a grouped list long enough that, with nothing selected, clicking the checkbox at the top of the list opens a menu with "Select all on this page" and "Select all". If it selects the page straight away, the list is too short for this test.

  1. With the list grouped by Category, click the top checkbox and choose "Select all". Verify the button says "All matching items selected".
  2. Open Travel so 50 of its expenses show. Uncheck Travel's checkbox.
  3. Verify the button count equals all matching expenses minus 60 (all of Travel, including the expenses not shown).
  4. Check one expense in Travel. Verify the count goes up by 1 and Travel's checkbox shows a dash.
  5. Uncheck that expense again. Verify the count goes down by exactly 1.

Test 10. Select all, then select the page again

This needs an ungrouped Expenses list with more than 50 expenses.

  1. Go to Spend > Expenses with no grouping. Click the top checkbox and choose "Select all". Verify "All matching items selected".
  2. Uncheck two expenses. Verify the count drops by 2.
  3. Click the top checkbox. Verify every expense on the page is checked and the button says "All matching items selected".
  4. Wait a few seconds. Verify the expenses stay checked.
  • Verify that no errors appear in the JS console

Offline tests

Same as tests

QA Steps

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
  • 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 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 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)
  • 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)
  • 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.
  • 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 October 9, 2026 15:45
@melvin-bot
melvin-bot Bot requested review from situchan and removed request for a team October 9, 2026 15:45
@melvin-bot

melvin-bot Bot commented Oct 9, 2026

Copy link
Copy Markdown

@situchan 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 joekaufmanexpensify and removed request for a team October 9, 2026 15:45
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-10-10T11:37:41.930540Z fa4c673 Manual request
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@codecov

codecov Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ Changes either increased or maintained existing code coverage, great job!

Files with missing lines Coverage Δ
.../components/MoneyRequestHeaderSecondaryActions.tsx 66.81% <ø> (ø)
src/components/Search/SearchBulkActionsButton.tsx 92.39% <100.00%> (ø)
...ponents/Search/SearchList/ListItem/GroupHeader.tsx 81.81% <100.00%> (+0.46%) ⬆️
...h/SearchList/ListItem/TransactionGroupListItem.tsx 79.60% <100.00%> (+0.41%) ⬆️
...nts/Search/SearchList/ListItem/useGroupChildren.ts 100.00% <100.00%> (ø)
src/components/Search/SearchSelectionProvider.tsx 92.95% <100.00%> (+13.25%) ⬆️
...c/components/Search/SearchWriteActionsProvider.tsx 95.72% <100.00%> (+0.41%) ⬆️
src/hooks/useExpenseActions.ts 66.20% <ø> (ø)
...micReportDetailsPage/ReportDetailsDeleteAction.tsx 57.69% <ø> (ø)
src/pages/iou/RejectReasonPage.tsx 0.00% <ø> (ø)
... and 7 more
... and 12 files with indirect coverage changes

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Something went wrong. Try again later by commenting “@codex review”.

Failed to sample tokens
ℹ️ 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".

1 similar comment
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Something went wrong. Try again later by commenting “@codex review”.

Failed to sample tokens
ℹ️ 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 Oct 9, 2026

Copy link
Copy Markdown
Contributor Author

@MelvinBot review

@MelvinBot

Copy link
Copy Markdown
Contributor

Code review

I found no blocking bugs. The selection, exclusion and checkbox logic holds up. There is one gap to fix and one edge case to check.

1. Fix: "Download receipts" still shows when a partly loaded group is checked. useSearchBulkActions.ts:2984-2991

The merged selection swaps the group's rows for its group_ entry, and this filter drops group_ keys. Say you check Travel's header (60 expenses, 50 loaded) plus one expense in Car. The button says "61 selected", but the menu offers "Download 1 receipt", which leaves out all of Travel. Before this PR, Travel's 50 loaded receipts were included.

To match the "only whole-group actions" rule, gate this option on !hasGroupEntrySelected the way Edit multiple is gated at line 2668.

2. Check: deleting an expense from a header-checked, partly loaded group. selectionBuilders.ts:331

removeTransaction(id, {isDeleted: true}) keeps the other rows' group claim, so the group is still merged from the snapshot's count and total. Your own comment at line 39 says that count isn't decremented while a row is pending delete. So the footer may keep counting the deleted expense until the search refreshes, or until you reconnect if you're offline. Test 7 covers only a fully loaded group. Please try it with Travel too.

What I checked and found correct
  • applySelection: deselectedWithoutEntry can't be dropped by the early return. It's only set when the updater returns a new object.
  • removeTransaction: all 7 callers pass the right isDeleted flag. Deletes pass true, and reject and move pass false.
  • The merged group entry has every action flag off and no transaction. Hold, Move, Delete, Pay, Approve, Submit, Split and Reject stay hidden. No group_ key reaches an API as a transaction ID.
  • Export drops group_ keys from transactionIDList and turns them into a group filter.
  • The footer doesn't count rows twice. Merging drops every row of a partly loaded group, and re-checked rows in excluded groups are only added back under Select all.
  • Pay under Select all still shows when nothing is excluded. Mark as exported leaves out unchecked reports correctly.
  • Minor: the new useMemo at useSearchBulkActions.ts:625 goes against the repo rule if this hook compiles with React Compiler. npm run react-compiler-compliance-check check-changed will confirm.

This review is from reading the code at 22f0cde. I didn't run the tests or test it in the app.


view run

@joekaufmanexpensify joekaufmanexpensify left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Good for product

…election-exclusions

# Conflicts:
#	src/components/Search/SearchBulkActionsButton.tsx
#	tests/unit/Search/SearchSelectionFooterTest.tsx
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Something went wrong. Try again later by commenting “@codex review”.

Failed to sample tokens
ℹ️ 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".

@MelvinBot

Copy link
Copy Markdown
Contributor

⏱️ Ran out of time before I could finish. This usually means the task was too complex or I got stuck exploring. Please try again with a more specific request or post in #melvinbot-ai.

Run details

@TaduJR

TaduJR commented Oct 10, 2026

Copy link
Copy Markdown
Contributor Author

All yours @situchan

@situchan

situchan commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Reviewer Checklist

  • I have verified the author checklist is complete (all boxes are checked off).
  • I verified the correct issue is linked in the ### Fixed Issues section above
  • I verified testing steps are clear and they cover the changes made in this PR
    • I verified the steps for local testing are in the Tests section
    • I verified the steps for Staging and/or Production testing are in the QA steps section
    • I verified the steps cover any possible 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 checked that screenshots or videos are included for tests on all platforms
  • I included screenshots or videos for tests on all platforms
  • I verified that the composer does not automatically focus or open the keyboard on mobile unless explicitly intended. This includes checking that returning the app from the background does not unexpectedly open the keyboard.
  • I verified tests pass on all platforms & I tested again on:
    • Android: HybridApp
    • Android: mWeb Chrome
    • iOS: HybridApp
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
  • If there are any errors in the console that are unrelated to this PR, I either fixed them (preferred) or linked to where I reported them in Slack
  • I verified any copy / text that was added to the app 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)
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I verified other components that can be impacted by these changes have been tested, and I retested again (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar have been tested & I retested again)
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
  • 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 the PR adds or modifies the UI:
    • I asked an AI agent to review the changes for accessibility issues and addressed its findings.
    • I tested with a screen reader (VoiceOver on macOS) and verified all new/changed elements are reachable with a logical focus order.
    • I verified all new/changed elements have meaningful accessible names and roles.
    • I verified state changes are announced (e.g. checked/unchecked, expanded/collapsed, selected).
  • For any bug fix or new feature in this PR, I verified that sufficient unit tests are included to prevent regressions in this 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.
  • I have checked off every checkbox in the PR reviewer checklist, including those that don't apply to this PR.

Screenshots/Videos

Android: HybridApp
Android: mWeb Chrome
iOS: HybridApp
iOS: mWeb Safari
MacOS: Chrome / Safari
test1.2.mov
test3.4.mov
test5.6.mov
test7.mov

@situchan

Copy link
Copy Markdown
Contributor

Please fix conflict

@situchan

Copy link
Copy Markdown
Contributor

Test 9. Select all: unchecking a group that hasn't fully loaded

This is failing. I don't see "Select all" option when list grouped by category

Screen.Recording.2026-10-18.at.5.08.00.PM.mov

Please make sure to add screen recordings for all 10 test cases

@situchan

Copy link
Copy Markdown
Contributor

Test 10. Select all, then select the page again

This test is failing too.
When click top checkbox after dropping count, every expense is unchecked - this is expected. Your test case is wrong.

Screen.Recording.2026-10-18.at.5.10.37.PM.mov

Please make sure to validate test cases yourself (if wrong, correct them). Otherwise this PR will be fail QA.

@situchan

Copy link
Copy Markdown
Contributor

Bug: Fully loaded group is treated as still loading when its count is stale

Precondition: Report A has 2 expenses and Report B has 1.

  1. Go to Reports > Expenses and search type:expense status:drafts group-by:from.
  2. Expand your own group. It shows 3 expenses.
  3. Go offline.
  4. Click Report B's expense, click Submit in its header, and close the details.
  5. The group now shows 2 expenses.
  6. Check the group's header checkbox.
  7. Clear the selection, then check both expenses one by one.

Expected: "2 selected"
Actual: "3 selected"

Screen.Recording.2026-10-18.at.5.26.48.PM.mov

@situchan

Copy link
Copy Markdown
Contributor

Test 8. An expense moved to another category goes with it

This is failing.
After changing category, moved expense is unchecked

Screen.Recording.2026-10-18.at.5.40.28.PM.mov

@situchan

Copy link
Copy Markdown
Contributor

Test 6. A new expense added to a fully checked group stays unchecked

This is failing because of the bug happening on main. Shows skeleton and then disappears. New expense is not added to the group until collapse and expand again

test5.6.mov

@TaduJR

TaduJR commented Oct 18, 2026

Copy link
Copy Markdown
Contributor Author

Please make sure to add screen recordings for all 10 test cases

I remember testing all 10 before the account ban. Have you merged main when testing I think that my have led to inconsistencies

Anyways will review all tomorrow thanks

@situchan

Copy link
Copy Markdown
Contributor

I remember testing all 10 before the account ban.

If so, why not uploaded in checklist

Have you merged main when testing I think that my have led to inconsistencies

yes, I merged main. Fixed conflicts locally.

@TaduJR

TaduJR commented Oct 18, 2026

Copy link
Copy Markdown
Contributor Author

If so, why not uploaded in checklist

Because I didn't record vid formally. The account got rate limited and banned before recording.

This branch has not been deployed

No deployments
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.

4 participants