-
Notifications
You must be signed in to change notification settings - Fork 3
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
UIPFU-77 - Add 'User assignment status' filter group #249
Conversation
src/UserSearchContainer.js
Outdated
@@ -32,6 +34,28 @@ const compileQuery = template( | |||
{ interpolate: /%{([\s\S]+?)}/g } | |||
); | |||
|
|||
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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure about the usage of substring
here. Is this method from String? If so, then it only accepts startIndex
and endIndex
src/utils.js
Outdated
* 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(','); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Won't startsWith(`${UAS}`)
remove uas.Assigned
too? In case when there are filters selected from other groups and both Assigned and Unassigned are checked?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
uas.Assigned should be removed in any case, as it will never participate in cql formation. So here the logic is appropriate. I see a need to update the comment above this code of line. Thank you.
src/utils.js
Outdated
/* | ||
* 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably needs to be uas
instead of aus
src/utils.js
Outdated
} 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few typos here
src/utils.js
Outdated
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, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand this case. If there 100 assigned users, and we need to see only staff members for example - can we not do this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For any combination (from other filter groups) with "Assigned" filter, there is no need to fetch the users once again(as the users list is already available through initialSelectedUsers
prop) and hence we don't need any filters to participate in cql formation.
getUsersBasedOnAssignmentStatus
does the needful.
src/utils.js
Outdated
}; | ||
|
||
const filterUsersList = (filterString, initialSelectedUsers, users, filterCheck) => { | ||
let usersList; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's make it an empty array by default to prevent any exceptions
src/utils.js
Outdated
let usersList; | ||
if (filterString === `${ASSIGNED}`) { | ||
const assignedUsers = Object.values(initialSelectedUsers); | ||
if (filterCheck) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can give filterCheck
argument a default value () => true
to remove this if else
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
src/utils.js
Outdated
} else if (filterString === `${UNASSIGNED}`) { | ||
// when ONLY "Unassigned" filter is selected | ||
const assignedUserIds = Object.keys(initialSelectedUsers); | ||
if (filterCheck) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here regarding filterCheck
src/utils.js
Outdated
return usersList; | ||
}; | ||
|
||
// eslint-disable-next-line consistent-return |
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
src/utils.test.js
Outdated
const activeFilterState = { uas: ['Assigned'] }; | ||
const uasFilterValue = ['Assigned']; | ||
const initialSelectedUsers = { | ||
'7daa365a-d8c1-4e5d-90ac-ab38f8230827': { |
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
src/utils.js
Outdated
|
||
// 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); |
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
src/UserSearchContainer.js
Outdated
} | ||
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]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need check other filter values because this result list is alredy returned from back-end for a search with these filters. We just need to select from fetched users assigned or not assigned based on uas filter value
if (activeFilters.includes(`${UAS}`)) {
const assignedUserIds = Object.keys(initialSelectedUsers);
const uasFilterValues = activeFilters.split(',').filter(f => f.find(`${UAS}`));
// both or neither Assignment status values are selected, so we can return result from BE
if (uasFilterValues.length === 2 || uasFilterValues.length === 0) {
return fetchedUsers;
}
if (uasFilterValues.includes(ASSIGNED_FILTER_KEY)) {
return fetchedUsers.filter(user => assignedUserIds.includes(user.id));
} else {
return fetchedUsers.filter(user => !assignedUserIds.includes(user.id));
}
}
return fetchedUsers;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you again for your review!
I agree that it is not needed for Unassigned filter as we are propagating the filters to make cql. But I think it is needed in case of Assigned filter as we are not propagating the filter string to make the cql(as we don't actually need to fetch)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you cover new functionality in UserSearchContainer.js file by jest/RTL tests?
src/UserSearchContainer.js
Outdated
@@ -32,6 +39,28 @@ const compileQuery = template( | |||
{ interpolate: /%{([\s\S]+?)}/g } | |||
); | |||
|
|||
export function buildQuery(queryParams, pathComponents, resourceData, logger, props) { | |||
const filters = props.initialSelectedUsers ? filterConfigWithUserAssignedStatus : filterConfig; | |||
const updatedResourceData = props.initialSelectedUsers && resourceData?.query?.filters?.includes(`${UAS}`) ? updateResourceData(resourceData) : resourceData; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const updatedResourceData = props.initialSelectedUsers && resourceData?.query?.filters?.includes(`${UAS}`) ? updateResourceData(resourceData) : resourceData; | |
const updatedResourceData = props.initialSelectedUsers && resourceData?.query?.filters?.includes(UAS) ? updateResourceData(resourceData) : resourceData; |
src/UserSearchContainer.js
Outdated
const activeFilters = get(resources, 'query.filters', ''); | ||
const assignedUsers = Object.values(initialSelectedUsers); | ||
|
||
if (activeFilters === `${ASSIGNED_FILTER_KEY}`) return assignedUsers; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (activeFilters === `${ASSIGNED_FILTER_KEY}`) return assignedUsers; | |
if (activeFilters === ASSIGNED_FILTER_KEY) return assignedUsers; |
src/UserSearchContainer.js
Outdated
|
||
if (activeFilters === `${ASSIGNED_FILTER_KEY}`) return assignedUsers; | ||
|
||
if (activeFilters.includes(`${UAS}`)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (activeFilters.includes(`${UAS}`)) { | |
if (activeFilters.includes(UAS)) { |
src/UserSearchContainer.js
Outdated
|
||
if (activeFilters.includes(`${UAS}`)) { | ||
const assignedUserIds = Object.keys(initialSelectedUsers); | ||
const hasBothUASFilters = activeFilters.includes(`${ASSIGNED_FILTER_KEY}`) && activeFilters.includes(`${UNASSIGNED_FILTER_KEY}`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const hasBothUASFilters = activeFilters.includes(`${ASSIGNED_FILTER_KEY}`) && activeFilters.includes(`${UNASSIGNED_FILTER_KEY}`); | |
const hasBothUASFilters = activeFilters.includes(ASSIGNED_FILTER_KEY) && activeFilters.includes(UNASSIGNED_FILTER_KEY); |
src/UserSearchContainer.js
Outdated
const hasNoneOfUASFilters = !activeFilters.includes(`${ASSIGNED_FILTER_KEY}`) && !activeFilters.includes(`${UNASSIGNED_FILTER_KEY}`); | ||
const uasFilterValue = activeFilters.split(',').filter(f => f.includes(`${UAS}`))[0].split('.')[1]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const hasNoneOfUASFilters = !activeFilters.includes(`${ASSIGNED_FILTER_KEY}`) && !activeFilters.includes(`${UNASSIGNED_FILTER_KEY}`); | |
const uasFilterValue = activeFilters.split(',').filter(f => f.includes(`${UAS}`))[0].split('.')[1]; | |
const hasNoneOfUASFilters = !activeFilters.includes(ASSIGNED_FILTER_KEY) && !activeFilters.includes(UNASSIGNED_FILTER_KEY); | |
const uasFilterValue = activeFilters.split(',').filter(f => f.includes(UAS))[0].split('.')[1]; |
src/UserSearchContainer.js
Outdated
return fetchedUsers; | ||
} | ||
|
||
if (uasFilterValue === `${ASSIGNED}`) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (uasFilterValue === `${ASSIGNED}`) { | |
if (uasFilterValue === ASSIGNED) { |
@@ -168,6 +181,35 @@ class UserSearchContainer extends React.Component { | |||
return get(this.props.resources, 'query', {}); | |||
} | |||
|
|||
getUsers = () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest to move this function outside the component. I will much easier to test all if...else
conditions.
But it is up to you.
src/utils.js
Outdated
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}`) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (filterString === `${UNASSIGNED_FILTER_KEY}` || filterString === `${ASSIGNED_FILTER_KEY},${UNASSIGNED_FILTER_KEY}` || filterString === `${UNASSIGNED_FILTER_KEY},${ASSIGNED_FILTER_KEY}`) { | |
if (filterString === UNASSIGNED_FILTER_KEY || filterString === `${ASSIGNED_FILTER_KEY},${UNASSIGNED_FILTER_KEY}` || filterString === `${UNASSIGNED_FILTER_KEY},${ASSIGNED_FILTER_KEY}`) { |
src/utils.js
Outdated
const alteredfilters = 'active.active,active.inactive'; | ||
newRData.query.filters = alteredfilters; | ||
} else { | ||
const alteredfilters = newRData.query.filters.split(',').filter(str => !str.startsWith(`${UAS}`)).join(','); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const alteredfilters = newRData.query.filters.split(',').filter(str => !str.startsWith(`${UAS}`)).join(','); | |
const alteredfilters = newRData.query.filters.split(',').filter(str => !str.startsWith(UAS)).join(','); |
src/utils.test.js
Outdated
|
||
describe('updatedResourceData', () => { | ||
describe('when only UnAssigned filter is selected', () => { | ||
[`${UNASSIGNED_FILTER_KEY}`, `${ASSIGNED_FILTER_KEY},${UNASSIGNED_FILTER_KEY}`, `${UNASSIGNED_FILTER_KEY},${ASSIGNED_FILTER_KEY}`].forEach(filterStr => ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[`${UNASSIGNED_FILTER_KEY}`, `${ASSIGNED_FILTER_KEY},${UNASSIGNED_FILTER_KEY}`, `${UNASSIGNED_FILTER_KEY},${ASSIGNED_FILTER_KEY}`].forEach(filterStr => ( | |
[UNASSIGNED_FILTER_KEY, `${ASSIGNED_FILTER_KEY},${UNASSIGNED_FILTER_KEY}`, `${UNASSIGNED_FILTER_KEY},${ASSIGNED_FILTER_KEY}`].forEach(filterStr => ( |
Hey @artem-blazhko |
Co-authored-by: Artem Blazhko <[email protected]>
Quality Gate failedFailed conditions 0.0% Coverage on New Code (required ≥ 80%) |
Purpose
UIPFU-77 - Add "User assignment status" filter in find-user-plugin
Approach
The requirement is to create a new filter group in this plugin.
How is it different?
The new filters do not participate in cql formation.
The cql that could be formed by this filter group could not be supported by BE API for various other challenges and design reasons. Hence an alternative mechanism is chosen to populate the users based on "Assigned" and "Unassinged" filters.
Unit tests
We will gradually migrate unit tests in this module to Jest/RTL .
For the new files, Jest minimal setup has been introduced and unit tests have been written.
Screencast
DFcQyHnddK.mp4
Pre-Merge Checklist
Before merging this PR, please go through the following list and take appropriate actions.
If there are breaking changes, please STOP and consider the following:
Ideally all of the PRs involved in breaking changes would be merged in the same day to avoid breaking the folio-testing environment. Communication is paramount if that is to be achieved, especially as the number of intermodule and inter-team dependencies increase.
While it's helpful for reviewers to help identify potential problems, ensuring that it's safe to merge is ultimately the responsibility of the PR assignee.