From 27eab74e7d5ebb08b48394817a511beeb3a304f1 Mon Sep 17 00:00:00 2001 From: elsenhans Date: Thu, 24 Oct 2024 13:04:23 +0200 Subject: [PATCH 1/6] UIFC-371-clean-viewcollections-and-findcollections --- CHANGELOG.md | 1 + .../Filters/Collections/CollectionsForm.js | 4 - .../Filters/Collections/CollectionsView.js | 18 ++-- .../FindCollections/FindCollections.js | 31 +----- .../FindCollections/ViewCollections.js | 56 +---------- src/components/Filters/FilterView.js | 98 +++++++++---------- 6 files changed, 63 insertions(+), 145 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cde81e6..dea61dd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ * Remove deprecated pane properties ([UIFC-339](https://issues.folio.org/browse/UIFC-339)) * Buttons should be disabled if lacking required permissions ([UIFC-322](https://issues.folio.org/browse/UIFC-322)) * Use translation keys of stripes-components ([UIFC-348](https://folio-org.atlassian.net/browse/UIFC-348)) +* Check selectCollection function, clean ViewCollections and FindCollections ([UIFC-371](https://folio-org.atlassian.net/browse/UIFC-371)) ## [6.0.0](https://github.com/folio-org/ui-finc-select/tree/v6.0.0) (2023-10-18) * Upgrade `react-dropzone` to v10 ([UIFC-329](https://issues.folio.org/browse/UIFC-329)) diff --git a/src/components/Filters/Collections/CollectionsForm.js b/src/components/Filters/Collections/CollectionsForm.js index b6db47f..56dc62b 100644 --- a/src/components/Filters/Collections/CollectionsForm.js +++ b/src/components/Filters/Collections/CollectionsForm.js @@ -3,7 +3,6 @@ import { FormattedMessage } from 'react-intl'; import { FieldArray } from 'react-final-form-arrays'; import { Accordion } from '@folio/stripes/components'; -import { stripesShape } from '@folio/stripes-core'; import FindCollections from './FindCollections/FindCollections'; @@ -14,7 +13,6 @@ const CollectionsForm = ({ filterId, form, onToggle, - ...props }) => { return ( @@ -53,7 +50,6 @@ CollectionsForm.propTypes = { }) }), onToggle: PropTypes.func, - stripes: stripesShape.isRequired, }; export default CollectionsForm; diff --git a/src/components/Filters/Collections/CollectionsView.js b/src/components/Filters/Collections/CollectionsView.js index a05eb12..af1b936 100644 --- a/src/components/Filters/Collections/CollectionsView.js +++ b/src/components/Filters/Collections/CollectionsView.js @@ -6,22 +6,16 @@ import ViewCollections from './FindCollections/ViewCollections'; const CollectionsView = ({ collectionIds, filter, - ...props }) => { const filterId = get(filter, 'id', '-'); return ( - <> -
- -
- + ); }; diff --git a/src/components/Filters/Collections/FindCollections/FindCollections.js b/src/components/Filters/Collections/FindCollections/FindCollections.js index a79d64c..4ddd88b 100644 --- a/src/components/Filters/Collections/FindCollections/FindCollections.js +++ b/src/components/Filters/Collections/FindCollections/FindCollections.js @@ -1,7 +1,6 @@ import PropTypes from 'prop-types'; import { FormattedMessage } from 'react-intl'; -import { Col, Row } from '@folio/stripes/components'; import { Pluggable } from '@folio/stripes/core'; const FindCollections = ({ @@ -9,51 +8,27 @@ const FindCollections = ({ filterId, form, isEditable, - ...props }) => { const getSelectedCollections = (records) => { form.mutators.setCollection({}, records); }; - const disableRecordCreation = true; - const buttonProps = { 'marginBottom0': true }; - - const pluggable = + return ( { - modalProps.parentMutator.query.update({ - query: '', - filters: '', - sort: 'name', - }); - }} searchButtonStyle="default" searchLabel={} selectRecordsModal={getSelectedCollections} type="find-finc-metadata-collection" - visibleColumns={['label']} - {...props} >
-
; - - return ( - <> - - - { pluggable } - - - + ); }; diff --git a/src/components/Filters/Collections/FindCollections/ViewCollections.js b/src/components/Filters/Collections/FindCollections/ViewCollections.js index e531c11..13413d4 100644 --- a/src/components/Filters/Collections/FindCollections/ViewCollections.js +++ b/src/components/Filters/Collections/FindCollections/ViewCollections.js @@ -1,80 +1,34 @@ import PropTypes from 'prop-types'; import { FormattedMessage } from 'react-intl'; -import { useState } from 'react'; -import { Col, Row } from '@folio/stripes/components'; import { Pluggable } from '@folio/stripes/core'; const ViewCollections = ({ - initCollectionIds, + collectionIds, filterId, - form, - intialCollection, isEditable, - ...props }) => { - const [collectionIds, setCollectionIds] = useState(() => { // eslint-disable-line no-unused-vars - const c = intialCollection || {}; - return { c }; - }); - - const selectCollection = (c) => { - form.mutators.setCollection([c]); - - setCollectionIds({ c }); - }; - - const disableRecordCreation = true; - const buttonProps = { 'marginBottom0': true }; - const pluggable = + return ( { - modalProps.parentMutator.query.update({ - query: '', - filters: '', - sort: 'name', - }); - }} searchButtonStyle="default" searchLabel={} - selectCollection={selectCollection} type="find-finc-metadata-collection" - visibleColumns={['label']} - {...props} >
-
; - - return ( - <> - - - { pluggable } - - - + ); }; ViewCollections.propTypes = { collectionIds: PropTypes.arrayOf(PropTypes.object), filterId: PropTypes.string, - form: PropTypes.shape({ - mutators: PropTypes.shape({ - setCollection: PropTypes.func, - }), - }), - intialCollection: PropTypes.object, - initCollectionIds: PropTypes.arrayOf(PropTypes.object), isEditable: PropTypes.bool, }; diff --git a/src/components/Filters/FilterView.js b/src/components/Filters/FilterView.js index f1f63fc..7edc8fa 100644 --- a/src/components/Filters/FilterView.js +++ b/src/components/Filters/FilterView.js @@ -110,61 +110,59 @@ const FilterView = ({ const docs = get(record, 'filterFiles', []); return ( - <> - - - + + + + + + + + + } + onToggle={handleAccordionToggle} + open={accordions.fileAccordion} + > + - + } + onToggle={handleAccordionToggle} + open={accordions.collectionAccordion} + > + - - - - - - } - onToggle={handleAccordionToggle} - open={accordions.fileAccordion} - > - - - } - onToggle={handleAccordionToggle} - open={accordions.collectionAccordion} - > - - - - - + + + ); }; From a725aad359b12fb6f968d36c3a4fdb6fb320338c Mon Sep 17 00:00:00 2001 From: elsenhans Date: Thu, 24 Oct 2024 13:50:12 +0200 Subject: [PATCH 2/6] UIFC-371-clean-viewcollections-and-findcollections --- src/components/Filters/FilterFile/FilterFileForm.js | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/components/Filters/FilterFile/FilterFileForm.js b/src/components/Filters/FilterFile/FilterFileForm.js index 38a9dad..50aa544 100644 --- a/src/components/Filters/FilterFile/FilterFileForm.js +++ b/src/components/Filters/FilterFile/FilterFileForm.js @@ -3,6 +3,7 @@ import { FormattedMessage } from 'react-intl'; import { FieldArray } from 'react-final-form-arrays'; import { Accordion } from '@folio/stripes/components'; +import { useStripes } from '@folio/stripes/core'; import DocumentsFieldArray from './UploadFile/DocumentsFieldArray'; import fetchWithDefaultOptions from '../../DisplayUtils/fetchWithDefaultOptions'; @@ -11,10 +12,11 @@ const FilterFileForm = ({ accordionId, expanded, onToggle, - stripes, }) => { + const { okapi } = useStripes(); + const handleUploadFile = (file) => { - return fetchWithDefaultOptions(stripes.okapi, '/finc-select/files', { + return fetchWithDefaultOptions(okapi, '/finc-select/files', { method: 'POST', headers: { 'Content-Type': 'application/octet-stream' }, body: file, @@ -42,13 +44,6 @@ FilterFileForm.propTypes = { accordionId: PropTypes.string.isRequired, expanded: PropTypes.bool, onToggle: PropTypes.func, - stripes: PropTypes.shape({ - okapi: PropTypes.shape({ - tenant: PropTypes.string.isRequired, - token: PropTypes.string.isRequired, - url: PropTypes.string, - }).isRequired, - }).isRequired, }; export default FilterFileForm; From bf6d29746a03bd71c5ae73af1b3d19ca7ff3c15c Mon Sep 17 00:00:00 2001 From: elsenhans Date: Mon, 28 Oct 2024 11:31:37 +0100 Subject: [PATCH 3/6] UIFC-371-clean-viewcollections-and-findcollections --- src/components/Filters/Collections/CollectionsView.js | 1 - src/components/Filters/FilterView.js | 2 -- 2 files changed, 3 deletions(-) diff --git a/src/components/Filters/Collections/CollectionsView.js b/src/components/Filters/Collections/CollectionsView.js index af1b936..3702ec0 100644 --- a/src/components/Filters/Collections/CollectionsView.js +++ b/src/components/Filters/Collections/CollectionsView.js @@ -14,7 +14,6 @@ const CollectionsView = ({ collectionIds={collectionIds} filterId={filterId} isEditable={false} - name="collectionIds" /> ); }; diff --git a/src/components/Filters/FilterView.js b/src/components/Filters/FilterView.js index 7edc8fa..66120dd 100644 --- a/src/components/Filters/FilterView.js +++ b/src/components/Filters/FilterView.js @@ -157,8 +157,6 @@ const FilterView = ({ From fabb8e098aa0fffcc56ff372833ad5587c63be95 Mon Sep 17 00:00:00 2001 From: elsenhans Date: Mon, 28 Oct 2024 14:26:04 +0100 Subject: [PATCH 4/6] UIFC-371-clean-viewcollections-and-findcollections --- .../Filters/Collections/CollectionsForm.js | 4 +-- .../Filters/Collections/CollectionsView.js | 4 +-- .../{FindCollections.js => Collections.js} | 16 +++++---- .../FindCollections/ViewCollections.js | 35 ------------------- 4 files changed, 13 insertions(+), 46 deletions(-) rename src/components/Filters/Collections/FindCollections/{FindCollections.js => Collections.js} (68%) delete mode 100644 src/components/Filters/Collections/FindCollections/ViewCollections.js diff --git a/src/components/Filters/Collections/CollectionsForm.js b/src/components/Filters/Collections/CollectionsForm.js index 56dc62b..af4dc0d 100644 --- a/src/components/Filters/Collections/CollectionsForm.js +++ b/src/components/Filters/Collections/CollectionsForm.js @@ -4,7 +4,7 @@ import { FieldArray } from 'react-final-form-arrays'; import { Accordion } from '@folio/stripes/components'; -import FindCollections from './FindCollections/FindCollections'; +import Collections from './FindCollections/Collections'; const CollectionsForm = ({ accordionId, @@ -25,7 +25,7 @@ const CollectionsForm = ({ {/* Plugin has to be inside of Field, otherwise pristine is not working */} { const getSelectedCollections = (records) => { - form.mutators.setCollection({}, records); + form?.mutators?.setCollection({}, records); }; + const searchLabel = isEditable ? : ; + return ( } - selectRecordsModal={getSelectedCollections} + searchLabel={searchLabel} + selectRecordsModal={isEditable ? getSelectedCollections : undefined} type="find-finc-metadata-collection" >
@@ -32,15 +34,15 @@ const FindCollections = ({ ); }; -FindCollections.propTypes = { +Collections.propTypes = { collectionIds: PropTypes.arrayOf(PropTypes.object), filterId: PropTypes.string, form: PropTypes.shape({ mutators: PropTypes.shape({ setCollection: PropTypes.func, - }).isRequired, + }), }), isEditable: PropTypes.bool, }; -export default FindCollections; +export default Collections; diff --git a/src/components/Filters/Collections/FindCollections/ViewCollections.js b/src/components/Filters/Collections/FindCollections/ViewCollections.js deleted file mode 100644 index 13413d4..0000000 --- a/src/components/Filters/Collections/FindCollections/ViewCollections.js +++ /dev/null @@ -1,35 +0,0 @@ -import PropTypes from 'prop-types'; -import { FormattedMessage } from 'react-intl'; - -import { Pluggable } from '@folio/stripes/core'; - -const ViewCollections = ({ - collectionIds, - filterId, - isEditable, -}) => { - return ( - } - type="find-finc-metadata-collection" - > -
-
- ); -}; - -ViewCollections.propTypes = { - collectionIds: PropTypes.arrayOf(PropTypes.object), - filterId: PropTypes.string, - isEditable: PropTypes.bool, -}; - -export default ViewCollections; From 90b428c2b0a5c22b11205a53d44ec8e8419cd7a4 Mon Sep 17 00:00:00 2001 From: elsenhans Date: Mon, 28 Oct 2024 15:07:21 +0100 Subject: [PATCH 5/6] UIFC-371-clean-viewcollections-and-findcollections --- .../Filters/Collections/CollectionsForm.js | 6 +++++- .../Collections/FindCollections/Collections.js | 14 +++----------- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/src/components/Filters/Collections/CollectionsForm.js b/src/components/Filters/Collections/CollectionsForm.js index af4dc0d..2d1c4a6 100644 --- a/src/components/Filters/Collections/CollectionsForm.js +++ b/src/components/Filters/Collections/CollectionsForm.js @@ -14,6 +14,10 @@ const CollectionsForm = ({ form, onToggle, }) => { + const getSelectedCollections = (records) => { + form?.mutators?.setCollection({}, records); + }; + return ( diff --git a/src/components/Filters/Collections/FindCollections/Collections.js b/src/components/Filters/Collections/FindCollections/Collections.js index f1b6f70..1be3ab8 100644 --- a/src/components/Filters/Collections/FindCollections/Collections.js +++ b/src/components/Filters/Collections/FindCollections/Collections.js @@ -6,13 +6,9 @@ import { Pluggable } from '@folio/stripes/core'; const Collections = ({ collectionIds, filterId, - form, isEditable, + selectRecords, }) => { - const getSelectedCollections = (records) => { - form?.mutators?.setCollection({}, records); - }; - const searchLabel = isEditable ? : ; return ( @@ -26,7 +22,7 @@ const Collections = ({ isEditable={isEditable} searchButtonStyle="default" searchLabel={searchLabel} - selectRecordsModal={isEditable ? getSelectedCollections : undefined} + selectRecords={selectRecords} type="find-finc-metadata-collection" >
@@ -37,12 +33,8 @@ const Collections = ({ Collections.propTypes = { collectionIds: PropTypes.arrayOf(PropTypes.object), filterId: PropTypes.string, - form: PropTypes.shape({ - mutators: PropTypes.shape({ - setCollection: PropTypes.func, - }), - }), isEditable: PropTypes.bool, + selectRecords: PropTypes.func, }; export default Collections; From 35e5380cfcf2392035eb65a8672b1cefa834e2cb Mon Sep 17 00:00:00 2001 From: elsenhans Date: Mon, 28 Oct 2024 15:26:44 +0100 Subject: [PATCH 6/6] UIFC-371-clean-viewcollections-and-findcollections --- src/components/Filters/Collections/CollectionsForm.js | 4 ++-- src/components/Filters/Collections/CollectionsView.js | 4 ++-- .../FindCollections/{Collections.js => FindCollections.js} | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) rename src/components/Filters/Collections/FindCollections/{Collections.js => FindCollections.js} (92%) diff --git a/src/components/Filters/Collections/CollectionsForm.js b/src/components/Filters/Collections/CollectionsForm.js index 2d1c4a6..35fc645 100644 --- a/src/components/Filters/Collections/CollectionsForm.js +++ b/src/components/Filters/Collections/CollectionsForm.js @@ -4,7 +4,7 @@ import { FieldArray } from 'react-final-form-arrays'; import { Accordion } from '@folio/stripes/components'; -import Collections from './FindCollections/Collections'; +import FindCollections from './FindCollections/FindCollections'; const CollectionsForm = ({ accordionId, @@ -29,7 +29,7 @@ const CollectionsForm = ({ {/* Plugin has to be inside of Field, otherwise pristine is not working */}