diff --git a/src/UserSearchContainer.js b/src/UserSearchContainer.js index f3abd26..af49c96 100644 --- a/src/UserSearchContainer.js +++ b/src/UserSearchContainer.js @@ -10,7 +10,11 @@ import { import filterConfig, { filterConfigWithUserAssignedStatus } from './filterConfig'; import { updateResourceData } from './utils'; -import { UAS } from './constants'; +import { + ASSIGNED_FILTER_KEY, + UNASSIGNED_FILTER_KEY, + UAS, +} from './constants'; const INITIAL_RESULT_COUNT = 30; const RESULT_COUNT_INCREMENT = 30; @@ -36,7 +40,7 @@ const compileQuery = template( export function buildQuery(queryParams, pathComponents, resourceData, logger, props) { const filters = props.initialSelectedUsers ? filterConfigWithUserAssignedStatus : filterConfig; - const updatedResourceData = props.initialSelectedUsers && resourceData?.query?.filters?.substring(`${UAS}`) ? updateResourceData(resourceData) : resourceData; + const updatedResourceData = props.initialSelectedUsers && resourceData?.query?.filters?.includes(`${UAS}`) ? updateResourceData(resourceData) : resourceData; return makeQueryFunction( 'cql.allRecords=1', @@ -120,6 +124,7 @@ class UserSearchContainer extends React.Component { */ // eslint-disable-next-line react/no-unused-prop-types tenantId: PropTypes.string.isRequired, + initialSelectedUsers: PropTypes.object, } constructor(props) { @@ -175,6 +180,46 @@ class UserSearchContainer extends React.Component { return get(this.props.resources, 'query', {}); } + getUsers = () => { + const { + resources, + initialSelectedUsers, + } = this.props; + const fetchedUsers = get(resources, 'records.records', []); + const activeFilters = get(resources, 'query.filters', ''); + + if (activeFilters.includes(`${UAS}`)) { + const assignedUsers = Object.values(initialSelectedUsers); + const assignedUserIds = Object.keys(initialSelectedUsers); + const hasBothUASFilters = activeFilters.includes(`${ASSIGNED_FILTER_KEY}`) && activeFilters.includes(`${UNASSIGNED_FILTER_KEY}`); + const hasNoneOfUASFilters = !activeFilters.includes(`${ASSIGNED_FILTER_KEY}`) && !activeFilters.includes(`${UNASSIGNED_FILTER_KEY}`); + + if (hasBothUASFilters || hasNoneOfUASFilters) { + return fetchedUsers; + } + const uasFilterValue = activeFilters.split(',').filter(f => f.includes(`${UAS}`))[0].split('.')[1]; + + let otherFilterGroups = activeFilters.split(',').filter(f => !f.includes(`${UAS}`)).map(f => f.split('.')[0]); + if (otherFilterGroups.indexOf('pg') !== -1) { + otherFilterGroups = otherFilterGroups.with(otherFilterGroups.indexOf('pg'), 'patronGroup'); + } + + let otherFilterValues = activeFilters.split(',').filter(f => !f.includes(`${UAS}`)).map(f => f.split('.')[1]); + if (otherFilterValues.indexOf('active') !== -1) { + otherFilterValues = otherFilterValues.with(otherFilterValues.indexOf('active'), true); + } + + if (uasFilterValue === 'Assigned') { + if (!otherFilterGroups.length) return assignedUsers; + return assignedUsers.filter(u => otherFilterGroups.every((g, i) => u[g] === otherFilterValues[i])); + } + const unAssignedUsers = fetchedUsers.filter(u => !assignedUserIds.includes(u.id)); + if (!otherFilterGroups.length) return unAssignedUsers; + return unAssignedUsers.filter(u => otherFilterGroups.every((g, i) => u[g] === otherFilterValues[i])); + } + return fetchedUsers; + } + render() { const { resources, @@ -195,7 +240,7 @@ class UserSearchContainer extends React.Component { resultOffset, data: { patronGroups: (resources.patronGroups || {}).records || [], - users: get(resources, 'records.records', []), + users: this.getUsers(), }, }); } diff --git a/src/UserSearchView.js b/src/UserSearchView.js index 522cf19..8f21bdd 100644 --- a/src/UserSearchView.js +++ b/src/UserSearchView.js @@ -24,8 +24,6 @@ import { SearchAndSortSearchButton as FilterPaneToggle, } from '@folio/stripes/smart-components'; -import { UAS } from './constants'; -import { getUsersBasedOnAssignmentStatus } from './utils'; import filterConfig, { filterConfigWithUserAssignedStatus } from './filterConfig'; import Filters from './Filters'; @@ -295,19 +293,6 @@ class UserSearchView extends React.Component { return true; }; - const getContentData = () => { - const activeFilterState = activeFilters?.state; - const isUasFilterGroupActive = Object.hasOwn(activeFilterState, UAS); - const uasFilterValue = activeFilterState.uas; - - if (isUasFilterGroupActive && uasFilterValue.length === 1) { - const filteredUsers = getUsersBasedOnAssignmentStatus(activeFilterState, uasFilterValue, initialSelectedUsers, users); - return filteredUsers; - } - // when both 'Assigned' and 'Unassigned' filters are applied or both are not applied - return users; - }; - return ( {intl => ( @@ -377,7 +362,8 @@ class UserSearchView extends React.Component { { const newRData = cloneDeep(rData); if (filterString === `${UNASSIGNED_FILTER_KEY}` || filterString === `${ASSIGNED_FILTER_KEY},${UNASSIGNED_FILTER_KEY}` || filterString === `${UNASSIGNED_FILTER_KEY},${ASSIGNED_FILTER_KEY}`) { /* - * When Unassigned filter is selected on 'User assigbment Status' filter group, with no other filter from other groups, + * When Unassigned filter is selected on 'User assignment Status' filter group, with no other filter from other groups, * fetch all the user records. The filter string is adjusted to include both active and inactive status filters. This will result in (cql.allRecords=1) * * The same applies when both Assigned and Unassigned are selected in any sequential order. @@ -24,60 +20,19 @@ export const updateResourceData = (rData) => { newRData.query.filters = alteredfilters; } else if (filterString.includes(`${UNASSIGNED_FILTER_KEY}`)) { /* - * When UnAssigned filter is selected incombination with any other filters(in other filter groups), - * filter astring for Unassigned is removed and th erest of the filter string is propagated to makeQueryFunction. + * When UnAssigned filter is selected in combination with any other filters, + * filter a string for Unassigned is removed and the rest of the filter string is propagated to makeQueryFunction. */ const alteredfilters = newRData.query.filters.split(',').filter(str => !str.startsWith(`${UAS}`)).join(','); newRData.query.filters = alteredfilters; } else if (filterString.includes(`${ASSIGNED_FILTER_KEY}`)) { /* - * When Assigned filter is selected on 'User assigbment Status' filter group, in any combination of filters in other filter groups, + * When Assigned filter is selected on 'User assignment Status' filter group, in any combination of filters in other filter groups, * cql formation is not needed. - * hence remove aus filter before propagating it further to makeQueryFunction + * hence remove uas filter before propagating it further to makeQueryFunction */ const alteredfilters = ''; newRData.query.filters = alteredfilters; } return newRData; }; - -const filterUsersList = (filterString, initialSelectedUsers, users, filterCheck) => { - let usersList; - if (filterString === `${ASSIGNED}`) { - const assignedUsers = Object.values(initialSelectedUsers); - if (filterCheck) { - // "Assigned" filter along with one or more other filters from other filter groups are selected - usersList = assignedUsers.filter(u => filterCheck(u)); - } else { - // when ONLY "Assigned" filter is selected - usersList = assignedUsers; - } - } else if (filterString === `${UNASSIGNED}`) { - // when ONLY "Unassigned" filter is selected - const assignedUserIds = Object.keys(initialSelectedUsers); - if (filterCheck) { - // "Unassigned" filter along with one or more other filters from other filter groups are selected - usersList = users.filter(u => !assignedUserIds.includes(u.id) && (filterCheck(u))); - } else { - // when ONLY "Unassigned" filter is selected - 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); - - 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; -}; diff --git a/src/utils.test.js b/src/utils.test.js index c1c6dd3..3db5bd7 100644 --- a/src/utils.test.js +++ b/src/utils.test.js @@ -1,4 +1,4 @@ -import { updateResourceData, getUsersBasedOnAssignmentStatus } from './utils'; +import { updateResourceData } from './utils'; import { UNASSIGNED_FILTER_KEY, ASSIGNED_FILTER_KEY } from './constants'; describe('updatedResourceData', () => { @@ -38,7 +38,7 @@ describe('updatedResourceData', () => { }); }); - describe('when Assigned filter is selected with or without combonation of filters from other filter groups', () => { + describe('when Assigned filter is selected with or without combination of filters from other filter groups', () => { it('should remove filter string', () => { const resourceData = { query: { @@ -55,565 +55,3 @@ describe('updatedResourceData', () => { }); }); }); - -describe('getUsersBasedOnAssignmentStatus', () => { - describe('when ONLY Assigned filter is selected', () => { - it('should return assigned users', () => { - const activeFilterState = { uas: ['Assigned'] }; - const uasFilterValue = ['Assigned']; - const initialSelectedUsers = { - '7daa365a-d8c1-4e5d-90ac-ab38f8230827': { - 'username': 'acq-admin', - 'id': '7daa365a-d8c1-4e5d-90ac-ab38f8230827', - 'barcode': '1704852123910366583', - 'active': true, - 'type': 'patron', - 'departments': [], - 'proxyFor': [], - 'createdDate': '2024-01-10T02:02:03.939+00:00', - 'updatedDate': '2024-01-10T02:02:03.939+00:00', - 'metadata': { - 'createdDate': '2024-01-10T02:02:03.936+00:00', - 'createdByUserId': '4074b75e-5c13-5dde-b78c-b07a420c6e3b', - 'updatedDate': '2024-01-10T02:02:03.936+00:00', - 'updatedByUserId': '4074b75e-5c13-5dde-b78c-b07a420c6e3b' - }, - 'personal': { - 'lastName': 'Admin', - 'firstName': 'acq-admin', - 'addresses': [] - }, - 'patronGroup': '3684a786-6671-4268-8ed0-9db82ebca60b', - 'fullName': 'Admin, acq-admin', - 'groupName': 'staff' - } - }; - const users = []; - expect(getUsersBasedOnAssignmentStatus(activeFilterState, uasFilterValue, initialSelectedUsers, users)).toMatchObject(Object.values(initialSelectedUsers)); - }); - }); - - describe('when Assigned filter is selected along with other filters from one of the other filter groups', () => { - it('should filter active filters from assigned users', () => { - const activeFilterState = { uas: ['Assigned'], active: ['active'] }; - const uasFilterValue = ['Assigned']; - const initialSelectedUsers = { - '7daa365a-d8c1-4e5d-90ac-ab38f8230827': { - 'username': 'acq-admin', - 'id': '7daa365a-d8c1-4e5d-90ac-ab38f8230827', - 'barcode': '1704852123910366583', - 'active': true, - 'type': 'patron', - 'departments': [], - 'proxyFor': [], - 'createdDate': '2024-01-10T02:02:03.939+00:00', - 'updatedDate': '2024-01-10T02:02:03.939+00:00', - 'metadata': { - 'createdDate': '2024-01-10T02:02:03.936+00:00', - 'createdByUserId': '4074b75e-5c13-5dde-b78c-b07a420c6e3b', - 'updatedDate': '2024-01-10T02:02:03.936+00:00', - 'updatedByUserId': '4074b75e-5c13-5dde-b78c-b07a420c6e3b' - }, - 'personal': { - 'lastName': 'Admin', - 'firstName': 'acq-admin', - 'addresses': [] - }, - 'patronGroup': '3684a786-6671-4268-8ed0-9db82ebca60b', - 'fullName': 'Admin, acq-admin', - 'groupName': 'staff' - } - }; - const users = []; - const expectedAssignedUsers = [initialSelectedUsers['7daa365a-d8c1-4e5d-90ac-ab38f8230827']]; - expect(getUsersBasedOnAssignmentStatus(activeFilterState, uasFilterValue, initialSelectedUsers, users)).toMatchObject(Object.values(expectedAssignedUsers)); - }); - }); - - describe('when Assigned filter is selected along with filters from other filter groups', () => { - it('should filter assigned user based on the filters from other filter groups - status and patrongroup', () => { - const activeFilterState = { uas: ['Assigned'], active: ['active'], pg: ['3684a786-6671-4268-8ed0-9db82ebca60b'] }; - const uasFilterValue = ['Assigned']; - const initialSelectedUsers = { - '7daa365a-d8c1-4e5d-90ac-ab38f8230827': { - 'username': 'acq-admin', - 'id': '7daa365a-d8c1-4e5d-90ac-ab38f8230827', - 'barcode': '1704852123910366583', - 'active': true, - 'type': 'patron', - 'departments': [], - 'proxyFor': [], - 'createdDate': '2024-01-10T02:02:03.939+00:00', - 'updatedDate': '2024-01-10T02:02:03.939+00:00', - 'metadata': { - 'createdDate': '2024-01-10T02:02:03.936+00:00', - 'createdByUserId': '4074b75e-5c13-5dde-b78c-b07a420c6e3b', - 'updatedDate': '2024-01-10T02:02:03.936+00:00', - 'updatedByUserId': '4074b75e-5c13-5dde-b78c-b07a420c6e3b' - }, - 'personal': { - 'lastName': 'Admin', - 'firstName': 'acq-admin', - 'addresses': [] - }, - 'patronGroup': '3684a786-6671-4268-8ed0-9db82ebca60b', - 'fullName': 'Admin, acq-admin', - 'groupName': 'staff' - } - }; - const users = []; - const expectedAssignedUsers = [initialSelectedUsers['7daa365a-d8c1-4e5d-90ac-ab38f8230827']]; - expect(getUsersBasedOnAssignmentStatus(activeFilterState, uasFilterValue, initialSelectedUsers, users)).toMatchObject(Object.values(expectedAssignedUsers)); - }); - }); - - describe('when ONLY Unassigned filter is selected', () => { - it('should filter unassigned users from the list of users and return the rest', () => { - const activeFilterState = { uas: ['Unassigned'] }; - const uasFilterValue = ['Unassigned']; - const initialSelectedUsers = { - '7daa365a-d8c1-4e5d-90ac-ab38f8230827': { - 'username': 'acq-admin', - 'id': '7daa365a-d8c1-4e5d-90ac-ab38f8230827', - 'barcode': '1704852123910366583', - 'active': true, - 'type': 'patron', - 'departments': [], - 'proxyFor': [], - 'createdDate': '2024-01-10T02:02:03.939+00:00', - 'updatedDate': '2024-01-10T02:02:03.939+00:00', - 'metadata': { - 'createdDate': '2024-01-10T02:02:03.936+00:00', - 'createdByUserId': '4074b75e-5c13-5dde-b78c-b07a420c6e3b', - 'updatedDate': '2024-01-10T02:02:03.936+00:00', - 'updatedByUserId': '4074b75e-5c13-5dde-b78c-b07a420c6e3b' - }, - 'personal': { - 'lastName': 'Admin', - 'firstName': 'acq-admin', - 'addresses': [] - }, - 'patronGroup': '3684a786-6671-4268-8ed0-9db82ebca60b', - 'fullName': 'Admin, acq-admin', - 'groupName': 'staff' - } - }; - const users = [ - { - 'username': 'acq-admin', - 'id': '7daa365a-d8c1-4e5d-90ac-ab38f8230827', - 'barcode': '1704852123910366583', - 'active': true, - 'type': 'patron', - 'departments': [], - 'proxyFor': [], - 'createdDate': '2024-01-10T02:02:03.939+00:00', - 'updatedDate': '2024-01-10T02:02:03.939+00:00', - 'metadata': { - 'createdDate': '2024-01-10T02:02:03.936+00:00', - 'createdByUserId': '4074b75e-5c13-5dde-b78c-b07a420c6e3b', - 'updatedDate': '2024-01-10T02:02:03.936+00:00', - 'updatedByUserId': '4074b75e-5c13-5dde-b78c-b07a420c6e3b' - }, - 'personal': { - 'lastName': 'Admin', - 'firstName': 'acq-admin', - 'addresses': [] - }, - 'patronGroup': '3684a786-6671-4268-8ed0-9db82ebca60b', - 'fullName': 'Admin, acq-admin', - 'groupName': 'staff' - }, - { - 'username': 'devonte', - 'id': 'a208cf17-a7f0-452d-ae0e-64011232c86d', - 'barcode': '745758690367580', - 'active': true, - 'type': 'patron', - 'patronGroup': 'ad0bc554-d5bc-463c-85d1-5562127ae91b', - 'departments': [], - 'proxyFor': [], - 'personal': { - 'lastName': 'Abbott', - 'firstName': 'Candace', - 'middleName': 'Fanny', - 'email': 'guy@lemke-llc.ok.us', - 'phone': '(136)082-4680 x8231', - 'mobilePhone': '(436)763-7413', - 'dateOfBirth': '1986-06-26T00:00:00.000+00:00', - 'addresses': [ - { - 'countryId': 'US', - 'addressLine1': '43069 Lobby', - 'city': 'Seal Beach', - 'region': 'NC', - 'postalCode': '35848-5877', - 'addressTypeId': '93d3d88d-499b-45d0-9bc7-ac73c3a19880', - 'primaryAddress': true - } - ], - 'preferredContactTypeId': '002' - }, - 'enrollmentDate': '2015-08-28T00:00:00.000+00:00', - 'expirationDate': '2026-01-01T23:59:59.000+00:00', - 'createdDate': '2024-01-10T07:32:22.263+00:00', - 'updatedDate': '2024-01-10T07:32:22.263+00:00', - 'metadata': { - 'createdDate': '2024-01-10T01:51:44.010+00:00', - 'updatedDate': '2024-01-10T07:32:22.260+00:00', - 'updatedByUserId': '43470c3d-1823-4b99-a24f-143728fc894a' - }, - 'tags': { - 'tagList': [] - }, - 'customFields': {} - } - ]; - const expectedUnAssignedUsers = [{ - 'username': 'devonte', - 'id': 'a208cf17-a7f0-452d-ae0e-64011232c86d', - 'barcode': '745758690367580', - 'active': true, - 'type': 'patron', - 'patronGroup': 'ad0bc554-d5bc-463c-85d1-5562127ae91b', - 'departments': [], - 'proxyFor': [], - 'personal': { - 'lastName': 'Abbott', - 'firstName': 'Candace', - 'middleName': 'Fanny', - 'email': 'guy@lemke-llc.ok.us', - 'phone': '(136)082-4680 x8231', - 'mobilePhone': '(436)763-7413', - 'dateOfBirth': '1986-06-26T00:00:00.000+00:00', - 'addresses': [ - { - 'countryId': 'US', - 'addressLine1': '43069 Lobby', - 'city': 'Seal Beach', - 'region': 'NC', - 'postalCode': '35848-5877', - 'addressTypeId': '93d3d88d-499b-45d0-9bc7-ac73c3a19880', - 'primaryAddress': true - } - ], - 'preferredContactTypeId': '002' - }, - 'enrollmentDate': '2015-08-28T00:00:00.000+00:00', - 'expirationDate': '2026-01-01T23:59:59.000+00:00', - 'createdDate': '2024-01-10T07:32:22.263+00:00', - 'updatedDate': '2024-01-10T07:32:22.263+00:00', - 'metadata': { - 'createdDate': '2024-01-10T01:51:44.010+00:00', - 'updatedDate': '2024-01-10T07:32:22.260+00:00', - 'updatedByUserId': '43470c3d-1823-4b99-a24f-143728fc894a' - }, - 'tags': { - 'tagList': [] - }, - 'customFields': {} - }]; - expect(getUsersBasedOnAssignmentStatus(activeFilterState, uasFilterValue, initialSelectedUsers, users)).toMatchObject(Object.values(expectedUnAssignedUsers)); - }); - }); - - describe('when Unassigned filter is selected along with one of the filrers from other filter groups', () => { - it('should filter unassigned users based on the the filter', () => { - const activeFilterState = { uas: ['Unassigned'], active: ['active'] }; - const uasFilterValue = ['Unassigned']; - const initialSelectedUsers = { - '7daa365a-d8c1-4e5d-90ac-ab38f8230827': { - 'username': 'acq-admin', - 'id': '7daa365a-d8c1-4e5d-90ac-ab38f8230827', - 'barcode': '1704852123910366583', - 'active': true, - 'type': 'patron', - 'departments': [], - 'proxyFor': [], - 'createdDate': '2024-01-10T02:02:03.939+00:00', - 'updatedDate': '2024-01-10T02:02:03.939+00:00', - 'metadata': { - 'createdDate': '2024-01-10T02:02:03.936+00:00', - 'createdByUserId': '4074b75e-5c13-5dde-b78c-b07a420c6e3b', - 'updatedDate': '2024-01-10T02:02:03.936+00:00', - 'updatedByUserId': '4074b75e-5c13-5dde-b78c-b07a420c6e3b' - }, - 'personal': { - 'lastName': 'Admin', - 'firstName': 'acq-admin', - 'addresses': [] - }, - 'patronGroup': '3684a786-6671-4268-8ed0-9db82ebca60b', - 'fullName': 'Admin, acq-admin', - 'groupName': 'staff' - } - }; - const users = [ - { - 'username': 'acq-admin', - 'id': '7daa365a-d8c1-4e5d-90ac-ab38f8230827', - 'barcode': '1704852123910366583', - 'active': true, - 'type': 'patron', - 'departments': [], - 'proxyFor': [], - 'createdDate': '2024-01-10T02:02:03.939+00:00', - 'updatedDate': '2024-01-10T02:02:03.939+00:00', - 'metadata': { - 'createdDate': '2024-01-10T02:02:03.936+00:00', - 'createdByUserId': '4074b75e-5c13-5dde-b78c-b07a420c6e3b', - 'updatedDate': '2024-01-10T02:02:03.936+00:00', - 'updatedByUserId': '4074b75e-5c13-5dde-b78c-b07a420c6e3b' - }, - 'personal': { - 'lastName': 'Admin', - 'firstName': 'acq-admin', - 'addresses': [] - }, - 'patronGroup': '3684a786-6671-4268-8ed0-9db82ebca60b', - 'fullName': 'Admin, acq-admin', - 'groupName': 'staff' - }, - { - 'username': 'devonte', - 'id': 'a208cf17-a7f0-452d-ae0e-64011232c86d', - 'barcode': '745758690367580', - 'active': true, - 'type': 'patron', - 'patronGroup': 'ad0bc554-d5bc-463c-85d1-5562127ae91b', - 'departments': [], - 'proxyFor': [], - 'personal': { - 'lastName': 'Abbott', - 'firstName': 'Candace', - 'middleName': 'Fanny', - 'email': 'guy@lemke-llc.ok.us', - 'phone': '(136)082-4680 x8231', - 'mobilePhone': '(436)763-7413', - 'dateOfBirth': '1986-06-26T00:00:00.000+00:00', - 'addresses': [ - { - 'countryId': 'US', - 'addressLine1': '43069 Lobby', - 'city': 'Seal Beach', - 'region': 'NC', - 'postalCode': '35848-5877', - 'addressTypeId': '93d3d88d-499b-45d0-9bc7-ac73c3a19880', - 'primaryAddress': true - } - ], - 'preferredContactTypeId': '002' - }, - 'enrollmentDate': '2015-08-28T00:00:00.000+00:00', - 'expirationDate': '2026-01-01T23:59:59.000+00:00', - 'createdDate': '2024-01-10T07:32:22.263+00:00', - 'updatedDate': '2024-01-10T07:32:22.263+00:00', - 'metadata': { - 'createdDate': '2024-01-10T01:51:44.010+00:00', - 'updatedDate': '2024-01-10T07:32:22.260+00:00', - 'updatedByUserId': '43470c3d-1823-4b99-a24f-143728fc894a' - }, - 'tags': { - 'tagList': [] - }, - 'customFields': {} - } - ]; - const expectedUnAssignedUsers = [{ - 'username': 'devonte', - 'id': 'a208cf17-a7f0-452d-ae0e-64011232c86d', - 'barcode': '745758690367580', - 'active': true, - 'type': 'patron', - 'patronGroup': 'ad0bc554-d5bc-463c-85d1-5562127ae91b', - 'departments': [], - 'proxyFor': [], - 'personal': { - 'lastName': 'Abbott', - 'firstName': 'Candace', - 'middleName': 'Fanny', - 'email': 'guy@lemke-llc.ok.us', - 'phone': '(136)082-4680 x8231', - 'mobilePhone': '(436)763-7413', - 'dateOfBirth': '1986-06-26T00:00:00.000+00:00', - 'addresses': [ - { - 'countryId': 'US', - 'addressLine1': '43069 Lobby', - 'city': 'Seal Beach', - 'region': 'NC', - 'postalCode': '35848-5877', - 'addressTypeId': '93d3d88d-499b-45d0-9bc7-ac73c3a19880', - 'primaryAddress': true - } - ], - 'preferredContactTypeId': '002' - }, - 'enrollmentDate': '2015-08-28T00:00:00.000+00:00', - 'expirationDate': '2026-01-01T23:59:59.000+00:00', - 'createdDate': '2024-01-10T07:32:22.263+00:00', - 'updatedDate': '2024-01-10T07:32:22.263+00:00', - 'metadata': { - 'createdDate': '2024-01-10T01:51:44.010+00:00', - 'updatedDate': '2024-01-10T07:32:22.260+00:00', - 'updatedByUserId': '43470c3d-1823-4b99-a24f-143728fc894a' - }, - 'tags': { - 'tagList': [] - }, - 'customFields': {} - }]; - expect(getUsersBasedOnAssignmentStatus(activeFilterState, uasFilterValue, initialSelectedUsers, users)).toMatchObject(Object.values(expectedUnAssignedUsers)); - }); - }); - - describe('when Unassigned filter is selected along with filters from other filter groups', () => { - it('should filter assigned user based on the filters from other filter groups - status and patrongroup', () => { - const activeFilterState = { uas: ['Unassigned'], active: ['active'], pg: ['ad0bc554-d5bc-463c-85d1-5562127ae91b'] }; - const uasFilterValue = ['Unassigned']; - const initialSelectedUsers = { - '7daa365a-d8c1-4e5d-90ac-ab38f8230827': { - 'username': 'acq-admin', - 'id': '7daa365a-d8c1-4e5d-90ac-ab38f8230827', - 'barcode': '1704852123910366583', - 'active': true, - 'type': 'patron', - 'departments': [], - 'proxyFor': [], - 'createdDate': '2024-01-10T02:02:03.939+00:00', - 'updatedDate': '2024-01-10T02:02:03.939+00:00', - 'metadata': { - 'createdDate': '2024-01-10T02:02:03.936+00:00', - 'createdByUserId': '4074b75e-5c13-5dde-b78c-b07a420c6e3b', - 'updatedDate': '2024-01-10T02:02:03.936+00:00', - 'updatedByUserId': '4074b75e-5c13-5dde-b78c-b07a420c6e3b' - }, - 'personal': { - 'lastName': 'Admin', - 'firstName': 'acq-admin', - 'addresses': [] - }, - 'patronGroup': '3684a786-6671-4268-8ed0-9db82ebca60b', - 'fullName': 'Admin, acq-admin', - 'groupName': 'staff' - } - }; - const users = [ - { - 'username': 'acq-admin', - 'id': '7daa365a-d8c1-4e5d-90ac-ab38f8230827', - 'barcode': '1704852123910366583', - 'active': true, - 'type': 'patron', - 'departments': [], - 'proxyFor': [], - 'createdDate': '2024-01-10T02:02:03.939+00:00', - 'updatedDate': '2024-01-10T02:02:03.939+00:00', - 'metadata': { - 'createdDate': '2024-01-10T02:02:03.936+00:00', - 'createdByUserId': '4074b75e-5c13-5dde-b78c-b07a420c6e3b', - 'updatedDate': '2024-01-10T02:02:03.936+00:00', - 'updatedByUserId': '4074b75e-5c13-5dde-b78c-b07a420c6e3b' - }, - 'personal': { - 'lastName': 'Admin', - 'firstName': 'acq-admin', - 'addresses': [] - }, - 'patronGroup': '3684a786-6671-4268-8ed0-9db82ebca60b', - 'fullName': 'Admin, acq-admin', - 'groupName': 'staff' - }, - { - 'username': 'devonte', - 'id': 'a208cf17-a7f0-452d-ae0e-64011232c86d', - 'barcode': '745758690367580', - 'active': true, - 'type': 'patron', - 'patronGroup': 'ad0bc554-d5bc-463c-85d1-5562127ae91b', - 'departments': [], - 'proxyFor': [], - 'personal': { - 'lastName': 'Abbott', - 'firstName': 'Candace', - 'middleName': 'Fanny', - 'email': 'guy@lemke-llc.ok.us', - 'phone': '(136)082-4680 x8231', - 'mobilePhone': '(436)763-7413', - 'dateOfBirth': '1986-06-26T00:00:00.000+00:00', - 'addresses': [ - { - 'countryId': 'US', - 'addressLine1': '43069 Lobby', - 'city': 'Seal Beach', - 'region': 'NC', - 'postalCode': '35848-5877', - 'addressTypeId': '93d3d88d-499b-45d0-9bc7-ac73c3a19880', - 'primaryAddress': true - } - ], - 'preferredContactTypeId': '002' - }, - 'enrollmentDate': '2015-08-28T00:00:00.000+00:00', - 'expirationDate': '2026-01-01T23:59:59.000+00:00', - 'createdDate': '2024-01-10T07:32:22.263+00:00', - 'updatedDate': '2024-01-10T07:32:22.263+00:00', - 'metadata': { - 'createdDate': '2024-01-10T01:51:44.010+00:00', - 'updatedDate': '2024-01-10T07:32:22.260+00:00', - 'updatedByUserId': '43470c3d-1823-4b99-a24f-143728fc894a' - }, - 'tags': { - 'tagList': [] - }, - 'customFields': {} - } - ]; - const expectedUnAssignedUsers = [{ - 'username': 'devonte', - 'id': 'a208cf17-a7f0-452d-ae0e-64011232c86d', - 'barcode': '745758690367580', - 'active': true, - 'type': 'patron', - 'patronGroup': 'ad0bc554-d5bc-463c-85d1-5562127ae91b', - 'departments': [], - 'proxyFor': [], - 'personal': { - 'lastName': 'Abbott', - 'firstName': 'Candace', - 'middleName': 'Fanny', - 'email': 'guy@lemke-llc.ok.us', - 'phone': '(136)082-4680 x8231', - 'mobilePhone': '(436)763-7413', - 'dateOfBirth': '1986-06-26T00:00:00.000+00:00', - 'addresses': [ - { - 'countryId': 'US', - 'addressLine1': '43069 Lobby', - 'city': 'Seal Beach', - 'region': 'NC', - 'postalCode': '35848-5877', - 'addressTypeId': '93d3d88d-499b-45d0-9bc7-ac73c3a19880', - 'primaryAddress': true - } - ], - 'preferredContactTypeId': '002' - }, - 'enrollmentDate': '2015-08-28T00:00:00.000+00:00', - 'expirationDate': '2026-01-01T23:59:59.000+00:00', - 'createdDate': '2024-01-10T07:32:22.263+00:00', - 'updatedDate': '2024-01-10T07:32:22.263+00:00', - 'metadata': { - 'createdDate': '2024-01-10T01:51:44.010+00:00', - 'updatedDate': '2024-01-10T07:32:22.260+00:00', - 'updatedByUserId': '43470c3d-1823-4b99-a24f-143728fc894a' - }, - 'tags': { - 'tagList': [] - }, - 'customFields': {} - }]; - expect(getUsersBasedOnAssignmentStatus(activeFilterState, uasFilterValue, initialSelectedUsers, users)).toMatchObject(Object.values(expectedUnAssignedUsers)); - }); - }); -});