From 16e11ee25a102aaefc1b64df02e904ec4e854538 Mon Sep 17 00:00:00 2001 From: Priyanka Date: Fri, 12 Jan 2024 18:07:16 +0530 Subject: [PATCH] UIPFU-fix review comments --- src/UserSearchContainer.js | 14 +++++++------- src/utils.js | 4 ++-- src/utils.test.js | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/UserSearchContainer.js b/src/UserSearchContainer.js index fc0c450..2a799b3 100644 --- a/src/UserSearchContainer.js +++ b/src/UserSearchContainer.js @@ -41,7 +41,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?.includes(`${UAS}`) ? updateResourceData(resourceData) : resourceData; + const updatedResourceData = props.initialSelectedUsers && resourceData?.query?.filters?.includes(UAS) ? updateResourceData(resourceData) : resourceData; return makeQueryFunction( 'cql.allRecords=1', @@ -190,19 +190,19 @@ class UserSearchContainer extends React.Component { const activeFilters = get(resources, 'query.filters', ''); const assignedUsers = Object.values(initialSelectedUsers); - if (activeFilters === `${ASSIGNED_FILTER_KEY}`) return assignedUsers; + if (activeFilters === ASSIGNED_FILTER_KEY) return assignedUsers; - if (activeFilters.includes(`${UAS}`)) { + if (activeFilters.includes(UAS)) { 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}`); - const uasFilterValue = activeFilters.split(',').filter(f => f.includes(`${UAS}`))[0].split('.')[1]; + const hasBothUASFilters = activeFilters.includes(`${ASSIGNED_FILTER_KEY}`) && activeFilters.includes(UNASSIGNED_FILTER_KEY); + const hasNoneOfUASFilters = !activeFilters.includes(ASSIGNED_FILTER_KEY) && !activeFilters.includes(UNASSIGNED_FILTER_KEY); + const uasFilterValue = activeFilters.split(',').filter(f => f.includes(UAS))[0].split('.')[1]; if (hasBothUASFilters || hasNoneOfUASFilters) { return fetchedUsers; } - if (uasFilterValue === `${ASSIGNED}`) { + if (uasFilterValue === ASSIGNED) { return fetchedUsers.filter(u => assignedUserIds.includes(u.id)); } return fetchedUsers.filter(u => !assignedUserIds.includes(u.id)); diff --git a/src/utils.js b/src/utils.js index be258b3..6ebe5f2 100644 --- a/src/utils.js +++ b/src/utils.js @@ -9,7 +9,7 @@ import { 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}`) { + 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 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) @@ -19,7 +19,7 @@ export const updateResourceData = (rData) => { const alteredfilters = 'active.active,active.inactive'; newRData.query.filters = alteredfilters; } else { - const alteredfilters = newRData.query.filters.split(',').filter(str => !str.startsWith(`${UAS}`)).join(','); + const alteredfilters = newRData.query.filters.split(',').filter(str => !str.startsWith(UAS)).join(','); newRData.query.filters = alteredfilters; } return newRData; diff --git a/src/utils.test.js b/src/utils.test.js index 722a5d8..41d4574 100644 --- a/src/utils.test.js +++ b/src/utils.test.js @@ -3,7 +3,7 @@ import { UNASSIGNED_FILTER_KEY, ASSIGNED_FILTER_KEY } from './constants'; 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 => ( + [UNASSIGNED_FILTER_KEY, `${ASSIGNED_FILTER_KEY},${UNASSIGNED_FILTER_KEY}`, `${UNASSIGNED_FILTER_KEY},${ASSIGNED_FILTER_KEY}`].forEach(filterStr => ( it(`should remove ${filterStr} from filter string and add active and inactive filter strings`, () => { const resourceData = { query: {