From 062b5a842bdfeff2df132a2d9a3c011ae9a8248f Mon Sep 17 00:00:00 2001 From: Mariia Sychova <84023879+mariiaschv@users.noreply.github.com> Date: Tue, 7 Dec 2021 15:25:19 +0200 Subject: [PATCH] UIMARCAUTH-16: MARC Authorities Search Box (#28) * UIMARCAUTH-16 Implement MARC Authorities Search Box * UIMARCAUTH-16 Make updates * UIMARCAUTH-16 Add tests * UIMARCAUTH-16 Fix import path in test * UIMARCAUTH-16 Fix comments * UIMARCAUTH-16 Fix tests * UIMARCAUTH-16 Add @rehooks/local-storage to resolutions in package.json * UIMARCAUTH-16 Change @rehooks/local-storage version in dependencies --- CHANGELOG.md | 1 + Jenkinsfile | 2 +- package.json | 7 +- .../SearchResultsList.js} | 45 ++-- .../SearchResultsList.test.js} | 2 +- src/components/SearchResultsList/index.js | 1 + .../SearchTextareaField.css | 9 + .../SearchTextareaField.js | 81 +++++++ .../SearchTextareaField.test.js | 54 +++++ src/components/SearchTextareaField/index.js | 1 + src/components/index.js | 3 +- src/components/search-results-list/index.js | 1 - src/constants/index.js | 3 + src/constants/rawSearchableIndexes.js | 15 ++ src/constants/searchableIndexesMap.js | 71 ++++++ src/constants/searchableIndexesValues.js | 13 ++ .../{authority-shape.js => authority.js} | 0 src/constants/shapes/index.js | 2 +- src/hooks/useAuthorities/index.js | 1 + src/hooks/useAuthorities/useAuthorities.js | 70 ++++++ .../useAuthorities/useAuthorities.test.js | 66 ++++++ src/hooks/utils/buildQuery.js | 59 +++++ src/hooks/utils/buildQuery.test.js | 36 ++++ src/hooks/utils/index.js | 1 + src/index.js | 10 +- src/routes/SearchRoute.js | 9 + src/routes/search.js | 29 --- .../AuthoritiesSearch/AuthoritiesSearch.css | 9 + .../AuthoritiesSearch/AuthoritiesSearch.js | 204 ++++++++++++++++++ .../AuthoritiesSearch.test.js | 181 ++++++++++++++++ src/views/AuthoritiesSearch/index.js | 1 + src/views/index.js | 1 + test/jest/__mock__/stripesCore.mock.js | 6 + translations/ui-marc-authorities/en.json | 15 +- 34 files changed, 938 insertions(+), 71 deletions(-) rename src/components/{search-results-list/search-results-list.js => SearchResultsList/SearchResultsList.js} (66%) rename src/components/{search-results-list/search-results-test.test.js => SearchResultsList/SearchResultsList.test.js} (92%) create mode 100644 src/components/SearchResultsList/index.js create mode 100644 src/components/SearchTextareaField/SearchTextareaField.css create mode 100644 src/components/SearchTextareaField/SearchTextareaField.js create mode 100644 src/components/SearchTextareaField/SearchTextareaField.test.js create mode 100644 src/components/SearchTextareaField/index.js delete mode 100644 src/components/search-results-list/index.js create mode 100644 src/constants/index.js create mode 100644 src/constants/rawSearchableIndexes.js create mode 100644 src/constants/searchableIndexesMap.js create mode 100644 src/constants/searchableIndexesValues.js rename src/constants/shapes/{authority-shape.js => authority.js} (100%) create mode 100644 src/hooks/useAuthorities/index.js create mode 100644 src/hooks/useAuthorities/useAuthorities.js create mode 100644 src/hooks/useAuthorities/useAuthorities.test.js create mode 100644 src/hooks/utils/buildQuery.js create mode 100644 src/hooks/utils/buildQuery.test.js create mode 100644 src/hooks/utils/index.js create mode 100644 src/routes/SearchRoute.js delete mode 100644 src/routes/search.js create mode 100644 src/views/AuthoritiesSearch/AuthoritiesSearch.css create mode 100644 src/views/AuthoritiesSearch/AuthoritiesSearch.js create mode 100644 src/views/AuthoritiesSearch/AuthoritiesSearch.test.js create mode 100644 src/views/AuthoritiesSearch/index.js create mode 100644 src/views/index.js diff --git a/CHANGELOG.md b/CHANGELOG.md index f4e74bb9..11023b28 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,3 +5,4 @@ * New app created with stripes-cli * [UIMARCAUTH-6](https://issues.folio.org/browse/UIMARCAUTH-6) Add View MARC authority record permission. * [UIMARCAUTH-5](https://issues.folio.org/browse/UIMARCAUTH-5) Add Edit MARC authority record permission. +* [UIMARCAUTH-16](https://issues.folio.org/browse/UIMARCAUTH-16) Implement MARC Authorities Search Box. diff --git a/Jenkinsfile b/Jenkinsfile index fed373ea..213c5e0a 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,7 +1,7 @@ buildNPM { publishModDescriptor = true runLint = true - runTest = false + runTest = true runSonarqube = false runScripts = [ ['formatjs-compile': ''], diff --git a/package.json b/package.json index ae122c6a..326678e4 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,9 @@ "regenerator-runtime": "^0.13.3" }, "dependencies": { - "prop-types": "^15.6.0" + "@rehooks/local-storage": "2.4.0", + "prop-types": "^15.6.0", + "query-string": "^7.0.1" }, "peerDependencies": { "@folio/stripes": "^7.0.0", @@ -85,7 +87,8 @@ "permissionName": "ui-marc-authorities.authority-record.view", "displayName": "View MARC authority record", "subPermissions": [ - "records-editor.records.item.get" + "records-editor.records.item.get", + "search.authorities.collection.get" ], "visible": true }, diff --git a/src/components/search-results-list/search-results-list.js b/src/components/SearchResultsList/SearchResultsList.js similarity index 66% rename from src/components/search-results-list/search-results-list.js rename to src/components/SearchResultsList/SearchResultsList.js index 04709086..b85f4a96 100644 --- a/src/components/search-results-list/search-results-list.js +++ b/src/components/SearchResultsList/SearchResultsList.js @@ -1,17 +1,9 @@ import PropTypes from 'prop-types'; import { FormattedMessage } from 'react-intl'; -import { - MultiColumnList, - Pane, -} from '@folio/stripes/components'; -import { - AppIcon, -} from '@folio/stripes/core'; +import { MultiColumnList } from '@folio/stripes/components'; -import { - AuthorityShape, -} from '../../constants/shapes'; +import { AuthorityShape } from '../../constants/shapes'; const propTypes = { authorities: PropTypes.arrayOf(AuthorityShape).isRequired, @@ -60,26 +52,19 @@ const SearchResultsList = ({ ]; return ( - } - defaultWidth="fill" - paneTitle={} - > - - + ); }; diff --git a/src/components/search-results-list/search-results-test.test.js b/src/components/SearchResultsList/SearchResultsList.test.js similarity index 92% rename from src/components/search-results-list/search-results-test.test.js rename to src/components/SearchResultsList/SearchResultsList.test.js index f1a3dc13..25859eeb 100644 --- a/src/components/search-results-list/search-results-test.test.js +++ b/src/components/SearchResultsList/SearchResultsList.test.js @@ -4,7 +4,7 @@ import { import noop from 'lodash/noop'; import Harness from '../../../test/jest/helpers/harness'; -import SearchResultsList from './search-results-list'; +import SearchResultsList from './SearchResultsList'; import authorities from '../../../mocks/authorities.json'; const renderSearchResultsList = (props = {}) => render( diff --git a/src/components/SearchResultsList/index.js b/src/components/SearchResultsList/index.js new file mode 100644 index 00000000..7d4a51e2 --- /dev/null +++ b/src/components/SearchResultsList/index.js @@ -0,0 +1 @@ +export { default as SearchResultsList } from './SearchResultsList'; diff --git a/src/components/SearchTextareaField/SearchTextareaField.css b/src/components/SearchTextareaField/SearchTextareaField.css new file mode 100644 index 00000000..ec5d5470 --- /dev/null +++ b/src/components/SearchTextareaField/SearchTextareaField.css @@ -0,0 +1,9 @@ +.searchFieldWrap .select { + /* To make sure it's position is above + so the focus style isn't hidden by the input */ + margin-bottom: -1px; + + &:focus { + z-index: 5; + } +} diff --git a/src/components/SearchTextareaField/SearchTextareaField.js b/src/components/SearchTextareaField/SearchTextareaField.js new file mode 100644 index 00000000..e8b12acd --- /dev/null +++ b/src/components/SearchTextareaField/SearchTextareaField.js @@ -0,0 +1,81 @@ +import PropTypes from 'prop-types'; +import classNames from 'classnames'; +import { useIntl } from 'react-intl'; + +import { + Select, + TextArea, +} from '@folio/stripes/components'; + +import css from './SearchTextareaField.css'; + +const propTypes = { + className: PropTypes.string, + disabled: PropTypes.bool, + id: PropTypes.string.isRequired, + loading: PropTypes.bool, + onChange: PropTypes.func, + onChangeIndex: PropTypes.func, + searchableIndexes: PropTypes.arrayOf(PropTypes.shape({ + label: PropTypes.string, + value: PropTypes.string, + })).isRequired, + selectedIndex: PropTypes.string, + value: PropTypes.string, +}; + +const SearchTextareaField = ({ + className, + id, + value, + onChange, + loading, + searchableIndexes, + onChangeIndex, + selectedIndex, + disabled, + ...rest +}) => { + const intl = useIntl(); + + const indexLabel = intl.formatMessage({ id: 'stripes-components.searchFieldIndex' }); + + const rootStyles = classNames( + css.searchFieldWrap, + className, + ); + + return ( +
+