Skip to content

Commit

Permalink
Release UIU-3239 for Ramsons Bugfix (#2794)
Browse files Browse the repository at this point in the history
* UIU-3239 Process more item tokens in due date print (#2787)

* Release v11.0.1

* Update CHANGELOG.md

Co-authored-by: Dmytro-Melnyshyn <[email protected]>

---------

Co-authored-by: Mikita Siadykh <[email protected]>
Co-authored-by: Dmytro-Melnyshyn <[email protected]>
  • Loading branch information
3 people authored Nov 8, 2024
1 parent 8092e41 commit 1b3b526
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 5 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Change history for ui-users

## [11.0.1](https://github.com/folio-org/ui-users/tree/v11.1.0) (2024-11-08)
[Full Changelog](https://github.com/folio-org/ui-users/compare/v11.0.0...v11.0.1)

* Process more item tokens in due date print. Refs UIU-3239.

## [11.0.0](https://github.com/folio-org/ui-users/tree/v11.0.0) (2024-10-31)
[Full Changelog](https://github.com/folio-org/ui-users/compare/v10.1.2...v11.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/users",
"version": "11.0.0",
"version": "11.0.1",
"description": "User management",
"repository": "folio-org/ui-users",
"publishConfig": {
Expand Down Expand Up @@ -1164,6 +1164,7 @@
"moment-timezone": "^0.5.43",
"prop-types": "^15.5.10",
"query-string": "^5.0.0",
"react-barcode": "^1.5.3",
"react-easy-crop": "^5.0.5",
"react-final-form": "^6.3.0",
"react-final-form-arrays": "^3.1.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,29 @@
import React from 'react';
import Barcode from 'react-barcode';
import PropTypes from 'prop-types';
import { Parser } from 'html-to-react';
import HtmlToReact, { Parser } from 'html-to-react';
import { sanitize } from 'dompurify';

const processNodeDefinitions = new HtmlToReact.ProcessNodeDefinitions(React);
const rules = [
{
replaceChildren: true,
shouldProcessNode: node => node.name === 'barcode',
processNode: (_, children) => (<Barcode value={children[0] ? children[0].trim() : ' '} />),
},
{
shouldProcessNode: () => true,
processNode: processNodeDefinitions.processDefaultNode,
}
];

const parser = new Parser();

const PrintTemplate = ({ dataSource, templateFn }) => {
const componentStr = sanitize(templateFn(dataSource));
const componentStr = sanitize(templateFn(dataSource), { ADD_TAGS: ['Barcode'] });
const Component = parser.parseWithInstructions(componentStr, () => true, rules) || null;

return parser.parse(componentStr) || null;
return Component;
};

PrintTemplate.propTypes = {
Expand Down
28 changes: 27 additions & 1 deletion src/hooks/usePrintData/usePrintData.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,26 @@ export function buildTemplate(template = '') {
return dataSource => {
return template.replace(/{{([^{}]*)}}/g, (token, tokenName) => {
const tokenValue = dataSource[tokenName];
return typeof tokenValue === 'string' || typeof tokenValue === 'number' ? escape(tokenValue) : '';

if (
typeof tokenValue === 'string'
&& tokenValue.startsWith('<Barcode>')
&& tokenValue.endsWith('</Barcode>')
) {
return tokenValue;
} else if (typeof tokenValue === 'string' || typeof tokenValue === 'number') {
return escape(tokenValue);
} else {
return '';
}
});
};
}

export const mapEntityToTemplate = (entity, type, formatTime, patronGroup) => {
if (type === SLIPS_TYPES.DUE_DATE) {
const barcode = get(entity, 'item.barcode');

return {
'borrower.firstName': get(entity, 'borrower.firstName'),
'borrower.preferredFirstName': get(entity, 'borrower.preferredFirstName'),
Expand All @@ -28,6 +41,19 @@ export const mapEntityToTemplate = (entity, type, formatTime, patronGroup) => {

'item.title': get(entity, 'item.title'),
'item.primaryContributor': get(entity, 'item.primaryContributor'),
'item.allContributors': get(entity, 'item.contributors')?.map(({ name }) => name).join(', '),
'item.barcode': barcode,
'item.barcodeImage': barcode && `<Barcode>${barcode}</Barcode>`,
'item.callNumber': get(entity, 'item.callNumber'),
'item.callNumberPrefix': get(entity, 'item.callNumberComponents.prefix'),
'item.callNumberSuffix': get(entity, 'item.callNumberComponents.suffix'),
'item.copy': get(entity, 'item.copyNumber'),
'item.displaySummary': get(entity, 'item.displaySummary'),
'item.enumeration': get(entity, 'item.enumeration'),
'item.volume': get(entity, 'item.volume'),
'item.chronology': get(entity, 'item.chronology'),
'item.materialType': get(entity, 'item.materialType')?.name,

'loan.dueDate': formatDateAndTime(get(entity, 'dueDate'), formatTime),
};
}
Expand Down
13 changes: 13 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9118,6 +9118,11 @@ js-yaml@^3.13.1:
argparse "^1.0.7"
esprima "^4.0.0"

jsbarcode@^3.8.0:
version "3.11.6"
resolved "https://registry.yarnpkg.com/jsbarcode/-/jsbarcode-3.11.6.tgz#96e8fbc3395476e162982a6064b98a09b5ea02c0"
integrity sha512-G5TKGyKY1zJo0ZQKFM1IIMfy0nF2rs92BLlCz+cU4/TazIc4ZH+X1GYeDRt7TKjrYqmPfTjwTBkU/QnQlsYiuA==

jsbn@~0.1.0:
version "0.1.1"
resolved "https://registry.yarnpkg.com/jsbn/-/jsbn-0.1.1.tgz#a5e654c2e5a2deb5f201d96cefbca80c0ef2f513"
Expand Down Expand Up @@ -11386,6 +11391,14 @@ [email protected], rc@^1.2.7:
minimist "^1.2.0"
strip-json-comments "~2.0.1"

react-barcode@^1.5.3:
version "1.5.3"
resolved "https://registry.yarnpkg.com/react-barcode/-/react-barcode-1.5.3.tgz#d9e887d87004062e7901d250dbd8f112c47f8544"
integrity sha512-EJPUwuERKpApcQ9qXzdVZzddFYRT7+3R/jJ3OrTfW6m2iq+WT+CBaVB7DsQazhPRXDfMcx9+dmMmzjsmveOViQ==
dependencies:
jsbarcode "^3.8.0"
prop-types "^15.6.2"

react-beautiful-dnd@^13.1.0:
version "13.1.1"
resolved "https://registry.yarnpkg.com/react-beautiful-dnd/-/react-beautiful-dnd-13.1.1.tgz#b0f3087a5840920abf8bb2325f1ffa46d8c4d0a2"
Expand Down

0 comments on commit 1b3b526

Please sign in to comment.