Skip to content

Commit

Permalink
UIPFU-77 - fix review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Terala-Priyanka committed Jan 11, 2024
1 parent a016d97 commit a3adb92
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 39 deletions.
26 changes: 8 additions & 18 deletions src/UserSearchContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
ASSIGNED_FILTER_KEY,
UNASSIGNED_FILTER_KEY,
UAS,
ASSIGNED,
} from './constants';

const INITIAL_RESULT_COUNT = 30;
Expand Down Expand Up @@ -187,35 +188,24 @@ class UserSearchContainer extends React.Component {
} = this.props;
const fetchedUsers = get(resources, 'records.records', []);
const activeFilters = get(resources, 'query.filters', '');
const assignedUsers = Object.values(initialSelectedUsers);

if (activeFilters === `${ASSIGNED_FILTER_KEY}`) return assignedUsers;

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}`);
const uasFilterValue = activeFilters.split(',').filter(f => f.includes(`${UAS}`))[0].split('.')[1];

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]));
if (uasFilterValue === `${ASSIGNED}`) {
return fetchedUsers.filter(u => assignedUserIds.includes(u.id));
}
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.filter(u => !assignedUserIds.includes(u.id));
}
return fetchedUsers;
}
Expand Down
3 changes: 1 addition & 2 deletions src/UserSearchView.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ class UserSearchView extends React.Component {
const builtVisibleColumns = isMultiSelect ? ['isChecked', ...visibleColumns] : visibleColumns;

const query = queryGetter ? queryGetter() || {} : {};
const count = source ? source.totalCount() : 0;
const count = users?.length;
const sortOrder = query.sort || '';
const resultsStatusMessage = source ? (
<div data-test-find-user-no-results-message>
Expand Down Expand Up @@ -362,7 +362,6 @@ class UserSearchView extends React.Component {
<MultiColumnList
visibleColumns={builtVisibleColumns}
isSelected={this.isSelected}
// contentData={getContentData()}
contentData={users}
totalCount={count}
id="list-plugin-find-user"
Expand Down
5 changes: 1 addition & 4 deletions src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,4 @@
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';
export const ASSIGNED = 'Assigned';
14 changes: 1 addition & 13 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,9 @@ export const updateResourceData = (rData) => {
*/
const alteredfilters = 'active.active,active.inactive';
newRData.query.filters = alteredfilters;
} else if (filterString.includes(`${UNASSIGNED_FILTER_KEY}`)) {
/*
* 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.
*/
} else {
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 assignment Status' filter group, in any combination of filters in other filter groups,
* cql formation is not needed.
* hence remove uas filter before propagating it further to makeQueryFunction
*/
const alteredfilters = '';
newRData.query.filters = alteredfilters;
}
return newRData;
};
4 changes: 2 additions & 2 deletions src/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ describe('updatedResourceData', () => {
});

describe('when Assigned filter is selected with or without combination of filters from other filter groups', () => {
it('should remove filter string', () => {
it('should remove assigned filter string', () => {
const resourceData = {
query: {
filters: `${ASSIGNED_FILTER_KEY},active.active`,
Expand All @@ -48,7 +48,7 @@ describe('updatedResourceData', () => {
const expectedResourceData = {
query: {
...resourceData.query,
filters: '',
filters: 'active.active',
},
};
expect(updateResourceData(resourceData)).toMatchObject(expectedResourceData);
Expand Down

0 comments on commit a3adb92

Please sign in to comment.