Skip to content

Commit

Permalink
Refactor logic
Browse files Browse the repository at this point in the history
  • Loading branch information
DonOmalVindula committed Aug 27, 2024
1 parent 19751f6 commit abaf65c
Showing 1 changed file with 19 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,25 @@ export const AddGroupUserModal: FunctionComponent<AddGroupUserModalProps> = (
}

if (originalUserList.Resources) {
setUserList(originalUserList.Resources);
const filteredUsers: UserBasicInterface[] = [];

originalUserList.Resources.map((user: UserBasicInterface) => {
let isUserExistInGroup: boolean = false;
if (user?.groups?.length > 0) {

Check warning on line 112 in features/admin.groups.v1/components/edit-group/add-group-user-modal.tsx

View workflow job for this annotation

GitHub Actions / ⬣ ESLint (STATIC ANALYSIS) (lts/*, 8.7.4)

Expected blank line before this statement
user.groups.map((userGroup: UserRoleInterface) => {
if (userGroup.display === group.displayName) {
isUserExistInGroup = true;
}
});
}

// Do not show the user if the user is already assigned to the group.
if (!isUserExistInGroup) {
filteredUsers.push(user);
}
});

setUserList(filteredUsers);
}
}, [ originalUserList, isUserListFetchRequestLoading ]);

Expand Down Expand Up @@ -244,21 +262,6 @@ export const AddGroupUserModal: FunctionComponent<AddGroupUserModalProps> = (
const resolvedGivenName: string = UserManagementUtils.resolveUserListSubheader(user);
const resolvedUsername: string = getUserNameWithoutDomain(user?.userName);

// Do not show the user if the user is already assigned to the group.
let filterUser: boolean = false;

if (user?.groups?.length > 0) {
user.groups.map((userGroup: UserRoleInterface) => {
if (userGroup.display === group.displayName) {
filterUser = true;
}
});
}

if (filterUser) {
return null;
}

return (
<TransferListItem
handleItemChange={ () => handleItemCheckboxChange(user) }
Expand Down

0 comments on commit abaf65c

Please sign in to comment.