Skip to content

Commit

Permalink
[#3688] Complete prop types and small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Viicos committed Feb 21, 2024
1 parent 05e6346 commit 8360c81
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import PropTypes from 'prop-types';
import React, {useContext} from 'react';
import {useIntl} from 'react-intl';

Expand Down Expand Up @@ -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;
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import PropTypes from 'prop-types';
import React, {useEffect} from 'react';
import useAsync from 'react-use/esm/useAsync';

Expand Down Expand Up @@ -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 [];

Expand All @@ -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(
Expand All @@ -67,16 +68,21 @@ const ObjectTypeVersionSelect = ({
});

return (
<>
<Select
id="root_objecttypeVersion"
name="objecttypeVersion"
choices={choices}
value={selectedVersion ?? ''}
onChange={onChange}
/>
</>
<Select
id="root_objecttypeVersion"
name="objecttypeVersion"
choices={choices}
value={selectedVersion ?? ''}
onChange={onChange}
/>
);
};

ObjectTypeVersionSelect.propTypes = {
availableObjecttypes: PropTypes.array,
selectedObjecttype: PropTypes.string.isRequired,
selectedVersion: PropTypes.string.isRequired,
onChange: PropTypes.func.isRequired,
};

export default ObjectTypeVersionSelect;
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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;
})
Expand Down Expand Up @@ -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;
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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;

0 comments on commit 8360c81

Please sign in to comment.