Skip to content

Fix initial selected ordering in approver selection lists - #95523

Merged
robertjchen merged 19 commits into
Expensify:mainfrom
marufsharifi:fix/approver-selection-initial-order
Jul 25, 2026
Merged

robertjchen merged 19 commits into
Expensify:mainfrom
marufsharifi:fix/approver-selection-initial-order

Conversation

@marufsharifi

@marufsharifi marufsharifi commented Jul 7, 2026 •

Copy link
Copy Markdown

Explanation of Change

This PR follows up on the selected-list-item ordering work from the linked issue.

It updates ApproverSelectionList so approver/member selectors preserve the initially selected item ordering when opened, without reordering the list again during live selection changes.

This covers workflow approval selectors such as:

  • Workflow approver
  • Over-limit approver
  • Expenses from member selector
  • Invite message approver selector

Fixed Issues

$ #69184
PROPOSAL:#69184 (comment)

Tests

Flow 1: Single approver selectors

  1. Navigate to Workspaces and open a workspace with many members.
  2. Go to More features and enable Workflows.
  3. Navigate to Workflows / Approvals.
  4. Create or edit an approval workflow.
  5. Open the approver selector.
  6. Select an approver far down in the list.
  7. Save the workflow or leave the selector.
  8. Reopen the same approver selector.
  9. Verify the previously selected approver appears at the top of the list.
  10. Select a different approver from the list.
  11. Verify the selected tick moves to the new approver.
  12. Verify the list does not jump or reorder after selecting the new approver.
  13. Search for an approver.
  14. Verify the initially selected approvers are still pinned at the top.
  15. Repeat the same checks for the over-limit approver selector.

Flow 2: Multi-select member selector

  1. Navigate to Workspaces and open a workspace with many members.
  2. Go to More features and enable Workflows.
  3. Navigate to Workflows / Approvals.
  4. Create or edit an approval workflow.
  5. Open the Expenses from member selector.
  6. Select one or more members far down in the list.
  7. Save or leave the selector.
  8. Reopen the Expenses from selector.
  9. Verify the initially selected members appear at the top.
  10. Select or deselect another member.
  11. Verify the list does not jump or reorder during the same open.
  12. Search for a member.
    13 Verify the initially selected members are still pinned at the top.
  • Verify that no errors appear in the JS console

Offline tests

QA Steps

// TODO: These must be filled out, or the issue title must include "[No QA]."

  • 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.

Screenshots/Videos

Android: Native

Flow1

flow11.mov

Flow2

flow22.mov
Android: mWeb Chrome

Flow1

flow1.mp4

Flow2

flow2.mp4
iOS: Native

Flow1

flow01.mov

Flow2

flow02.mov
iOS: mWeb Safari

Flow1

flow011.mov

Flow2

Screen.Recording.2026-07-10.at.7.07.49.PM.mov
MacOS: Chrome / Safari

Flow1

flow1.mov

Flow2

flow2.mov

@codecov

codecov Bot commented Jul 7, 2026 •

Copy link
Copy Markdown

@melvin-bot

melvin-bot Bot commented Jul 8, 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 request for a team July 8, 2026 06:10

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

Good for product

@marufsharifi

Copy link
Copy Markdown
Author

@linhvovan29546 Could you please review the PR when you get a chance ? thanks

@linhvovan29546

Copy link
Copy Markdown
Contributor

@marufsharifi This change introduces several unnecessary useEffects and state variables, and some of the changes seem like workarounds to me, such as focusCycleKey and hasUserChangedSelectionRef. We should try to find a solution that follows the same pattern we used in the previous PR.

@marufsharifi

Copy link
Copy Markdown
Author

We should try to find a solution that follows the same pattern we used in the previous PR.

@linhvovan29546 Thanks for pointing that out.

I first tried the existing pattern, but it didn’t fully handle this flow because the workflow RHP pages can stay mounted between steps. I added focus/scroll handling after that, but I agree it became too workaround-like.

I’ve updated it to use useInitialSelection(..., {resetOnFocus: true}) and derive the list remount from the refreshed initial selection key, so it follows the existing pattern more closely.

@marufsharifi

Copy link
Copy Markdown
Author

@linhvovan29546, Gentle bump. thanks.

const currentFocusedApproverKey = initiallyFocusedOptionKey ?? selectedApproverFocusKey;
const initialSelectionOptions = {isVisible: allApprovers.length > 0, resetOnFocus: true};
const initialSelectedApproverKeys = useInitialSelection(selectedApproverKeys, initialSelectionOptions);
const initiallyFocusedApproverKey = useInitialSelection(currentFocusedApproverKey, initialSelectionOptions);

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.

Why do we need to use useInitialSelection for initiallyFocusedApproverKey? Also, why are there two useInitialSelection hooks here?

@linhvovan29546

Copy link
Copy Markdown
Contributor

Bug: The selected item moves when I search

Screen.Recording.2026-07-16.at.14.39.07.mov

@linhvovan29546

Copy link
Copy Markdown
Contributor

Bug: The initially selected item is not moved to the top.

Screen.Recording.2026-07-16.at.15.17.44.mov

@marufsharifi

Copy link
Copy Markdown
Author

Bug: The selected item moves when I search

@linhvovan29546 Sorry for the confusion, but could you please clarify the expected behavior here?

In the previous PR #92765 the selected member was not pinned while searching. Should we follow the same behavior here, or should the selected item stay pinned during search too?

@linhvovan29546

Copy link
Copy Markdown
Contributor

In the previous PR #92765 the selected member was not pinned while searching. Should we follow the same behavior here, or should the selected item stay pinned during search too?

They should stay in the same position and not be reordered. If they are reordered when searching, that's a bug. For example, we already did that in the first PR.

Screen.Recording.2026-07-16.at.18.43.06.mov

@linhvovan29546

Copy link
Copy Markdown
Contributor

For context, we've had a long discussion here: #69655 (comment) and throughout the PR: #69655

@marufsharifi

Copy link
Copy Markdown
Author

@linhvovan29546 Thanks for the clarifications, I will handle that as well.

@marufsharifi

Copy link
Copy Markdown
Author

@linhvovan29546 I have addressed the feedbacks, could you please take another look when you get a chance ? thanks

@linhvovan29546

Copy link
Copy Markdown
Contributor

I'm still reviewing this

@marufsharifi

Copy link
Copy Markdown
Author

@linhvovan29546, Gentle bump. thanks.


const isLoadingApprovalWorkflow = isLoadingOnyxValue(approvalWorkflowResults);
const [selectedMembers, setSelectedMembers] = useState<SelectionListApprover[]>([]);
const [hasSyncedSelectedMembers, setHasSyncedSelectedMembers] = useState(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.

I'm not sure this is the right approach to fix the issue. Maybe we should remove setSelectedMembers and handle selectedMembers the same way we do in other parts of the app?

@marufsharifi

Copy link
Copy Markdown
Author

@linhvovan29546, could you please take another look. thanks.

@linhvovan29546

linhvovan29546 commented Jul 25, 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
telegram-cloud-document-5-6278098973831994567.mp4
Android: mWeb Chrome
telegram-cloud-document-5-6278098973831994568.mp4
iOS: HybridApp
Screen.Recording.2026-07-25.at.18.10.48.mov
iOS: mWeb Safari
Screen.Recording.2026-07-25.at.17.48.48.mov
MacOS: Chrome / Safari
Screen.Recording.2026-07-25.at.17.09.32.mov
Screen.Recording.2026-07-25.at.17.08.00.mov
Screen.Recording.2026-07-25.at.17.25.38.mov

@melvin-bot
melvin-bot Bot requested a review from robertjchen July 25, 2026 11:13
@marufsharifi

Copy link
Copy Markdown
Author

@linhvovan29546 Thanks for the helpful feedback! I've addressed them as well — you can take another look when you get a chance. thanks

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

thanks!

@robertjchen
robertjchen merged commit 6998346 into Expensify:main Jul 25, 2026
35 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

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

@OSBotify

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.

@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to staging by https://github.com/robertjchen in version: 9.4.45-0 🚀

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

@MelvinBot

Copy link
Copy Markdown
Contributor

🤖 Help site review: no changes required.

I reviewed the changes in this PR against the help site articles under App/docs/articles.

This is a purely internal UI/behavior fix in the approver selection lists — it preserves the initially selected item ordering (moving already-selected approvers/members to the top when the selector opens) and prevents the list from reordering mid-selection. It touches ApproverSelectionList, SelectionListOrderUtils, and the workflow approver/over-limit/expenses-from selector pages.

None of this changes any documented, user-facing steps:

  • The help articles for approval workflows and adding approvers explain how to configure workflows, approvers, and over-limit approvers — the steps are unchanged.
  • The ordering/sorting behavior of the selector picker is an implementation detail that is not (and doesn't need to be) documented on the help site.

Because there are no new or changed features, settings, labels, or user-facing flows, no help site documentation update is needed, so I have not created a docs PR.

@marufsharifi, please review the linked help site PR and confirm it reflects the current behavior. Then mark the linked help site PR Ready for review.

(Note: no help site PR was created because this change does not require any documentation updates — there is nothing to link. If you believe a specific article should be updated, let me know which one and I'll draft the change.)

@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to production by https://github.com/marcaaron in version: 9.4.45-14 🚀

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants