From 556ce31a7ae8f8b56e985b7f8b4fbcb545313d6e Mon Sep 17 00:00:00 2001 From: Ethan Freestone Date: Thu, 15 Sep 2022 14:41:40 +0100 Subject: [PATCH 01/16] feat: Number Generator Hooked up Number generator to Organizations --- package.json | 2 + .../FieldCode/FieldCode.js | 47 ++++++++--- src/Settings/NumberGeneratorOptions.js | 83 +++++++++++++++++++ src/Settings/SettingsPage.js | 7 ++ src/common/constants/api.js | 2 + src/common/hooks/index.js | 1 + src/common/hooks/useSettings/index.js | 1 + src/common/hooks/useSettings/useSettings.js | 61 ++++++++++++++ translations/ui-organizations/en.json | 4 + 9 files changed, 198 insertions(+), 10 deletions(-) create mode 100644 src/Settings/NumberGeneratorOptions.js create mode 100644 src/common/hooks/useSettings/index.js create mode 100644 src/common/hooks/useSettings/useSettings.js diff --git a/package.json b/package.json index 5a827c60..fa3abc37 100644 --- a/package.json +++ b/package.json @@ -246,6 +246,7 @@ "@bigtest/mocha": "^0.5.2", "@bigtest/react": "^0.1.2", "@folio/eslint-config-stripes": "^6.1.0", + "@folio/service-interaction": "^1.0.0", "@folio/stripes": "^7.0.0", "@folio/stripes-cli": "^2.4.0", "@formatjs/cli": "^4.2.16", @@ -292,6 +293,7 @@ "redux-form": "^8.3.0" }, "peerDependencies": { + "@folio/service-interaction": "^1.0.0", "@folio/stripes": "^7.0.0", "react": "^17.0.2", "react-dom": "^17.0.2", diff --git a/src/Organizations/OrganizationForm/OrganizationSummaryForm/FieldCode/FieldCode.js b/src/Organizations/OrganizationForm/OrganizationSummaryForm/FieldCode/FieldCode.js index 201e31e1..c8c89c87 100644 --- a/src/Organizations/OrganizationForm/OrganizationSummaryForm/FieldCode/FieldCode.js +++ b/src/Organizations/OrganizationForm/OrganizationSummaryForm/FieldCode/FieldCode.js @@ -1,13 +1,17 @@ import React, { useCallback } from 'react'; -import { Field } from 'react-final-form'; +import { Field, useForm } from 'react-final-form'; import { FormattedMessage } from 'react-intl'; import PropTypes from 'prop-types'; import { stripesConnect } from '@folio/stripes/core'; -import { TextField } from '@folio/stripes/components'; +import { Col, Row, TextField } from '@folio/stripes/components'; +import { NumberGeneratorButton } from '@folio/service-interaction'; import { fetchOrgsByParam } from '../../../../common/resources'; import { validateOrgCode } from './validateOrgCode'; +import { useSettings } from '../../../../common/hooks'; + +const CONFIG_NAME = 'number_generator'; const FieldCode = ({ orgId, mutator }) => { const validate = useCallback(value => { @@ -16,15 +20,38 @@ const FieldCode = ({ orgId, mutator }) => { // eslint-disable-next-line react-hooks/exhaustive-deps [orgId]); + const { change } = useForm(); + + const { settings } = useSettings([CONFIG_NAME]); + const vendorCodeSetting = settings?.find(sett => sett?.configName === CONFIG_NAME)?.parsedSettings?.vendorGeneratorSetting ?? 'useTextField'; + return ( - } - name="code" - required - validate={validate} - /> + + + } + name="code" + required + validate={validate} + /> + + {( + vendorCodeSetting === 'useGenerator' || + vendorCodeSetting === 'useBoth' + ) && + + change('code', generated)} + id="vendor-code-generator" + generator="Vendor" + sequence="vendor" + /> + + } + ); }; diff --git a/src/Settings/NumberGeneratorOptions.js b/src/Settings/NumberGeneratorOptions.js new file mode 100644 index 00000000..21c85ec0 --- /dev/null +++ b/src/Settings/NumberGeneratorOptions.js @@ -0,0 +1,83 @@ +import React from 'react'; +import PropTypes from 'prop-types'; +import { FormattedMessage } from 'react-intl'; +import { Field } from 'react-final-form'; + +import { stripesConnect, withStripes } from '@folio/stripes/core'; +import { ConfigManager } from '@folio/stripes/smart-components'; + +import { Col, RadioButton, Row } from '@folio/stripes/components'; + +const NumberGeneratorOptions = (props) => { + const ConnectedConfigManager = stripesConnect(ConfigManager); + + const defaultValues = { + useGenerator: 'useBoth', + }; + + const beforeSave = (data) => { + return JSON.stringify(data); + }; + + const getInitialValues = (settings) => { + let loadedValues = {}; + + try { + const value = settings.length === 0 ? '' : settings[0].value; + + loadedValues = JSON.parse(value); + } catch (e) { } // eslint-disable-line no-empty + + return { + ...defaultValues, + ...loadedValues, + }; + }; + + return ( + } + moduleName="ORGANIZATIONS" + onBeforeSave={beforeSave} + stripes={props.stripes} + formType="final-form" + > + + + } + type="radio" + value="useGenerator" + /> + } + type="radio" + value="useTextField" + /> + } + type="radio" + value="useBoth" + /> + + + + ); +}; + +NumberGeneratorOptions.propTypes = { + stripes: PropTypes.object, +}; + +export default withStripes(NumberGeneratorOptions); diff --git a/src/Settings/SettingsPage.js b/src/Settings/SettingsPage.js index d3737b1a..effebaf6 100644 --- a/src/Settings/SettingsPage.js +++ b/src/Settings/SettingsPage.js @@ -5,6 +5,7 @@ import { Settings } from '@folio/stripes/smart-components'; import CategorySettings from './CategorySettings'; import { TypeSettings } from './TypeSettings'; +import NumberGeneratorOptions from './NumberGeneratorOptions'; const pages = [ { @@ -19,6 +20,12 @@ const pages = [ perm: 'settings.organizations.enabled', route: 'type', }, + { + component: NumberGeneratorOptions, + label: , + perm: 'settings.organizations.enabled', + route: 'numberGeneratorOptions', + }, ]; const SettingsPage = (props) => ( diff --git a/src/common/constants/api.js b/src/common/constants/api.js index e4d3413e..e05c34bc 100644 --- a/src/common/constants/api.js +++ b/src/common/constants/api.js @@ -4,4 +4,6 @@ export const INTERFACES_API = 'organizations-storage/interfaces'; export const TYPES_API = 'organizations-storage/organization-types'; export const AGREEMENTS_API = 'erm/sas'; +export const CONFIG_API = 'configurations/entries'; + export const MAX_LIMIT = 2147483647; diff --git a/src/common/hooks/index.js b/src/common/hooks/index.js index 393e24a9..f74bbf4c 100644 --- a/src/common/hooks/index.js +++ b/src/common/hooks/index.js @@ -4,3 +4,4 @@ export * from './useIntegrationConfigMutation'; export * from './useLinkedAgreements'; export * from './useTranslatedCategories'; export * from './useTypes'; +export * from './useSettings'; diff --git a/src/common/hooks/useSettings/index.js b/src/common/hooks/useSettings/index.js new file mode 100644 index 00000000..3deefacf --- /dev/null +++ b/src/common/hooks/useSettings/index.js @@ -0,0 +1 @@ +export { useSettings } from './useSettings'; diff --git a/src/common/hooks/useSettings/useSettings.js b/src/common/hooks/useSettings/useSettings.js new file mode 100644 index 00000000..7cc05169 --- /dev/null +++ b/src/common/hooks/useSettings/useSettings.js @@ -0,0 +1,61 @@ +import { useQuery } from 'react-query'; + +import { + useNamespace, + useOkapiKy, +} from '@folio/stripes/core'; + +import { CONFIG_API } from '../../constants'; + +export const useSettings = (configNames = []) => { + const ky = useOkapiKy(); + const [namespace] = useNamespace({ key: 'settings' }); + + let query = 'module==ORGANIZATIONS'; + + if (configNames?.length > 0) { + const configNamesString = configNames?.map(cfn => `configName==${cfn}`).join(' or '); + + query = `${query} AND (${configNamesString})`; + } + + const searchParams = { + query, + }; + + const queryKeys = [ + namespace, + ]; + + const queryFn = () => ky.get(CONFIG_API, { searchParams }).json(); + const options = { + enabled: configNames?.length > 0, + keepPreviousData: true, + }; + + const { + data, + isFetching, + isLoading, + ...rest + } = useQuery( + queryKeys, + queryFn, + options, + ); + + const settings = data?.configs ?? []; + + const parsedSettings = settings?.map(sett => ({ + ...sett, + parsedSettings: JSON.parse(sett?.value ?? '{}'), + })); + + return ({ + settings: parsedSettings, + isFetching, + isLoading, + totalCount: data?.totalRecords, + ...rest, + }); +}; diff --git a/translations/ui-organizations/en.json b/translations/ui-organizations/en.json index 8aef4c6a..d4568a6d 100644 --- a/translations/ui-organizations/en.json +++ b/translations/ui-organizations/en.json @@ -428,6 +428,10 @@ "settings.type": "Type", "settings.typeStatus.Active": "Active", "settings.typeStatus.Inactive": "Inactive", + "settings.numberGeneratorOptions": "Number generator options", + "settings.numberGeneratorOptions.useGeneratorForVendor": "Use number generator for vendor code.", + "settings.numberGeneratorOptions.useTextFieldForVendor": "Use text field for vendor code.", + "settings.numberGeneratorOptions.useBothForVendor": "Use number generator for vendor code but allow editing via text field.", "permission.view": "Organizations: View", "permission.edit": "Organizations: View, edit", "permission.create": "Organizations: View, edit, create", From 7a04e05b49b0a0e9a6f14741a294d93055bced00 Mon Sep 17 00:00:00 2001 From: Ethan Freestone Date: Fri, 16 Sep 2022 10:42:21 +0100 Subject: [PATCH 02/16] chore: Interfaces Added servint as an optionalOkapiInterface dependency, and protected code against being called when interface is not present --- package.json | 3 ++ .../FieldCode/FieldCode.js | 9 +++- src/Settings/SettingsPage.js | 45 +++++++++++++------ 3 files changed, 42 insertions(+), 15 deletions(-) diff --git a/package.json b/package.json index fa3abc37..d267a0b4 100644 --- a/package.json +++ b/package.json @@ -309,5 +309,8 @@ "optionalDependencies": { "@folio/plugin-find-contact": "^3.2.0", "@folio/plugin-find-interface": "^3.2.0" + }, + "optionalOkapiInterfaces": { + "servint": "2.0" } } diff --git a/src/Organizations/OrganizationForm/OrganizationSummaryForm/FieldCode/FieldCode.js b/src/Organizations/OrganizationForm/OrganizationSummaryForm/FieldCode/FieldCode.js index c8c89c87..910f6700 100644 --- a/src/Organizations/OrganizationForm/OrganizationSummaryForm/FieldCode/FieldCode.js +++ b/src/Organizations/OrganizationForm/OrganizationSummaryForm/FieldCode/FieldCode.js @@ -3,7 +3,7 @@ import { Field, useForm } from 'react-final-form'; import { FormattedMessage } from 'react-intl'; import PropTypes from 'prop-types'; -import { stripesConnect } from '@folio/stripes/core'; +import { stripesConnect, useStripes } from '@folio/stripes/core'; import { Col, Row, TextField } from '@folio/stripes/components'; import { NumberGeneratorButton } from '@folio/service-interaction'; @@ -21,9 +21,14 @@ const FieldCode = ({ orgId, mutator }) => { [orgId]); const { change } = useForm(); + const stripes = useStripes(); const { settings } = useSettings([CONFIG_NAME]); - const vendorCodeSetting = settings?.find(sett => sett?.configName === CONFIG_NAME)?.parsedSettings?.vendorGeneratorSetting ?? 'useTextField'; + let vendorCodeSetting = 'useTextField'; + + if (stripes.hasInterface('servint')) { + vendorCodeSetting = settings?.find(sett => sett?.configName === CONFIG_NAME)?.parsedSettings?.vendorGeneratorSetting ?? 'useTextField'; + } return ( diff --git a/src/Settings/SettingsPage.js b/src/Settings/SettingsPage.js index effebaf6..70f2bfc7 100644 --- a/src/Settings/SettingsPage.js +++ b/src/Settings/SettingsPage.js @@ -1,4 +1,5 @@ import React from 'react'; +import PropTypes from 'prop-types'; import { FormattedMessage } from 'react-intl'; import { Settings } from '@folio/stripes/smart-components'; @@ -20,20 +21,38 @@ const pages = [ perm: 'settings.organizations.enabled', route: 'type', }, - { - component: NumberGeneratorOptions, - label: , - perm: 'settings.organizations.enabled', - route: 'numberGeneratorOptions', - }, ]; -const SettingsPage = (props) => ( - } - /> -); +const SettingsPage = (props) => { + const { stripes } = props; + + if (stripes.hasInterface('servint')) { + pages.push({ + component: NumberGeneratorOptions, + label: , + perm: 'settings.organizations.enabled', + route: 'numberGeneratorOptions', + },) + } + + return ( + } + /> + ); +}; + +SettingsPage.propTypes = { + stripes: PropTypes.shape({ + hasInterface: PropTypes.func.isRequired, + timezone: PropTypes.string.isRequired, + store: PropTypes.shape({ + dispatch: PropTypes.func.isRequired, + getState: PropTypes.func, + }), + }).isRequired, +} export default SettingsPage; From b3d112e03d01086b81ecc3d7cce51c3f7fd2530a Mon Sep 17 00:00:00 2001 From: Ethan Freestone Date: Fri, 3 Feb 2023 10:13:52 +0000 Subject: [PATCH 03/16] chore: Tweaks Small tweaks, brought number generator code in line with users PR refs UIORGS-336, UIORGS-337 --- src/Settings/NumberGeneratorOptions.js | 5 ++++- src/Settings/SettingsPage.js | 20 ++++++++------------ translations/ui-organizations/en.json | 6 +++--- 3 files changed, 15 insertions(+), 16 deletions(-) diff --git a/src/Settings/NumberGeneratorOptions.js b/src/Settings/NumberGeneratorOptions.js index 21c85ec0..ab67580a 100644 --- a/src/Settings/NumberGeneratorOptions.js +++ b/src/Settings/NumberGeneratorOptions.js @@ -26,7 +26,10 @@ const NumberGeneratorOptions = (props) => { const value = settings.length === 0 ? '' : settings[0].value; loadedValues = JSON.parse(value); - } catch (e) { } // eslint-disable-line no-empty + } catch (e) { + // Make sure we return _something_ because ConfigManager no longer has a safety check here + return {}; + } return { ...defaultValues, diff --git a/src/Settings/SettingsPage.js b/src/Settings/SettingsPage.js index 70f2bfc7..68e4834d 100644 --- a/src/Settings/SettingsPage.js +++ b/src/Settings/SettingsPage.js @@ -21,20 +21,16 @@ const pages = [ perm: 'settings.organizations.enabled', route: 'type', }, + { + component: NumberGeneratorOptions, + label: , + perm: 'settings.organizations.enabled', + interface: 'servint', + route: 'numberGeneratorOptions', + }, ]; const SettingsPage = (props) => { - const { stripes } = props; - - if (stripes.hasInterface('servint')) { - pages.push({ - component: NumberGeneratorOptions, - label: , - perm: 'settings.organizations.enabled', - route: 'numberGeneratorOptions', - },) - } - return ( Date: Thu, 16 Feb 2023 16:33:35 +0000 Subject: [PATCH 04/16] fix: Generator code Update generator code to use the new codes defined in this PR: https://github.com/folio-org/mod-service-interaction/pull/72 --- .../OrganizationSummaryForm/FieldCode/FieldCode.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Organizations/OrganizationForm/OrganizationSummaryForm/FieldCode/FieldCode.js b/src/Organizations/OrganizationForm/OrganizationSummaryForm/FieldCode/FieldCode.js index 910f6700..72a04dfc 100644 --- a/src/Organizations/OrganizationForm/OrganizationSummaryForm/FieldCode/FieldCode.js +++ b/src/Organizations/OrganizationForm/OrganizationSummaryForm/FieldCode/FieldCode.js @@ -51,7 +51,7 @@ const FieldCode = ({ orgId, mutator }) => { change('code', generated)} id="vendor-code-generator" - generator="Vendor" + generator="organizations_vendorCode" sequence="vendor" /> From 0017207f0d01c5c11842e0a40668684d56097251 Mon Sep 17 00:00:00 2001 From: Ethan Freestone Date: Thu, 16 Feb 2023 16:43:16 +0000 Subject: [PATCH 05/16] feat: Permission Added new permission and blocked access to number generator page based on that permission --- package.json | 8 ++++++++ src/Settings/SettingsPage.js | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 6790eb4a..d4d48a27 100644 --- a/package.json +++ b/package.json @@ -215,6 +215,14 @@ "organizations-storage.categories.item.post", "organizations-storage.categories.item.put" ] + }, + { + "permissionName": "ui-organizations.settings.numberGenerator.manage", + "displayName": "Settings (Organizations): Manage number generator options", + "subPermissions": [ + "settings.organizations.enabled" + ], + "visible": true } ] }, diff --git a/src/Settings/SettingsPage.js b/src/Settings/SettingsPage.js index 68e4834d..d1eb47e9 100644 --- a/src/Settings/SettingsPage.js +++ b/src/Settings/SettingsPage.js @@ -24,7 +24,7 @@ const pages = [ { component: NumberGeneratorOptions, label: , - perm: 'settings.organizations.enabled', + perm: 'ui-organizations.settings.numberGenerator.manage', interface: 'servint', route: 'numberGeneratorOptions', }, From f9a299d8a6c495e48de7868e16ed4c182ca3613a Mon Sep 17 00:00:00 2001 From: Ethan Freestone Date: Tue, 20 Jun 2023 09:26:59 +0100 Subject: [PATCH 06/16] build: OptionalOkapiInterfaces Update to use servint 3 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 2fde1b00..902c7197 100644 --- a/package.json +++ b/package.json @@ -314,7 +314,7 @@ "@folio/plugin-find-interface": "^3.2.0" }, "optionalOkapiInterfaces": { - "servint": "2.0", + "servint": "2.0 3.0", "@folio/plugin-find-contact": "^4.0.0", "@folio/plugin-find-interface": "^4.0.0" } From ce20f2305b1cc709c31ced5c4acbfa5d65f980f6 Mon Sep 17 00:00:00 2001 From: Ethan Freestone Date: Mon, 7 Aug 2023 17:44:06 +0100 Subject: [PATCH 07/16] build: New service interaction Use new service-interaction --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 902c7197..b02a217f 100644 --- a/package.json +++ b/package.json @@ -252,7 +252,7 @@ "@bigtest/mocha": "^0.5.2", "@bigtest/react": "^0.1.2", "@folio/eslint-config-stripes": "^6.1.0", - "@folio/service-interaction": "^1.0.0", + "@folio/service-interaction": "^2.0.0", "@folio/stripes": "^8.0.0", "@folio/stripes-cli": "^2.4.0", "@formatjs/cli": "^4.2.16", @@ -299,7 +299,7 @@ "redux-form": "^8.3.0" }, "peerDependencies": { - "@folio/service-interaction": "^1.0.0", + "@folio/service-interaction": "^2.0.0", "@folio/stripes": "^8.0.0", "react": "^17.0.2", "react-dom": "^17.0.2", From 5366269e97933cad5f3255ec9ceba9318e992c1d Mon Sep 17 00:00:00 2001 From: Ethan Freestone Date: Fri, 8 Sep 2023 14:53:56 +0100 Subject: [PATCH 08/16] feat: Number generator Swapped implementation to full Modal implementation as per the other apps --- .../FieldCode/FieldCode.js | 11 ++++++++--- src/Settings/NumberGeneratorOptions.js | 16 ++++++++-------- translations/ui-organizations/en.json | 2 ++ 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/Organizations/OrganizationForm/OrganizationSummaryForm/FieldCode/FieldCode.js b/src/Organizations/OrganizationForm/OrganizationSummaryForm/FieldCode/FieldCode.js index 72a04dfc..e5a8aaef 100644 --- a/src/Organizations/OrganizationForm/OrganizationSummaryForm/FieldCode/FieldCode.js +++ b/src/Organizations/OrganizationForm/OrganizationSummaryForm/FieldCode/FieldCode.js @@ -5,7 +5,7 @@ import PropTypes from 'prop-types'; import { stripesConnect, useStripes } from '@folio/stripes/core'; import { Col, Row, TextField } from '@folio/stripes/components'; -import { NumberGeneratorButton } from '@folio/service-interaction'; +import { NumberGeneratorModalButton } from '@folio/service-interaction'; import { fetchOrgsByParam } from '../../../../common/resources'; import { validateOrgCode } from './validateOrgCode'; @@ -48,11 +48,16 @@ const FieldCode = ({ orgId, mutator }) => { vendorCodeSetting === 'useBoth' ) && - } callback={(generated) => change('code', generated)} + fullWidth id="vendor-code-generator" + generateButtonLabel={} generator="organizations_vendorCode" - sequence="vendor" + modalProps={{ + label: + }} /> } diff --git a/src/Settings/NumberGeneratorOptions.js b/src/Settings/NumberGeneratorOptions.js index ab67580a..e49a4cb9 100644 --- a/src/Settings/NumberGeneratorOptions.js +++ b/src/Settings/NumberGeneratorOptions.js @@ -49,14 +49,6 @@ const NumberGeneratorOptions = (props) => { > - } - type="radio" - value="useGenerator" - /> { type="radio" value="useBoth" /> + } + type="radio" + value="useGenerator" + /> diff --git a/translations/ui-organizations/en.json b/translations/ui-organizations/en.json index 43a37277..c424da00 100644 --- a/translations/ui-organizations/en.json +++ b/translations/ui-organizations/en.json @@ -443,6 +443,8 @@ "settings.numberGeneratorOptions.useGeneratorForVendor": "Number generator on, fixed: the vendor code can be filled using the generator only.", "settings.numberGeneratorOptions.useTextFieldForVendor": "Number generator off: the vendor code can be filled manually only.", "settings.numberGeneratorOptions.useBothForVendor": "Number generator on, editable: the vendor code can be filled using the generator and be edited, or filled manually.", + "numberGenerator.vendorCodeGenerator": "Vendor code generator", + "numberGenerator.generateVendorCode": "Generate vendor code", "permission.view": "Organizations: View", "permission.edit": "Organizations: View, edit", "permission.create": "Organizations: View, edit, create", From fbaabdf7a1196cf8168ea82417cbf84e0bfc658d Mon Sep 17 00:00:00 2001 From: Ethan Freestone Date: Fri, 29 Sep 2023 12:43:10 +0100 Subject: [PATCH 09/16] chore: Button UX Changed Button from fullWidth to scale with text --- .../OrganizationSummaryForm/FieldCode/FieldCode.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Organizations/OrganizationForm/OrganizationSummaryForm/FieldCode/FieldCode.js b/src/Organizations/OrganizationForm/OrganizationSummaryForm/FieldCode/FieldCode.js index e5a8aaef..960f46df 100644 --- a/src/Organizations/OrganizationForm/OrganizationSummaryForm/FieldCode/FieldCode.js +++ b/src/Organizations/OrganizationForm/OrganizationSummaryForm/FieldCode/FieldCode.js @@ -51,7 +51,6 @@ const FieldCode = ({ orgId, mutator }) => { } callback={(generated) => change('code', generated)} - fullWidth id="vendor-code-generator" generateButtonLabel={} generator="organizations_vendorCode" From d618b90dba271a3380bc55d89ccfd9b4933d2bcd Mon Sep 17 00:00:00 2001 From: Ethan Freestone Date: Fri, 8 Dec 2023 11:09:03 +0000 Subject: [PATCH 10/16] chore: Revert to state on master Change back to do what is done on master --- src/Settings/SettingsPage.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/Settings/SettingsPage.js b/src/Settings/SettingsPage.js index a37b76de..24ac0117 100644 --- a/src/Settings/SettingsPage.js +++ b/src/Settings/SettingsPage.js @@ -39,14 +39,15 @@ const pages = [ }, ]; +const bankingAccountTypesPage = { + component: BankingAccountTypeSettings, + label: , + perm: 'settings.organizations.enabled', + route: 'banking-account-types', +}; + const SettingsPage = (props) => { const { enabled } = useBankingInformationSettings(); - const bankingAccountTypesPage = { - component: BankingAccountTypeSettings, - label: , - perm: 'settings.organizations.enabled', - route: 'banking-account-types', - }; const settingsPages = useMemo(() => (enabled ? pages.concat(bankingAccountTypesPage) : pages), [enabled]); From 5724de30741cb25c569c411034d5d6a84fc51ee4 Mon Sep 17 00:00:00 2001 From: Ethan Freestone Date: Fri, 1 Mar 2024 11:49:38 +0000 Subject: [PATCH 11/16] test: mock useSettings Mocked useSettings to rectify failing test --- .../OrganizationSummaryForm.test.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/Organizations/OrganizationForm/OrganizationSummaryForm/OrganizationSummaryForm.test.js b/src/Organizations/OrganizationForm/OrganizationSummaryForm/OrganizationSummaryForm.test.js index 15e5b133..f48ad93d 100644 --- a/src/Organizations/OrganizationForm/OrganizationSummaryForm/OrganizationSummaryForm.test.js +++ b/src/Organizations/OrganizationForm/OrganizationSummaryForm/OrganizationSummaryForm.test.js @@ -11,6 +11,15 @@ import { useTypes } from '../../../common/hooks'; jest.mock('../../../common/hooks', () => ({ useTypes: jest.fn(), + useSettings: jest.fn(() => ([ + { + id: 'f2b84177-d85a-4b0c-93dd-279e8f9d1d42', + module: 'ORGANIZATIONS', + configName: 'number_generator', + enabled: true, + value: '{"vendorGeneratorSetting":"useBoth"}', + }, + ])), })); const TestForm = stripesFinalForm({})( From e0f9cff5befb2e7cf0d850d22887375b213e926b Mon Sep 17 00:00:00 2001 From: Ethan Freestone Date: Fri, 1 Mar 2024 11:53:44 +0000 Subject: [PATCH 12/16] test: Updated jest snapshot --- .../OrganizationSummaryForm.test.js.snap | 72 ++++++++++--------- 1 file changed, 40 insertions(+), 32 deletions(-) diff --git a/src/Organizations/OrganizationForm/OrganizationSummaryForm/__snapshots__/OrganizationSummaryForm.test.js.snap b/src/Organizations/OrganizationForm/OrganizationSummaryForm/__snapshots__/OrganizationSummaryForm.test.js.snap index 1e46016a..a2bd9669 100644 --- a/src/Organizations/OrganizationForm/OrganizationSummaryForm/__snapshots__/OrganizationSummaryForm.test.js.snap +++ b/src/Organizations/OrganizationForm/OrganizationSummaryForm/__snapshots__/OrganizationSummaryForm.test.js.snap @@ -52,42 +52,50 @@ exports[`OrganizationSummaryForm should render correct structure 1`] = ` class="col-xs-6 col-md-3" >
-
- +
+ +
+ +
+
+
-
Date: Fri, 1 Mar 2024 12:00:47 +0000 Subject: [PATCH 13/16] test: Test fails on CI because of non mocked component -- easy fix --- .../OrganizationSummaryForm/OrganizationSummaryForm.test.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Organizations/OrganizationForm/OrganizationSummaryForm/OrganizationSummaryForm.test.js b/src/Organizations/OrganizationForm/OrganizationSummaryForm/OrganizationSummaryForm.test.js index f48ad93d..d727575d 100644 --- a/src/Organizations/OrganizationForm/OrganizationSummaryForm/OrganizationSummaryForm.test.js +++ b/src/Organizations/OrganizationForm/OrganizationSummaryForm/OrganizationSummaryForm.test.js @@ -22,6 +22,10 @@ jest.mock('../../../common/hooks', () => ({ ])), })); +jest.mock('@folio/service-interaction', () => ({ + NumberGeneratorModalButton: () =>
NumberGeneratorModalButton
+})); + const TestForm = stripesFinalForm({})( () => { return ( From 79e4c34c13d2648a05cd5ae34d0e4f8bf44e9ed8 Mon Sep 17 00:00:00 2001 From: Ethan Freestone Date: Thu, 28 Mar 2024 10:38:40 +0000 Subject: [PATCH 14/16] build: Change service interaction dependency to ^3.0.0 --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 6b0f273b..25b15d4f 100644 --- a/package.json +++ b/package.json @@ -331,7 +331,7 @@ "@bigtest/react": "^0.1.2", "@folio/eslint-config-stripes": "^7.0.0", "@folio/jest-config-stripes": "^2.0.0", - "@folio/service-interaction": "^2.0.0", + "@folio/service-interaction": "^3.0.0", "@folio/stripes": "^9.0.0", "@folio/stripes-cli": "^3.0.0", "@formatjs/cli": "^6.1.3", @@ -371,7 +371,7 @@ "redux-form": "^8.3.0" }, "peerDependencies": { - "@folio/service-interaction": "^2.0.0", + "@folio/service-interaction": "^3.0.0", "@folio/stripes": "^9.0.0", "react": "^18.2.0", "react-dom": "^18.2.0", From 5e4e4c2166f500b44b80451c27faf8e8b6a25c7f Mon Sep 17 00:00:00 2001 From: Ethan Freestone Date: Fri, 12 Apr 2024 13:32:13 +0100 Subject: [PATCH 15/16] refactor: Refactor tweaks Moved connected component outside of component render, removed default values --- src/Settings/NumberGeneratorOptions.js | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/Settings/NumberGeneratorOptions.js b/src/Settings/NumberGeneratorOptions.js index e49a4cb9..019c6603 100644 --- a/src/Settings/NumberGeneratorOptions.js +++ b/src/Settings/NumberGeneratorOptions.js @@ -3,18 +3,17 @@ import PropTypes from 'prop-types'; import { FormattedMessage } from 'react-intl'; import { Field } from 'react-final-form'; -import { stripesConnect, withStripes } from '@folio/stripes/core'; +import { + stripesConnect, + withStripes, +} from '@folio/stripes/core'; import { ConfigManager } from '@folio/stripes/smart-components'; import { Col, RadioButton, Row } from '@folio/stripes/components'; -const NumberGeneratorOptions = (props) => { - const ConnectedConfigManager = stripesConnect(ConfigManager); - - const defaultValues = { - useGenerator: 'useBoth', - }; +const ConnectedConfigManager = stripesConnect(ConfigManager); +const NumberGeneratorOptions = (props) => { const beforeSave = (data) => { return JSON.stringify(data); }; @@ -32,7 +31,6 @@ const NumberGeneratorOptions = (props) => { } return { - ...defaultValues, ...loadedValues, }; }; @@ -41,11 +39,11 @@ const NumberGeneratorOptions = (props) => { } moduleName="ORGANIZATIONS" onBeforeSave={beforeSave} stripes={props.stripes} - formType="final-form" > From bae809dcd8c2f5889f2560da8e143c918c3fcad4 Mon Sep 17 00:00:00 2001 From: Ethan Freestone Date: Tue, 7 May 2024 13:01:19 +0100 Subject: [PATCH 16/16] chore: MessageBanner Added messageBanner to settings page explaining the number generator options --- src/Settings/NumberGeneratorOptions.css | 5 +++++ src/Settings/NumberGeneratorOptions.js | 13 ++++++++++++- translations/ui-organizations/en.json | 1 + 3 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 src/Settings/NumberGeneratorOptions.css diff --git a/src/Settings/NumberGeneratorOptions.css b/src/Settings/NumberGeneratorOptions.css new file mode 100644 index 00000000..78ddf841 --- /dev/null +++ b/src/Settings/NumberGeneratorOptions.css @@ -0,0 +1,5 @@ +@import '@folio/stripes-components/lib/variables'; + +.marginBottomGutter { + margin-bottom: var(--gutter); +} diff --git a/src/Settings/NumberGeneratorOptions.js b/src/Settings/NumberGeneratorOptions.js index 019c6603..77ceb929 100644 --- a/src/Settings/NumberGeneratorOptions.js +++ b/src/Settings/NumberGeneratorOptions.js @@ -9,7 +9,9 @@ import { } from '@folio/stripes/core'; import { ConfigManager } from '@folio/stripes/smart-components'; -import { Col, RadioButton, Row } from '@folio/stripes/components'; +import { Col, MessageBanner, RadioButton, Row } from '@folio/stripes/components'; + +import css from './NumberGeneratorOptions.css'; const ConnectedConfigManager = stripesConnect(ConfigManager); @@ -45,6 +47,15 @@ const NumberGeneratorOptions = (props) => { onBeforeSave={beforeSave} stripes={props.stripes} > + + +
+ + + +
+ +