Refactored usage of ONYXKEYS.PERSONAL_DETAILS_LIST from Member Actions#70581
Conversation
Codecov Report❌ Patch coverage is
... and 9 files with indirect coverage changes 🚀 New features to boost your workflow:
|
|
@parasharrajat 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] |
| }, {}); | ||
| return {policyMemberEmailsToAccountIDs: emailsToAccountIDs, employeeListDetails: details}; | ||
| }, [policy?.employeeList]); | ||
| const policyMemberEmailsToAccountIDs = useMemo(() => getMemberAccountIDsForWorkspace(policy?.employeeList, true), [policy?.employeeList]); |
There was a problem hiding this comment.
I don't think we should change every accountID-based logic to email-based for the reason that we opted to use accountID instead of emails all over the app in the past migration. Switching this logic back is like promoting this pattern again.
Can you restrict the changes to only the passing email where needed as part of this refactor by getting it from personaldetails?
cc: @tgolen What do you say about this?
There was a problem hiding this comment.
@parasharrajat, where did we do the migration? The changes made here were due to the fact that every member has a login field filled with a guarantee.
There was a problem hiding this comment.
It was a long time back when we switched from using login as the primary key to account ID.
Found the issue #19007
There was a problem hiding this comment.
Looks like it was different from what you are talking about here. Additionally, in employeeList, the key is the login, not the account ID, to match the BE structure, and this was introduced later during a migration.
List & categorize all changes needed to remove contact information from API calls
Also, this invariant is false for DeleteMembersFromWorkspace which is deliberate.
There was a problem hiding this comment.
Sure, let's wait for confirmation
There was a problem hiding this comment.
Yeah, to be honest, I'm having a hard time following all the changes in this PR. Can this be broken down into smaller pieces so that it's more apparent when changes are necessary?
Ideally, we should be using accountID as much as possible, but there are still a lot of places where that's not possible (such as with isApprover()).
So, if we can decrease the amount of accountID->email mapping to only the absolute bare minimum necessary for isApprover(), then that would be ideal.
There was a problem hiding this comment.
I agree with @tgolen. Also, we should restrict ourselves from making unnecessary code cleanups on these PRs. It is very tempting to clean the code but these refactor PRs are alreay prone to mistakes to let's not do that.
|
Looks like we are missing some tests in src/libs/actions/Policy/Member.ts related to the changed code. Can you please add those tests too if possible? |
|
@parasharrajat Can you please review this as we have discussed in the chat? |
|
Sure, I will continue here. |
|
bump @parasharrajat for review I believe |
|
yes, going test it today. |
|
@parasharrajat Will you be able to test this soon? |
|
Testing now... Thanks for the ping. |
parasharrajat
left a comment
There was a problem hiding this comment.
Need clarity on what is changed
| const firstSelectedEmployeeAccountID = policyMemberEmailsToAccountIDs[selectedEmployees[0]]; | ||
| return translate('workspace.people.removeMembersPrompt', { | ||
| count: selectedEmployees.length, | ||
| memberName: formatPhoneNumber(getPersonalDetailsByIDs({accountIDs: selectedEmployees, currentUserAccountID}).at(0)?.displayName ?? ''), | ||
| memberName: formatPhoneNumber(getPersonalDetailsByIDs({accountIDs: [firstSelectedEmployeeAccountID], currentUserAccountID}).at(0)?.displayName ?? ''), |
There was a problem hiding this comment.
Same here why are we using first from selectedEmployees?
There was a problem hiding this comment.
Cause it was not needed. See .at(0) usage here which does limit us to use the name for first selected employee.
| /** | ||
| * Check if the current selection includes members that cannot be removed | ||
| */ | ||
| const validateSelection = useCallback(() => { | ||
| const newErrors: Errors = {}; | ||
| selectedEmployees.forEach((member) => { | ||
| if (member !== policy?.ownerAccountID && member !== session?.accountID) { | ||
| return; | ||
| } | ||
| newErrors[member] = translate('workspace.people.error.cannotRemove'); | ||
| }); | ||
| setErrors(newErrors); | ||
| }, [selectedEmployees, policy?.ownerAccountID, session?.accountID, translate]); | ||
|
|
There was a problem hiding this comment.
Same.. I don't see how it was deemed necessary for this refactor.
There was a problem hiding this comment.
@parasharrajat This will never be triggered at all. So I removed the logic.
| validateSelection(); | ||
| }, [validateSelection]); | ||
|
|
||
| useEffect(() => { | ||
| if (removeMembersConfirmModalVisible && !deepEqual(accountIDs, prevAccountIDs)) { | ||
| setRemoveMembersConfirmModalVisible(false); | ||
| if (!removeMembersConfirmModalVisible || deepEqual(accountIDs, prevAccountIDs)) { | ||
| return; | ||
| } | ||
| setSelectedEmployees((prevSelectedEmployees) => { | ||
| // Filter all personal details in order to use the elements needed for the current workspace | ||
| const currentPersonalDetails = filterPersonalDetails(policy?.employeeList ?? {}, personalDetails); | ||
| // We need to filter the previous selected employees by the new personal details, since unknown/new user id's change when transitioning from offline to online | ||
| const prevSelectedElements = prevSelectedEmployees.map((id) => { | ||
| const prevItem = prevPersonalDetails?.[id]; | ||
| const res = Object.values(currentPersonalDetails).find((item) => prevItem?.login === item?.login); | ||
| return res?.accountID ?? id; | ||
| }); | ||
|
|
||
| const currentSelectedElements = Object.entries(getMemberAccountIDsForWorkspace(policy?.employeeList)) | ||
| .filter((employee) => policy?.employeeList?.[employee[0]]?.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE) | ||
| .map((employee) => employee[1]); | ||
|
|
||
| // This is an equivalent of the lodash intersection function. The reduce method below is used to filter the items that exist in both arrays. | ||
| return [prevSelectedElements, currentSelectedElements].reduce((prev, members) => prev.filter((item) => members.includes(item))); | ||
| }); |
There was a problem hiding this comment.
Can you please explain these changes? What have been changed here?
There was a problem hiding this comment.
Ok, earlier our index was based on accountID. So, when I add an user optimistically, it has an optimistically generated accountID for the users that we don't have details for. But when API returns the response, it will have different accountID, which might cause de-selection of user here if we have selected the user before API finishes.
But now we shifted to login based index, which do not change at all after API response, so we don't need this useEffect to correct selection.
| if (!isEmptyObject(errors)) { | ||
| return; | ||
| } |
There was a problem hiding this comment.
This change also. I didn't understand it.
There was a problem hiding this comment.
I removed the error validation logic as it will never give any error. That's why errors will always be empty.
| */ | ||
| const toggleAllUsers = (memberList: MemberOption[]) => { | ||
| const enabledAccounts = memberList.filter((member) => !member.isDisabled && !member.isDisabledCheckbox); | ||
| const someSelected = enabledAccounts.some((member) => selectedEmployees.includes(member.accountID)); |
There was a problem hiding this comment.
This seems to be changing the business logic.
There was a problem hiding this comment.
@parasharrajat I am sorry, what behavior will my change cause. Cause I thought doing simple check on selectedEmployees should be sufficient here.
|
@parasharrajat Bump here |
|
Thanks for the bump. I will have the checklist completed tomorrow morning. |
|
On it... |
|
@shubham1206agra Can you please add #72387 to the issues list it also fixes that one? |
@parasharrajat Done |
There was a problem hiding this comment.
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 Issuessection 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
Testssection - I verified the steps for Staging and/or Production testing are in the
QA stepssection - 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 verified the steps for local testing are in the
- 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 tests pass on all platforms & I tested again on:
- Android: Native
- Android: mWeb Chrome
- iOS: Native
- iOS: mWeb Safari
- MacOS: Chrome / Safari
- MacOS: Desktop
- 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.
toggleReportand notonIconClick). - I verified that the left part of a conditional rendering a React component is a boolean and NOT a string, e.g.
myBool && <MyComponent />. - 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 - 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 approved by marketing by adding the
Waiting for Copylabel for a copy review on the original GH to get the correct copy. - 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
- 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.
- 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 usingAvatarhave been tested & I retested again) - 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.js or at the top of the file that uses the constant) are defined as such
- 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
thisproperly so there are no scoping issues (i.e. foronClick={this.submit}the methodthis.submitshould be bound tothisin the constructor) - Any internal methods bound to
thisare necessary to be bound (i.e. avoidthis.submit = this.submit.bind(this);ifthis.submitis never passed to a component event handler likeonClick) - 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
Avataris modified, I verified thatAvataris 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 form input styles:
- I verified that all the inputs inside a form are aligned with each other.
- I added
Designlabel so the design team can review the changes.
- If a new page is added, I verified it's using the
ScrollViewcomponent to make it scrollable when more elements are added to the page. - If the
mainbranch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTeststeps. - I have checked off every checkbox in the PR reviewer checklist, including those that don't apply to this PR.
Screenshots
23.10.2025_04.22.51_REC.mp4
23.10.2025_04.21.07_REC.mp4
23.10.2025_02.24.44_REC.mp4
🎀 👀 🎀 C+ reviewed
|
✋ 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/tgolen in version: 9.2.38-0 🚀
|
|
🚀 Deployed to production by https://github.com/puneetlath in version: 9.2.38-5 🚀
|
Explanation of Change
Fixed Issues
$ #66568
$ #72387
Tests
Offline tests
Same as Tests
QA Steps
Same as Tests
PR Author Checklist
### Fixed Issuessection aboveTestssectionOffline stepssectionQA stepssectioncanBeMissingparam foruseOnyxtoggleReportand 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
Screen.Recording.2025-10-07.at.9.25.41.AM.mov