Skip to content
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

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 34 additions & 1 deletion src/pages/workspace/WorkspaceMembersPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -116,7 +139,17 @@ function WorkspaceMembersPage(props) {
if (removeMembersConfirmModalVisible && !_.isEqual(accountIDs, prevAccountIDs)) {
setRemoveMembersConfirmModalVisible(false);
}
setSelectedEmployees((prevSelected) => _.intersection(prevSelected, _.values(PolicyUtils.getMemberAccountIDsForWorkspace(props.policyMembers, props.personalDetails))));
setSelectedEmployees((prevSelected) => {
// Filter all personal details in order to use the elements needed for the current workspace
const currentPersonalDetails = filterPersonalDetails(props.policyMembers, props.personalDetails);
Copy link
Contributor

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?

Copy link
Contributor Author

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

// 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 = _.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, _.values(PolicyUtils.getMemberAccountIDsForWorkspace(props.policyMembers, props.personalDetails)));
});
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [props.policyMembers]);

Expand Down
Loading