Skip to content

Commit

Permalink
✨ [#4398] Add authAttributePath to objects prefill form
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenbal committed Nov 25, 2024
1 parent e1d5777 commit 2eae26d
Show file tree
Hide file tree
Showing 11 changed files with 166 additions and 139 deletions.
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
import {useField} from 'formik';
import PropTypes from 'prop-types';
import {FormattedMessage} from 'react-intl';
import {useContext} from 'react';
import {FormattedMessage, useIntl} from 'react-intl';

import {FeatureFlagsContext} from 'components/admin/form_design/Context';
import Field from 'components/admin/forms/Field';
import Fieldset from 'components/admin/forms/Fieldset';
import FormRow from 'components/admin/forms/FormRow';
import {TextArea, TextInput} from 'components/admin/forms/Inputs';
import {
AuthAttributePath,
ObjectTypeSelect,
ObjectTypeVersionSelect,
ObjectsAPIGroup,
} from 'components/admin/forms/objects_api';
import ErrorBoundary from 'components/errors/ErrorBoundary';

import {
AuthAttributePath,
DocumentTypesFieldet,
LegacyDocumentTypesFieldet,
OrganisationRSIN,
Expand All @@ -31,89 +33,94 @@ const onApiGroupChange = prevValues => ({
objecttypeVersion: undefined,
});

const LegacyConfigFields = ({apiGroupChoices}) => (
<>
<Fieldset>
<ObjectsAPIGroup apiGroupChoices={apiGroupChoices} onApiGroupChange={onApiGroupChange} />
const LegacyConfigFields = ({apiGroupChoices}) => {
const intl = useIntl();
const {REGISTRATION_OBJECTS_API_ENABLE_EXISTING_OBJECT_INTEGRATION = false} =
useContext(FeatureFlagsContext);

const [updateExistingObject] = useField('updateExistingObject');
const authAttributePathRequired = !!updateExistingObject.value;

return (
<>
<Fieldset>
<ObjectsAPIGroup apiGroupChoices={apiGroupChoices} onApiGroupChange={onApiGroupChange} />
<ErrorBoundary
errorMessage={
<FormattedMessage
description="Legacy Objects API registrations options: unknown error"
defaultMessage={`Something went wrong retrieving the available object types and/or versions.
Please check that the services in the selected API group are configured correctly.`}
/>
}
>
<ObjectTypeSelect
label={intl.formatMessage({
description: "Objects API registration options 'Objecttype' label",
defaultMessage: 'Objecttype',
})}
helpText={intl.formatMessage({
description: "Objects API registration options 'Objecttype' helpText",
defaultMessage: 'The registration result will be an object from the selected type.',
})}
/>
<ObjectTypeVersionSelect
label={intl.formatMessage({
description: "Objects API registration options 'objecttypeVersion' label",
defaultMessage: 'Version',
})}
/>
</ErrorBoundary>
</Fieldset>

<Fieldset
title={
<FormattedMessage
description="Objects registration: object definition"
defaultMessage="Object and/or product request definition"
/>
}
collapsible
initialCollapsed={false}
>
<ProductAanvraag />
<ContentJSON />
<PaymentStatusUpdateJSON />
</Fieldset>

<ErrorBoundary
errorMessage={
<FormattedMessage
description="Legacy Objects API registrations options: unknown error"
defaultMessage={`Something went wrong retrieving the available object types and/or versions.
Please check that the services in the selected API group are configured correctly.`}
description="Objects API registrations options: document types selection error"
defaultMessage="Something went wrong while retrieving the available catalogues and/or document types."
/>
}
>
<ObjectTypeSelect
label={
<FormattedMessage
description="Objects API registration options 'Objecttype' label"
defaultMessage="Objecttype"
/>
}
helpText={
<FormattedMessage
description="Objects API registration options 'Objecttype' helpText"
defaultMessage="The registration result will be an object from the selected type."
/>
}
/>
<ObjectTypeVersionSelect
label={
<FormattedMessage
description="Objects API registration options 'objecttypeVersion' label"
defaultMessage="Version"
/>
}
/>
<DocumentTypesFieldet />
</ErrorBoundary>
</Fieldset>

<Fieldset
title={
<FormattedMessage
description="Objects registration: object definition"
defaultMessage="Object and/or product request definition"
/>
}
collapsible
initialCollapsed={false}
>
<ProductAanvraag />
<ContentJSON />
<PaymentStatusUpdateJSON />
</Fieldset>

<ErrorBoundary
errorMessage={
<FormattedMessage
description="Objects API registrations options: document types selection error"
defaultMessage="Something went wrong while retrieving the available catalogues and/or document types."
/>
}
>
<DocumentTypesFieldet />
</ErrorBoundary>

<LegacyDocumentTypesFieldet />

<Fieldset
title={
<FormattedMessage
description="Objects registration: other options"
defaultMessage="Other options"
/>
}
collapsible
fieldNames={['organisatieRsin']}
>
<UploadSubmissionCsv />
<UpdateExistingObject />
<AuthAttributePath />
<OrganisationRSIN />
</Fieldset>
</>
);
<LegacyDocumentTypesFieldet />

<Fieldset
title={
<FormattedMessage
description="Objects registration: other options"
defaultMessage="Other options"
/>
}
collapsible
fieldNames={['organisatieRsin']}
>
<UploadSubmissionCsv />
<UpdateExistingObject />
{REGISTRATION_OBJECTS_API_ENABLE_EXISTING_OBJECT_INTEGRATION ? (
<AuthAttributePath name={'authAttributePath'} required={authAttributePathRequired} />
) : null}
<OrganisationRSIN />
</Fieldset>
</>
);
};

LegacyConfigFields.propTypes = {
apiGroupChoices: PropTypes.arrayOf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ ObjectsApiOptionsForm.propTypes = {
objecttype: PropTypes.string,
objecttypeVersion: PropTypes.number,
updateExistingObject: PropTypes.bool,
authAttributePath: PropTypes.bool,
authAttributePath: PropTypes.array,
productaanvraagType: PropTypes.string,
informatieobjecttypeSubmissionReport: PropTypes.string,
uploadSubmissionCsv: PropTypes.bool,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
import {useFormikContext} from 'formik';
import {useField, useFormikContext} from 'formik';
import PropTypes from 'prop-types';
import {useContext} from 'react';
import {useIntl} from 'react-intl';
import {FormattedMessage} from 'react-intl';

import {FeatureFlagsContext} from 'components/admin/form_design/Context';
import useConfirm from 'components/admin/form_design/useConfirm';
import Fieldset from 'components/admin/forms/Fieldset';
import {
AuthAttributePath,
ObjectTypeSelect,
ObjectTypeVersionSelect,
ObjectsAPIGroup,
} from 'components/admin/forms/objects_api';
import ErrorBoundary from 'components/errors/ErrorBoundary';

import {
AuthAttributePath,
DocumentTypesFieldet,
LegacyDocumentTypesFieldet,
OrganisationRSIN,
Expand All @@ -31,6 +34,13 @@ const onApiGroupChange = prevValues => ({
});

const V2ConfigFields = ({apiGroupChoices}) => {
const intl = useIntl();
const {REGISTRATION_OBJECTS_API_ENABLE_EXISTING_OBJECT_INTEGRATION = false} =
useContext(FeatureFlagsContext);

const [updateExistingObject] = useField('updateExistingObject');
const authAttributePathRequired = !!updateExistingObject.value;

const {
values: {variablesMapping = []},
setFieldValue,
Expand Down Expand Up @@ -70,18 +80,14 @@ const V2ConfigFields = ({apiGroupChoices}) => {
}
>
<ObjectTypeSelect
label={
<FormattedMessage
description="Objects API registration options 'Objecttype' label"
defaultMessage="Objecttype"
/>
}
helpText={
<FormattedMessage
description="Objects API registration options 'Objecttype' helpText"
defaultMessage="The registration result will be an object from the selected type."
/>
}
label={intl.formatMessage({
description: "Objects API registration options 'Objecttype' label",
defaultMessage: 'Objecttype',
})}
helpText={intl.formatMessage({
description: "Objects API registration options 'Objecttype' helpText",
defaultMessage: 'The registration result will be an object from the selected type.',
})}
onChangeCheck={async () => {
if (variablesMapping.length === 0) return true;
const confirmSwitch = await openObjectTypeConfirmation();
Expand All @@ -101,12 +107,10 @@ const V2ConfigFields = ({apiGroupChoices}) => {
}
>
<ObjectTypeVersionSelect
label={
<FormattedMessage
description="Objects API registration options 'objecttypeVersion' label"
defaultMessage="Version"
/>
}
label={intl.formatMessage({
description: "Objects API registration options 'objecttypeVersion' label",
defaultMessage: 'Version',
})}
/>
</ErrorBoundary>
</Fieldset>
Expand Down Expand Up @@ -136,7 +140,9 @@ const V2ConfigFields = ({apiGroupChoices}) => {
>
<UploadSubmissionCsv />
<UpdateExistingObject />
<AuthAttributePath />
{REGISTRATION_OBJECTS_API_ENABLE_EXISTING_OBJECT_INTEGRATION ? (
<AuthAttributePath name={'authAttributePath'} required={authAttributePathRequired} />
) : null}
<OrganisationRSIN />
</Fieldset>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@ export {DocumentTypesFieldet} from './DocumentTypes';
export {default as UpdateExistingObject} from './UpdateExistingObject';
export {default as UploadSubmissionCsv} from './UploadSubmissionCSV';
export {default as OrganisationRSIN} from './OrganisationRSIN';
export {default as AuthAttributePath} from './AuthAttributePath';
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,7 @@ export const ConfigurePrefillObjectsAPIWithCopyButton = {
objectsApiGroup: 1,
objecttype: '2c77babf-a967-4057-9969-0200320d23f1',
objecttypeVersion: 2,
authAttributePath: ['path', 'to', 'bsn'],
variablesMapping: [
{
variableKey: 'formioComponent',
Expand Down Expand Up @@ -705,7 +706,6 @@ export const ConfigurePrefillObjectsAPIWithCopyButton = {
// Cannot do selectOption with react-select
const options = await canvas.findAllByText('Example Objects API reg.');
const option = options[1];
console.log(option);
await userEvent.click(option);

const copyButton = await canvas.findByRole('button', {
Expand Down Expand Up @@ -735,6 +735,9 @@ export const ConfigurePrefillObjectsAPIWithCopyButton = {
'options.objecttypeUuid': '2c77babf-a967-4057-9969-0200320d23f1',
'options.objecttypeVersion': '2',
});
expect(canvas.getByTestId('options.authAttributePath-0')).toHaveValue('path');
expect(canvas.getByTestId('options.authAttributePath-1')).toHaveValue('to');
expect(canvas.getByTestId('options.authAttributePath-2')).toHaveValue('bsn');

expect(propertyDropdowns[0]).toHaveValue(serializeValue(['height']));
expect(propertyDropdowns[1]).toHaveValue(serializeValue(['species']));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const CopyConfigurationFromRegistrationBackend = ({backends, setShowCopyButton})
onClick={async e => {
e.preventDefault();
const confirmSwitch = await openCopyConfigurationConfirmationModal();
if (confirmSwitch) {
if (confirmSwitch && selectedBackend) {
setValues(prevValues => ({
...prevValues,
// Trying to set multiple nested values doesn't work, since it sets them
Expand All @@ -68,6 +68,7 @@ const CopyConfigurationFromRegistrationBackend = ({backends, setShowCopyButton})
objectsApiGroup: selectedBackend.options.objectsApiGroup,
objecttypeUuid: selectedBackend.options.objecttype,
objecttypeVersion: selectedBackend.options.objecttypeVersion,
authAttributePath: selectedBackend.options.authAttributePath,
variablesMapping: selectedBackend.options.variablesMapping,
},
}));
Expand Down
Loading

0 comments on commit 2eae26d

Please sign in to comment.