From 446fc7497c27f58fcbe9cd0f33d4ab931637fc22 Mon Sep 17 00:00:00 2001 From: vashjs Date: Thu, 1 Aug 2024 16:31:36 +0200 Subject: [PATCH] UITEN-299 Rewrite all class components to functional ones (ui-tenant-settings module) --- package.json | 1 + src/components/Period/Period.js | 190 ++--- src/hooks/useCampusDetails.js | 20 + src/hooks/useCampuses.js | 19 + src/hooks/useConfigurations.js | 19 + src/hooks/useConfigurationsCreate.js | 16 + src/hooks/useConfigurationsUpdate.js | 16 + src/hooks/useInstitutionDetails.js | 20 + src/hooks/useInstitutions.js | 19 + src/hooks/useLibraries.js | 19 + src/hooks/useLibraryDetails.js | 20 + src/hooks/useLocationCreate.js | 16 + src/hooks/useLocationDelete.js | 16 + src/hooks/useLocationUpdate.js | 16 + src/hooks/useLocations.js | 19 + src/hooks/useRemoteStorageConfigurations.js | 21 + src/hooks/useRemoteStorageMappingDelete.js | 16 + src/hooks/useRemoteStorageMappingUpdate.js | 16 + src/hooks/useRemoteStorageMappings.js | 21 + src/hooks/useSamlConfiguration.js | 19 + src/hooks/useSamlConfigurationUpdate.js | 16 + src/hooks/useSamlDownload.js | 24 + src/hooks/useServicePoints.js | 19 + src/settings/Addresses.js | 192 ++--- src/settings/Bindings/Bindings.js | 52 +- src/settings/Bindings/BindingsForm.js | 139 ++-- src/settings/Locale.js | 77 +- src/settings/LocaleForm.js | 263 +++--- src/settings/LocationCampuses.js | 255 +++--- src/settings/LocationCampuses.test.js | 115 ++- src/settings/LocationInstitutions.js | 141 ++-- src/settings/LocationInstitutions.test.js | 63 +- src/settings/LocationLibraries.js | 327 +++----- src/settings/LocationLibraries.test.js | 111 ++- .../LocationLocations/LocationDetail.js | 115 ++- .../LocationForm/DetailsField.js | 99 +-- .../LocationForm/DetailsField.test.js | 9 +- .../LocationForm/LocationForm.js | 580 ++++++------- .../LocationForm/LocationFormContainer.js | 53 +- .../LocationFormContainer.test.js | 270 +++--- .../LocationForm/RemoteStorageField.js | 13 +- .../LocationForm/ServicePointsFields.js | 118 ++- .../LocationLocations/LocationManager.js | 779 +++++++----------- .../LocationLocations/LocationManager.test.js | 233 ++---- .../RemoteStorage/Control.js | 17 +- .../RemoteStorage/Control.test.js | 26 +- .../RemoteStorage/Provider.js | 100 +-- .../LocationLocations/RemoteStorageDetails.js | 3 +- .../LocationLocations/locationDetail.test.js | 76 +- .../remoteStorageDetails.test.js | 23 +- src/settings/LocationLocations/utils.js | 8 +- src/settings/Plugins/PluginForm.js | 126 ++- src/settings/Plugins/Plugins.js | 153 ++-- src/settings/Plugins/Plugins.test.js | 67 +- .../ReadingRoomAccess/ReadingRoomAccess.js | 16 +- .../ReadingRoomAccess.test.js | 13 +- src/settings/SSOSettings/SSOSettings.js | 174 ++-- src/settings/SSOSettings/SSOSettings.test.js | 63 +- src/settings/SSOSettings/SamlForm.js | 292 ++++--- .../ServicePoints/StaffSlipEditList.js | 36 +- src/settings/ServicePoints/StaffSlipList.js | 49 +- src/settings/index.js | 228 +++-- src/settings/index.test.js | 47 +- test/jest/__mocks__/stripesCore.mock.js | 160 ++-- 64 files changed, 2842 insertions(+), 3417 deletions(-) create mode 100644 src/hooks/useCampusDetails.js create mode 100644 src/hooks/useCampuses.js create mode 100644 src/hooks/useConfigurations.js create mode 100644 src/hooks/useConfigurationsCreate.js create mode 100644 src/hooks/useConfigurationsUpdate.js create mode 100644 src/hooks/useInstitutionDetails.js create mode 100644 src/hooks/useInstitutions.js create mode 100644 src/hooks/useLibraries.js create mode 100644 src/hooks/useLibraryDetails.js create mode 100644 src/hooks/useLocationCreate.js create mode 100644 src/hooks/useLocationDelete.js create mode 100644 src/hooks/useLocationUpdate.js create mode 100644 src/hooks/useLocations.js create mode 100644 src/hooks/useRemoteStorageConfigurations.js create mode 100644 src/hooks/useRemoteStorageMappingDelete.js create mode 100644 src/hooks/useRemoteStorageMappingUpdate.js create mode 100644 src/hooks/useRemoteStorageMappings.js create mode 100644 src/hooks/useSamlConfiguration.js create mode 100644 src/hooks/useSamlConfigurationUpdate.js create mode 100644 src/hooks/useSamlDownload.js create mode 100644 src/hooks/useServicePoints.js diff --git a/package.json b/package.json index c1ce21e0..7f108ad2 100644 --- a/package.json +++ b/package.json @@ -305,6 +305,7 @@ "react": "^18.2.0", "react-dom": "^18.2.0", "react-intl": "^6.4.4", + "react-query": "^3.6.0", "react-router-dom": "^5.2.0" } } diff --git a/src/components/Period/Period.js b/src/components/Period/Period.js index 9f999028..65d6b441 100644 --- a/src/components/Period/Period.js +++ b/src/components/Period/Period.js @@ -1,31 +1,24 @@ -import React from 'react'; +import React, { useRef } from 'react'; import PropTypes from 'prop-types'; import { FormattedMessage } from 'react-intl'; - -import { - Field, -} from 'react-final-form'; - -import { - get, - isEmpty, - isNumber, -} from 'lodash'; +import { Field } from 'react-final-form'; +import { get, isEmpty, isNumber } from 'lodash'; import { Col, Row, Select, TextField, - Label, + Label } from '@folio/stripes/components'; -import css from './Period.css'; import { shortTermExpiryPeriod, shortTermClosedDateManagementMenu, longTermClosedDateManagementMenu } from '../../settings/ServicePoints/constants'; +import css from './Period.css'; + const validateDuration = value => { if (typeof value !== 'number') { @@ -39,32 +32,19 @@ const validateDuration = value => { return undefined; }; -class Period extends React.Component { - static propTypes = { - fieldLabel: PropTypes.string.isRequired, - selectPlaceholder: PropTypes.string.isRequired, - dependentValuePath: PropTypes.string.isRequired, - inputValuePath: PropTypes.string.isRequired, - selectValuePath: PropTypes.string.isRequired, - entity: PropTypes.object.isRequired, - intervalPeriods: PropTypes.arrayOf(PropTypes.object), - changeFormValue: PropTypes.func.isRequired, - }; - - constructor(props) { - super(props); - - this.inputRef = React.createRef(); - } - - onInputBlur = () => { - const { - inputValuePath, - selectValuePath, - entity, - changeFormValue, - } = this.props; - +const Period = ({ + fieldLabel, + selectPlaceholder, + dependentValuePath, + inputValuePath, + selectValuePath, + entity, + intervalPeriods, + changeFormValue +}) => { + const inputRef = useRef(null); + + const onInputBlur = () => { const inputValue = get(entity, inputValuePath); if (isNumber(inputValue)) { @@ -74,22 +54,11 @@ class Period extends React.Component { changeFormValue(selectValuePath, ''); }; - onInputClear = () => { - const { - inputValuePath, - changeFormValue, - } = this.props; - + const onInputClear = () => { changeFormValue(inputValuePath, ''); }; - onSelectChange = (e) => { - const { - selectValuePath, - changeFormValue, - dependentValuePath, - } = this.props; - + const onSelectChange = (e) => { changeFormValue(selectValuePath, e.target.value); const holdShelfClosedLibraryDateManagementValue = shortTermExpiryPeriod.findIndex(item => item === e.target.value) > -1 @@ -97,10 +66,10 @@ class Period extends React.Component { : longTermClosedDateManagementMenu[0].value; changeFormValue(dependentValuePath, holdShelfClosedLibraryDateManagementValue); - this.inputRef.current.focus(); + inputRef.current.focus(); }; - transformInputValue = (value) => { + const transformInputValue = (value) => { if (isEmpty(value)) { return ''; } @@ -108,12 +77,7 @@ class Period extends React.Component { return Number(value); }; - generateOptions = () => { - const { - intervalPeriods, - selectValuePath, - } = this.props; - + const generateOptions = () => { return intervalPeriods.map(({ value, label }) => (