-
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 4 commits
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,29 @@ function WorkspaceMembersPage(props) { | |
const prevAccountIDs = usePrevious(accountIDs); | ||
const textInputRef = useRef(null); | ||
const isOfflineAndNoMemberDataAvailable = _.isEmpty(props.policyMembers) && props.network.isOffline; | ||
const prevPersonalDetails = usePrevious(props.personalDetails); | ||
|
||
/** | ||
* Get filtered personalDetails list with current policyMembers | ||
* @param {Object} policyMembers | ||
* @param {Object} personalDetails | ||
* @returns {Object} | ||
*/ | ||
const filterPersonalDetails = (policyMembers, personalDetails) => | ||
_.reduce( | ||
_.keys(policyMembers), | ||
(result, key) => { | ||
if (personalDetails[key]) { | ||
return { | ||
...result, | ||
[key]: personalDetails[key], | ||
}; | ||
} | ||
return result; | ||
}, | ||
{}, | ||
); | ||
|
||
/** | ||
* Get members for the current workspace | ||
*/ | ||
|
@@ -116,12 +139,20 @@ function WorkspaceMembersPage(props) { | |
if (removeMembersConfirmModalVisible && !_.isEqual(accountIDs, prevAccountIDs)) { | ||
setRemoveMembersConfirmModalVisible(false); | ||
} | ||
setSelectedEmployees((prevSelected) => | ||
_.intersection( | ||
prevSelected, | ||
setSelectedEmployees((prevSelected) => { | ||
// Filter all personal details in order to use the elements needed for the current workspace | ||
const currentPersonalDetails = filterPersonalDetails(props.policyMembers, props.personalDetails); | ||
// Checking selected elements. Necessary in cases where there is a transition from offline to online mode, since after this the id changes for new members | ||
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. I think this comment could be better: "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" or, note this change also covers others cases where we just need to use the most up to date personal details we know. 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. It makes sense ) |
||
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.
@ZhenjaHorbach Why do we need to filter the personal details 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.
For optimization )
Instead of using all known PersonalDetails items
We will use only those that are needed only by the current workspace