Skip to content

[CP Staging] Fix: open flagged expense thread when its report holds multiple transactions#95163

Merged
cristipaval merged 1 commit into
mainfrom
claude-reviewFlaggedExpenseSingleThread
Jul 2, 2026
Merged

[CP Staging] Fix: open flagged expense thread when its report holds multiple transactions#95163
cristipaval merged 1 commit into
mainfrom
claude-reviewFlaggedExpenseSingleThread

Conversation

@MelvinBot

@MelvinBot MelvinBot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Explanation of Change

The "Review X expenses" row on Home opened the whole expense report when a single flagged expense lived inside a report that still held other (unflagged) transactions, instead of opening the RHP for the flagged expense.

The handler in useReviewFlaggedExpenses decided between "open the report directly" and "open the single transaction thread" with:

if (flaggedExpenses.length === 1 && isMoneyRequestReport(firstFlaggedReport)) { ... }

isMoneyRequestReport only checks the report type (isIOUReport || isExpenseReport), which is always true for the OPEN expense reports this hook scans. So flaggedExpenses.length === 1 alone drove the branch, and the "open the report directly" shortcut — intended only for genuine one-transaction reports — fired even when the report contained multiple expenses.

The fix swaps the type check for the transaction-count check that expresses the real intent, isOneTransactionReport (report?.transactionCount === 1):

if (flaggedExpenses.length === 1 && isOneTransactionReport(firstFlaggedReport)) { ... }

Now a lone flagged expense inside a multi-transaction report falls through to navigateToTransactionThread, opening the RHP for that single flagged expense (matching the Expected Result). The "open the report directly" shortcut stays reserved for reports that genuinely hold only one expense.

Added unit coverage in tests/unit/hooks/useReviewFlaggedExpenses.test.ts (lone flagged expense in a 2-transaction report → opens the thread) and UI coverage in tests/ui/ForYouSectionTest.tsx for both the multi-transaction (→ thread) and single-transaction (→ report directly) paths.

Fixed Issues

$ #95089
PROPOSAL: #95089 (comment)

Tests

  1. Go to a workspace chat.
  2. Create two expenses without a category.
  3. Go to Home.
  4. Click Review 2 expenses.
  5. Click Category and select any category.
  6. Close the report view.
  7. Click Review 1 expense.
  8. Verify the expense RHP for the expense with the missing category opens (not the expense report showing both expenses).
  • Verify that no errors appear in the JS console

Offline tests

Same as tests.

QA Steps

  1. Go to a workspace chat.
  2. Create two expenses without a category.
  3. Go to Home.
  4. Click Review 2 expenses.
  5. Click Category and select any category.
  6. Close the report view.
  7. Click Review 1 expense.
  8. Verify the expense RHP for the expense with the missing category opens (not the expense report showing both 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 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 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 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.
  • 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.

…actions

The Review row shortcut used isMoneyRequestReport (report type) to decide whether to open the report directly. That check is always true for expense reports, so a single flagged expense inside a multi-transaction report opened the whole report instead of the flagged expense. Gate on isOneTransactionReport (transactionCount === 1) so a lone flagged expense in a multi-transaction report opens its own thread.

Co-authored-by: Cristi Paval <cristipaval@users.noreply.github.com>
@codecov

codecov Bot commented Jul 2, 2026

Copy link
Copy Markdown

Codecov Report

✅ Changes either increased or maintained existing code coverage, great job!

Files with missing lines Coverage Δ
...ges/home/ForYouSection/useReviewFlaggedExpenses.ts 95.52% <100.00%> (+2.98%) ⬆️
... and 16 files with indirect coverage changes

@MelvinBot

Copy link
Copy Markdown
Contributor Author

🤖 I looked into the failing checks. There's no code fix to push — the only failing check is the PR Author Checklist, which is a human-completion gate, not a code problem.

What's failing: PR Author Checklist / checklist — the action reports "You completed 2 out of 41 checklist items with 39 unfinished items." It fails simply because the checklist boxes in the PR description aren't all ticked.

Why I can't fix it: those checkboxes (plus the Tests and QA Steps sections) are the human co-author's responsibility — MelvinBot isn't allowed to fill out those human-only sections on someone's behalf. So cristipaval needs to review the checklist, run the test steps, and tick the boxes to clear this check.

Everything else is green or on track: typecheck, ESLint, Prettier, Storybook, React Compiler, unused-styles, and all 8 Jest test jobs (which include the new useReviewFlaggedExpenses and ForYouSection tests added here) have passed. The only checks still running are the long builds and perf tests (build, baseline-perf-tests, branch-perf-tests) — none of which are affected by this one-line import swap plus test additions.

TL;DR: nothing to fix in code. Complete the PR Author Checklist to turn the checklist check green.

@github-actions

github-actions Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

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

@MelvinBot

Copy link
Copy Markdown
Contributor Author

🤖 I re-checked the checks now that the builds finished. Two checks are red, and neither is a code problem — there's nothing to fix in the PR.

1. build (New Expensify Dev, DebugDevelopment, false) — flaky iOS build, unrelated to this PR.

The log shows no source-level compile error — no error:, no "The following build commands failed", no linker/symbol errors. The only error line is an infrastructure one:

Remote cache failure error: NoSuchKey: The specified key does not exist.

followed by a generic RockError: Failed to build the project from xcodebuild. This is a remote-build-cache miss on the Rock CI infra, not a build break.

Evidence it's not caused by the changes here:

  • This PR only swaps one TypeScript import (isMoneyRequestReportisOneTransactionReport) in useReviewFlaggedExpenses.ts plus two test files — nothing native/iOS.
  • The Android build of the same JS/TS (build (Expensify Dev, Debug, true)) and both other build variants passed. A broken bundle would have failed those too.

I can't re-trigger the job from here (permission-gated in this run). cristipaval — please hit "Re-run failed jobs" on that run, or push any commit to re-trigger; it should go green.

2. PR Author Checklist / checklist — human-completion gate.

Fails with "You completed 2 out of 41 checklist items." These checkboxes (and the Tests/QA Steps sections) are the human co-author's responsibility — I'm not allowed to fill them out. Complete the checklist to clear it.

Everything else is green: typecheck, ESLint, Prettier, Storybook, React Compiler, unused-styles, and all 8 Jest test jobs (including the new useReviewFlaggedExpenses and ForYouSection tests).

@cristipaval
cristipaval requested a review from truph01 July 2, 2026 10:44
@github-actions

This comment has been minimized.

@cristipaval
cristipaval marked this pull request as ready for review July 2, 2026 10:45
@cristipaval
cristipaval requested a review from a team as a code owner July 2, 2026 10:45
@melvin-bot
melvin-bot Bot requested review from JmillsExpensify and cristipaval and removed request for a team July 2, 2026 10:45
@melvin-bot

melvin-bot Bot commented Jul 2, 2026

Copy link
Copy Markdown

@cristipaval 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 July 2, 2026 10:45
@MelvinBot

Copy link
Copy Markdown
Contributor Author

🤖 Update: a second check has now failed, but neither failing check is caused by this PR, and there's nothing for me to fix in code.

1. build (New Expensify Dev, DebugDevelopment, false) — unrelated iOS infra failure.
The iOS build fails compiling native Swift, not JS:

ios/CertificatePinning.swift:83:82: error: cannot find type 'TSKPinningValidationResult' in scope

TSKPinningValidationResult comes from the TrustKit CocoaPod, and ios/CertificatePinning.swift:83 is not in this PR's diff — the only files changed here are useReviewFlaggedExpenses.ts and two test files. A JS import swap can't produce a Swift "type not in scope" error. I confirmed the same Remote Build iOS failure is currently hitting main and other unrelated branches (e.g. claude-perDiemSubtitleFlexRow, a revert-* branch) at the same time — so this is a broad Pods/TrustKit resolution issue in CI, not something in this PR. It should clear once the underlying pod/env issue is resolved on main; a re-run alone likely won't help since it's a deterministic compile error, not a flake.

2. PR Author Checklist / checklist — human-completion gate.
"You completed 2 out of 41 checklist items." This just needs cristipaval to fill out the checklist boxes / Tests / QA sections — MelvinBot isn't allowed to complete those human-only sections.

Everything code-related is green: typecheck, ESLint, Prettier, Storybook, React Compiler, unused-styles, and all 8 Jest test jobs (including the new useReviewFlaggedExpenses and ForYouSection tests) passed.

TL;DR: no code fix to push. The iOS build break is a pre-existing infra issue affecting main too; the checklist just needs to be completed by the author.

@truph01

truph01 commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. What shall we delve into next?

Reviewed commit: 1fd663a922

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

@cristipaval
cristipaval requested a review from ZhenjaHorbach July 2, 2026 12:53
@ZhenjaHorbach

ZhenjaHorbach commented Jul 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 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
2026-07-02.15.10.34.mov
Android: mWeb Chrome
2026-07-02.15.12.42.mov
iOS: HybridApp
2026-07-02.15.10.34.mov
iOS: mWeb Safari
2026-07-02.15.12.42.mov
MacOS: Chrome / Safari
2026-07-02.15.05.59.mov

@ZhenjaHorbach

ZhenjaHorbach commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

@MelvinBot
Add test steps from the issue in the PR description

@MelvinBot

Copy link
Copy Markdown
Contributor Author

🤖 Added the concrete reproduction steps from #95089 to the Tests and QA Steps sections of the PR description:

  1. Go to a workspace chat.
  2. Create two expenses without a category.
  3. Go to Home.
  4. Click Review 2 expenses.
  5. Click Category and select any category.
  6. Close the report view.
  7. Click Review 1 expense.
  8. Verify the expense RHP for the expense with the missing category opens (not the expense report showing both expenses).

@melvin-bot
melvin-bot Bot requested a review from cristipaval July 2, 2026 13:14
@cristipaval
cristipaval merged commit 9fb8f63 into main Jul 2, 2026
45 of 48 checks passed
@cristipaval
cristipaval deleted the claude-reviewFlaggedExpenseSingleThread branch July 2, 2026 13:44
@github-actions

github-actions Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

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

@OSBotify

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

@cristipaval cristipaval changed the title Fix: open flagged expense thread when its report holds multiple transactions [CP Staging] Fix: open flagged expense thread when its report holds multiple transactions Jul 2, 2026
OSBotify pushed a commit that referenced this pull request Jul 2, 2026
…ingleThread

Fix: open flagged expense thread when its report holds multiple transactions
(cherry picked from commit 9fb8f63)

(cherry-picked to staging by cristipaval)
@OSBotify OSBotify added the CP Staging marks PRs that have been CP'd to staging label Jul 2, 2026
@OSBotify

OSBotify commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

🚀 Cherry-picked to staging by https://github.com/cristipaval in version: 9.4.26-5 🚀

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

@MelvinBot

Copy link
Copy Markdown
Contributor Author

🤖 Help site review: no docs changes required.

This PR is a pure navigation bug fix. It changes only the internal logic in useReviewFlaggedExpenses.ts (swapping a report-type check for isOneTransactionReport) plus test files, so that clicking Review 1 expense on Home opens the RHP for the single flagged expense instead of the whole expense report.

There is no new feature, no new/renamed UI element, no changed setting, and no change to any documented workflow — it simply restores the expected behavior. Nothing under App/docs/articles describes this "Review X expenses" navigation detail, so no help site article needs to be added or updated.

Because no changes are required, I did not create a draft help site PR. If you disagree and think an article should be updated, let me know which flow to document and I'll draft one.

cristipaval, please confirm whether you agree that no help site changes are needed here.

@OSBotify

OSBotify commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

🚀 Cherry-picked to staging by https://github.com/cristipaval in version: 9.4.27-1 🚀

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

@MelvinBot

Copy link
Copy Markdown
Contributor Author

🤖 Help site review — no changes required.

This PR is a bug fix that makes the actual behavior match what the help site already documents, so no updates to App/docs/articles are needed and no draft docs PR was created.

Why no docs change is needed

The only help article that documents where the Review item on Home navigates is Understanding-the-For-you-Section.md. It already states the intended behavior:

  • Line 40: "Review – expenses on your draft reports that are flagged against your workspace's rules and need to be reviewed before the report can be submitted"
  • Line 72: "Review takes you to the first flagged expense so you can resolve the rule violation"

This PR fixes an edge case where a lone flagged expense living inside a multi-transaction report incorrectly opened the whole report instead of the flagged expense's RHP. After the fix, a lone flagged expense opens the expense thread — which is exactly what the article already describes. The docs were already correct; only the app behavior needed to be brought in line.

I checked the other candidate articles (Expensify-Home-Overview.md, How-to-Find-and-Resolve-Flagged-Duplicate-Expenses.md) — none document the Review navigation target, so nothing there needs to change either.

@cristipaval, since no help site changes are required, there's no linked docs PR to review. If you believe the For you section article should be more explicit about this navigation behavior, let me know and I'll draft the change.

@OSBotify

OSBotify commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

🚀 Deployed to production by https://github.com/grgia in version: 9.4.27-2 🚀

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

CP Staging marks PRs that have been CP'd to staging

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants