-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Selected workspace members unselect on switch from offline to online #29587
Changes from 1 commit
ff22661
5932418
c1000e8
392d9ae
e654ca0
684c1bf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -80,6 +80,21 @@ | |
const prevAccountIDs = usePrevious(accountIDs); | ||
const textInputRef = useRef(null); | ||
const isOfflineAndNoMemberDataAvailable = _.isEmpty(props.policyMembers) && props.network.isOffline; | ||
const prevPersonalDetails = usePrevious(props.personalDetails); | ||
|
||
function filterPersonalDetails(policyMembers, personalDetails) { | ||
return _.reduce( | ||
_.keys(policyMembers), | ||
(value, key) => { | ||
if (personalDetails[key]) { | ||
value[key] = personalDetails[key]; | ||
} | ||
return value; | ||
}, | ||
{}, | ||
); | ||
} | ||
|
||
/** | ||
* Get members for the current workspace | ||
*/ | ||
|
@@ -116,12 +131,18 @@ | |
if (removeMembersConfirmModalVisible && !_.isEqual(accountIDs, prevAccountIDs)) { | ||
setRemoveMembersConfirmModalVisible(false); | ||
} | ||
setSelectedEmployees((prevSelected) => | ||
_.intersection( | ||
prevSelected, | ||
setSelectedEmployees((prevSelected) => { | ||
const currentPersonalDetails = filterPersonalDetails(props.policyMembers, props.personalDetails); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ZhenjaHorbach Why do we need to filter the personal details here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For optimization ) |
||
const prevSelectedElements = _.map(prevSelected, (id) => { | ||
const prevItem = lodashGet(prevPersonalDetails, id); | ||
const res = _.find(_.values(currentPersonalDetails), (item) => lodashGet(prevItem, 'login') === lodashGet(item, 'login')); | ||
return lodashGet(res, 'accountID', id); | ||
}); | ||
return _.intersection( | ||
prevSelectedElements, | ||
_.map(_.values(PolicyUtils.getMemberAccountIDsForWorkspace(props.policyMembers, props.personalDetails)), (accountID) => Number(accountID)), | ||
), | ||
); | ||
); | ||
}); | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [props.policyMembers]); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be an arrow function, and also please add JSDoc here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done )