Skip to content

fix: Preserve all matching selection after deselecting an expense#95902

Open
emkhalid wants to merge 3 commits into
Expensify:mainfrom
emkhalid:fix/preserve-all-matching-selection
Open

fix: Preserve all matching selection after deselecting an expense#95902
emkhalid wants to merge 3 commits into
Expensify:mainfrom
emkhalid:fix/preserve-all-matching-selection

Conversation

@emkhalid

@emkhalid emkhalid commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

Explanation of Change

This PR preserves the “all matching items” selection when individual expenses are unchecked.

It:

  • Tracks unchecked expenses as explicit exclusions while keeping all-matching selection active.
  • Automatically selects newly loaded matching expenses while preserving exclusions.
  • Shows the total matching count minus excluded expenses.
  • Keeps the count and selection stable while loading additional pages or opening and closing expenses.
  • Calculates totals on demand without advancing pagination or recalculating totals for every page.
  • Passes excluded transaction IDs to supported basic/current-view CSV exports.

Fixed Issues

$ #94143
PROPOSAL: #94143 (comment)

Tests

Precondition: Use an account with more than 50 expenses.

  1. Select all matching expenses and Exclude one expense

    1. Navigate to Spend > Expenses.
    2. Open the bulk-selection menu and choose Select all.
    3. Verify the button displays “All matching items selected”.
    4. After selecting all matching expenses, uncheck one expense.
    5. Verify only that expense becomes unchecked.
    6. Verify the button displays the total matching count minus one.
    7. Verify all other matching expenses remain selected.
  2. Preserve selection during pagination

    1. Exclude one expense after selecting all matching expenses.
    2. Scroll to the bottom and load the next page.
    3. Verify newly loaded expenses are automatically checked.
    4. Verify the excluded expense remains unchecked.
    5. Verify the selected count does not increase when the next page loads.
  3. Avoid recalculating totals during pagination

    1. Select all matching expenses and wait for the total to load.
    2. Scroll to load another page.
    3. Verify the pagination Search request uses shouldCalculateTotals: false.
    4. Verify the request loads only the next page.
  4. Recheck an excluded expense

    1. Select all matching expenses.
    2. Uncheck one expense.
    3. Recheck the same expense.
    4. Verify it is selected again.
    5. Verify the button returns to “All matching items selected” when no exclusions remain.
  5. Exclude multiple expenses

    1. Select all matching expenses.
    2. Uncheck multiple expenses across loaded pages.
    3. Verify every unchecked expense remains excluded.
    4. Verify the selected count decreases once for each excluded expense.
    5. Recheck the expenses and verify the count increases correctly.
  6. Verify grouped and expense-report selection

    1. Open a grouped expense or expense-report search.
    2. Select all matching items.
    3. Exclude one selection unit.
    4. Verify the excluded row is displayed as unchecked.
    5. Verify the parent group/report is not displayed as fully selected when one of its expenses is excluded.
    6. Verify newly loaded matching rows remain selected.
  7. Verify the selection footer

    1. Select all matching expenses and wait for the count and total.
    2. Exclude one expense.
    3. Verify the footer count subtracts the excluded expense.
    4. Verify the footer total subtracts the excluded expense amount.
    5. Recheck the expense and verify its count and amount are restored.
  • Verify that no errors appear in the JS console

Offline tests

N/A

QA Steps

Same as Tests

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

  • 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 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 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
  1. Select all matching expenses and Exclude one expense
android-native-Select.all.matching.expenses.and.Exclude.one.expense.mov
  1. Preserve selection during pagination
android-native-Preserve.selection.during.pagination.mp4
  1. Avoid recalculating totals during pagination

Not applicable.

  1. Recheck an excluded expense
android-native-Recheck.an.excluded.expense.mov
  1. Exclude multiple expenses
android-native-Exclude.multiple.expenses.mov
  1. Verify grouped and expense-report selection
android-native-Verify.grouped.and.expense-report.selection.mp4
  1. Verify the selection footer
andoir-native-Verify.the.selection.footer.mov
Android: mWeb Chrome
  1. Select all matching expenses and Exclude one expense
android-web-Select.all.matching.expenses.and.Exclude.one.expense.mov
  1. Preserve selection during pagination
android-web-Preserve.selection.during.pagination.mp4
  1. Avoid recalculating totals during pagination

Not applicable.

  1. Recheck an excluded expense
android-web-Recheck.an.excluded.expense.mov
  1. Exclude multiple expenses
android-web-Exclude.multiple.expenses.mov
  1. Verify grouped and expense-report selection
android-web-Verify.grouped.and.expense-report.selection.mp4
  1. Verify the selection footer
andoir-web-Verify.the.selection.footer.mov
iOS: Native
  1. Select all matching expenses and Exclude one expense
ios-native-Select.all.matching.expenses.and.Exclude.one.expense.mov
  1. Preserve selection during pagination
ios-native-Preserve.selection.during.pagination.mp4
  1. Avoid recalculating totals during pagination

Not applicable.

  1. Recheck an excluded expense
ios-native-Recheck.an.excluded.expense.mov
  1. Exclude multiple expenses
ios-native-Exclude.multiple.expenses.mov
  1. Verify grouped and expense-report selection
ios-native-Verify.grouped.and.expense-report.selection.mov
  1. Verify the selection footer
ios-native-Verify.the.selection.footer.mov
iOS: mWeb Safari
  1. Select all matching expenses and Exclude one expense
ios-web-Select.all.matching.expenses.and.Exclude.one.expense.mov
  1. Preserve selection during pagination
ios-web-Preserve.selection.during.pagination.mp4
  1. Avoid recalculating totals during pagination

Not applicable.

  1. Recheck an excluded expense
ios-web-Recheck.an.excluded.expense.mov
  1. Exclude multiple expenses
ios-web-Exclude.multiple.expenses.mov
  1. Verify grouped and expense-report selection
ios-web-Verify.grouped.and.expense-report.selection.mov
  1. Verify the selection footer
ios-web-Verify.the.selection.footer.mov
MacOS: Chrome / Safari
  1. Select all matching expenses and Exclude one expense
Select.all.matching.expenses.and.Exclude.one.expense.mov
  1. Preserve selection during pagination
Preserve.selection.during.pagination.mov
  1. Avoid recalculating totals during pagination
Avoid.recalculating.totals.during.pagination.mp4
  1. Recheck an excluded expense
Recheck.an.excluded.expense.mov
  1. Exclude multiple expenses
Exclude.multiple.expenses.mov
  1. Verify grouped and expense-report selection
Verify.grouped.and.expense-report.selection.webm
  1. Verify the selection footer
Verify.the.selection.footer.mov

@codecov

codecov Bot commented Jul 11, 2026

Copy link
Copy Markdown

Codecov Report

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

Files with missing lines Coverage Δ
src/components/Search/SearchContextDefinitions.ts 51.85% <ø> (ø)
...h/SearchList/ListItem/TransactionGroupListItem.tsx 74.50% <100.00%> (ø)
src/hooks/useSearchBulkActions.ts 53.89% <100.00%> (+0.04%) ⬆️
src/hooks/useSearchShouldCalculateTotals.ts 100.00% <100.00%> (ø)
src/libs/actions/Search.ts 42.63% <100.00%> (+2.59%) ⬆️
...arch/SearchList/ListItem/ExpenseReportListItem.tsx 0.00% <0.00%> (ø)
src/components/Search/SearchBulkActionsButton.tsx 88.88% <76.47%> (+87.43%) ⬆️
src/components/Search/SearchSelectionFooter.tsx 88.88% <81.81%> (+47.22%) ⬆️
src/components/Search/SearchSelectionProvider.tsx 68.42% <80.00%> (+16.56%) ⬆️
...c/components/Search/SearchWriteActionsProvider.tsx 0.00% <0.00%> (ø)
... and 1 more
... and 16 files with indirect coverage changes

@emkhalid emkhalid marked this pull request as ready for review July 12, 2026 19:55
@emkhalid emkhalid requested review from a team as code owners July 12, 2026 19:55
@melvin-bot melvin-bot Bot requested review from flaviadefaria and mkhutornyi July 12, 2026 19:55
@melvin-bot

melvin-bot Bot commented Jul 12, 2026

Copy link
Copy Markdown

@mkhutornyi 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 removed request for a team July 12, 2026 19:55

@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: dc68c95a59

ℹ️ 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".

Comment on lines +230 to +231
const hasSelectedTransactions =
selectionState.areAllMatchingItemsSelected || selectionState.selectedTransactionIDs.length > 0 || Object.values(selectionState.selectedTransactions).some((t) => t.isSelected);

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 Keep bulk actions visible for all-matching selections

When an all-matching selection is preserved, this state can now have areAllMatchingItemsSelected === true while selectedTransactions is empty, e.g. select all matching and then exclude every currently loaded row. The wide actions bar still renders SearchBulkActionsButton only when useSelectionCounts() sees selectedTransactions entries, so in that scenario it switches back to the normal search controls even though off-screen matching items remain selected and can no longer be exported/cleared from the header. Please gate the wide bulk actions on hasSelectedTransactions/all-matching state instead of only the loaded selection count.

Useful? React with 👍 / 👎.

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.

1 participant