-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
UIPFU-77 - Add 'User assignment status' filter group
- Loading branch information
1 parent
1e3f510
commit 0024421
Showing
14 changed files
with
836 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,27 @@ | ||
{ | ||
"parser": "@babel/eslint-parser", | ||
"extends": "@folio/eslint-config-stripes" | ||
"extends": "@folio/eslint-config-stripes", | ||
"overrides": [ | ||
{ | ||
"files": [ "src/**/tests/*", "*.test.js", "test/**/*" ], | ||
"rules": { | ||
"react/prop-types": "off", | ||
"import/prefer-default-export": "off" | ||
} | ||
} | ||
], | ||
"env": { | ||
"jest": true | ||
}, | ||
"settings": { | ||
"import/resolver": { | ||
"alias": { | ||
"map": [ | ||
["__mock__", "./test/jest/__mock__"], | ||
["fixtures", "./test/jest/fixtures"], | ||
["helpers", "./test/jest/helpers"] | ||
] | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
node_modules | ||
artifacts | ||
artifacts | ||
junit.xml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
const path = require('path'); | ||
const config = require('@folio/jest-config-stripes'); | ||
|
||
module.exports = { | ||
...config, | ||
setupFiles: [ | ||
...config.setupFiles, | ||
path.join(__dirname, './test/jest/setupFiles.js'), | ||
], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/* eslint-disable import/prefer-default-export */ | ||
export const UAS = 'uas'; | ||
export const ASSIGNED_FILTER_KEY = 'uas.Assigned'; | ||
export const UNASSIGNED_FILTER_KEY = 'uas.Unassigned'; | ||
export const ASSIGNED = 'Assigned'; | ||
export const UNASSIGNED = 'Unassigned'; | ||
export const ACTIVE = 'active'; | ||
export const INACTIVE = 'inactive'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import cloneDeep from 'lodash/cloneDeep'; | ||
import { | ||
ASSIGNED_FILTER_KEY, | ||
UNASSIGNED_FILTER_KEY, | ||
ASSIGNED, | ||
UNASSIGNED, | ||
UAS, | ||
ACTIVE, | ||
INACTIVE | ||
} from './constants'; | ||
|
||
// eslint-disable-next-line import/prefer-default-export | ||
export const updateResourceData = (rData) => { | ||
const filterString = rData?.query?.filters; | ||
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, | ||
* 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. | ||
*/ | ||
const alteredfilters = 'active.active,active.inactive'; | ||
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. | ||
*/ | ||
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, | ||
* cql formation is not needed. | ||
* hence remove aus filter before propagating it further to makeQueryFunction | ||
*/ | ||
const alteredfilters = ''; | ||
newRData.query.filters = alteredfilters; | ||
} | ||
return newRData; | ||
}; | ||
|
||
// 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 | ||
|
||
// 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 "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; | ||
} | ||
}; |
Oops, something went wrong.