Skip to content
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

UIREQ-1140 - Add Sorting to 'Copies' and 'Printed' columns in Requests table #1204

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* Add missing sub-permissions to fetch "pick-slips" and "search-slips" records in "Requests: View, edit, cancel" permission. Refs UIREQ-1137.
* Optimize performance of the "print-events-entry" API to reduce slowness during the initial call. Refs UIREQ-1130.
* Revert Custom "Print Status" filter code implementation. Refs UIREQ-1146.
* Sorting 'Printed' and '# Copies' columns in the Request App. Refs UIREQ-1140.

## [9.1.2] (https://github.com/folio-org/ui-requests/tree/v9.1.2) (2024-09-13)
[Full Changelog](https://github.com/folio-org/ui-requests/compare/v9.1.1...v9.1.2)
Expand Down
2 changes: 1 addition & 1 deletion src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ export const requestableItemStatuses = [
];

export const PRINT_DETAILS_COLUMNS = {
COPIES: 'printDetails.count',
COPIES: 'printDetails.printCount',
PRINTED: 'printDetails.lastPrintedDetails',
};

Expand Down
22 changes: 16 additions & 6 deletions 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 @@ -127,8 +128,8 @@ export const extractPickSlipRequestIds = (pickSlipsData) => {

export const getLastPrintedDetails = (printDetails, intl) => {
const fullName = getFullName(printDetails?.lastPrintRequester);
const formattedDate = intl.formatDate(printDetails?.lastPrintedDate);
const formattedTime = intl.formatTime(printDetails?.lastPrintedDate);
const formattedDate = intl.formatDate(printDetails?.printEventDate);
const formattedTime = intl.formatTime(printDetails?.printEventDate);
const localizedDateTime = `${formattedDate}${formattedTime ? ', ' : ''}${formattedTime}`;

return fullName + ' ' + localizedDateTime;
Expand Down Expand Up @@ -269,7 +270,7 @@ export const getListFormatter = (
'year': rq => getFormattedYears(rq.instance?.publication, DEFAULT_DISPLAYED_YEARS_AMOUNT),
'callNumber': rq => effectiveCallNumber(rq.item),
'servicePoint': rq => get(rq, 'pickupServicePoint.name', DEFAULT_FORMATTER_VALUE),
'copies': rq => get(rq, PRINT_DETAILS_COLUMNS.COPIES, DEFAULT_FORMATTER_VALUE),
'copies': rq => get(rq, 'printDetails.printCount', DEFAULT_FORMATTER_VALUE),
'printed': rq => (rq.printDetails ? getLastPrintedDetails(rq.printDetails, intl) : DEFAULT_FORMATTER_VALUE),
});

Expand Down Expand Up @@ -333,6 +334,8 @@ class RequestsRoute extends React.Component {
'requestDate': 'requestDate',
'position': 'position/number',
'proxy': 'proxy',
'copies': 'printDetails.printCount/number',
'printed': 'printDetails.printEventDate',
},
RequestsFiltersConfig,
2, // do not fetch unless we have a query or a filter
Expand Down Expand Up @@ -683,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 @@ -728,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 Expand Up @@ -887,7 +897,7 @@ class RequestsRoute extends React.Component {
}
if (record.printDetails) {
const fullName = getFullNameForCsvRecords(record.printDetails.lastPrintRequester);
const lastPrintedDate = record.printDetails.lastPrintedDate || '';
const lastPrintedDate = record.printDetails.printEventDate || '';
const date = lastPrintedDate ? `, ${lastPrintedDate}` : '';

record.printDetails.lastPrintedDetails = `${fullName}${date}`;
Expand Down Expand Up @@ -1640,7 +1650,7 @@ class RequestsRoute extends React.Component {
resultIsSelected={this.resultIsSelected}
onFilterChange={this.handleFilterChange}
sortableColumns={['requestDate', 'title', 'year', 'itemBarcode', 'callNumber', 'type', 'requestStatus',
'position', 'servicePoint', 'requester', 'requesterBarcode', 'proxy']}
'position', 'servicePoint', 'requester', 'requesterBarcode', 'proxy', 'copies', 'printed']}
pageAmount={100}
pagingType={MCLPagingTypes.PREV_NEXT}
/>
Expand Down
15 changes: 8 additions & 7 deletions src/routes/RequestsRoute.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,8 @@ const mockedRequest = {
id: 'requestId',
};
const printDetailsMockData = {
count: 11,
lastPrintedDate: '2024-08-03T13:33:31.868Z',
printCount: 11,
printEventDate: '2024-08-03T13:33:31.868Z',
lastPrintRequester: { firstName: 'firstName', middleName: 'middleName', lastName: 'lastName' },
};

Expand Down 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 Expand Up @@ -1301,16 +1302,16 @@ describe('RequestsRoute', () => {

describe('when formatting copies column', () => {
it('should return copies for copies column', () => {
expect(listFormatter.copies(requestWithData)).toBe(requestWithData.printDetails.count);
expect(listFormatter.copies(requestWithData)).toBe(requestWithData.printDetails.printCount);
});
});

describe('when formatting printed column', () => {
it('should return last printed details for printed column', () => {
getFullName.mockReturnValueOnce('lastName, firstName middleName');

const expectedFormattedDate = intl.formatDate(requestWithData.printDetails.lastPrintedDate);
const expectedFormattedTime = intl.formatTime(requestWithData.printDetails.lastPrintedDate);
const expectedFormattedDate = intl.formatDate(requestWithData.printDetails.printEventDate);
const expectedFormattedTime = intl.formatTime(requestWithData.printDetails.printEventDate);
const expectedOutput =
`lastName, firstName middleName ${expectedFormattedDate}${expectedFormattedTime ? ', ' : ''}${expectedFormattedTime}`;

Expand Down Expand Up @@ -1362,8 +1363,8 @@ describe('RequestsRoute', () => {

it('should return the formatted full name and date/time correctly', () => {
const printedDetails = getLastPrintedDetails(lastPrintDetails, intl);
const expectedFormattedDate = intl.formatDate(lastPrintDetails.lastPrintedDate);
const expectedFormattedTime = intl.formatTime(lastPrintDetails.lastPrintedDate);
const expectedFormattedDate = intl.formatDate(lastPrintDetails.printEventDate);
const expectedFormattedTime = intl.formatTime(lastPrintDetails.printEventDate);
const expectedOutput =
`lastName, firstName middleName ${expectedFormattedDate}${expectedFormattedTime ? ', ' : ''}${expectedFormattedTime}`;

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);
});
});
});
2 changes: 1 addition & 1 deletion translations/ui-requests/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@
"pickupServicePoint.name": "Pickup service point",
"requester.patronGroup.group": "Requester patron group",
"tags.tagList": "Tags",
"printDetails.count": "# Copies",
"printDetails.printCount": "# Copies",
"printDetails.lastPrintedDetails": "Printed",

"notes.staffNotes": "Staff notes",
Expand Down
Loading