Skip to content

fix: auto report when card expense belongs to other workspace - #102017

Merged
yuwenmemon merged 14 commits into
Expensify:mainfrom
daledah:fix/101767
Oct 7, 2026
Merged

yuwenmemon merged 14 commits into
Expensify:mainfrom
daledah:fix/101767

Conversation

@daledah

@daledah daledah commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

Explanation of Change

Fixed Issues

$ #101767
PROPOSAL:

Tests

Precondition:
For Admin:

  • Invite User B to the workspace.
  • Create a company card feed with two cards that have transactions.
  • Assign a card to yourself and User B.
  • Unreport your card transactions so that the card transactions are in self DM.

For User B:

  • Create a company card feed with two cards that have transactions.
  • Assign a card to yourself.
  • Move the card transactions to the draft report in the invited workspace.

Perform the steps below as admin:

  1. Go to Reports > Expenses.
  2. Select an unreported card expense and draft card expense from User B (from User B's own workspace).
  3. Click Move to report.
  4. Verify that: auto report options isn't displayed
  • 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
  • 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.
  • 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).
  • 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

iOS: Native
ios.mov
MacOS: Chrome / Safari
web.mov

@codecov

codecov Bot commented Sep 23, 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/ONYXKEYS.ts 100.00% <ø> (ø)
...omponents/Search/FilterComponents/CardSelector.tsx 90.38% <100.00%> (-0.85%) ⬇️
src/libs/CardUtils.ts 87.68% <100.00%> (+0.07%) ⬆️
src/libs/ExportOnyxState/masking.ts 80.95% <ø> (ø)
src/setup/index.ts 100.00% <ø> (ø)
src/hooks/useLoadSearchCardData.ts 91.66% <91.66%> (ø)
src/hooks/useSearchBulkActions.ts 79.92% <66.66%> (+0.02%) ⬆️
...es/iou/request/step/IOURequestEditReportCommon.tsx 85.71% <50.00%> (ø)
src/libs/actions/Search.ts 67.32% <0.00%> (-0.20%) ⬇️
...rc/pages/Search/SearchTransactionsChangeReport.tsx 0.00% <0.00%> (ø)
... and 18 files with indirect coverage changes

@daledah
daledah marked this pull request as ready for review September 24, 2026 08:56
@daledah
daledah requested review from a team as code owners September 24, 2026 08:56
@melvin-bot
melvin-bot Bot requested review from heyjennahay and mkhutornyi and removed request for a team September 24, 2026 08:56
@melvin-bot

melvin-bot Bot commented Sep 24, 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 the request for review from a team September 24, 2026 08:57
Comment thread src/hooks/useSearchBulkActions.ts Outdated
Comment thread src/libs/CardUtils.ts Outdated
Comment thread src/pages/Search/SearchTransactionsChangeReport.tsx Outdated
Comment thread src/pages/iou/request/step/IOURequestEditReportCommon.tsx Outdated
Comment thread tests/unit/CardUtilsTest.ts Outdated
@mkhutornyi

Copy link
Copy Markdown
Contributor

Please fix conflict

@MelvinBot

Copy link
Copy Markdown
Contributor

Review: 1 likely regression

Auto report can disappear for valid admin moves when workspace card lists aren't loaded in Onyx.

The new gate canResolveTransactionCard looks up each card in NON_PERSONAL_AND_WORKSPACE_CARD_LIST. That list is CARD_LIST (the viewer's own cards) plus WORKSPACE_CARDS_LIST (config).

Auto report only shows when hasMultipleSubmitters is true (IOURequestEditReportCommon.tsx:372). So at least one card always belongs to another member, and it can only come from WORKSPACE_CARDS_LIST.

In App code, WORKSPACE_CARDS_LIST is only filled by the workspace card pages (OpenPolicyCompanyCardsPage, OpenPolicyExpensifyCardsPage) and card actions. The Reports > Expenses page never fetches it. Search even has a separate openSearchCardFiltersPage call for card data.

How to reproduce:

  1. As an admin, sign in on a fresh device or with a cleared cache.
  2. Without opening Workspace > Company cards or Expensify Card, go to Reports > Expenses.
  3. Select card expenses from two members. The cards are on a feed you administer.
  4. Click Move to report.

Auto report is hidden, but the move would succeed. Before this PR, the option showed here. The same happens if the admin only opened one feed, because each feed's cards load separately.

Suggested fix: Load the admin's workspace card lists before gating. Or gate only on cards you know can't resolve, for example a card on a feed of a workspace the viewer doesn't administer, instead of treating "not in Onyx" as "can't resolve." The backend may already return these lists at sign-in. I can't confirm that from App code, so please check.

Other notes (no action needed)
  • The issue scenario is fixed: User B's card sits on a feed in User B's own workspace, so it's never in the admin's lists and Auto report stays hidden.
  • useSearchBulkActions (line 2928) and SearchTransactionsChangeReport use the same check, and the dependency arrays are updated. Undefined transactions still fail closed.
  • I didn't run a web test. The setup needs company card feeds on two accounts, which the test account doesn't have.

view run

@daledah

daledah commented Sep 28, 2026

Copy link
Copy Markdown
Contributor Author

@mkhutornyi i resolved

@mkhutornyi

Copy link
Copy Markdown
Contributor

What do you think of #102017 (comment)?

@mkhutornyi

mkhutornyi commented Sep 29, 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 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 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 and each prop has a /** comment above it */
    • The file is named correctly
    • 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
    • For Class Components, any internal methods passed to components event handlers are bound to this properly so there are no scoping issues (i.e. for onClick={this.submit} the method this.submit should be bound to this in the constructor)
    • Any internal methods bound to this are necessary to be bound (i.e. avoid this.submit = this.submit.bind(this); if this.submit is never passed to a component event handler like onClick)
    • All JSX used for rendering exists in the render method
    • 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 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 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
Android: mWeb Chrome
iOS: HybridApp
iOS: mWeb Safari
MacOS: Chrome / Safari
102017.mov

@mkhutornyi

Copy link
Copy Markdown
Contributor

Please confirm if we should fix #102017 (comment) or demote as edge case

@melvin-bot
melvin-bot Bot requested a review from yuwenmemon September 29, 2026 09:30
@daledah

daledah commented Sep 30, 2026

Copy link
Copy Markdown
Contributor Author

The failing test is not related to this PR, will merge main to fix it soon

@daledah

daledah commented Sep 30, 2026

Copy link
Copy Markdown
Contributor Author

Auto report can disappear for valid admin moves when workspace card lists aren't loaded in Onyx.

I can't reproduce this bug on my end.

@daledah

daledah commented Oct 1, 2026

Copy link
Copy Markdown
Contributor Author

@mkhutornyi could you please update your checklist?

@mkhutornyi

Copy link
Copy Markdown
Contributor

Author Checklist is failing

@daledah

daledah commented Oct 1, 2026

Copy link
Copy Markdown
Contributor Author

I updated

@mkhutornyi

Copy link
Copy Markdown
Contributor

All checks pass

Comment thread src/libs/CardUtils.ts
function canResolveTransactionCard(transaction: OnyxEntry<Pick<Transaction, 'managedCard' | 'cardID'>>, nonPersonalAndWorkspaceCards: OnyxEntry<CardList>): boolean {
// Inlined rather than calling isManagedCardTransaction: TransactionUtils already imports this file.
if (!transaction?.managedCard || !transaction.cardID) {
return false;

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.

nonPersonalAndWorkspaceCards is not authoritative: OpenSearchPage loads only 50 admin-visible cards. A valid card outside that subset makes this return false, hiding Move even though auto-report would succeed.

I think you would need to load or resolve the selected card IDs before treating absence as no access.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@yuwenmemon i updated, canResolveTransactionCard now takes whether the card list is complete, and only reads a card's absence as no access once it is

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

Thanks -- this handles the 50-card case after a successful fetch, but returning true while the list is incomplete reintroduces the original bug.

Also, you have Jest tests failing.

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

This still treats an unknown card as accessible while the full list is pending or unavailable offline, which can reproduce the original error. The completion flag is also set in finallyData, so failed requests are treated as complete. Please keep Auto report unavailable/loading until the request succeeds and retry after failure.

@MelvinBot

Copy link
Copy Markdown
Contributor

Review: 2 regressions, 1 risk

All three come from how the IS_SEARCH_FILTERS_CARD_DATA_LOADED flag gates Auto report. yuwenmemon raised the first two in the latest review. I confirmed them in the code at 47e4be0.

1. The original bug still reproduces while the card list is loading or offline.
When the flag is false, canResolveTransactionCard returns true for any managed card. The fetch starts only after you select rows, because useSearchBulkActions mounts only while the bulk bar shows (SearchBulkActionsBarWide.tsx:17-24). The hook also skips the fetch offline (useSearchBulkActions.ts:690-696).

To reproduce:

  1. As the admin from the test steps, sign in fresh, or go offline before you select anything.
  2. Go to Reports > Expenses and select the two card expenses from the test steps.
  3. Click Move to report right away. Auto report shows, and choosing it fails the whole move.

2. A failed fetch marks the list complete and hides valid Auto report.
openSearchCardFiltersPage sets the flag in finallyData, so a failed request also sets it to true. The flag is persisted, so the hook never retries. After that, any card missing from Onyx counts as "no access." Auto report then hides even for feeds the admin manages.

3. Risk: the flag never resets until sign-out. It isn't RAM-only. If the admin later gets a new feed or workspace, Auto report hides for valid moves unless those cards reach WORKSPACE_CARDS_LIST some other way. I couldn't confirm from App code whether the backend pushes them.

Suggested fix:

  • Set the "complete" flag in successData only. Use a RAM-only loading flag for the pending state.
  • Hide Auto report, or show it as loading, while the request is pending or you're offline.
  • Retry after a failure.
  • Start the fetch when Move to report opens, not only when the bulk bar mounts.
Other notes
  • Once the list loads successfully, the issue scenario is fixed. User B's card isn't in the admin's lists, so Auto report stays hidden.
  • No other component uses the renamed prop. Other IOURequestEditReportCommon callers keep the default, so Auto report stays hidden for them.
  • Search now calls OpenSearchCardFiltersPage the first time a user selects rows, once per sign-in. For admins with many feeds, this loads every workspace card list. Check it with a high-traffic account.
  • I didn't run a web test. The setup needs company card feeds on two accounts, and the test account doesn't have them.

@daledah

daledah commented Oct 7, 2026

Copy link
Copy Markdown
Contributor Author

@mkhutornyi @yuwenmemon i resolved all comments, could you please check again?

@yuwenmemon

Copy link
Copy Markdown
Contributor

@daledah Unit tests are still failing

@daledah

daledah commented Oct 7, 2026

Copy link
Copy Markdown
Contributor Author

@yuwenmemon all looks good now

@yuwenmemon
yuwenmemon merged commit 54a16e9 into Expensify:main Oct 7, 2026
34 of 35 checks passed
@OSBotify

OSBotify commented Oct 7, 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.

@github-actions

github-actions Bot commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

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

@OSBotify OSBotify mentioned this pull request Oct 8, 2026
90 tasks done
@OSBotify

OSBotify commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

🚀 Deployed to staging by https://github.com/yuwenmemon in version: 9.5.6-0 🚀

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

@MelvinBot

Copy link
Copy Markdown
Contributor

No help site update is needed. This bug fix only hides the Auto report option when a selected card expense uses a card on a feed the user doesn't administer. That is an edge case, and no article under docs/articles mentions Auto report.


view run

@OSBotify

OSBotify commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

🚀 Deployed to production by https://github.com/puneetlath in version: 9.5.6-6 🚀

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

Bundle Size Analysis (Sentry):

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.

5 participants