Skip to content

Commit

Permalink
🚧 [#5012] WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
viktorvanwijk committed Jan 29, 2025
1 parent 713dfe2 commit 1bab25e
Show file tree
Hide file tree
Showing 14 changed files with 387 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def as_json_schema(self):
return {
"title": "Authentication type",
"type": "string",
"enum": AuthAttribute.values,
"enum": [*AuthAttribute.values, ""],
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -771,6 +771,8 @@ export const ConfiguredBackends = {
service: 1,
path: 'example/endpoint',
variables: [],
requiredMetadataVariables: [],
additionalMetadataVariables: [],
},
},
],
Expand Down Expand Up @@ -1030,6 +1032,8 @@ export const JSONDump = {
service: 1,
path: 'example/endpoint',
variables: [],
requiredMetadataVariables: ["form_name"],
additionalMetadataVariables: ["auth_bsn"],
},
},
],
Expand Down Expand Up @@ -1089,7 +1093,7 @@ export const JSONDump = {
formDefinition: null,
name: 'BSN',
key: 'auth_bsn',
source: 'static',
source: '',
prefillPlugin: '',
prefillAttribute: '',
prefillIdentifierRole: '',
Expand All @@ -1100,6 +1104,22 @@ export const JSONDump = {
serviceFetchConfiguration: undefined,
initialValue: '',
},
{
form: null,
formDefinition: null,
name: 'Form name',
key: 'form_name',
source: '',
prefillPlugin: '',
prefillAttribute: '',
prefillIdentifierRole: '',
prefillOptions: {},
dataType: 'string',
dataFormat: '',
isSensitiveData: false,
serviceFetchConfiguration: undefined,
initialValue: '',
}
],
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
} from 'components/admin/forms/ValidationErrors';
import {getChoicesFromSchema} from 'utils/json-schema';

import {Path, ServiceSelect, Variables} from './fields';
import {MetadataVariables, Path, ServiceSelect, Variables} from './fields';

const JSONDumpOptionsForm = ({name, label, schema, formData, onChange}) => {
const validationErrors = useContext(ValidationErrorContext);
Expand All @@ -38,6 +38,8 @@ const JSONDumpOptionsForm = ({name, label, schema, formData, onChange}) => {
service: null,
path: '',
variables: [],
requiredMetadataVariables: [],
additionalMetadataVariables: [],
...formData,
}}
onSubmit={values => onChange({formData: values})}
Expand All @@ -48,6 +50,7 @@ const JSONDumpOptionsForm = ({name, label, schema, formData, onChange}) => {
<ServiceSelect options={serviceOptions} />
<Path />
<Variables />
<MetadataVariables />
</Fieldset>
</ValidationErrorsProvider>
</ModalOptionsConfiguration>
Expand All @@ -69,6 +72,8 @@ JSONDumpOptionsForm.propTypes = {
service: PropTypes.number,
path: PropTypes.string,
variables: PropTypes.arrayOf(PropTypes.string),
requiredMetadataVariables: PropTypes.arrayOf(PropTypes.string),
additionalMetadataVariables: PropTypes.arrayOf(PropTypes.string)
}),
onChange: PropTypes.func.isRequired,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,39 @@ import PropTypes from 'prop-types';
import React from 'react';

import {IconNo, IconYes} from 'components/admin/BooleanIcons';
import {FormattedMessage} from 'react-intl';

const JSONDumpSummaryHandler = ({variable, backendOptions}) => {
const isIncluded = backendOptions.variables.includes(variable.key);
const isIncludedInVariables = backendOptions.variables.includes(variable.key)
const isIncludedInMetadata = backendOptions.requiredMetadataVariables.includes(variable.key)
|| backendOptions.additionalMetadataVariables.includes(variable.key)

return isIncluded ? <IconYes /> : <IconNo />;
return (
<>
<FormattedMessage
description="Label indicating the 'values' part of the data"
defaultMessage="Values: "
/>
{isIncludedInVariables ? <IconYes /> : <IconNo />}
{/*TODO-5012: maybe exclude this for non static variables?*/}
<br />
<FormattedMessage
description="Label indicating the 'metadata' part of the data"
defaultMessage="Metadata: "
/>
{isIncludedInMetadata ? <IconYes /> : <IconNo />}
</>
);
};

JSONDumpSummaryHandler.propTypes = {
variable: PropTypes.shape({
key: PropTypes.string.isRequired,
source: PropTypes.string.isRequired,
}).isRequired,
backendOptions: PropTypes.shape({
variables: PropTypes.arrayOf(PropTypes.string).isRequired,
requiredMetadataVariables: PropTypes.arrayOf(PropTypes.string).isRequired,
additionalMetadataVariables: PropTypes.arrayOf(PropTypes.string).isRequired,
}).isRequired,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,39 +9,72 @@ import {Checkbox} from 'components/admin/forms/Inputs';

const JSONDumpVariableConfigurationEditor = ({variable}) => {
const {
values: {variables = []},
values: {variables = [], additionalMetadataVariables = [], requiredMetadataVariables = []},
setFieldValue,
} = useFormikContext();
const isIncluded = variables.includes(variable.key);
const isRequiredInMetadata = requiredMetadataVariables.includes(variable.key)
const isInAdditionalMetadata = additionalMetadataVariables.includes(variable.key)

return (
<FormRow>
<Field name="includeVariable">
<Checkbox
name="includeVariableCheckbox"
label={
<FormattedMessage
description="'Include variable' checkbox label"
defaultMessage="Include variable"
/>
}
helpText={
<FormattedMessage
description="'Include variable' checkbox help text"
defaultMessage="Whether to include this variable in the data to be sent."
/>
}
checked={isIncluded}
onChange={event => {
const shouldBeIncluded = event.target.checked;
const newVariables = shouldBeIncluded
? [...variables, variable.key] // add the variable to the array
: variables.filter(key => key !== variable.key); // remove the variable from the array
setFieldValue('variables', newVariables);
}}
/>
</Field>
</FormRow>
<>
<FormRow>
<Field name="includeVariable">
<Checkbox
name="includeVariableCheckbox"
label={
<FormattedMessage
description="'Include variable' checkbox label"
defaultMessage="Include variable"
/>
}
helpText={
<FormattedMessage
description="'Include variable' checkbox help text"
defaultMessage="Whether to include this variable in the data to be sent."
/>
}
checked={isIncluded}
onChange={event => {
const shouldBeIncluded = event.target.checked;
const newVariables = shouldBeIncluded
? [...variables, variable.key] // add the variable to the array
: variables.filter(key => key !== variable.key); // remove the variable from the array
setFieldValue('variables', newVariables);
}}
/>
</Field>
</FormRow>

<FormRow>
<Field name="includeVariableInMetadata">
<Checkbox
name="includeVariableInMetadataCheckbox"
label={
<FormattedMessage
description="'Include variable in metadata' checkbox label"
defaultMessage="Include variable in metadata"
/>
}
helpText={
<FormattedMessage
description="'Include variable in metadata' checkbox help text"
defaultMessage="Whether to include this variable in the metadata to be sent."
/>
}
checked={isInAdditionalMetadata || isRequiredInMetadata}
onChange={event => {
const shouldBeIncluded = event.target.checked;
const newVariables = shouldBeIncluded
? [...additionalMetadataVariables, variable.key] // add the variable to the array
: additionalMetadataVariables.filter(key => key !== variable.key); // remove the variable from the array
setFieldValue('additionalMetadataVariables', newVariables);
}}
disabled={isRequiredInMetadata || variable.source !== ""} // disable if it is not required or the variable is not a static variable
/>
</Field>
</FormRow>
</>
);
};

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { useField } from 'formik';
import React from 'react';
import { FormattedMessage } from 'react-intl';



import Field from 'components/admin/forms/Field';
import FormRow from 'components/admin/forms/FormRow';
import VariableSelection from 'components/admin/forms/VariableSelection';


// TODO-5012: rename to additionalMetadataVariables?
const MetadataVariables = () => {
const [fieldProps] = useField('additionalMetadataVariables');
const [, {value}] = useField('requiredMetadataVariables');

return (
<FormRow>
<Field
name="additionalMetadataVariables"
label={
<FormattedMessage
description="JSON registration options 'additionalMetadataVariables' label"
defaultMessage="Additional metadata variables"
/>
}
helpText={
<FormattedMessage
description="JSON registration options 'additionalMetadataVariables' helpText"
defaultMessage="Which additional variables to include in the metadata (the following are already included by default: {alreadyIncluded})"
values={{alreadyIncluded: value.join(", ")}}
/>
}
noManageChildProps
>
<VariableSelection
{...fieldProps}
isMulti
closeMenuOnSelect={false}
includeStaticVariables
filter={variable => variable.source === "" && !value.includes(variable.key)} // Only show static variables and variables which are not already required
/>
</Field>
</FormRow>
);
};

export default MetadataVariables;
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import MetadataVariables from './MetadataVariables';
import Path from './Path';
import ServiceSelect from './ServiceSelect';
import Variables from './Variables';

export {Path, ServiceSelect, Variables};
export {MetadataVariables, Path, ServiceSelect, Variables};
Original file line number Diff line number Diff line change
Expand Up @@ -664,10 +664,35 @@ export const WithJSONDumpRegistrationBackend = {
options: {
service: 2,
path: 'test',
variables: ['aSingleFile', 'now'],
variables: ['aSingleFile'],
requiredMetadataVariables: ['public_registration_reference'],
additionalMetadataVariables: ['now']
},
},
],
registrationPluginsVariables: [
{
pluginIdentifier: 'json_dump',
pluginVerboseName: 'JSON dump registration',
pluginVariables: [
{
form: null,
formDefinition: null,
name: 'Public registration reference',
key: 'public_registration_reference',
source: '',
prefillPlugin: '',
prefillAttribute: '',
prefillIdentifierRole: 'main',
dataType: 'string',
dataFormat: '',
isSensitiveData: false,
serviceFetchConfiguration: undefined,
initialValue: '',
},
],
},
],
},
play: async ({canvasElement, step}) => {
const canvas = within(canvasElement);
Expand Down
7 changes: 6 additions & 1 deletion src/openforms/js/components/admin/forms/VariableSelection.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ const VariableOption = props => {

const allowAny = () => true;

// TODO-5012: can we add the registrationPluginsVariables as well? Seems difficult, as there is no
// guarantee that the names of the variables are unique across different registration plugins.
// They would all be added under the static variables label, as they don't have a source (not
// user-defined nor component), which means they might get overwritten. I could change the grouping
// behaviour, but not sure if this is something we should be doing
const VariableSelection = ({
id,
name,
Expand All @@ -46,7 +51,7 @@ const VariableSelection = ({
filter = allowAny,
...props
}) => {
const {formSteps, formVariables, staticVariables} = useContext(FormContext);
const {formSteps, formVariables, staticVariables, registrationPluginsVariables, registrationBackends} = useContext(FormContext);
const intl = useIntl();

let formDefinitionsNames = {};
Expand Down
22 changes: 22 additions & 0 deletions src/openforms/registrations/contrib/json_dump/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,26 @@ class JSONDumpOptionsSerializer(JsonSchemaSerializerMixin, serializers.Serialize
required=True,
min_length=1,
)
required_metadata_variables = serializers.ReadOnlyField(
default=[
"public_reference",
"form_name",
"form_version",
"registration_timestamp",
"auth_type",
],
label=_("Required metadata variable key list"),
help_text=_(
"A list of required variables to use in the metadata. These include "
"the registration variables of the JSON dump plugin"
),
)
additional_metadata_variables = serializers.ListField(
child=FormioVariableKeyField(),
label=_("Additional metadata variable key list"),
help_text=_("A list of additional variables to use in the metadata"),
required=True,
)


class JSONDumpOptions(TypedDict):
Expand All @@ -60,3 +80,5 @@ class JSONDumpOptions(TypedDict):
service: Service
path: str
variables: list[str]
required_metadata_variables: list[str]
additional_metadata_variables: list[str]
Loading

0 comments on commit 1bab25e

Please sign in to comment.