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 1 commit
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
31 changes: 26 additions & 5 deletions src/pages/workspace/WorkspaceMembersPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done )

return _.reduce(
_.keys(policyMembers),
(value, key) => {
if (personalDetails[key]) {
value[key] = personalDetails[key];

Check failure on line 90 in src/pages/workspace/WorkspaceMembersPage.js

View workflow job for this annotation

GitHub Actions / lint

Assignment to property of function parameter 'value'
}
return value;
},
{},
);
}

/**
* Get members for the current workspace
*/
Expand Down Expand Up @@ -116,12 +131,18 @@
if (removeMembersConfirmModalVisible && !_.isEqual(accountIDs, prevAccountIDs)) {
setRemoveMembersConfirmModalVisible(false);
}
setSelectedEmployees((prevSelected) =>
_.intersection(
prevSelected,
setSelectedEmployees((prevSelected) => {
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

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