Skip to content

Commit

Permalink
UIREQ-1140 - remove copies and printed from query sorting case
Browse files Browse the repository at this point in the history
  • Loading branch information
manvendra-s-rathore committed Sep 18, 2024
2 parents 16d480a + bd0ec5e commit 0a1aa98
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/routes/RequestsRoute.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ import {
getFormattedYears,
getStatusQuery,
getFullNameForCsvRecords,
processQuerySortString,
} from './utils';
import SinglePrintButtonForPickSlip from '../components/SinglePrintButtonForPickSlip';

Expand Down Expand Up @@ -685,7 +686,7 @@ class RequestsRoute extends React.Component {
const { id: currentServicePointId } = this.getCurrentServicePointInfo();
const prevStateServicePointId = get(prevProps.resources.currentServicePoint, 'id');
const { configs: prevConfigs } = prevProps.resources;
const { configs } = this.props.resources;
const { configs, query } = this.props.resources;
const instanceId = parse(this.props.location?.search)?.instanceId;

if (prevExpired.length > 0 && expired.length === 0) {
Expand Down Expand Up @@ -730,6 +731,13 @@ class RequestsRoute extends React.Component {
if (isViewPrintDetailsEnabled !== prevState.isViewPrintDetailsEnabled && !isViewPrintDetailsEnabled) {
this.columnHeadersMap = getFilteredColumnHeadersMap(this.columnHeadersMap);
}

if (!isViewPrintDetailsEnabled && (query.sort?.includes('printed') || query.sort?.includes('copies'))) {
// Remove 'copies' and 'printed' from query sorting when the user disables
// 'Enable view print details (Pick slips)' in settings and returns to the Requests App.
const sort = processQuerySortString(query.sort);
this.props.mutator.query.update({ sort });
}
}

toggleAllRows = () => {
Expand Down
1 change: 1 addition & 0 deletions src/routes/RequestsRoute.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,7 @@ describe('RequestsRoute', () => {
},
query: {
filters: 'filter1.value1,filter1.value2,filter2.value3',
sort: 'printed, requestDate',
instanceId: 'instanceId',
query: 'testQueryTerm',
},
Expand Down
7 changes: 7 additions & 0 deletions src/routes/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,10 @@ export const getFullNameForCsvRecords = (record) => {
const { firstName = '', middleName = '', lastName = '' } = record;
return [firstName, middleName, lastName].filter(Boolean).join(' ');
};

export const processQuerySortString = (str) => {
const removeSubstrings = ['printed', 'copies', '-copies', '-printed'];
const remainingParts = str.split(',').filter(part => !removeSubstrings.includes(part));

return remainingParts.join(',') || '';
};
27 changes: 27 additions & 0 deletions src/routes/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
isReorderableRequest,
getStatusQuery,
getFullNameForCsvRecords,
processQuerySortString,
} from './utils';

describe('utils', () => {
Expand Down Expand Up @@ -185,4 +186,30 @@ describe('utils', () => {
expect(getFullNameForCsvRecords(record)).toBe('');
});
});

describe('processQuerySortString', () => {
it('should return the same string if no removable substrings are present', () => {
const input = 'title,requestDate';
const expectedOutput = 'title,requestDate';
expect(processQuerySortString(input)).toBe(expectedOutput);
});

it('should remove removable substrings and return non-removable substrings', () => {
const input = 'title,printed';
const expectedOutput = 'title';
expect(processQuerySortString(input)).toBe(expectedOutput);
});

it('should return an empty string when the input is empty', () => {
const input = '';
const expectedOutput = '';
expect(processQuerySortString(input)).toBe(expectedOutput);
});

it('should return an empty string when only removable substrings are present', () => {
const input = 'printed,copies';
const expectedOutput = '';
expect(processQuerySortString(input)).toBe(expectedOutput);
});
});
});

0 comments on commit 0a1aa98

Please sign in to comment.