Skip to content

Commit

Permalink
UIPFU-77 - refine complexity
Browse files Browse the repository at this point in the history
  • Loading branch information
Terala-Priyanka committed Jan 10, 2024
1 parent a309cc4 commit e5287a2
Showing 1 changed file with 64 additions and 34 deletions.
98 changes: 64 additions & 34 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,47 +41,77 @@ export const updateResourceData = (rData) => {
return newRData;
};

const filterUsersList = (filterString, initialSelectedUsers, users, filterCheck) => {
let usersList;
if (filterString === `${ASSIGNED}`) {
const assignedUsers = Object.values(initialSelectedUsers);
if (filterCheck) {
usersList = assignedUsers.filter(u => filterCheck(u));
} else {
usersList = assignedUsers;
}
} else if (filterString === `${UNASSIGNED}`) {
const assignedUserIds = Object.keys(initialSelectedUsers);
if (filterCheck) {
usersList = users.filter(u => !assignedUserIds.includes(u.id) && (filterCheck(u)));
} else {
usersList = users.filter(u => !assignedUserIds.includes(u.id));
}
}
return usersList;
};

// eslint-disable-next-line consistent-return
export const getUsersBasedOnAssignmentStatus = (activeFilterState, uasFilterValue, initialSelectedUsers, users) => {
const condForOneOfTheFilters = (u) => activeFilterState?.active?.includes(u.active ? `${ACTIVE}` : `${INACTIVE}`) || activeFilterState?.pg?.includes(u.patronGroup);
const condForBothTheFilters = (u) => activeFilterState?.active?.includes(u.active ? `${ACTIVE}` : `${INACTIVE}`) && activeFilterState?.pg?.includes(u.patronGroup);
if (uasFilterValue[0] === `${ASSIGNED}`) {
// when ONLY "Assigned" filter is selected
const assignedUsers = Object.values(initialSelectedUsers);
if (Object.keys(activeFilterState).length === 1) {
return assignedUsers;
}
// several filters are selected
// filter users based on the filter group values in place
// if (uasFilterValue[0] === `${ASSIGNED}`) {
// // when ONLY "Assigned" filter is selected
// const assignedUsers = Object.values(initialSelectedUsers);
// if (Object.keys(activeFilterState).length === 1) {
// return assignedUsers;
// }
// // several filters are selected
// // filter users based on the filter group values in place

// when "Assigned" from "User Assignment Status" filter group along with some other filter in one of the other filter groups
if (Object.keys(activeFilterState).length === 2) {
const filteredAssignedUsers = assignedUsers.filter(u => condForOneOfTheFilters(u));
return filteredAssignedUsers;
}
// // when "Assigned" from "User Assignment Status" filter group along with some other filter in one of the other filter groups
// if (Object.keys(activeFilterState).length === 2) {
// const filteredAssignedUsers = assignedUsers.filter(u => condForOneOfTheFilters(u));
// return filteredAssignedUsers;
// }

// when filters from all the filter groups are selected
const filteredAssignedUsers = assignedUsers.filter(u => condForBothTheFilters(u));
return filteredAssignedUsers;
}
if (uasFilterValue[0] === `${UNASSIGNED}`) {
// when ONLY "Unassigned" filter is selected
const assignedUserIds = Object.keys(initialSelectedUsers);
if (Object.keys(activeFilterState).length === 1) {
const filteredUsers = users.filter(u => !assignedUserIds.includes(u.id));
return filteredUsers;
}
// several filters are selected
// filter users based on the filter group values in place
// // when filters from all the filter groups are selected
// const filteredAssignedUsers = assignedUsers.filter(u => condForBothTheFilters(u));
// return filteredAssignedUsers;
// }
// if (uasFilterValue[0] === `${UNASSIGNED}`) {
// // when ONLY "Unassigned" filter is selected
// const assignedUserIds = Object.keys(initialSelectedUsers);
// if (Object.keys(activeFilterState).length === 1) {
// const filteredUsers = users.filter(u => !assignedUserIds.includes(u.id));
// return filteredUsers;
// }
// // several filters are selected
// // filter users based on the filter group values in place

// when "UnAssigned" from "User Assignment Status" filter group along with some other filter in one of the other filter groups
if (Object.keys(activeFilterState).length === 2) {
const filteredAssignedUsers = users.filter(u => !assignedUserIds.includes(u.id) && (condForOneOfTheFilters(u)));
return filteredAssignedUsers;
}
// // when "UnAssigned" from "User Assignment Status" filter group along with some other filter in one of the other filter groups
// if (Object.keys(activeFilterState).length === 2) {
// const filteredAssignedUsers = users.filter(u => !assignedUserIds.includes(u.id) && (condForOneOfTheFilters(u)));
// return filteredAssignedUsers;
// }

// // when filters from all the filter groups are selected
// const filteredAssignedUsers = users.filter(u => !assignedUserIds.includes(u.id) && (condForBothTheFilters(u)));
// return filteredAssignedUsers;
// }

// when filters from all the filter groups are selected
const filteredAssignedUsers = users.filter(u => !assignedUserIds.includes(u.id) && (condForBothTheFilters(u)));
return filteredAssignedUsers;
let usersList;
if (Object.keys(activeFilterState).length === 1) {
usersList = filterUsersList(uasFilterValue[0], initialSelectedUsers, users);
} else if (Object.keys(activeFilterState).length === 2) {
usersList = filterUsersList(uasFilterValue[0], initialSelectedUsers, users, condForOneOfTheFilters);
} else {
usersList = filterUsersList(uasFilterValue[0], initialSelectedUsers, users, condForBothTheFilters);
}
return usersList;
};

0 comments on commit e5287a2

Please sign in to comment.