Skip to content

[NoQA] Send searchKey in reconciliation CSV export so cash back rows are included - #99106

Open
ShridharGoel wants to merge 4 commits into
Expensify:mainfrom
ShridharGoel:fix/export-send-searchkey
Open

[NoQA] Send searchKey in reconciliation CSV export so cash back rows are included#99106
ShridharGoel wants to merge 4 commits into
Expensify:mainfrom
ShridharGoel:fix/export-send-searchkey

Conversation

@ShridharGoel

@ShridharGoel ShridharGoel commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

Explanation of Change

This PR fixes two bugs that caused Expensify Card cash back rows to disappear from the bank reconciliation view.

Bug 1: CSV export dropped cash back rows

The CSV export built the backend query without searchKey. The search() call already sends searchKey, and the backend uses it to pick the right result set. For the bank reconciliation view, searchKey is reconciliation, and the backend uses it to add the Expensify Card cash back rows.

Because the export did not send searchKey, the backend treated the export as a plain expense search and dropped the cash back rows. This caused two symptoms:

  • Selecting a mix of settlement rows and cash back rows: the CSV had the settlements but no cash back.
  • Selecting only a cash back row: the export failed with "No results found to be exported."

Fix: send searchKey in the export query, the same way search() does, so the exported rows match the rows the user sees.

Bug 2: Feed or bank account filter hid cash back rows from the live view

The reconciliation tab identity (currentSearchKey) is derived by matching similarSearchHash against the suggested searches. When a user applied a feed or bank account filter, the filter key was added to similarSearchHash, which no longer matched the reconciliation suggested search. This made currentSearchKey undefined, so the search() call sent no searchKey, and the backend skipped the cash back arm entirely.

Fix: add FEED and BANK_ACCOUNT to similarSearchIgnoredFilters so these filters refine results without changing the tab identity or the backend searchKey.

Fixed Issues

For #94133
PROPOSAL:

Tests

  1. Open a workspace that is on the Expensify Card cash back reconciliation beta.
  2. Go to the Bank reconciliation search, grouped by withdrawal, so the list shows Expensify Card settlements and cash back rows.
  3. Select one settlement row and one cash back row, then export the current view to CSV.
  4. Verify the CSV file downloads and contains both the settlement row and the cash back row.
  5. Select only a cash back row, then export the current view to CSV.
  6. Verify the CSV file downloads and contains the cash back row, with no "No results found to be exported" error.
  7. Apply a feed filter in the reconciliation view.
  8. Verify cash back rows still appear alongside the filtered settlements.
  9. Remove the feed filter and apply a bank account filter.
  10. Verify cash back rows still appear alongside the filtered settlements.
Screenshot 2026-08-21 at 3 06 10 AM Screenshot 2026-08-21 at 3 06 55 AM
  1. Open a workspace that is on the Expensify Card cash back reconciliation beta and has cashback.
  2. Go to Spend > Bank reconciliation.
  3. Verify that cashback rows show.
  4. Apply some feed filters.
  5. Verify that cashback rows still show.
Screen.Recording.2026-08-26.at.10.55.30.PM.mov
  • Verify that no errors appear in the JS console

Offline tests

QA Steps

N/A - will be tested along with the Cashback feature.

  • 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 Guideline
  • 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
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari

The CSV export serialized the query without searchKey, so the
backend treated reconciliation exports as a plain expense
search and dropped the Expensify Card cash back arm. search()
already sends searchKey; the export now matches that so the
exported rows match the viewed rows.
@ShridharGoel

Copy link
Copy Markdown
Contributor Author

@MelvinBot review, can this lead to regressions?

@MelvinBot

Copy link
Copy Markdown
Contributor

Low regression risk. The change is a targeted, additive fix that mirrors an already-established pattern in the codebase, and it's effectively a no-op for the large majority of searches.

Why it's safe:

  • Same pattern search() already uses. The view is produced by search(), which sends searchKey in the backend query the same way (Search.ts:1196-1206). The footer-conversion path does the identical thing with a near-identical comment (Search.ts:1346-1356). This PR just makes the CSV export consistent with both, so the exported set matches the viewed set.
  • No change for searches without a searchKey. currentSearchKey is SearchKey | undefined and is only set for suggested/todo searches; for custom and saved searches it's undefined. serializeQueryJSONForBackend runs the object through JSON.stringify, which drops undefined keys — so for those searches the serialized query is byte-identical to before. The new behavior only kicks in for searches that actually have a key (reconciliation, unapprovedCash, etc.).
  • Can't drop legitimately-selected rows. The export also sends transactionIDList/reportIDList of selected items, and selected items are by definition a subset of the current view — which was itself built with currentSearchKey. Sending the key can only align the backend's generated row set to the view; it won't exclude rows the user actually selected. currentSearchKey and the exported queryJSON both come from the same current-search context, so they stay in sync (including the all-matching path at useSearchBulkActions.ts:954).

One thing worth noting (not a regression from this PR): the template/group export path at useSearchBulkActions.ts:843-859 (queueExportSearchWithTemplate) still builds its jsonQuery without searchKey. If reconciliation views can be exported via a template, the same "cash back rows dropped" bug would still surface there. Might be worth confirming whether that path is reachable for reconciliation and, if so, fixing it in the same spirit.

Verification
  • The changed call: useSearchBulkActions.ts:920-923.
  • getCSVExportParameters feeds both queueExportSearchItemsToCSV (all-matching) and exportSearchItemsToCSV (normal selection) paths; both now carry searchKey, both aligned with the view.
  • serializeQueryJSONForBackend just spreads and stringifies, so an undefined searchKey is omitted — confirming the no-op behavior for keyless searches.
  • Type-safe: the object is spread into the generic serializeQueryJSONForBackend<T>, so the extra searchKey field needs no signature change.

I did not run a device test — this is a code-review question, and exercising the reconciliation cash-back path needs a workspace on the Expensify Card cash-back beta that the test account doesn't have, so a UI run wouldn't add signal beyond the static analysis above.


view run

@ShridharGoel

Copy link
Copy Markdown
Contributor Author

the template/group export path at useSearchBulkActions.ts:843-859 (queueExportSearchWithTemplate) still builds its jsonQuery without searchKey. If reconciliation views can be exported via a template, the same "cash back rows dropped" bug would still surface there. Might be worth confirming whether that path is reachable for reconciliation and, if so, fixing it in the same spirit.

Cash back is a group-only row (no nested transactions), so selecting it makes includesGroupExport = true, which makes the gate if (!allSelectedAreDeleted && !includesGroupExport) in useSearchBulkActions as false → template export options are not offered.

@ShridharGoel ShridharGoel changed the title Send searchKey in reconciliation CSV export so cash back rows are included [HOLD] Send searchKey in reconciliation CSV export so cash back rows are included Aug 25, 2026
@ShridharGoel ShridharGoel changed the title [HOLD] Send searchKey in reconciliation CSV export so cash back rows are included [NoQA] Send searchKey in reconciliation CSV export so cash back rows are included Aug 25, 2026
@ShridharGoel
ShridharGoel marked this pull request as ready for review August 25, 2026 10:53
@ShridharGoel
ShridharGoel requested review from a team as code owners August 25, 2026 10:53
@melvin-bot
melvin-bot Bot requested review from flaviadefaria and puneetlath and removed request for a team August 25, 2026 10:53
@melvin-bot

melvin-bot Bot commented Aug 25, 2026

Copy link
Copy Markdown

@puneetlath 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]

@ShridharGoel
ShridharGoel requested review from JS00001 and removed request for puneetlath August 25, 2026 10:54
@JS00001

JS00001 commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

I think it makes sense to send the searchKey, so that we're sure we're getting the right results from the search

@ShridharGoel

Copy link
Copy Markdown
Contributor Author

@JS00001 Thanks, can we merge it then?

JS00001
JS00001 previously approved these changes Aug 26, 2026
@JS00001

JS00001 commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

@ShridharGoel can you add videos please?

@ShridharGoel

ShridharGoel commented Aug 26, 2026

Copy link
Copy Markdown
Contributor Author

@JS00001 Do you mean videos showing the export being done? Asking since screenshots of the exported CSV are already there

@ShridharGoel
ShridharGoel force-pushed the fix/export-send-searchkey branch from fb682ac to f6c314c Compare August 26, 2026 17:06
@ShridharGoel

Copy link
Copy Markdown
Contributor Author

@JS00001 Added another change and also included a video for that

@JS00001

JS00001 commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

Jest is failing

@ShridharGoel

Copy link
Copy Markdown
Contributor Author

Seem unrelated:

FAIL tests/actions/IOU/SearchUpdateTest.ts
  ● actions/IOU › shouldOptimisticallyUpdateSearch › when the current hash is submit action query it should only return true if the iou report is in draft state

    expect(received).toBeTruthy()

    Received: false

      194 |
      195 |             // When the report is in draft status it should return true
    > 196 |             expect(shouldOptimisticallyUpdateSearch(currentSearchQueryJSON, iouReport, false, RORY_ACCOUNT_ID, transaction)).toBeTruthy();
          |                                                                                                                              ^
      197 |
      198 |             // If the report is not in draft state it should return false
      199 |             iouReport.stateNum = CONST.REPORT.STATE_NUM.SUBMITTED;

      at Object.toBeTruthy (tests/actions/IOU/SearchUpdateTest.ts:196:126)

  ● actions/IOU › shouldOptimisticallyUpdateSearch › when the current hash is approve action query it should only return true if the iou report is in outstanding state

    expect(received).toBeTruthy()

    Received: false

      261 |             iouReport.stateNum = CONST.REPORT.STATE_NUM.SUBMITTED;
      262 |             iouReport.statusNum = CONST.REPORT.STATUS_NUM.SUBMITTED;
    > 263 |             expect(shouldOptimisticallyUpdateSearch(currentSearchQueryJSON, iouReport, false, RORY_ACCOUNT_ID, transaction)).toBeTruthy();
          |                                                                                                                              ^
      264 |         });
      265 |
      266 |         it('when the current hash is unapproved cash action query it should only return true if the iou report is in either draft or outstanding state', () => {

      at Object.toBeTruthy (tests/actions/IOU/SearchUpdateTest.ts:263:126)

@ShridharGoel

Copy link
Copy Markdown
Contributor Author

Latest main is already merged

Comment thread src/libs/SearchQueryUtils.ts
@ShridharGoel
ShridharGoel requested a review from JS00001 August 26, 2026 17:59
@JS00001

JS00001 commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

The failing tests do seem related:
when the current hash is approve action query

This PR logic changed the logic used to calculate the hash

@ShridharGoel

Copy link
Copy Markdown
Contributor Author

Got it, shouldn't the tests derive the hash from the runtime suggested searches instead of hardcoding values?

Like suggestedSearches[CONST.SEARCH.SEARCH_KEYS.SUBMIT].similarSearchHash instead of 1855682507 ?

@JS00001

JS00001 commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Yes, i agree

@ShridharGoel

Copy link
Copy Markdown
Contributor Author

Thanks, updated.

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.

3 participants