Skip to content

Show the auto-approval limit notice on the expense preview - #99796

Merged
arosiclair merged 17 commits into
Expensify:mainfrom
KioCoan:showOverLimitNoticeOnExpensePreview
Sep 8, 2026
Merged

arosiclair merged 17 commits into
Expensify:mainfrom
KioCoan:showOverLimitNoticeOnExpensePreview

Conversation

@KioCoan

@KioCoan KioCoan commented Aug 28, 2026 •

Copy link
Copy Markdown
Contributor

Explanation of Change

Follow-up to Show the auto-approval limit notice when the submitter is also the approver, as requested in review.

That PR let a submitter who is also the report's approver see the overAutoApprovalLimit notice, so they finally learn why their report was held for manual approval. It landed on the expense detail Amount row and in Search, but not on the expense preview card, which is what this issue reports.

The preview is the only surface that gates on the showInReview flag that comes down with the violation. createTransactionPreviewConditionals asks hasNoticeTypeViolation(..., showInReview = true), which counts a notice only when the payload literally carries showInReview: true. The backend never sets it for this viewer: it decides that flag from whether the requester owns the report, and the violations query does not look at managerID, so it cannot tell that this submitter is also the approver. I confirmed the payload on a live held report, and it arrives with no showInReview key at all:

{"name": "overAutoApprovalLimit", "type": "notice", "data": {"amount": 10000, "currency": "USD", "formattedLimit": "$100"}}

The expense detail (useViolations) and the Search transaction row apply no showInReview filter, which is why they show it today and the preview does not.

Rather than change that flag in the backend, this adds a narrow exception on the client, next to the distance MODIFIED_AMOUNT exception that already sits in the same two functions. shouldShowViolation is the single rule for who should see this notice, so the new helper asks it directly. It re-applies that rule rather than trusting the incoming array, because TransactionPreview passes violations already filtered by useTransactionViolations while MoneyRequestReportTransactionList passes raw Onyx violations, where a bare name check would light up the row for a plain submitter who must not see it.

The helper is called from both createTransactionPreviewConditionals and transactionHasRBR, which the file documents as mirrors of each other, so the report transaction list keeps sorting RBR rows the same way the preview flags them.

The preview shows the dot and "Review required" rather than the full sentence. "Expense exceeds auto-approval limit of $100.00" is 46 characters against the 40 character RBR_MESSAGE_MAX_CHARACTERS_FOR_PREVIEW cap, so it takes the same reviewRequired fallback every other long violation message takes on a preview card. The full sentence still shows on the expense detail and in Search.

Fixed Issues

$#99613

Tests

Unit tests

  1. Added four cases to tests/unit/TransactionPreviewUtils.test.ts, two for createTransactionPreviewConditionals and two for transactionHasRBR, using an overAutoApprovalLimit notice with no showInReview key, which is the shape the backend actually sends. Every violation fixture already in that file stamps showInReview: true, which is why this gap was never caught.
  2. Ran them against main first and confirmed the two positive cases fail, so the tests prove the fix rather than the fixture.
  3. Ran npx jest tests/unit/TransactionPreviewUtils.test.ts tests/unit/TransactionUtilsTest.ts tests/unit/useTransactionViolationsTest.ts tests/ui/TransactionPreviewContentTest.tsx tests/ui/MoneyRequestReportPreview.test.tsx and all pass. The TransactionUtilsTest and useTransactionViolationsTest runs guard the shouldShowViolation behavior from PR 99016.

Browser, against a local backend

Set up a workspace where I am the admin and submit to myself, with auto-approval enabled and a limit of $100, then created four reports on it: $175 held, $101 held, $150 approved and $99 auto-approved.

  1. With the change stashed, opened the workspace chat and confirmed the baseline: the held $175 card shows no dot and no message.
  2. Restored the change and confirmed exactly two cards now show the dot and "Review required", the two held over-limit reports, while both approved reports stay clean. That is the isProcessingReport half of the rule holding.
  3. Opened the $175 expense and confirmed the Amount row still shows the full "Expense exceeds auto-approval limit of $100.00" notice, so the detail view is unchanged.
  4. Ran an A/B/A control from the console: Onyx.merge('report_<reportID>', {managerID: <some other accountID>}) makes the dot and message disappear and flips the card button from Approve to View, and merging the real approver back restores both. That is the isReportManager half of the rule holding, without needing a second account.
  • Verify that no errors appear in the JS console

Offline tests

N/A

QA Steps

  1. Create a new workspace and make sure it is on the Control plan, since these approval rules only exist there.
  2. Go to Workspace settings > More features and enable both Workflows and Rules.
  3. Go to Workspace settings > Workflows and turn on Add approvals. Leave yourself as the approver, so you are both the submitter and the approver.
  4. Go to Workspace settings > Rules > Advanced. Leave Prevent self-approvals off, turn on Auto-approve compliant reports, and set Auto-approve reports with all expenses under to $100. If Random report audit is present, set it to 0%.

Every expense below needs a merchant and a category, otherwise a missing field violation blocks auto-approval on its own and hides the behavior being tested.

  1. Open the workspace chat, create an expense of $175 with a merchant and a category, and submit it.
  2. Verify the report is held for manual approval: the preview card shows the Outstanding badge and an Approve button.
  3. Verify the preview card now shows a red dot and "Review required" on the line under the merchant. This is the fix. The message reads "Review required" rather than the full sentence because the full sentence is longer than a preview card line allows, which is how every long violation message behaves on these cards.
  4. Open the expense from that card and verify the Amount row shows the full notice, "Expense exceeds auto-approval limit of $100.00".
  • 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.
  • 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

Before: the $175 expense is correctly held for manual approval and the card offers an Approve button, but nothing on it says why it was not auto-approved. The approved $150 report above it is the control.
99613-before-full

After: the same screen, same scroll position. The held report now explains itself with the dot and "Review required", and the approved report above is untouched, so the change does not leak outside reports awaiting approval.

99613-after-full

Control, a different approver: the same held report with the approver set to someone else. No dot, no message, and the button reads View rather than Approve. This is the behavior we are deliberately preserving, since a submitter who cannot approve the report has nothing to act on.

99613-control-other-approver-full

@KioCoan

KioCoan commented Aug 28, 2026

Copy link
Copy Markdown
Contributor Author

@arosiclair do we need a C+ to review this?

Comment thread src/libs/TransactionPreviewUtils.ts Resolved
Comment thread src/libs/TransactionPreviewUtils.ts Resolved
@KioCoan
KioCoan marked this pull request as ready for review September 1, 2026 01:38
@KioCoan
KioCoan requested review from a team as code owners September 1, 2026 01:38
@melvin-bot
melvin-bot Bot requested review from heyjennahay and linhvovan29546 and removed request for a team September 1, 2026 01:38
@melvin-bot

melvin-bot Bot commented Sep 1, 2026

Copy link
Copy Markdown

@linhvovan29546 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 1, 2026 01:38
@linhvovan29546

linhvovan29546 commented Sep 1, 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 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
    • 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
    • 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 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 Screenshot_1788266777
Android: mWeb Chrome Screenshot_1788266623
iOS: HybridApp Simulator Screenshot - iPhone 16 Pro Max - 2026-09-01 at 19 49 09
iOS: mWeb Safari Simulator Screenshot - iPhone 16 Pro Max - 2026-09-01 at 19 43 14
MacOS: Chrome / Safari
Screen.Recording.2026-09-01.at.16.39.56.mov

@linhvovan29546

linhvovan29546 commented Sep 1, 2026 •

Copy link
Copy Markdown
Contributor

Not sure if we consider this a bug. The RBR flashes when I add a category.

Screen.Recording.2026-09-01.at.16.43.17.mov

Edit: the RBR flashes in the expense detail as well. It happens in both production and staging.

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

LGTM so far

@arosiclair

Copy link
Copy Markdown
Contributor

Not sure if we consider this a bug. The RBR flashes when I add a category.

We should fix that preferably. @KioCoan do you know what the root cause of that is?

@KioCoan

KioCoan commented Sep 2, 2026

Copy link
Copy Markdown
Contributor Author

@linhvovan29546 I included changes to fix the flashing RBR.

@melvin-bot
melvin-bot Bot requested a review from arosiclair September 2, 2026 08:22
@KioCoan

KioCoan commented Sep 2, 2026

Copy link
Copy Markdown
Contributor Author

I think the failed check is not related to the PR and it's already tracked.

@codecov

codecov Bot commented Sep 3, 2026 •

Copy link
Copy Markdown

Codecov Report

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

Files with missing lines Coverage Δ
...c/components/ReportActionItem/MoneyRequestView.tsx 79.27% <100.00%> (+0.04%) ⬆️
src/hooks/useAllTransactionViolations.ts 100.00% <100.00%> (ø)
src/libs/TransactionPreviewUtils.ts 86.19% <100.00%> (+0.47%) ⬆️
src/libs/actions/IOU/SplitTransactionUpdate.ts 91.30% <ø> (ø)
src/libs/actions/IOU/UpdateMoneyRequest.ts 92.46% <ø> (+2.71%) ⬆️
src/libs/actions/TransactionInlineEdit.ts 93.82% <ø> (ø)
.../request/step/DynamicIOURequestStepDescription.tsx 79.72% <100.00%> (+0.27%) ⬆️
...iou/request/step/DynamicIOURequestStepDistance.tsx 85.55% <100.00%> (+0.05%) ⬆️
...quest/step/DynamicIOURequestStepDistanceManual.tsx 80.43% <ø> (ø)
...ou/request/step/IOURequestStepDistanceOdometer.tsx 83.61% <100.00%> (+0.06%) ⬆️
... and 6 more
... and 7 files with indirect coverage changes

@arosiclair

Copy link
Copy Markdown
Contributor

@KioCoan what was the root problem for the flashing issue? The comments written in the PR are pretty confusing.

@KioCoan

KioCoan commented Sep 5, 2026

Copy link
Copy Markdown
Contributor Author

@KioCoan what was the root problem for the flashing issue? The comments written in the PR are pretty confusing.

Editing an expense optimistically recalculates that transaction's violations and overwrites the whole transactionViolations_<transactionID> key. The recalculation starts from the violations it gets handed, and updateMoneyRequestCategory had no violations param, so it always started from [].

The client can only recompute the violations it knows how to calculate, so backend-only ones (overAutoApprovalLimit, duplicatedTransaction, rter) got wiped until the API response put them back about 500ms later (making it flash).

The fix just passes the stored violations in so it starts from the real list.

@arosiclair
arosiclair merged commit b15583d into Expensify:main Sep 8, 2026
34 of 35 checks passed
@github-actions

github-actions Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

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

@OSBotify

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

@KioCoan
KioCoan deleted the showOverLimitNoticeOnExpensePreview branch September 8, 2026 14:34
@OSBotify OSBotify mentioned this pull request Sep 8, 2026
69 tasks done
@OSBotify

OSBotify commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

🚀 Deployed to staging by https://github.com/arosiclair in version: 9.4.74-0 🚀

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

@MelvinBot

MelvinBot commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

🤖 No help site changes are required for this PR. No draft PR created.

Why

This PR fixes a delivery gap in an existing indicator. It does not add a feature, setting, label, or workflow step, and it does not invalidate any sentence currently on the help site.

  • The copy is pre-existing and unchanged. Both strings this PR causes to surface already ship today: overAutoApprovalLimit → "Expense exceeds auto-approval limit of {limit}" (src/languages/en.ts:10244) and reviewRequired → "Review required" (src/languages/en.ts:10301). This PR touches no language file.
  • No setting changed. The behaviour is still driven entirely by Auto-approve compliant reports and Auto-approve reports with all expenses under, which are documented as-is in Add-Approvals.md.
  • Nothing on the help site describes the surface that changed. No article under docs/articles documents per-surface violation indicators — the red dot, the "Review required" line, or which of the expense preview card / expense detail / Search shows what. I grepped for "Review required", "auto-approval limit", "red dot", and "RBR" across docs/articles: zero hits for the indicator wording. Understanding-Report-Statuses-and-Actions.md covers statuses and header buttons only, so the preview-card fix leaves it accurate.
  • The second change is internal. Passing violations through the updateMoneyRequest* actions (src/libs/actions/IOU/UpdateMoneyRequest.ts) stops the optimistic recalculation from wiping backend-only violations. It restores correct behaviour rather than defining new behaviour, so there is nothing to document.

Two things worth flagging

1. The QA steps point QA at the wrong page. QA step 4 says "Workspace settings > Rules > Advanced" for Auto-approve compliant reports. I drove the current web UI on a Control-plan workspace and the Rules page has no Advanced section at all — its sections are Expenses, Merchant, and Agent rules. The auto-approval settings live under Workflows > Advanced, together with Prevent self-approvals, Auto-approve reports with all expenses under, Random report audit, and Auto-pay approved reports.

Workflows > Advanced showing Auto-approve compliant reports

The src/pages/workspace/rules/ file path is what makes this look like a Rules setting; the rendered location is Workflows. Since this is already on staging, QA will follow those steps as written — worth correcting.

That same check confirms Add-Approvals.md is correct today: "On the Workflows page, click the Auto-approve compliant reports toggle" matches the live UI.

2. A pre-existing help site inaccuracy, unrelated to this PR. Workspace-Rules.md:121-129 lists Prevent self-approvals, Auto-approve compliant reports, and Auto-Pay approved reports under "How to configure Expense Report rules" in an article whose other sections all navigate to the Rules tab. Those four settings are on Workflows > Advanced, so a reader following that article will look in the wrong place. It also renders Auto-Pay approved reports with a capital P, where the UI reads Auto-pay approved reports.

I did not open a PR for this, because it is not required by these changes and sits outside the scope you asked me to review. Say the word and I will open a draft PR fixing that section.


@KioCoan — there is no linked help site PR to review, because these changes need no doc updates. The two items above are the only follow-ups, and neither is caused by this PR. Reply if you want me to open the draft PR for item 2.


view run · no recording available

@OSBotify

OSBotify commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

🚀 Deployed to production by https://github.com/mountiny in version: 9.4.74-2 🚀

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.

5 participants