From dbe440c4b0fad7a0664456b1793d473c55966443 Mon Sep 17 00:00:00 2001 From: MonireRasouli Date: Tue, 17 Dec 2024 21:33:25 +0000 Subject: [PATCH] ERM-3452, Centralise content filter array used in Licenses and Agreements --- index.js | 1 + lib/DocumentFilter/DocumentFilterArray.js | 136 ++++++++++++++++++++ translations/stripes-erm-components/en.json | 2 + 3 files changed, 139 insertions(+) create mode 100644 lib/DocumentFilter/DocumentFilterArray.js diff --git a/index.js b/index.js index a70394da..0761d899 100644 --- a/index.js +++ b/index.js @@ -7,6 +7,7 @@ export { default as DocumentCard } from './lib/DocumentCard'; export { default as DocumentFilter } from './lib/DocumentFilter'; export { default as DocumentFilterForm } from './lib/DocumentFilter/DocumentFilterForm'; export { default as DocumentFilterFieldArray } from './lib/DocumentFilter/DocumentFilterFieldArray'; +export { default as DocumentFilterArray } from './lib/DocumentFilter/DocumentFilterArray'; export { default as DocumentsFieldArray } from './lib/DocumentsFieldArray'; export { default as DuplicateModal } from './lib/DuplicateModal'; export { default as EditCard } from './lib/EditCard'; diff --git a/lib/DocumentFilter/DocumentFilterArray.js b/lib/DocumentFilter/DocumentFilterArray.js new file mode 100644 index 00000000..a4a04763 --- /dev/null +++ b/lib/DocumentFilter/DocumentFilterArray.js @@ -0,0 +1,136 @@ +import PropTypes from 'prop-types'; +import { useState } from 'react'; +import { Field, useForm, useFormState } from 'react-final-form'; +import { FieldArray } from 'react-final-form-arrays'; +import { FormattedMessage, useIntl } from 'react-intl'; +import { + Dropdown, + DropdownMenu, + MultiSelection, + Select, + Button, + Label, + IconButton, + Row, + Col, +} from '@folio/stripes/components'; + +const DocumentFilterArray = ({ translatedContentOptions, handleSubmit, name }) => { + const [open, setOpen] = useState(false); + const { values } = useFormState(); + const { change } = useForm(); + + const intl = useIntl(); + + return ( + + {({ fields }) => ( + <> + {fields?.map((filter, index) => { + return ( +
+ {values?.[name][index]?.grouping === '&&' && ( + + )} + {values?.[name][index]?.grouping === '||' && ( + + )} + + + { + change(`${filter}.attribute`, e?.target?.value); + handleSubmit(); + }} + /> + { + change(`${filter}.content`, e); + handleSubmit(); + }} + /> + + {index !== 0 && ( + + { + e.stopPropagation(); + fields.remove(index); + handleSubmit(); + }} + /> + + )} + +
+ ); + })} + + } + onToggle={() => setOpen(!open)} + open={open} + > + + + + + + + )} +
+ ); +}; + +DocumentFilterArray.propTypes = { + translatedContentOptions: PropTypes.arrayOf(PropTypes.object), + handleSubmit: PropTypes.func, + name: PropTypes.string, +}; + +export default DocumentFilterArray; diff --git a/translations/stripes-erm-components/en.json b/translations/stripes-erm-components/en.json index 1daed908..abd01b51 100644 --- a/translations/stripes-erm-components/en.json +++ b/translations/stripes-erm-components/en.json @@ -218,6 +218,8 @@ "documentFilter.comparator": "Comparator", "documentFilter.addRule": "Add rule", "documentFilter.removeRule": "Remove rule {number}", + "documentFilter.has": "Has", + "documentFilter.hasNot": "Has not", "comparator": "Operator", "value": "Value", "contentType": "Content type",