Skip to content

Label Reports tab "Select all" with matching-report count - #99689

Merged
JS00001 merged 7 commits into
Expensify:mainfrom
dilshodmackbook-sketch:fix/99067-reports-select-all-report-count
Sep 3, 2026
Merged

Label Reports tab "Select all" with matching-report count#99689
JS00001 merged 7 commits into
Expensify:mainfrom
dilshodmackbook-sketch:fix/99067-reports-select-all-report-count

Conversation

@dilshodmackbook-sketch

@dilshodmackbook-sketch dilshodmackbook-sketch commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Explanation of Change

On Spend → Reports, using Select all (the cross-page "Select all matching" affordance) labelled the header with the wrong number: it showed the count of expenses instead of the count of reports.

For a type: expense-report search, currentSearchResults.search.count is the number of expenses, not reports. When areAllMatchingItemsSelected is on, selectedAllMatchingItemsCount only reconciled the count for the Expenses tab (isExpenseType); the Reports tab fell through the else and rendered count verbatim — the expense total. Re-toggling bulk select looked correct only because it dropped out of all-matching mode and used the locally-selected report count.

The genuinely correct value — how many reports match across all pages — is not derivable on the client (selectAllMatchingItems never loads the un-selected rows, so selectedItemsCount is only the loaded page). The server now returns it as a new reportCount field on the Search response.

This change:

  1. Adds the reportCount field to the SearchResultsInfo type.
  2. For expense-report all-matching selections, labels the button with the server reportCount (matching reports) instead of count (expenses), holding the button in its loading state until the report count arrives, and falling back to the loaded-page report count when offline / on error.
  3. Clears reportCount alongside count/total/currency when a non-totals search starts, so a stale report count is not shown on the next "Select all".

The isExpenseType branch and its exclusion arithmetic are untouched, so the Expenses tab and the invoice/trip/chat/task types are unaffected. The footer keeps reading search.count, so Expenses: N is unchanged.

Fixed Issues

$ #99067
$ #99502
PROPOSAL: #99067 (comment)

Tests

  1. Sign in to an account with a workspace that has more than 50 reports in a single month.
  2. Go to Reports (Spend → Reports).
  3. Click Filter, select Custom date, and set the range to the month containing more than 50 reports.
  4. Click Bulk select.
  5. Click Select all.
  6. Verify the button briefly shows a loading state, then displays the total number of reports selected (not the number of expenses).
  7. Deselect and re-open bulk select; verify the report count stays consistent.
  • Verify that no errors appear in the JS console

Offline tests

  1. With bulk select active on the Reports tab, go offline before clicking Select all.
  2. Click Select all.
  3. Verify the button does not spin forever — it falls back to the count of the reports currently loaded rather than hanging on a count that can't arrive.

QA Steps

  1. Sign in to an account with a workspace that has more than 50 reports in a single month.
  2. Go to Reports (Spend → Reports).
  3. Click Filter, select Custom date, and set the range to the month containing more than 50 reports.
  4. Click Bulk select, then Select all.
  5. Verify the button shows the total number of reports selected, not the number of expenses.
  • 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
Screen.Recording.2026-09-01.at.18.37.50.mov
Android: mWeb Chrome
Screen.Recording.2026-09-01.at.18.33.26.mov
iOS: Native
Screen.Recording.2026-09-01.at.18.56.56.mp4
iOS: mWeb Safari
Screen.Recording.2026-09-01.at.18.43.28.mp4
MacOS: Chrome / Safari
Screen.Recording.2026-09-01.at.17.41.29.mp4

Recorded on my own account with 50+ reports. On the Reports tab, Select all now shows 110 (the number of reports) while the footer shows 93 expenses - before the fix the button showed the expense count. Reports outnumber expenses here only because many are empty duplicates I created to get past 50 reports and surface the cross-page Select all.

For expense-report searches the Search snapshot's count is the number of
expenses, so Select all on the Reports tab showed the expense total instead
of the report total. Consume the server-provided reportCount for the
expense-report all-matching label, hold the button loading until it arrives
(falling back to the loaded-page report count offline), and clear reportCount
alongside the other totals when a non-totals search starts so a stale value
is not shown.
@dilshodmackbook-sketch

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. More of your lovely PRs please.

Reviewed commit: c30329474e

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

@dilshodmackbook-sketch
dilshodmackbook-sketch marked this pull request as ready for review August 28, 2026 16:16
@dilshodmackbook-sketch
dilshodmackbook-sketch requested review from a team as code owners August 28, 2026 16:16
@melvin-bot
melvin-bot Bot requested review from ZhenjaHorbach and removed request for a team August 28, 2026 16:17
@melvin-bot

melvin-bot Bot commented Aug 28, 2026

Copy link
Copy Markdown

@ZhenjaHorbach 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 JmillsExpensify and removed request for a team August 28, 2026 16:17
Comment thread src/components/Search/SearchBulkActionsButton.tsx Outdated
Comment thread src/components/Search/SearchBulkActionsButton.tsx Outdated

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

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

Comment thread src/components/Search/SearchBulkActionsButton.tsx
…ct-all

The bulk-actions button now waits for the server reportCount on an
expense-report 'select all matching'. The totals retry/skip predicates keyed
off the always-present expense count, so a snapshot with count but no
reportCount (persisted before the field shipped, or a colliding non-totals
response) never triggered a totals request and the button could stay loading
forever. Treat a missing reportCount as the missing total for expense-report
select-all so the totals retry fires.
@ZhenjaHorbach

Copy link
Copy Markdown
Contributor

@dilshodmackbook-sketch
Can you record your own videos?
AI is good, but we are responsible for regressions.

@dilshodmackbook-sketch

Copy link
Copy Markdown
Contributor Author

@ZhenjaHorbach could you share a test account with 50+ reports in a single month? My account doesn't have that data, and I need it to record the Select all flow. Thanks!

@JmillsExpensify JmillsExpensify 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.

LGTM

@ZhenjaHorbach

Copy link
Copy Markdown
Contributor

@ZhenjaHorbach could you share a test account with 50+ reports in a single month? My account doesn't have that data, and I need it to record the Select all flow. Thanks!

You can use splits flow to create 30 transactions
As a result, if you repeat it twice, you will have more than 50 transactions
Снимок экрана — 2026-09-01 в 09 25 45

@dilshodmackbook-sketch

Copy link
Copy Markdown
Contributor Author

@ZhenjaHorbach I re-recorded all the videos myself on a real account with 50+ reports - web, mWeb, iOS and Android. CI is green now too. Ready on my end, let me know if anything else is needed.

@ZhenjaHorbach

ZhenjaHorbach commented Sep 2, 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 proper code patterns were followed (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 verified that this PR follows the guidelines as stated in the Review Guidelines
  • 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 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 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.
  • 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
2026-09-03.10.33.17.mov
Android: mWeb Chrome
2026-09-03.10.33.17.mov
iOS: HybridApp
2026-09-03.10.27.01.mov
iOS: mWeb Safari
2026-09-03.10.21.36.mov
MacOS: Chrome / Safari
2026-09-03.10.17.14.mov

@ZhenjaHorbach

ZhenjaHorbach commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

I have an infinite loading when I have a custom date range and try to select all reports
I checked a bit, and we missed a few things

  1. Search.ts:1165 - dedupe's totals-upgrade check was EXPENSE-only and an EXPENSE_REPORT totals request colliding with an in-flight plain request got dropped.
  2. useSearchPageSetup.ts:38 - page-level fetch didn't know about areAllMatchingItemsSelected, so it could fire a plain request that explicitly clears totals on arrival, wiping the reportCount just fetched

So we can add these changes

src/hooks/useSearchPageSetup.ts
  @@ -1,4 +1,4 @@
  -import {useSearchQueryContext, useSearchResultsContext, useSearchSelectionActions} from '@components/Search/SearchContext';
  +import {useSearchQueryContext, useSearchResultsContext, useSearchSelectionActions, useSearchSelectionContext} from '@components/Search/SearchContext';
   import type {SearchQueryJSON} from '@components/Search/types';
   
   import {saveLastSearchParams} from '@libs/actions/ReportNavigation';
  @@ -33,9 +33,12 @@ function useSearchPageSetup(queryJSON: Readonly<SearchQueryJSON> | undefined) {
  +    const {areAllMatchingItemsSelected} = useSearchSelectionContext();
   
       const hash = queryJSON?.hash;
  -    const shouldCalculateTotals = useSearchShouldCalculateTotals(currentSearchKey, hash, true);
  +    // Without this, a plain page-level fetch during active select-all clears totals on arrival
  +    // (shouldClearTotals in getOnyxLoadingData), wiping a total the Search-internal effect already fetched.
  +    const shouldCalculateTotals = useSearchShouldCalculateTotals(currentSearchKey, hash, true, areAllMatchingItemsSelected);
   
       // Derived primitives so effects do not depend on the whole snapshot object (new reference every
       // Onyx merge) while exhaustive-deps still sees every transition that matters for firing search().
  +5 -2

src/libs/actions/Search.ts
  @@ -1162,7 +1162,10 @@ function search({
  -        const needsTotalsUpgrade = queryJSON.type === CONST.SEARCH.DATA_TYPES.EXPENSE && shouldCalculateTotals && !inFlightRequest.shouldCalculateTotals;
  +        // Not just EXPENSE: any type can now need totals (e.g. EXPENSE_REPORT's reportCount). Gating this
  +        // to one type let a totals request for another type collide with an in-flight request and get
  +        // silently dropped, so the total never arrived and the bulk-actions button spun forever.
  +        const needsTotalsUpgrade = shouldCalculateTotals && !inFlightRequest.shouldCalculateTotals;
           // A user-submitted query colliding with an unflagged in-flight request (e.g. a programmatic refresh
           // of the same query) must still reach the backend flagged, or it never enters recent searches.
           const needsSaveRecentSearchUpgrade = shouldSaveRecentSearch && !inFlightRequest.shouldSaveRecentSearch;
  +4 -1

@BartekObudzinski

Copy link
Copy Markdown
Contributor

I tested this PR and @ZhenjaHorbach comment is valid and need to be addressed for that case, it fixes #99502 as well
#99502 (comment)

@ZhenjaHorbach

ZhenjaHorbach commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

I tested this PR and @ZhenjaHorbach comment is valid and need to be addressed for that case, it fixes #99502 as well #99502 (comment)

@BartekObudzinski
I suppose you haven't opened your PR yet with a similar fix? 😅
And we can add it here?

@BartekObudzinski

Copy link
Copy Markdown
Contributor

No I did not create a PR, waiting for this one to be shipped, and yes you should add it here

@dilshodmackbook-sketch

Copy link
Copy Markdown
Contributor Author

@ZhenjaHorbach added both changes and updated the expense-report totals test to match the new behavior. Since the totals request no longer gets dropped, this should cover #99502 as well. Thanks for the detailed diagnosis.

@ZhenjaHorbach

Copy link
Copy Markdown
Contributor

@dilshodmackbook-sketch
Let's update the branch to the latest version of main to fix jest issues

@codecov

codecov Bot commented Sep 3, 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/SearchBulkActionsButton.tsx 90.80% <100.00%> (+0.44%) ⬆️
src/hooks/useSearchPageSetup.ts 97.14% <100.00%> (+0.08%) ⬆️
src/libs/actions/Search.ts 53.79% <100.00%> (ø)
src/components/Search/index.tsx 55.55% <66.66%> (+0.09%) ⬆️
... and 8 files with indirect coverage changes

@dilshodmackbook-sketch

Copy link
Copy Markdown
Contributor Author

Done - updated the branch to the latest main, and all jest/tests are green now. Ready for another look.

@JS00001
JS00001 merged commit af3078c into Expensify:main Sep 3, 2026
34 of 35 checks passed
@github-actions

github-actions Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

🚧 JS00001 has triggered a test Expensify/App build. You can view the workflow run here.

@OSBotify

OSBotify commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release.

@OSBotify

OSBotify commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

🚀 Deployed to staging by https://github.com/JS00001 in version: 9.4.70-0 🚀

platform result
🕸 web 🕸 success ✅
🤖 android 🤖 success ✅
🍎 iOS 🍎 success ✅

@MelvinBot

Copy link
Copy Markdown
Contributor

Yes — a help site change is needed. Draft PR: #100338

This PR changes what a number on screen means. Before it, choosing Select all on the Reports tab of the Spend page labelled the button with the matching expense count. Now it shows the matching report count — so the button and the footer legitimately disagree (your own recording: 110 selected above Expenses: 93). The help site described neither count, so a member who sees two different numbers has nothing to check against. That is the confusion the linked issues were filed as.

What the docs PR changesdocs/articles/new-expensify/reports-and-expenses/Getting-Started-with-the-Spend-Page.md:

  • New How to select every matching report on the Spend page section — the two options the select-all checkbox offers once a search has more results than the page has loaded (Select all on this page vs Select all), the brief loading state while the matching-report count arrives, and the offline fallback to the loaded-page count.
  • New What the selection count on the Reports tab counts section — the button counts reports, the footer counts expenses.
  • Clarified the existing Expenses footer bullet: it always counts expenses, including on the Reports tab (your PR leaves the footer on search.count).
  • Two new FAQ entries and expanded keywords metadata.
Articles reviewed and label verification

Reviewed, no change needed:

  • Search-and-Download-Expenses.md and How-to-Export-Reports.md — both reference the top checkbox and the N selected button only in the context of exporting, where reports are the unit either way.
  • How-to-Export-Expenses.md — Expenses tab only; isExpenseType arithmetic is untouched by this PR.

Label verificationSpend, Reports, and Filters were confirmed against the live web UI. Select all, Select all on this page, N selected, Total spend, and Expenses were confirmed against the shipped strings in src/languages/en.ts and their call sites (SearchSelectAllMenu.tsx:55-56, SearchPageFooter.tsx:133-138). The test account had no reports, so the multi-select header itself could not be driven live — worth a glance when you review.

Note the docs say Filters (plural), not Filter as written in your test steps. The live UI is Filters, so the article is already correct.

One thing I couldn't do: GitHub rejected the assignment — dilshodmackbook-sketch isn't assignable on Expensify/App (read-level access), so the PR is unassigned. The HelpDot label is applied and you're tagged in the body.

@dilshodmackbook-sketch, please review the linked help site PR and confirm it reflects the current behavior. Then mark the linked help site PR Ready for review


view run

@OSBotify

OSBotify commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

🚀 Deployed to staging by https://github.com/JS00001 in version: 9.4.72-0 🚀

platform result
🕸 web 🕸 success ✅
🤖 android 🤖 success ✅
🍎 iOS 🍎 success ✅

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.

7 participants