Report can be selected on confirm page when expense cannot be added#79583
Report can be selected on confirm page when expense cannot be added#79583MariaHCD merged 6 commits intoExpensify:mainfrom
Conversation
|
@dominictb 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] |
src/libs/ReportUtils.ts
Outdated
| const policy = allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${policyID}`]; | ||
| const reportNameValuePair = reportNameValuePairs?.[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${iouReport.reportID}`]; | ||
| const shouldAllowSubmittedReport = allowSubmitted || isInstantSubmitEnabled(policy) || isProcessingReport(activeReport); | ||
| const canSubmit = canSubmitReport(iouReport, policy, getReportTransactions(iouReport.reportID), undefined, false, currentUserEmail ?? ''); |
There was a problem hiding this comment.
❌ PERF-2 (docs)
The expensive canSubmitReport() function (which calls getReportTransactions() and iterates through all transactions) is being called before simple property checks. When isReportOutstanding is used in getOutstandingReportsForUser (line 11354), it filters through potentially many reports, calling canSubmitReport() for each one even if they would fail simple checks like isExpenseReport() or policyID matching.
Suggested fix: Restructure the function to perform simple property checks first before calling the expensive canSubmitReport(). This ensures the expensive operation only runs on reports that pass all simple validations.
src/libs/ReportUtils.ts
Outdated
| const policy = allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${policyID}`]; | ||
| const reportNameValuePair = reportNameValuePairs?.[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${iouReport.reportID}`]; | ||
| const shouldAllowSubmittedReport = allowSubmitted || isInstantSubmitEnabled(policy) || isProcessingReport(activeReport); | ||
| const canSubmit = canSubmitReport(iouReport, policy, getReportTransactions(iouReport.reportID), undefined, false, currentUserEmail ?? ''); |
There was a problem hiding this comment.
❌ PERF-11 (docs)
The expensive canSubmitReport() call (and getReportTransactions()) is computed unconditionally, even when not needed. When allowSubmitted is true (the default parameter value), the result of canSubmit is never used because the OR short-circuits. This means we are unnecessarily fetching all report transactions and performing expensive validation checks.
Suggested fix: Only compute canSubmit when actually needed by moving it inline with the OR expression to leverage short-circuit evaluation. This ensures the expensive operations only run when allowSubmitted and isProcessingReport(activeReport) are both false.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4fc1ab628c
ℹ️ 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".
src/libs/ReportUtils.ts
Outdated
| const canSubmit = canSubmitReport(iouReport, policy, getReportTransactions(iouReport.reportID), undefined, false, currentUserEmail ?? ''); | ||
| const shouldAllowSubmittedReport = allowSubmitted || canSubmit || isProcessingReport(activeReport); |
There was a problem hiding this comment.
Allow eligible processing reports in instant-submit flows
Replacing isInstantSubmitEnabled(policy) with canSubmitReport(...) makes shouldAllowSubmittedReport false for any report already in a submitted/processing state because canSubmitReport only returns true for open reports. In instant‑submit policies with approvals enabled, processing reports can still accept new expenses (see canAddTransaction, which allows processing reports awaiting first‑level approval). When creating an expense from workspace/global create (allowSubmitted=false and activeReport not processing), those eligible reports are now filtered out, so the report selector can’t target them even though adding is allowed. Consider preserving the instant‑submit allowance or basing this on canAddTransaction instead.
Useful? React with 👍 / 👎.
JmillsExpensify
left a comment
There was a problem hiding this comment.
Bit of an edge case, though makes sense that with instantly you wouldn't select the report. Product approved.
|
on it now |
|
@mkzie2 pls check the bot's comments above. They make sense to me |
|
@dukenv0307 I updated 👍 |
src/libs/ReportUtils.ts
Outdated
| if (allowSubmitted || isProcessingReport(activeReport)) { | ||
| return iouReport.stateNum <= CONST.REPORT.STATE_NUM.SUBMITTED && iouReport.statusNum <= CONST.REPORT.STATE_NUM.SUBMITTED; | ||
| } | ||
| if (canAddTransaction(iouReport, false, false)) { | ||
| return iouReport.stateNum <= CONST.REPORT.STATE_NUM.SUBMITTED && iouReport.statusNum <= CONST.REPORT.STATE_NUM.SUBMITTED; | ||
| } |
There was a problem hiding this comment.
| if (allowSubmitted || isProcessingReport(activeReport)) { | |
| return iouReport.stateNum <= CONST.REPORT.STATE_NUM.SUBMITTED && iouReport.statusNum <= CONST.REPORT.STATE_NUM.SUBMITTED; | |
| } | |
| if (canAddTransaction(iouReport, false, false)) { | |
| return iouReport.stateNum <= CONST.REPORT.STATE_NUM.SUBMITTED && iouReport.statusNum <= CONST.REPORT.STATE_NUM.SUBMITTED; | |
| } | |
| if (allowSubmitted || isProcessingReport(activeReport) || canAddTransaction(iouReport, false, false)) { | |
| return iouReport.stateNum <= CONST.REPORT.STATE_NUM.SUBMITTED && iouReport.statusNum <= CONST.REPORT.STATE_NUM.SUBMITTED; | |
| } |
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
Reviewer Checklist
Screenshots/VideosAndroid: HybridAppScreen.Recording.2026-01-26.at.23.56.41.movAndroid: mWeb ChromeScreen.Recording.2026-01-26.at.23.55.26.moviOS: HybridAppScreen.Recording.2026-01-26.at.23.55.00.moviOS: mWeb SafariScreen.Recording.2026-01-26.at.23.53.13.movMacOS: Chrome / SafariScreen.Recording.2026-01-26.at.23.51.20.mov |
Codecov Report✅ Changes either increased or maintained existing code coverage, great job!
|
|
✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release. |
|
🚀 Deployed to staging by https://github.com/MariaHCD in version: 9.3.10-0 🚀
|
|
🚀 Deployed to production by https://github.com/roryabraham in version: 9.3.10-6 🚀
|
Explanation of Change
Fixed Issues
$ #77661
PROPOSAL: #77661 (comment)
Tests
Offline tests
QA Steps
PR Author Checklist
### Fixed Issuessection aboveTestssectionOffline stepssectionQA stepssectioncanBeMissingparam foruseOnyxtoggleReportand notonIconClick)src/languages/*files and using the translation methodSTYLE.md) were followedAvatar, I verified the components usingAvatarare working as expected)StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))npm run compress-svg)Avataris modified, I verified thatAvataris working as expected in all cases)Designlabel and/or tagged@Expensify/designso the design team can review the changes.ScrollViewcomponent to make it scrollable when more elements are added to the page.mainbranch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTeststeps.Screenshots/Videos
Android: Native
Screen.Recording.2026-01-15.at.02.09.54.mov
Android: mWeb Chrome
Screen.Recording.2026-01-15.at.02.12.14.mov
iOS: Native
Screen.Recording.2026-01-15.at.02.13.07.mov
iOS: mWeb Safari
Screen.Recording.2026-01-15.at.02.15.18.mov
MacOS: Chrome / Safari
Screen.Recording.2026-01-15.at.02.54.45.mp4