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 4 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
41 changes: 36 additions & 5 deletions 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,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);
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

// 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
Copy link
Contributor

@Li357 Li357 Oct 16, 2023

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It makes sense )
Done )

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]);

Expand Down
Loading