From 8360c81bf6c6be701830f94dda4f31ddc0a083d9 Mon Sep 17 00:00:00 2001 From: Viicos <65306057+Viicos@users.noreply.github.com> Date: Wed, 21 Feb 2024 17:37:34 +0100 Subject: [PATCH] [#3688] Complete prop types and small fixes --- .../objectsapi/LegacyConfigFields.js | 20 +++++++++++++ .../objectsapi/ObjectTypeSelect.js | 5 +--- .../objectsapi/ObjectTypeVersionSelect.js | 28 +++++++++++-------- .../objectsapi/ObjectsApiOptionsFormFields.js | 27 ++++++++++++++++-- .../objectsapi/V2ConfigFields.js | 19 +++++++++++-- 5 files changed, 79 insertions(+), 20 deletions(-) diff --git a/src/openforms/js/components/admin/form_design/registrations/objectsapi/LegacyConfigFields.js b/src/openforms/js/components/admin/form_design/registrations/objectsapi/LegacyConfigFields.js index f38549ef09..53e04e8932 100644 --- a/src/openforms/js/components/admin/form_design/registrations/objectsapi/LegacyConfigFields.js +++ b/src/openforms/js/components/admin/form_design/registrations/objectsapi/LegacyConfigFields.js @@ -1,3 +1,4 @@ +import PropTypes from 'prop-types'; import React, {useContext} from 'react'; import {useIntl} from 'react-intl'; @@ -263,4 +264,23 @@ const LegacyConfigFields = ({index, name, formData, onChange}) => { ); }; +LegacyConfigFields.propTypes = { + index: PropTypes.number, + name: PropTypes.string, + formData: PropTypes.shape({ + version: PropTypes.number, + objecttype: PropTypes.string, + objecttypeVersion: PropTypes.string, + productaanvraagType: PropTypes.string, + informatieobjecttypeSubmissionReport: PropTypes.string, + uploadSubmissionCsv: PropTypes.string, + informatieobjecttypeSubmissionCsv: PropTypes.string, + informatieobjecttypeAttachment: PropTypes.string, + organisatieRsin: PropTypes.string, + contentJson: PropTypes.string, + paymentStatusUpdateJson: PropTypes.string, + }), + onChange: PropTypes.func.isRequired, +}; + export default LegacyConfigFields; diff --git a/src/openforms/js/components/admin/form_design/registrations/objectsapi/ObjectTypeSelect.js b/src/openforms/js/components/admin/form_design/registrations/objectsapi/ObjectTypeSelect.js index 720c06f11b..398b3d8351 100644 --- a/src/openforms/js/components/admin/form_design/registrations/objectsapi/ObjectTypeSelect.js +++ b/src/openforms/js/components/admin/form_design/registrations/objectsapi/ObjectTypeSelect.js @@ -49,12 +49,9 @@ const ObjectTypeSelect = ({availableObjectTypesState, objecttype, onChange}) => }; ObjectTypeSelect.propTypes = { - /** - * URL to the objecttype in the Object types API. - */ + availableObjectTypesState: PropTypes.object.isRequired, objecttype: PropTypes.string.isRequired, onChange: PropTypes.func.isRequired, - onLoadingError: PropTypes.func.isRequired, }; export default ObjectTypeSelect; diff --git a/src/openforms/js/components/admin/form_design/registrations/objectsapi/ObjectTypeVersionSelect.js b/src/openforms/js/components/admin/form_design/registrations/objectsapi/ObjectTypeVersionSelect.js index 3e01bb0e03..68991d2619 100644 --- a/src/openforms/js/components/admin/form_design/registrations/objectsapi/ObjectTypeVersionSelect.js +++ b/src/openforms/js/components/admin/form_design/registrations/objectsapi/ObjectTypeVersionSelect.js @@ -1,3 +1,4 @@ +import PropTypes from 'prop-types'; import React, {useEffect} from 'react'; import useAsync from 'react-use/esm/useAsync'; @@ -29,7 +30,7 @@ const ObjectTypeVersionSelect = ({ value: availableVersions = [], error, } = useAsync(async () => { - const objecttype = availableObjecttypes.find(ot => ot.url == selectedObjecttype); + const objecttype = availableObjecttypes.find(ot => ot.url === selectedObjecttype); // no match -> no versions to retrieve; if (!objecttype) return []; @@ -53,7 +54,7 @@ const ObjectTypeVersionSelect = ({ // synchronize the UI state back to the form state) useEffect(() => { // do nothing if no options have been loaded - if (loading || availableVersions.length == 0) return; + if (loading || availableVersions.length === 0) return; // check if a valid option is selected, if this is the case -> do nothing const isOptionPresent = availableVersions.find( @@ -67,16 +68,21 @@ const ObjectTypeVersionSelect = ({ }); return ( - <> - ); }; +ObjectTypeVersionSelect.propTypes = { + availableObjecttypes: PropTypes.array, + selectedObjecttype: PropTypes.string.isRequired, + selectedVersion: PropTypes.string.isRequired, + onChange: PropTypes.func.isRequired, +}; + export default ObjectTypeVersionSelect; diff --git a/src/openforms/js/components/admin/form_design/registrations/objectsapi/ObjectsApiOptionsFormFields.js b/src/openforms/js/components/admin/form_design/registrations/objectsapi/ObjectsApiOptionsFormFields.js index b3a71e4f1d..fcb713c08e 100644 --- a/src/openforms/js/components/admin/form_design/registrations/objectsapi/ObjectsApiOptionsFormFields.js +++ b/src/openforms/js/components/admin/form_design/registrations/objectsapi/ObjectsApiOptionsFormFields.js @@ -1,4 +1,5 @@ import {produce} from 'immer'; +import PropTypes from 'prop-types'; import React from 'react'; import {FormattedMessage, useIntl} from 'react-intl'; import {TabList, TabPanel, Tabs} from 'react-tabs'; @@ -30,15 +31,15 @@ const ObjectsApiOptionsFormFields = ({index, name, schema, formData, onChange}) const {version = 1} = formData; - const changeVersion = index => { - if (index === 1) { + const changeVersion = v => { + if (v === 1) { const confirmV2Switch = window.confirm(v2SwitchMessage); if (!confirmV2Switch) return; } onChange( produce(formData, draft => { - draft.version = index + 1; + draft.version = v + 1; delete draft.contentJson; delete draft.paymentStatusUpdateJson; }) @@ -99,4 +100,24 @@ const ObjectsApiOptionsFormFields = ({index, name, schema, formData, onChange}) ); }; +ObjectsApiOptionsFormFields.propTypes = { + index: PropTypes.number, + name: PropTypes.string, + schema: PropTypes.any, + formData: PropTypes.shape({ + version: PropTypes.number, + objecttype: PropTypes.string, + objecttypeVersion: PropTypes.string, + productaanvraagType: PropTypes.string, + informatieobjecttypeSubmissionReport: PropTypes.string, + uploadSubmissionCsv: PropTypes.string, + informatieobjecttypeSubmissionCsv: PropTypes.string, + informatieobjecttypeAttachment: PropTypes.string, + organisatieRsin: PropTypes.string, + contentJson: PropTypes.string, + paymentStatusUpdateJson: PropTypes.string, + }), + onChange: PropTypes.func.isRequired, +}; + export default ObjectsApiOptionsFormFields; diff --git a/src/openforms/js/components/admin/form_design/registrations/objectsapi/V2ConfigFields.js b/src/openforms/js/components/admin/form_design/registrations/objectsapi/V2ConfigFields.js index 903b9e2b25..6e328456a8 100644 --- a/src/openforms/js/components/admin/form_design/registrations/objectsapi/V2ConfigFields.js +++ b/src/openforms/js/components/admin/form_design/registrations/objectsapi/V2ConfigFields.js @@ -1,5 +1,5 @@ import PropTypes from 'prop-types'; -import React, {useContext, useState} from 'react'; +import React, {useContext} from 'react'; import {FormattedMessage, useIntl} from 'react-intl'; import {CustomFieldTemplate} from 'components/admin/RJSFWrapper'; @@ -244,7 +244,22 @@ const V2ConfigFields = ({index, name, formData, onChange}) => { }; V2ConfigFields.propTypes = { - index: PropTypes.number.isRequired, + index: PropTypes.number, + name: PropTypes.string, + formData: PropTypes.shape({ + version: PropTypes.number, + objecttype: PropTypes.string, + objecttypeVersion: PropTypes.string, + productaanvraagType: PropTypes.string, + informatieobjecttypeSubmissionReport: PropTypes.string, + uploadSubmissionCsv: PropTypes.string, + informatieobjecttypeSubmissionCsv: PropTypes.string, + informatieobjecttypeAttachment: PropTypes.string, + organisatieRsin: PropTypes.string, + contentJson: PropTypes.string, + paymentStatusUpdateJson: PropTypes.string, + }), + onChange: PropTypes.func.isRequired, }; export default V2ConfigFields;