@@ -33,8 +38,13 @@ const PrintContent = forwardRef(({ dataSource, template }, ref) => {
});
PrintContent.propTypes = {
+ id: PropTypes.string,
dataSource: PropTypes.arrayOf(PropTypes.object).isRequired,
template: PropTypes.string.isRequired,
};
+PrintContent.defaultProps = {
+ id: 'printContent',
+};
+
export default memo(PrintContent, isEqual);
diff --git a/src/components/PrintContent/PrintContent.test.js b/src/components/PrintContent/PrintContent.test.js
index d9a87577..0501a511 100644
--- a/src/components/PrintContent/PrintContent.test.js
+++ b/src/components/PrintContent/PrintContent.test.js
@@ -28,6 +28,7 @@ describe('PrintContent', () => {
},
}
],
+ id: testIds.printContent,
};
afterEach(() => {
diff --git a/src/constants.js b/src/constants.js
index a70da29c..a2fd4ddc 100644
--- a/src/constants.js
+++ b/src/constants.js
@@ -250,7 +250,10 @@ export const requestLevelFilters = [
{ label: 'ui-requests.filters.requestLevel.title', value: REQUEST_LEVEL_TYPES.TITLE },
];
-export const pickSlipType = 'pick slip';
+export const SLIPS_TYPE = {
+ PICK_SLIP: 'Pick slip',
+ SEARCH_SLIP_HOLD_REQUESTS: 'Search slip (Hold requests)',
+};
export const DOMAIN_NAME = 'requests';
diff --git a/src/routes/RequestsRoute.js b/src/routes/RequestsRoute.js
index 3c7b7087..73e96b1f 100644
--- a/src/routes/RequestsRoute.js
+++ b/src/routes/RequestsRoute.js
@@ -48,7 +48,7 @@ import {
reportHeaders,
fulfillmentTypes,
expiredHoldsReportHeaders,
- pickSlipType,
+ SLIPS_TYPE,
createModes,
requestStatusesTranslations,
requestTypesTranslations,
@@ -93,6 +93,15 @@ const INITIAL_RESULT_COUNT = 30;
const RESULT_COUNT_INCREMENT = 30;
export const DEFAULT_FORMATTER_VALUE = '';
+export const getPrintHoldRequestsEnabled = (printHoldRequests) => {
+ const value = printHoldRequests.records[0]?.value;
+ const {
+ printHoldRequestsEnabled = false,
+ } = value ? JSON.parse(value) : {};
+
+ return printHoldRequestsEnabled;
+};
+
export const urls = {
user: (value, idType) => {
const query = stringify({ query: `(${idType}=="${value}")` });
@@ -392,9 +401,22 @@ class RequestsRoute extends React.Component {
type: 'okapi',
records: 'pickSlips',
path: 'circulation/pick-slips/%{currentServicePoint.id}',
- fetch: true,
throwErrors: false,
},
+ searchSlips: {
+ type: 'okapi',
+ records: 'searchSlips',
+ path: 'circulation/search-slips/%{currentServicePoint.id}',
+ throwErrors: false,
+ },
+ printHoldRequests: {
+ type: 'okapi',
+ records: 'configs',
+ path: 'configurations/entries',
+ params: {
+ query: '(module==SETTINGS and configName==PRINT_HOLD_REQUESTS)',
+ },
+ },
currentServicePoint: {},
tags: {
throwErrors: false,
@@ -456,6 +478,9 @@ class RequestsRoute extends React.Component {
pickSlips: PropTypes.shape({
GET: PropTypes.func,
}).isRequired,
+ searchSlips: PropTypes.shape({
+ GET: PropTypes.func,
+ }).isRequired,
currentServicePoint: PropTypes.shape({
update: PropTypes.func.isRequired,
}).isRequired,
@@ -486,10 +511,17 @@ class RequestsRoute extends React.Component {
records: PropTypes.arrayOf(PropTypes.object).isRequired,
isPending: PropTypes.bool,
}),
+ searchSlips: PropTypes.shape({
+ records: PropTypes.arrayOf(PropTypes.object).isRequired,
+ isPending: PropTypes.bool,
+ }),
configs: PropTypes.shape({
hasLoaded: PropTypes.bool.isRequired,
records: PropTypes.arrayOf(PropTypes.object).isRequired,
}),
+ printHoldRequests: PropTypes.shape({
+ records: PropTypes.arrayOf(PropTypes.object).isRequired,
+ }),
}).isRequired,
stripes: PropTypes.shape({
connect: PropTypes.func.isRequired,
@@ -571,7 +603,8 @@ class RequestsRoute extends React.Component {
createTitleLevelRequestsByDefault,
};
- this.printContentRef = React.createRef();
+ this.pickSlipsPrintContentRef = React.createRef();
+ this.searchSlipsPrintContentRef = React.createRef();
this.paneTitleRef = React.createRef();
}
@@ -1037,10 +1070,12 @@ class RequestsRoute extends React.Component {
this.setState({ errorModalData: {} });
};
- getPrintTemplate() {
+ getPrintTemplate(slipType) {
const staffSlips = get(this.props.resources, 'staffSlips.records', []);
- const pickSlip = staffSlips.find(slip => slip.name.toLowerCase() === pickSlipType);
- return get(pickSlip, 'template', '');
+ const slipTypeInLowerCase = slipType.toLowerCase();
+ const slipTemplate = staffSlips.find(slip => slip.name.toLowerCase() === slipTypeInLowerCase);
+
+ return get(slipTemplate, 'template', '');
}
handleFilterChange = ({ name, values }) => {
@@ -1097,6 +1132,16 @@ class RequestsRoute extends React.Component {
);
};
+ onBeforeGetContentForPrintButton = (onToggle) => (
+ new Promise(resolve => {
+ this.context.sendCallout({ message:
});
+ onToggle();
+ // without the timeout the printing process starts right away
+ // and the callout and onToggle above are blocked
+ setTimeout(() => resolve(), 1000);
+ })
+ );
+
render() {
const {
resources,
@@ -1121,8 +1166,10 @@ class RequestsRoute extends React.Component {
holdsShelfReportPending,
createTitleLevelRequestsByDefault,
} = this.state;
+ const isPrintHoldRequestsEnabled = getPrintHoldRequestsEnabled(resources.printHoldRequests);
const { name: servicePointName } = this.getCurrentServicePointInfo();
const pickSlips = get(resources, 'pickSlips.records', []);
+ const searchSlips = get(resources, 'searchSlips.records', []);
const patronGroups = get(resources, 'patronGroups.records', []);
const addressTypes = get(resources, 'addressTypes.records', []);
const servicePoints = get(resources, 'servicePoints.records', []);
@@ -1135,11 +1182,15 @@ class RequestsRoute extends React.Component {
createTitleLevelRequest: createTitleLevelRequestsByDefault,
};
- const pickSlipsArePending = resources?.pickSlips?.isPending;
+ const isPickSlipsArePending = resources?.pickSlips?.isPending;
+ const isSearchSlipsArePending = resources?.searchSlips?.isPending;
const requestsEmpty = isEmpty(requests);
- const pickSlipsEmpty = isEmpty(pickSlips);
- const printTemplate = this.getPrintTemplate();
- const pickSlipsData = convertToSlipData(pickSlips, intl, timezone, locale);
+ const isPickSlipsEmpty = isEmpty(pickSlips);
+ const isSearchSlipsEmpty = isEmpty(searchSlips);
+ const pickSlipsPrintTemplate = this.getPrintTemplate(SLIPS_TYPE.PICK_SLIP);
+ const searchSlipsPrintTemplate = this.getPrintTemplate(SLIPS_TYPE.SEARCH_SLIP_HOLD_REQUESTS);
+ const pickSlipsData = convertToSlipData(pickSlips, intl, timezone, locale, SLIPS_TYPE.PICK_SLIP);
+ const searchSlipsData = convertToSlipData(searchSlips, intl, timezone, locale, SLIPS_TYPE.SEARCH_SLIP_HOLD_REQUESTS);
const resultsFormatter = getListFormatter(this.getRowURL, this.setURL);
const actionMenu = ({ onToggle, renderColumnsMenu }) => (
@@ -1173,7 +1224,7 @@ class RequestsRoute extends React.Component {
}
{
- pickSlipsArePending ?
+ isPickSlipsArePending ?
:
@@ -1196,18 +1247,10 @@ class RequestsRoute extends React.Component {
new Promise(resolve => {
- this.context.sendCallout({ message: });
- onToggle();
- // without the timeout the printing process starts right away
- // and the callout and onToggle above are blocked
- setTimeout(() => resolve(), 1000);
- })
- }
+ disabled={isPickSlipsEmpty}
+ template={pickSlipsPrintTemplate}
+ contentRef={this.pickSlipsPrintContentRef}
+ onBeforeGetContent={() => this.onBeforeGetContentForPrintButton(onToggle)}
>
>
}
+ {
+ isPrintHoldRequestsEnabled &&
+ <>
+ {
+ isSearchSlipsArePending ?
+
+
+ :
+ this.onBeforeGetContentForPrintButton(onToggle)}
+ >
+
+
+ }
+ >
+ }
{renderColumnsMenu}
>
@@ -1314,10 +1381,20 @@ class RequestsRoute extends React.Component {
/>
+ }
>
);
diff --git a/src/routes/RequestsRoute.test.js b/src/routes/RequestsRoute.test.js
index 79457819..5871d5ad 100644
--- a/src/routes/RequestsRoute.test.js
+++ b/src/routes/RequestsRoute.test.js
@@ -32,6 +32,7 @@ import RequestsRoute, {
buildHoldRecords,
getRequestErrorMessage,
getListFormatter,
+ getPrintHoldRequestsEnabled,
urls,
REQUEST_ERROR_MESSAGE_CODE,
REQUEST_ERROR_MESSAGE_TRANSLATION_KEYS,
@@ -117,7 +118,7 @@ jest.mock('../components', () => ({
{children}