Skip to content

Commit

Permalink
UIREQ-1039: Request Action - Create new option Print search slips
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmitriy-Litvinenko committed Nov 14, 2023
1 parent 69bdc4b commit 2395ef1
Show file tree
Hide file tree
Showing 9 changed files with 175 additions and 38 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* Hide all actions except "Cancel Request" in Action menu (Lending library). Refs UIREQ-1032.
* Hide all actions except "Cancel Request" in Action menu and DCB item links (Borrowing library). Refs UIREQ-1034.
* Hide all actions except "Cancel Request" in Action menu and DCB item links (Pickup library). Refs UIREQ-1035.
* Request Action - Create new option Print search slips. Refs UIREQ-1039.

## [9.0.0](https://github.com/folio-org/ui-requests/tree/v9.0.0) (2023-10-12)
[Full Changelog](https://github.com/folio-org/ui-requests/compare/v8.0.2...v9.0.0)
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@folio/requests",
"version": "9.0.0",
"version": "9.1.0",
"description": "Requests manager",
"repository": "folio-org/ui-requests",
"publishConfig": {
Expand Down Expand Up @@ -118,6 +118,7 @@
"circulation-storage.requests.item.post",
"circulation-storage.request-preferences.collection.get",
"circulation.pick-slips.get",
"circulation.search-slips.get",
"inventory-storage.locations.item.get"
],
"visible": true
Expand Down
9 changes: 7 additions & 2 deletions src/components/PrintContent/PrintContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@ import { buildTemplate } from '../../utils';

import css from './PrintContent.css';

const PrintContent = forwardRef(({ dataSource, template }, ref) => {
const PrintContent = forwardRef(({
dataSource,
template,
printContentTestId,
}, ref) => {
const templateFn = useMemo(() => buildTemplate(template), [template]);

return (
<div
data-testid="printContent"
data-testid={printContentTestId}
className={css.hiddenContent}
>
<div ref={ref}>
Expand All @@ -33,6 +37,7 @@ const PrintContent = forwardRef(({ dataSource, template }, ref) => {
});

PrintContent.propTypes = {
printContentTestId: PropTypes.string.isRequired,
dataSource: PropTypes.arrayOf(PropTypes.object).isRequired,
template: PropTypes.string.isRequired,
};
Expand Down
1 change: 1 addition & 0 deletions src/components/PrintContent/PrintContent.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ describe('PrintContent', () => {
},
}
],
printContentTestId: testIds.printContent,
};

afterEach(() => {
Expand Down
5 changes: 4 additions & 1 deletion src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
106 changes: 95 additions & 11 deletions src/routes/RequestsRoute.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ import {
reportHeaders,
fulfillmentTypes,
expiredHoldsReportHeaders,
pickSlipType,
SLIPS_TYPE,
createModes,
requestStatusesTranslations,
requestTypesTranslations,
Expand Down Expand Up @@ -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}")` });
Expand Down Expand Up @@ -395,6 +404,21 @@ class RequestsRoute extends React.Component {
fetch: true,
throwErrors: false,
},
searchSlips: {
type: 'okapi',
records: 'searchSlips',
path: 'circulation/search-slips/%{currentServicePoint.id}',
fetch: true,
throwErrors: false,
},
printHoldRequests: {
type: 'okapi',
records: 'configs',
path: 'configurations/entries',
params: {
query: '(module==SETTINGS and configName==PRINT_HOLD_REQUESTS)',
},
},
currentServicePoint: {},
tags: {
throwErrors: false,
Expand Down Expand Up @@ -456,6 +480,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,
Expand Down Expand Up @@ -486,10 +513,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,
Expand Down Expand Up @@ -571,7 +605,8 @@ class RequestsRoute extends React.Component {
createTitleLevelRequestsByDefault,
};

this.printContentRef = React.createRef();
this.pickSlipsPrintContentRef = React.createRef();
this.searchSlipsPrintContentRef = React.createRef();
this.paneTitleRef = React.createRef();
}

Expand Down Expand Up @@ -1037,10 +1072,11 @@ 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 slipTemplate = staffSlips.find(slip => slip.name.toLowerCase() === slipType.toLowerCase());

return get(slipTemplate, 'template', '');
}

handleFilterChange = ({ name, values }) => {
Expand Down Expand Up @@ -1121,8 +1157,10 @@ class RequestsRoute extends React.Component {
holdsShelfReportPending,
createTitleLevelRequestsByDefault,
} = this.state;
const printHoldRequestsEnabled = 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', []);
Expand All @@ -1136,10 +1174,14 @@ class RequestsRoute extends React.Component {
};

const pickSlipsArePending = resources?.pickSlips?.isPending;
const searchSlipsArePending = resources?.searchSlips?.isPending;
const requestsEmpty = isEmpty(requests);
const pickSlipsEmpty = isEmpty(pickSlips);
const printTemplate = this.getPrintTemplate();
const pickSlipsData = convertToSlipData(pickSlips, intl, timezone, locale);
const searchSlipsEmpty = 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 }) => (
Expand Down Expand Up @@ -1197,8 +1239,8 @@ class RequestsRoute extends React.Component {
buttonStyle="dropdownItem"
id="printPickSlipsBtn"
disabled={pickSlipsEmpty}
template={printTemplate}
contentRef={this.printContentRef}
template={pickSlipsPrintTemplate}
contentRef={this.pickSlipsPrintContentRef}
onBeforeGetContent={
() => new Promise(resolve => {
this.context.sendCallout({ message: <FormattedMessage id="ui-requests.printInProgress" /> });
Expand All @@ -1216,6 +1258,38 @@ class RequestsRoute extends React.Component {
</PrintButton>
</>
}
{
printHoldRequestsEnabled &&
<>
{
searchSlipsArePending ?
<LoadingButton>
<FormattedMessage id="ui-requests.searchSlipsLoading" />
</LoadingButton> :
<PrintButton
buttonStyle="dropdownItem"
id="printSearchSlipsBtn"
disabled={searchSlipsEmpty}
template={searchSlipsPrintTemplate}
contentRef={this.searchSlipsPrintContentRef}
onBeforeGetContent={
() => new Promise(resolve => {
this.context.sendCallout({ message: <FormattedMessage id="ui-requests.printInProgress" /> });
onToggle();
// without the timeout the printing process starts right away
// and the callout and onToggle above are blocked
setTimeout(() => resolve(), 1000);
})
}
>
<FormattedMessage
id="ui-requests.printSearchSlips"
values={{ sp: servicePointName }}
/>
</PrintButton>
}
</>
}
</MenuSection>
{renderColumnsMenu}
</>
Expand Down Expand Up @@ -1314,10 +1388,20 @@ class RequestsRoute extends React.Component {
/>
</div>
<PrintContent
ref={this.printContentRef}
template={printTemplate}
printContentTestId="pickSlipsPrintTemplate"
ref={this.pickSlipsPrintContentRef}
template={pickSlipsPrintTemplate}
dataSource={pickSlipsData}
/>
{
printHoldRequestsEnabled &&
<PrintContent
printContentTestId="searchSlipsPrintTemplate"
ref={this.searchSlipsPrintContentRef}
template={searchSlipsPrintTemplate}
dataSource={searchSlipsData}
/>
}
</>
</RequestsRouteShortcutsWrapper>
);
Expand Down
Loading

0 comments on commit 2395ef1

Please sign in to comment.