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-1039: Request Action - Create new option Print search slips #1122

Merged
merged 3 commits into from
Nov 16, 2023
Merged
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 @@ -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
14 changes: 12 additions & 2 deletions src/components/PrintContent/PrintContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,17 @@ import { buildTemplate } from '../../utils';

import css from './PrintContent.css';

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

return (
<div
data-testid="printContent"
id={id}
data-testid={id}
className={css.hiddenContent}
>
<div ref={ref}>
Expand All @@ -33,8 +38,13 @@ const PrintContent = forwardRef(({ dataSource, template }, ref) => {
});

PrintContent.propTypes = {
id: PropTypes.string,
Dmitriy-Litvinenko marked this conversation as resolved.
Show resolved Hide resolved
dataSource: PropTypes.arrayOf(PropTypes.object).isRequired,
template: PropTypes.string.isRequired,
};

PrintContent.defaultProps = {
id: 'printContent',
};

export default memo(PrintContent, isEqual);
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', () => {
},
}
],
id: 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
127 changes: 102 additions & 25 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 @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -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 }) => {
Expand Down Expand Up @@ -1097,6 +1132,16 @@ class RequestsRoute extends React.Component {
);
};

onBeforeGetContentForPrintButton = (onToggle) => (
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);
})
);

render() {
const {
resources,
Expand All @@ -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', []);
Expand All @@ -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 }) => (
Expand Down Expand Up @@ -1173,7 +1224,7 @@ class RequestsRoute extends React.Component {
</Button>
}
{
pickSlipsArePending ?
isPickSlipsArePending ?
<LoadingButton>
<FormattedMessage id="ui-requests.pickSlipsLoading" />
</LoadingButton> :
Expand All @@ -1196,18 +1247,10 @@ class RequestsRoute extends React.Component {
<PrintButton
buttonStyle="dropdownItem"
id="printPickSlipsBtn"
disabled={pickSlipsEmpty}
template={printTemplate}
contentRef={this.printContentRef}
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);
})
}
disabled={isPickSlipsEmpty}
template={pickSlipsPrintTemplate}
contentRef={this.pickSlipsPrintContentRef}
onBeforeGetContent={() => this.onBeforeGetContentForPrintButton(onToggle)}
>
<FormattedMessage
id="ui-requests.printPickSlips"
Expand All @@ -1216,6 +1259,30 @@ class RequestsRoute extends React.Component {
</PrintButton>
</>
}
{
isPrintHoldRequestsEnabled &&
<>
{
isSearchSlipsArePending ?
<LoadingButton>
<FormattedMessage id="ui-requests.searchSlipsLoading" />
</LoadingButton> :
<PrintButton
buttonStyle="dropdownItem"
id="printSearchSlipsBtn"
disabled={isSearchSlipsEmpty}
template={searchSlipsPrintTemplate}
contentRef={this.searchSlipsPrintContentRef}
onBeforeGetContent={() => this.onBeforeGetContentForPrintButton(onToggle)}
>
<FormattedMessage
id="ui-requests.printSearchSlips"
values={{ sp: servicePointName }}
/>
</PrintButton>
}
</>
}
</MenuSection>
{renderColumnsMenu}
</>
Expand Down Expand Up @@ -1314,10 +1381,20 @@ class RequestsRoute extends React.Component {
/>
</div>
<PrintContent
ref={this.printContentRef}
template={printTemplate}
printContentTestId="pickSlipsPrintTemplate"
ref={this.pickSlipsPrintContentRef}
template={pickSlipsPrintTemplate}
dataSource={pickSlipsData}
/>
{
isPrintHoldRequestsEnabled &&
<PrintContent
printContentTestId="searchSlipsPrintTemplate"
ref={this.searchSlipsPrintContentRef}
template={searchSlipsPrintTemplate}
dataSource={searchSlipsData}
/>
}
</>
</RequestsRouteShortcutsWrapper>
);
Expand Down
Loading
Loading