Repository navigation
Use comprehensive approver check for insights visibility - #84682
Conversation
The isApprover variable in getSuggestedSearchesVisibility only checked policy.approver (the single default approver), missing intermediate approvers configured via submitsTo/forwardsTo/overLimitForwardsTo in the employee list. This caused non-admin workflow approvers to not see the Top Spenders and Spend Over Time insights. Replace the narrow check with the existing isApprover utility from Policy/Member.ts which covers all approval routing fields. Co-authored-by: huult <huult@users.noreply.github.com>
|
I created this PR from an upstream branch since I don't have push access to your fork. To take ownership of this branch and be able to push updates, run: Then you can close this PR and open a new one from your fork. |
Co-authored-by: huult <huult@users.noreply.github.com>
|
Fixed the failing Prettier check: ran Prettier on |
The test Policy objects are intentionally partial (only the fields needed for the test), so direct `as OnyxTypes.Policy` fails because too many required properties are missing. Cast via `unknown` first. Co-authored-by: huult <huult@users.noreply.github.com>
|
Fixed the failing TypeScript check: the three test Policy objects in The previous commit already fixed the Prettier check. |
|
Fixed the failing checks:
Both fixes were pushed in commit |
|
The failing Analysis: The ESLint warnings (336 total, 0 errors) are in files not modified by this PR:
This PR only modifies Evidence: The Note: The |
This comment was marked as outdated.
This comment was marked as outdated.
|
@MelvinBot Ready for review |
|
PR has been marked as ready for review! ✅ |
Screen.Recording.2026-03-10.at.12.45.46.mov@heyjennahay This seems like expected behavior. However, should we also display |
| const isAdmin = policy.role === CONST.POLICY.ROLE.ADMIN; | ||
| const isExporter = policy.exporter === currentUserEmail; | ||
| const isApprover = policy.approver === currentUserEmail; | ||
| const isUserApprover = currentUserEmail && policy ? isApproverUtils(policy, currentUserEmail) : policy.approver === currentUserEmail; |
There was a problem hiding this comment.
❌ CONSISTENCY-3 (docs)
The isApproverUtils(policy, currentUserEmail) call iterates over policy.employeeList checking submitsTo, forwardsTo, and overLimitForwardsTo. A few lines below (line ~997-999), isSubmittedTo also iterates over policy.employeeList checking submitsTo and forwardsTo — this is duplicated iteration over the same data with overlapping field checks.
Additionally, the ternary guard currentUserEmail && policy ? ... : policy.approver === currentUserEmail contains a redundant policy check (policy is already null-checked at line 979) and a suspect fallback branch — when currentUserEmail is falsy, the fallback compares policy.approver against a falsy value, which is almost certainly not the intended behavior.
Consider simplifying to just isApproverUtils(policy, currentUserEmail) (since the utility already handles the checks safely) and refactoring isSubmittedTo to derive from the approver check or consolidating the iteration:
const isUserApprover = isApproverUtils(policy, currentUserEmail);Since policy is guaranteed non-null at this point and isApproverUtils uses optional chaining internally (policy?.approver, policy?.employeeList), no additional guards are needed.
Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.
There was a problem hiding this comment.
Addressed in 4b6068d:
- Simplified the ternary — removed the unnecessary
currentUserEmail && policy ?guard sincepolicyis already null-checked at the top of the loop body. Now directly assignspolicy.approver === currentUserEmail. - Consolidated iteration — replaced the separate
isSubmittedTo.some()call and the importedisApproverUtils()call with a singlefor...ofloop overpolicy.employeeListthat computes bothisSubmittedToandisUserApproverin one pass, with earlybreakwhen both are determined. - Removed the side-effectful import — this also addresses the Codex review comment about
Policy/Member.tstop-level Onyx listeners.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f53f937323
ℹ️ 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".
| import {hasSynchronizationErrorMessage} from './actions/connections'; | ||
| import {canApproveIOU, canIOUBePaid, canSubmitReport, startMoneyRequest} from './actions/IOU'; | ||
| import {setIsOpenConfirmNavigateExpensifyClassicModalOpen} from './actions/isOpenConfirmNavigateExpensifyClassicModal'; | ||
| import {isApprover as isApproverUtils} from './actions/Policy/Member'; |
There was a problem hiding this comment.
Avoid importing side-effectful policy member module
Replace this import with a side-effect-free helper, because src/libs/actions/Policy/Member.ts executes top-level Onyx.connect/connectWithoutView subscriptions as soon as it is imported (see lines 46-59 in that file). Pulling that module into SearchUIUtils means these listeners are now eagerly registered anywhere search utilities are loaded (including common search/IOU flows), which adds unnecessary startup work and persistent memory usage unrelated to suggested-search visibility.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Addressed in 4b6068d — removed the import from ./actions/Policy/Member entirely. The isApprover logic is now inlined directly in the loop body, so SearchUIUtils no longer pulls in the side-effectful module and its top-level Onyx.connect/connectWithoutView subscriptions.
|
The failing Analysis: The ESLint warnings are all
Evidence: This PR only modifies The other failing check ( |
|
@MelvinBot Please review the two comments above. If they make sense, please update the PR |
…prover check - Remove import of isApprover from actions/Policy/Member to avoid eagerly registering Onyx listeners (top-level Onyx.connect calls) whenever SearchUIUtils is loaded - Inline the approver logic and consolidate with isSubmittedTo into a single pass over policy.employeeList, eliminating duplicate iteration - Simplify by removing unnecessary ternary guard (policy is already null-checked) Co-authored-by: huult <huult@users.noreply.github.com>
|
Reviewed both code review comments — they both raised valid concerns. Pushed commit
All 257 unit tests pass (including the 3 approver-related tests added in this PR). |
|
@mjasikowski 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] |
|
The failing Analysis: The ESLint warnings are in files not touched by this PR:
This PR only modifies Evidence: The full ESLint check is also failing on the The other failing check ( |
Codecov Report✅ Changes either increased or maintained existing code coverage, great job!
|
|
@codex review |
|
Codex Review: Didn't find any major issues. Keep them coming! ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Reviewer Checklist
Screenshots/VideosAndroid: HybridAppScreen.Recording.2026-03-10.at.13.25.42.mp4Android: mWeb ChromeScreen.Recording.2026-03-10.at.13.26.31.mp4iOS: HybridAppScreen.Recording.2026-03-10.at.13.29.41.mp4iOS: mWeb SafariScreen.Recording.2026-03-10.at.13.30.19.mp4MacOS: Chrome / SafariScreen.Recording.2026-03-10.at.12.45.46.mov |
huult
left a comment
There was a problem hiding this comment.
LGTM. I think we should display "Spend Over Time" and "Top Spenders" for non-admin approvers as well, to keep the behavior consistent with admin approvers.
|
It looks like the bot added the internal engineer before I approved the PR: #84682 (comment) @mjasikowski Feel free to take a look at this PR. Thanks! |
|
ESLint checks failed on the main branch. |
|
@MelvinBot fix failing ESLint checks |
Add eslint-disable-next-line comments for react-hooks/set-state-in-effect and react-hooks/preserve-manual-memoization warnings in 4 unrelated files, and lower the max-warnings threshold from 334 to 331. Co-authored-by: Michał Jasikowski <mjasikowski@users.noreply.github.com>
|
Fixed the failing ESLint check by suppressing 5 pre-existing React Compiler warnings in unrelated files:
Also lowered the |
|
@MelvinBot do not alter the max-warnings setting. Leave comments explaining why ESLint rules were removed |
…able directives Co-authored-by: Michał Jasikowski <mjasikowski@users.noreply.github.com>
|
Addressed in 63df756:
|
|
@huult can you do a quick sanity check on the ESLint rule changes? |
|
Yes, I checked it and I think the new update is correct. |
|
🚧 @mjasikowski has triggered a test Expensify/App build. You can view the workflow run here. |
|
🧪🧪 Use the links below to test this adhoc build on Android, iOS, and Web. Happy testing! 🧪🧪
|
|
✋ 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/mjasikowski in version: 9.3.35-0 🚀
|
|
🚀 Deployed to production by https://github.com/luacmartins in version: 9.3.35-1 🚀
|

Explanation of Change
The
isApprovervariable ingetSuggestedSearchesVisibility(src/libs/SearchUIUtils.ts) only checkedpolicy.approver— the single default/primary approver on a workspace. In workspaces with advanced approval workflows, intermediate approvers are configured per-employee viasubmitsTo,forwardsTo, andoverLimitForwardsToinpolicy.employeeList. These workflow approvers were not detected by the narrow check, so they could not see the Top Spenders or Spend Over Time insights.This PR replaces the narrow inline check with the existing comprehensive
isApproverutility fromsrc/libs/actions/Policy/Member.ts, which checks bothpolicy.approverand all employee-level approval routing fields. The variable is also renamed fromisApprovertoisUserApproverfor clarity, following reviewer feedback.Three new unit tests are added to cover workflow approver scenarios (via
submitsToandforwardsTo) and to verify regular members remain excluded.Fixed Issues
$ #84635
PROPOSAL: #84635 (comment)
Tests
Offline tests
N/A — Insights visibility is determined from locally cached policy data. No network-dependent behavior changes.
QA Steps
PR Author Checklist
### Fixed Issuessection aboveTestssectionOffline stepssectionQA stepssectiontoggleReportand 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
N/A — Logic-only change, no UI modifications
Android: mWeb Chrome
N/A — Logic-only change, no UI modifications
iOS: Native
N/A — Logic-only change, no UI modifications
iOS: mWeb Safari
N/A — Logic-only change, no UI modifications
MacOS: Chrome / Safari
N/A — Logic-only change, no UI modifications