Skip to content

Fix: Web-Scan-Scan expense from Reports, the existing report disappears in filter for a while - #82042

Merged
luacmartins merged 17 commits into
Expensify:mainfrom
annaweber830:fix-80576
Apr 18, 2026
Merged

luacmartins merged 17 commits into
Expensify:mainfrom
annaweber830:fix-80576

Conversation

@annaweber830

Copy link
Copy Markdown
Contributor

Explanation of Change

Fixed Issues

$ #80576
PROPOSAL: #80576 (comment)

Tests

  1. Create a workspace and scan receipt to workspace chat
  2. Navigate to Reports tab
  3. Choose type: Expense report, To do Submit
  4. Drag and drop an image file to Scan receipts zone
  5. Select Category and click on Create expense
  6. Observe reports page and wait a time
  7. After creating scan expense from reports, the existing report in filter should still display
  • Verify that no errors appear in the JS console

Offline tests

Same as test

QA Steps

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

  1. Create a workspace and scan receipt to workspace chat
  2. Navigate to Reports tab
  3. Choose type: Expense report, To do Submit
  4. Drag and drop an image file to Scan receipts zone
  5. Select Category and click on Create expense
  6. Observe reports page and wait a time
  7. After creating scan expense from reports, the existing report in filter should still display
  • 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 verified there are no new alerts related to the canBeMissing param for useOnyx
  • 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 shown in the product is localized by adding it to src/languages/* files and using the translation method
      • If any non-english text was added/modified, I used JaimeGPT to get English > Spanish translation. I then posted it in #expensify-open-source and it was approved by an internal Expensify engineer. Link to Slack message:
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • 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)
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • 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)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.ts or at the top of the file that uses the constant) are defined as such
  • I verified that if a function's arguments changed that all usages have also been updated correctly
  • 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.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • 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
Screen.Recording.2026-02-10.at.11.51.32.AM.mp4

@annaweber830
annaweber830 requested review from a team as code owners February 10, 2026 19:55
@melvin-bot
melvin-bot Bot requested review from ZhenjaHorbach and trjExpensify and removed request for a team February 10, 2026 19:55
@melvin-bot

melvin-bot Bot commented Feb 10, 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]

const reportNameValuePair = allReportNameValuePairs?.[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report.chatReportID}`];
const reportActions = Object.values(allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.reportID}`] ?? []);
const reportTransactions = transactionsByReportID[report.reportID] ?? [];
const reportMetadata = allReportMetadata?.[`${ONYXKEYS.COLLECTION.REPORT_METADATA}${report.reportID}`];

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.

❌ CONSISTENCY-2 (docs)

The inline check isOpenExpenseReport(report) && isCurrentUserSubmitter(report) && reportTransactions.length > 0 && \!isArchivedReport(reportNameValuePair) is missing critical business logic that was present in the original isSubmitAction function.

Missing checks from original isSubmitAction:

  1. hasPendingDEWSubmit(reportMetadata, hasDynamicExternalWorkflow(policy)) - prevents submission when pending Dynamic External Workflow
  2. transactionAreComplete check - ensures all transactions have valid amounts (transaction.amount \!== 0 || transaction.modifiedAmount \!== 0)
  3. All-pending check - returns false if reportTransactions.every((transaction) => isPending(transaction))
  4. Scanning check - returns false if reportTransactions.some((transaction) => isScanning(transaction))
  5. Violation checks - checks for submission-blocking violations when violations are provided
  6. Self-approval prevention - prevents showing submit when submitToAccountID === report.ownerAccountID && policy?.preventSelfApproval

Suggested fix:

Instead of replacing isSubmitAction with an incomplete inline check, either:

  1. Continue using isSubmitAction but adjust its logic if needed, OR
  2. If the inline check is intentional for this specific use case, add a comment explaining why the simpler logic is correct here

If option 2 is chosen, the comment should explain why checks like scanning receipts, pending transactions, DEW submit status, and violations don't need to be checked in the todos context.


Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.

continue;
}
const policy = allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${report.policyID}`];
const reportNameValuePair = allReportNameValuePairs?.[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report.chatReportID}`];

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.

❌ PERF-2 (docs)

The reportActions computation using Object.values() happens unconditionally for every report, but it is only used in the isExportAction check. If the earlier checks (shouldShowInSubmitTodo, isApproveAction, or isPrimaryPayAction) would result in early returns or if isExportAction is not called, this computation is wasted.

Suggested fix:

Move the reportActions computation to just before it's needed:

const policy = allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${report.policyID}`];
const reportNameValuePair = allReportNameValuePairs?.[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report.chatReportID}`];
const reportTransactions = transactionsByReportID[report.reportID] ?? [];
const reportMetadata = allReportMetadata?.[`${ONYXKEYS.COLLECTION.REPORT_METADATA}${report.reportID}`];

const shouldShowInSubmitTodo = isOpenExpenseReport(report) && isCurrentUserSubmitter(report) && reportTransactions.length > 0 && !isArchivedReport(reportNameValuePair);
if (shouldShowInSubmitTodo) {
    reportsToSubmit.push(report);
}
if (isApproveAction(report, reportTransactions, currentUserAccountID, reportMetadata, policy)) {
    reportsToApprove.push(report);
}
if (isPrimaryPayAction(report, currentUserAccountID, login, bankAccountList, policy, reportNameValuePair)) {
    reportsToPay.push(report);
}

// Only compute reportActions when needed for export check
const reportActions = Object.values(allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.reportID}`] ?? []);
if (isExportAction(report, login, policy, reportActions)) {
    reportsToExport.push(report);
}

Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.

@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: 5de32919e9

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

const reportActions = Object.values(allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.reportID}`] ?? []);
const reportTransactions = transactionsByReportID[report.reportID] ?? [];
const reportMetadata = allReportMetadata?.[`${ONYXKEYS.COLLECTION.REPORT_METADATA}${report.reportID}`];
const shouldShowInSubmitTodo = isOpenExpenseReport(report) && isCurrentUserSubmitter(report) && reportTransactions.length > 0 && !isArchivedReport(reportNameValuePair);

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 Restore pending-submit guard for submit todos

The new shouldShowInSubmitTodo predicate now classifies submit todos using only open/owner/has-transactions/not-archived checks, which drops the pending-submit protections that isSubmitAction previously enforced (notably hasPendingDEWSubmit in src/libs/ReportPrimaryActionUtils.ts). In DEW-enabled policies, reports that are already mid-submit can now reappear in To do → Submit, so users see non-actionable items and incorrect submit counts while submission is still in flight.

Useful? React with 👍 / 👎.

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

Looking at the video evidence for this one on Web/Desktop doesn't seem to confirm or deny the bug fix. Could you please make sure to capture the bug fix?

As I understand the bug...

  1. User goes to the Submit tab
  2. They have a draft report to submit
  3. User scans a second receipt, it's added to that draft report
  4. They're navigated to Reports > Expenses upon taking that action to see feedback that it was added
  5. User clicks on the Submit tab while the receipt is scanning
  6. The draft report is no longer shown while the receipt is scanning
  7. The receipt scan completes and the draft report is shown again

So the bug we're addressing here is with steps 6&7. If there are eligible expenses to submit on the report, continue showing the report in the Submit tab as it is eligible to submit. If you submit a report with any scanning expenses on it, we should already be automatically moving those scanning expenses off the report on submission - and we don't show a submit button if all expenses on the report are still scanning.

CC: @JS00001 @luacmartins for vis btw!

@ZhenjaHorbach

Copy link
Copy Markdown
Contributor

@JS00001 @luacmartins

Looking at the video evidence for this one on Web/Desktop doesn't seem to confirm or deny the bug fix. Could you please make sure to capture the bug fix?

As I understand the bug...

  1. User goes to the Submit tab
  2. They have a draft report to submit
  3. User scans a second receipt, it's added to that draft report
  4. They're navigated to Reports > Expenses upon taking that action to see feedback that it was added
  5. User clicks on the Submit tab while the receipt is scanning
  6. The draft report is no longer shown while the receipt is scanning
  7. The receipt scan completes and the draft report is shown again

So the bug we're addressing here is with steps 6&7. If there are eligible expenses to submit on the report, continue showing the report in the Submit tab as it is eligible to submit. If you submit a report with any scanning expenses on it, we should already be automatically moving those scanning expenses off the report on submission - and we don't show a submit button if all expenses on the report are still scanning.

CC: @JS00001 @luacmartins for vis btw!

@JS00001 @luacmartins
Could you confirm this, please?

@JS00001

JS00001 commented Feb 17, 2026 •

Copy link
Copy Markdown
Contributor

That seems like the bug yes, from the original issue:

Expected Result:
After creating scan expense from reports, the existing report in filter should still display

Actual Result:
After creating scan expense from reports, the existing report in filter is disappeared for a short time

@luacmartins

Copy link
Copy Markdown
Contributor

I agree with the above. We currently return false here if not all transactions are complete (which is the case when the receipt is scanning). We should update that logic to check if at least one transaction is complete.

@annaweber830

Copy link
Copy Markdown
Contributor Author

Hi @ZhenjaHorbach, what should I do next?

@annaweber830

Copy link
Copy Markdown
Contributor Author

Hi @luacmartins, @ZhenjaHorbach What should I do next?

@ZhenjaHorbach

Copy link
Copy Markdown
Contributor

Oh
Sorry
I will recheck the PR today
@annaweber830
Could you fix conflicts?

@melvin-bot

melvin-bot Bot commented Mar 4, 2026

Copy link
Copy Markdown

Hey, I noticed you changed src/languages/en.ts in a PR from a fork. For security reasons, translations are not generated automatically for PRs from forks.

If you want to automatically generate translations for other locales, an Expensify employee will have to:

  1. Look at the code and make sure there are no malicious changes.
  2. Run the Generate static translations GitHub workflow. If you have write access and the K2 extension, you can simply click: [this button]

Alternatively, if you are an external contributor, you can run the translation script locally with your own OpenAI API key. To learn more, try running:

npx ts-node ./scripts/generateTranslations.ts --help

Typically, you'd want to translate only what you changed by running npx ts-node ./scripts/generateTranslations.ts --compare-ref main

@annaweber830

Copy link
Copy Markdown
Contributor Author

Hi @ZhenjaHorbach I updated my PR.

@codecov

codecov Bot commented Mar 4, 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/libs/ReportPrimaryActionUtils.ts 91.92% <100.00%> (-0.11%) ⬇️
src/libs/actions/OnyxDerived/configs/todos.ts 100.00% <ø> (ø)
... and 12 files with indirect coverage changes

@ZhenjaHorbach

Copy link
Copy Markdown
Contributor

Hi @ZhenjaHorbach I updated my PR.

@annaweber830
Sorry for delay
And looks like everything is correct with the requirements
But could you fix conflicts again, please? 😅

@luacmartins

Copy link
Copy Markdown
Contributor

@annaweber830 what's the latest update on this one?

@annaweber830

Copy link
Copy Markdown
Contributor Author

Hi @luacmartins I already updated PR.

@ZhenjaHorbach

Copy link
Copy Markdown
Contributor

Hi @luacmartins I already updated PR.

Nice then
I will complete checklist today or tomorrow

@annaweber830
And could you fix lint issues?

@annaweber830

Copy link
Copy Markdown
Contributor Author

Hi @ZhenjaHorbach I will fix lint issue.

@luacmartins

Copy link
Copy Markdown
Contributor

@annaweber830 what's the latest here?

@annaweber830

Copy link
Copy Markdown
Contributor Author

@ZhenjaHorbach I updated PR.

@luacmartins

Copy link
Copy Markdown
Contributor

Thanks @annaweber830. @ZhenjaHorbach let's review this one please

@ZhenjaHorbach

Copy link
Copy Markdown
Contributor

Reviewing!

@melvin-bot
melvin-bot Bot requested a review from aldo-expensify April 14, 2026 11:30
const reportMetadata = allReportMetadata?.[`${ONYXKEYS.COLLECTION.REPORT_METADATA}${report.reportID}`];

if (isSubmitAction(report, reportTransactions, reportMetadata, policy, reportNameValuePair, undefined, login, currentUserAccountID)) {
const shouldShowInSubmitTodo = isOpenExpenseReport(report) && isCurrentUserSubmitter(report) && reportTransactions.length > 0 && !isArchivedReport(reportNameValuePair);

@luacmartins luacmartins Apr 14, 2026 •

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.

Instead of creating a separate condition, can we please update it here and just call isSubmitAction as we used to? So that the issue is fixed everywhere?

trjExpensify
trjExpensify previously approved these changes Apr 14, 2026

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

@ZhenjaHorbach video here shows the bug being resolved: #82042 (comment)

@annaweber830 I think you can improve the test steps to cut out the irrelevant navigation from the Inbox and navigation.

  1. Create a workspace and scan receipt to workspace chat
  2. Navigate to Reports tab
  3. Choose type: Expense report, To do Submit
  4. Drag and drop an image file to Scan receipts zone
  5. Select Category and click on Create expense
  6. Observe reports page and wait a time
  7. After creating scan expense from reports, the existing report in filter should still display

I'd suggest...

  1. Go to the Reports page
  2. Create an expense
  3. Verify the "Submit" todo has a (1) counter in the LHN
  4. Drag and drop a receipt to create another expense
  5. Verify you're navigated to the "Expenses" LHN page
  6. Verify the "Submit" todo still has a (1) counter in the LHN
  7. Click on the "Submit" LHN page while the receipt is still scanning
  8. Verify the draft report remains visible

@luacmartins

Copy link
Copy Markdown
Contributor

@annaweber830 bump on my comment above #82042 (comment)

@luacmartins

Copy link
Copy Markdown
Contributor

@annaweber830 bump #82042 (comment)

@annaweber830

Copy link
Copy Markdown
Contributor Author

@luacmartins Sorry I updated PR.

@luacmartins
luacmartins merged commit 03023c1 into Expensify:main Apr 18, 2026
32 checks passed
@OSBotify

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

Copy link
Copy Markdown
Contributor

🚀 Deployed to staging by https://github.com/luacmartins in version: 9.3.61-0 🚀

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

Bundle Size Analysis (Sentry):

@MelvinBot

Copy link
Copy Markdown
Contributor

No help site changes are required for this PR.

The changes are purely internal bug fixes to ReportPrimaryActionUtils.ts — consolidating two transaction-state checks (pending and scanning) into a single condition. This fixes a display timing bug but doesn't change any user-facing features, workflows, UI labels, or settings that would be documented in App/docs/articles.

@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to production by https://github.com/marcaaron in version: 9.3.61-4 🚀

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