Skip to content

Implement bulk change approver flow for Search page v2#77857

Merged
marcaaron merged 32 commits intoExpensify:mainfrom
QichenZhu:feat/bulk-change-approver-v2
Apr 3, 2026
Merged

Implement bulk change approver flow for Search page v2#77857
marcaaron merged 32 commits intoExpensify:mainfrom
QichenZhu:feat/bulk-change-approver-v2

Conversation

@QichenZhu
Copy link
Copy Markdown
Contributor

@QichenZhu QichenZhu commented Dec 17, 2025

Explanation of Change

Fixed Issues

$ #75220
$ #77372
PROPOSAL:

Tests

Same as QA Steps.

  • Verify that no errors appear in the JS console

Offline tests

N/A.

QA Steps

Preconditions

  1. Create three accounts: A, B, and C.
  2. Account A has three Control plan workspaces with Submission frequency set to Manually and Add approvals enabled.
  3. Account A has submitted one expense in each of the three Control workspaces.
  4. Account B is a member of all three Control workspaces and can approve.
  5. Account C is a member of only one of the three Control workspaces.
  6. Create two additional non-Control workspaces (NonControl-1 and NonControl-2) with Add approvals enabled, and have Account A submit one expense in each.

Test 1: Bulk Add Approver

  1. Go to Reports → Reports.
  2. Open the Workspace filter and select the three Control workspaces, then tap Apply.
  3. Select any two of the reports created in the Preconditions.
  4. Tap “2 selected → Change approver.”
  5. Tap “Add approver → Change approver.”
  6. Select Account B and save.
  7. Verify the Action column for those two reports no longer shows Approve.

Test 2: Bulk Bypass Approver

  1. Select all three reports created in the Control workspaces.
  2. Tap “3 selected → Change approver.”
  3. Tap “Bypass approvers → Change approver.”
  4. Verify the Action column for all three reports shows Approve.

Test 3: Account C Visibility Rules

A. Multi-policy selection (C should NOT appear)

  1. With all three Control workspaces filtered, select two or more reports across different workspaces.
  2. Tap “X selected → Change approver.”
  3. Tap “Add approver → Change approver.”
  4. Verify Account C does not appear.

B. Single-policy selection (C may appear)

  1. Filter to only the Control workspace where Account C is a member.
  2. Select the report from that workspace.
  3. Tap “1 selected → Change approver.”
  4. Tap “Add approver → Change approver.”
  5. Verify Account C appears only if C can approve the report and is not already the approver.

Test 4: Single Non-Upgraded (Non-Control) Policy Selected

  1. Filter to NonControl-1 only.
  2. Select its report.
  3. Tap “1 selected → Change approver.”
  4. Tap “Add approver → Change approver.”
  5. Verify you are redirected to the workspace upgrade screen for NonControl-1.
  6. Navigate back and verify no changes were applied.

Test 5: Two Non-Upgraded (Non-Control) Policies Selected

  1. Filter to NonControl-1 and NonControl-2.
  2. Select one report from each.
  3. Tap “2 selected → Change approver.”
  4. Tap “Add approver → Change approver.”
  5. Verify you are redirected to the general workspace upgrade screen.
  6. Navigate back and verify no changes were applied.

Test 6: Mixed State Skip Behavior

  1. Select one report already assigned to Account A and one report not assigned to A.
  2. Tap “X selected → Change approver → Bypass approvers → Change approver.”
  3. Verify the report already assigned to A remains unchanged and the other report changes to A.
  • 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

Test 1: Bulk Add Approver

android-native-1.webm

Test 2: Bulk Bypass Approver

android-native-2.webm

Test 3: Account C Visibility Rules

android-native-3.webm

Test 4: Single Non-Upgraded (Non-Control) Policy Selected

android-native-4.webm

Test 5: Two Non-Upgraded (Non-Control) Policies Selected

android-native-5.webm

Test 6: Mixed State Skip Behavior

android-native-6.webm
Android: mWeb Chrome

Test 1: Bulk Add Approver

android-web-1.webm

Test 2: Bulk Bypass Approver

android-web-2.webm

Test 3: Account C Visibility Rules

android-web-3.webm

Test 4: Single Non-Upgraded (Non-Control) Policy Selected

android-web-4.webm

Test 5: Two Non-Upgraded (Non-Control) Policies Selected

android-web-5.webm

Test 6: Mixed State Skip Behavior

android-web-6.webm
iOS: Native

Test 1: Bulk Add Approver

ios-native-1.mov

Test 2: Bulk Bypass Approver

ios-native-2.mov

Test 3: Account C Visibility Rules

ios-native-3.mov

Test 4: Single Non-Upgraded (Non-Control) Policy Selected

ios-native-4.mov

Test 5: Two Non-Upgraded (Non-Control) Policies Selected

ios-native-5.mov

Test 6: Mixed State Skip Behavior

ios-native-6.mov
iOS: mWeb Safari

Test 1: Bulk Add Approver

ios-web-1.mov

Test 2: Bulk Bypass Approver

ios-web-2.mov

Test 3: Account C Visibility Rules

ios-web-3.mov

Test 4: Single Non-Upgraded (Non-Control) Policy Selected

ios-web-4.mov

Test 5: Two Non-Upgraded (Non-Control) Policies Selected

ios-web-5.mov

Test 6: Mixed State Skip Behavior

ios-web-6.mov
MacOS: Chrome / Safari

Test 1: Bulk Add Approver

mac-web-1.mov

Test 2: Bulk Bypass Approver

mac-web-2.mov

Test 3: Account C Visibility Rules

mac-web-3.mov

Test 4: Single Non-Upgraded (Non-Control) Policy Selected

mac-web-4.mov

Test 5: Two Non-Upgraded (Non-Control) Policies Selected

mac-web-5.mov

Test 6: Mixed State Skip Behavior

mac-web-6.mov

@melvin-bot
Copy link
Copy Markdown

melvin-bot bot commented Dec 17, 2025

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

@codecov
Copy link
Copy Markdown

codecov bot commented Dec 17, 2025

Codecov Report

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

Files with missing lines Coverage Δ
src/CONST/index.ts 95.16% <ø> (ø)
src/ONYXKEYS.ts 100.00% <ø> (ø)
src/ROUTES.ts 15.88% <ø> (ø)
src/SCREENS.ts 100.00% <ø> (ø)
...hList/ListItem/ActionCell/actionTranslationsMap.ts 100.00% <ø> (ø)
src/libs/API/types.ts 100.00% <ø> (ø)
...avigation/linkingConfig/RELATIONS/SEARCH_TO_RHP.ts 100.00% <ø> (ø)
src/libs/Navigation/linkingConfig/config.ts 76.92% <ø> (ø)
src/libs/SearchUIUtils.ts 68.37% <100.00%> (+0.03%) ⬆️
src/pages/ReportChangeApproverPage.tsx 0.00% <ø> (ø)
... and 6 more
... and 9 files with indirect coverage changes

@QichenZhu
Copy link
Copy Markdown
Contributor Author

@Krishna2323 I'm having trouble making the React Compiler check happy.

Failed to compile 1 added files with React Compiler:

src/pages/Search/SearchChangeApproverPage.tsx:106:39
React Compiler has skipped optimizing this component because the existing manual memoization could not be preserved. This value was memoized in source but not in compilation output.
src/pages/Search/SearchChangeApproverPage.tsx:153:8
React Compiler has skipped optimizing this component because the existing manual memoization could not be preserved. This dependency may be mutated later, which could cause the value to change unexpectedly

The error messages are quite technical to me and I can't tell if they mean a good thing or bad thing. The guide doesn't cover them.

src/pages/Search/SearchAddApproverPage.tsx:176:28
Found a manual memoization usage of useCallback. Newly added React component files must not contain any manual memoization and instead be auto-memoized by React Compiler. Remove useCallback or disable automatic memoization by adding the "use no memo"; directive at the beginning of the component and give a reason why automatic memoization is not applicable.

The files above failed the React Compiler compliance check. Do not remove any manual memoization patterns, unless a file is already able to compile with React Compiler. You can use the "React Compiler Marker" VS Code extension to check whether a file is being compiled with React Compiler.

However, the plugin shows the components are optimized by React Compiler successfully.

What do I need to do to fix them?

cc @marcaaron

@QichenZhu QichenZhu changed the title Implement bulk change approver flow for Search page v2 [WIP] Implement bulk change approver flow for Search page v2 Dec 18, 2025
@QichenZhu QichenZhu marked this pull request as ready for review December 18, 2025 10:06
@QichenZhu QichenZhu requested review from a team as code owners December 18, 2025 10:06
@melvin-bot melvin-bot bot requested review from Krishna2323 and joekaufmanexpensify and removed request for a team December 18, 2025 10:06
@melvin-bot
Copy link
Copy Markdown

melvin-bot bot commented Dec 18, 2025

@Krishna2323 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 December 18, 2025 10:06
@QichenZhu
Copy link
Copy Markdown
Contributor Author

@Krishna2323 I still need to do more testing. Feel free to do a preliminary review if you want.

return null;
}

const {avatar} = personalDetails?.[accountID] ?? {};
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-4 (docs)

Objects and functions passed as props should be properly memoized to prevent unnecessary re-renders.

The allApprovers array is computed by calling getAllApprovers() on every render without memoization. This creates a new array reference each time, causing the ApproverSelectionList component to re-render unnecessarily even when the underlying data hasn't changed.

Suggested fix:

const allApprovers = useMemo(() => getAllApprovers(), [
    selectedReports,
    allPolicies,
    allReports,
    personalDetails,
    formatPhoneNumber,
    translate,
    icons.FallbackAvatar,
    selectedApproverEmail,
]);


return isPolicyAdmin(policy) && isAllowedToApproveExpenseReport(report, currentUserDetails.accountID, policy);
});

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-4 (docs)

Objects and functions passed as props should be properly memoized to prevent unnecessary re-renders.

The approverTypes array is computed by calling getApproverTypes() on every render without memoization. This creates a new array reference each time, causing the SelectionList component to re-render unnecessarily even when the underlying data hasn't changed.

Suggested fix:

const approverTypes = useMemo(() => getApproverTypes(), [
    selectedReports,
    allPolicies,
    onyxReports,
    currentUserDetails.accountID,
    selectedApproverType,
    translate,
]);

if (!report) {
return false;
}

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-4 (docs)

Objects and functions passed as props should be properly memoized to prevent unnecessary re-renders.

The confirmButtonOptions object is created on every render without memoization. This creates a new object reference each time, causing the SelectionList component to re-render unnecessarily even when the underlying data hasn't changed.

Suggested fix:

const confirmButtonOptions = useMemo(() => ({
    showButton: true,
    text: translate('iou.changeApprover.title'),
    onConfirm: changeApprover,
}), [translate, changeApprover]);

Note: You'll also need to memoize the changeApprover function with useCallback.

});

if (shouldShowBypassApproversOption) {
data.push({
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-4 (docs)

Objects and functions passed as props should be properly memoized to prevent unnecessary re-renders.

The listHeader JSX element is created on every render without memoization. This creates a new element reference each time, causing the SelectionList component to re-render unnecessarily even when the underlying data hasn't changed.

Suggested fix:

const listHeader = useMemo(() => (
    <>
        <Text style={[styles.ph5, styles.mb5]}>
            {translate(selectedReports.length === 1 ? 'iou.changeApprover.subtitle' : 'iou.changeApprover.bulkSubtitle')}
        </Text>
        {selectedPolicies.length === 1 && (
            <View style={[styles.ph5, styles.mb5, styles.renderHTML, styles.flexRow]}>
                <RenderHTML
                    html={translate('iou.changeApprover.description', {
                        workflowSettingLink: `${environmentURL}/${ROUTES.WORKSPACE_WORKFLOWS.getRoute(selectedPolicies.at(0)?.id)}`,
                    })}
                />
            </View>
        )}
    </>
), [styles, translate, selectedReports.length, selectedPolicies, environmentURL]);

}, [hasLoadedApp, onyxReports, selectedReports]);

const getSelectedPolicies = () => {
const policies = new Map<string, Policy>();
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-4 (docs)

Objects and functions passed as props should be properly memoized to prevent unnecessary re-renders.

The selectedPolicies array is computed by calling getSelectedPolicies() on every render without memoization. This creates a new array reference each time, affecting the memoization of listHeader and other dependent values.

Suggested fix:

const selectedPolicies = useMemo(() => getSelectedPolicies(), [selectedReports, allPolicies]);

Copy link
Copy Markdown
Contributor

@joekaufmanexpensify joekaufmanexpensify left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whats next project 👍

@Krishna2323
Copy link
Copy Markdown
Contributor

@QichenZhu could you please check the Explanation of Change of this PR? We are doing the same in this PR.

@QichenZhu
Copy link
Copy Markdown
Contributor Author

Thanks for your review! Comments addressed.

@QichenZhu
Copy link
Copy Markdown
Contributor Author

Sorry if I missed it, but did we want to address the AI review comments about memoization? Please confirm @QichenZhu @Krishna2323 Thanks!

React Compiler Marker shows they are auto-memorized.

Screenshot 2026-03-02 at 11 47 44 PM Screenshot 2026-03-02 at 11 48 34 PM

@Krishna2323
Copy link
Copy Markdown
Contributor

@marcaaron this is ready :)

@QichenZhu

This comment was marked as outdated.

@QichenZhu
Copy link
Copy Markdown
Contributor Author

QichenZhu commented Mar 11, 2026

The new SearchContext unit tests were not directly related to this PR's core functionality and often conflicted or broke due to other changes in the main branch, so I removed them. I can add them back in a follow-up if needed.

@QichenZhu
Copy link
Copy Markdown
Contributor Author

@marcaaron, this is ready for your review.

@marcaaron
Copy link
Copy Markdown
Contributor

Sorry for the delay here. Please feel free to ping me next time to get my attention.

Copy link
Copy Markdown
Contributor

@marcaaron marcaaron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great. Thanks for your patience on this one @QichenZhu

}

const isApprovalEnabled = policy?.approvalMode && policy.approvalMode !== CONST.POLICY.APPROVAL_MODE.OPTIONAL;
if (report && policy && isPolicyAdmin(policy) && isExpenseReportUtil(report) && isProcessingReport(report) && !isMoneyRequestReportPendingDeletion(report) && isApprovalEnabled) {
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.

NAB, why isExpenseReportUtil and not isExpenseReport 🤔

@marcaaron marcaaron merged commit 28947ba into Expensify:main Apr 3, 2026
33 checks passed
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 3, 2026

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

@OSBotify
Copy link
Copy Markdown
Contributor

OSBotify commented Apr 4, 2026

✋ 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

OSBotify commented Apr 7, 2026

🚀 Deployed to staging by https://github.com/marcaaron in version: 9.3.53-0 🚀

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

Bundle Size Analysis (Sentry):

@MelvinBot
Copy link
Copy Markdown
Contributor

Yes, help site changes are needed. The bulk "Change approver" feature added in this PR is not covered in the existing documentation.

I've created a draft PR with the required updates: #87192

Changes made to 3 articles:

  1. Approve-Expenses.md — Added a new section "How to change the approver for multiple reports at once" with step-by-step instructions for the bulk flow, plus notes about cross-workspace member visibility and Control plan requirements.

  2. Getting-Started-with-the-Reports-Page.md — Added Change approver to the bulk actions list in the report table section.

  3. Understanding-Report-Statuses-and-Actions.md — Added "Change Approver" to the grey "More" button actions list.

All UI labels match the exact strings in src/languages/en.ts (e.g., "Change approver", "Add approver", "Bypass approvers"). Please mark the PR as "Ready for review" when it looks good.

@OSBotify
Copy link
Copy Markdown
Contributor

OSBotify commented Apr 7, 2026

🚀 Deployed to staging by https://github.com/marcaaron in version: 9.3.53-0 🚀

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

Bundle Size Analysis (Sentry):

@jponikarchuk
Copy link
Copy Markdown

Deploy Blocker #87213 was identified to be related to this PR.

@OSBotify
Copy link
Copy Markdown
Contributor

OSBotify commented Apr 7, 2026

🚀 Deployed to production by https://github.com/roryabraham in version: 9.3.53-7 🚀

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.

8 participants