From bd2af0e982297d9ddd5a1f90f4d7be5c7bd00c3f Mon Sep 17 00:00:00 2001 From: Viktor van Wijk Date: Thu, 2 Jan 2025 11:36:47 +0100 Subject: [PATCH] :art: [#4908] Fix imports and black code --- .../form_design/RegistrationFields.stories.js | 3 +- .../admin/form_design/registrations/index.js | 2 +- .../registrations/json/JSONOptionsForm.js | 13 ++++--- .../registrations/json/JSONSummaryHandler.js | 10 ++---- .../json/JSONVariableConfigurationEditor.js | 34 ++++++++++--------- .../json/fields/FormVariablesSelect.js | 1 - .../json/fields/RelativeAPIEndpoint.js | 1 - .../json/fields/ServiceSelect.js | 6 +--- .../variables/VariablesEditor.stories.js | 12 +++---- .../registrations/contrib/json/config.py | 9 +++-- .../registrations/contrib/json/plugin.py | 26 +++++--------- .../contrib/json/tests/test_backend.py | 21 +++--------- .../contrib/json/tests/test_config_checks.py | 7 ++-- 13 files changed, 57 insertions(+), 88 deletions(-) diff --git a/src/openforms/js/components/admin/form_design/RegistrationFields.stories.js b/src/openforms/js/components/admin/form_design/RegistrationFields.stories.js index afba50818d..b37b03232d 100644 --- a/src/openforms/js/components/admin/form_design/RegistrationFields.stories.js +++ b/src/openforms/js/components/admin/form_design/RegistrationFields.stories.js @@ -398,7 +398,7 @@ export default { properties: { service: { enum: [1, 2], - enumNames: ['Service 1', 'Service 2'], + enumNames: ['Service 1', 'Service 2'], }, relativeApiEndpoint: { minLength: 1, @@ -1015,7 +1015,6 @@ export const STUFZDS = { }, }; - export const JSON = { args: { configuredBackends: [ diff --git a/src/openforms/js/components/admin/form_design/registrations/index.js b/src/openforms/js/components/admin/form_design/registrations/index.js index 9a973dc8f7..76cac9cef3 100644 --- a/src/openforms/js/components/admin/form_design/registrations/index.js +++ b/src/openforms/js/components/admin/form_design/registrations/index.js @@ -49,7 +49,7 @@ export const BACKEND_OPTIONS_FORMS = { form: StufZDSOptionsForm, }, 'microsoft-graph': {form: MSGraphOptionsForm}, - 'json': { + json: { form: JSONOptionsForm, configurableFromVariables: true, summaryHandler: JSONSummaryHandler, diff --git a/src/openforms/js/components/admin/form_design/registrations/json/JSONOptionsForm.js b/src/openforms/js/components/admin/form_design/registrations/json/JSONOptionsForm.js index 9bb72a1974..45bde93ab9 100644 --- a/src/openforms/js/components/admin/form_design/registrations/json/JSONOptionsForm.js +++ b/src/openforms/js/components/admin/form_design/registrations/json/JSONOptionsForm.js @@ -19,13 +19,12 @@ import FormVariablesSelect from './fields/FormVariablesSelect'; import RelativeAPIEndpoint from './fields/RelativeAPIEndpoint'; import ServiceSelect from './fields/ServiceSelect'; - const JSONOptionsForm = ({name, label, schema, formData, onChange}) => { const validationErrors = useContext(ValidationErrorContext); const relevantErrors = filterErrors(name, validationErrors); // Get form variables and create form variable options - const formContext = useContext(FormContext) + const formContext = useContext(FormContext); const formVariables = formContext.formVariables ?? []; const staticVariables = formContext.staticVariables ?? []; const allFormVariables = staticVariables.concat(formVariables); @@ -37,9 +36,9 @@ const JSONOptionsForm = ({name, label, schema, formData, onChange}) => { // Create service options const {service} = schema.properties; - const serviceOptions = getChoicesFromSchema( - service.enum, service.enumNames - ).map(([value, label]) => ({value, label})); + const serviceOptions = getChoicesFromSchema(service.enum, service.enumNames).map( + ([value, label]) => ({value, label}) + ); return ( { >
- + - +
diff --git a/src/openforms/js/components/admin/form_design/registrations/json/JSONSummaryHandler.js b/src/openforms/js/components/admin/form_design/registrations/json/JSONSummaryHandler.js index 5725103986..adffe2e145 100644 --- a/src/openforms/js/components/admin/form_design/registrations/json/JSONSummaryHandler.js +++ b/src/openforms/js/components/admin/form_design/registrations/json/JSONSummaryHandler.js @@ -3,18 +3,13 @@ import React from 'react'; import {FormattedMessage} from 'react-intl'; const JSONSummaryHandler = ({variable, backendOptions}) => { - const isIncluded = backendOptions.formVariables.includes(variable.key); if (isIncluded) { return ( - + ); - } - else { + } else { return ( { } }; - JSONSummaryHandler.propTypes = { variable: PropTypes.shape({ key: PropTypes.string.isRequired, diff --git a/src/openforms/js/components/admin/form_design/registrations/json/JSONVariableConfigurationEditor.js b/src/openforms/js/components/admin/form_design/registrations/json/JSONVariableConfigurationEditor.js index 579cdf5a5f..7ffc1bfa8d 100644 --- a/src/openforms/js/components/admin/form_design/registrations/json/JSONVariableConfigurationEditor.js +++ b/src/openforms/js/components/admin/form_design/registrations/json/JSONVariableConfigurationEditor.js @@ -1,17 +1,16 @@ import {useField} from 'formik'; import PropTypes from 'prop-types'; import React from 'react'; - import {FormattedMessage} from 'react-intl'; + import Field from 'components/admin/forms/Field'; import FormRow from 'components/admin/forms/FormRow'; import {Checkbox} from 'components/admin/forms/Inputs'; - const JSONVariableConfigurationEditor = ({variable}) => { const [fieldProps, , {setValue}] = useField('formVariables'); - const formVariables = fieldProps.value + const formVariables = fieldProps.value; const isIncluded = formVariables.includes(variable.key); return ( @@ -33,19 +32,23 @@ const JSONVariableConfigurationEditor = ({variable}) => { } checked={isIncluded} onChange={event => { - const formVariablesNew = formVariables.slice() + const formVariablesNew = formVariables.slice(); const index = formVariablesNew.indexOf(variable.key); if (event.target.checked) { - if (index !== -1) {throw new Error( - "This form variable is already on the list of " + - "form variables to include. This shouldn't happen." - );} + if (index !== -1) { + throw new Error( + 'This form variable is already on the list of ' + + "form variables to include. This shouldn't happen." + ); + } formVariablesNew.push(variable.key); } else { - if (index === -1) {throw new Error( - "This form variable is not yet on the list of " + - "form variables to include. This shouldn't happen." - );} + if (index === -1) { + throw new Error( + 'This form variable is not yet on the list of ' + + "form variables to include. This shouldn't happen." + ); + } formVariablesNew.splice(index, 1); } setValue(formVariablesNew); @@ -53,8 +56,8 @@ const JSONVariableConfigurationEditor = ({variable}) => { /> - ) -} + ); +}; JSONVariableConfigurationEditor.propTypes = { variable: PropTypes.shape({ @@ -62,5 +65,4 @@ JSONVariableConfigurationEditor.propTypes = { }).isRequired, }; - -export default JSONVariableConfigurationEditor +export default JSONVariableConfigurationEditor; diff --git a/src/openforms/js/components/admin/form_design/registrations/json/fields/FormVariablesSelect.js b/src/openforms/js/components/admin/form_design/registrations/json/fields/FormVariablesSelect.js index b653bd2711..c3f527f84d 100644 --- a/src/openforms/js/components/admin/form_design/registrations/json/fields/FormVariablesSelect.js +++ b/src/openforms/js/components/admin/form_design/registrations/json/fields/FormVariablesSelect.js @@ -7,7 +7,6 @@ import Field from 'components/admin/forms/Field'; import FormRow from 'components/admin/forms/FormRow'; import ReactSelect from 'components/admin/forms/ReactSelect'; - // TODO-4908: the select box does not change size when you add more form variables, which causes // selected form variables to be hidden const FormVariablesSelect = ({options}) => { diff --git a/src/openforms/js/components/admin/form_design/registrations/json/fields/RelativeAPIEndpoint.js b/src/openforms/js/components/admin/form_design/registrations/json/fields/RelativeAPIEndpoint.js index a4febbc941..a59c14e2b5 100644 --- a/src/openforms/js/components/admin/form_design/registrations/json/fields/RelativeAPIEndpoint.js +++ b/src/openforms/js/components/admin/form_design/registrations/json/fields/RelativeAPIEndpoint.js @@ -6,7 +6,6 @@ import Field from 'components/admin/forms/Field'; import FormRow from 'components/admin/forms/FormRow'; import {TextInput} from 'components/admin/forms/Inputs'; - const RelativeAPIEndpoint = () => { const [fieldProps] = useField('relativeApiEndpoint'); return ( diff --git a/src/openforms/js/components/admin/form_design/registrations/json/fields/ServiceSelect.js b/src/openforms/js/components/admin/form_design/registrations/json/fields/ServiceSelect.js index 2afc14d9ba..e834cae168 100644 --- a/src/openforms/js/components/admin/form_design/registrations/json/fields/ServiceSelect.js +++ b/src/openforms/js/components/admin/form_design/registrations/json/fields/ServiceSelect.js @@ -24,11 +24,7 @@ const ServiceSelect = ({options}) => { /> } > - + ); diff --git a/src/openforms/js/components/admin/form_design/variables/VariablesEditor.stories.js b/src/openforms/js/components/admin/form_design/variables/VariablesEditor.stories.js index b56ad0802a..5a66c3f1f9 100644 --- a/src/openforms/js/components/admin/form_design/variables/VariablesEditor.stories.js +++ b/src/openforms/js/components/admin/form_design/variables/VariablesEditor.stories.js @@ -625,7 +625,7 @@ export const WithJSONRegistrationBackend = { const saveButton = canvas.getByRole('button', {name: 'Opslaan'}); await userEvent.click(saveButton); - }) + }); await step('aSingleFile checkbox checked', async () => { await userEvent.click(editIcons[1]); @@ -635,20 +635,18 @@ export const WithJSONRegistrationBackend = { const saveButton = canvas.getByRole('button', {name: 'Opslaan'}); await userEvent.click(saveButton); - }) + }); await step('now checkbox checked', async () => { const staticVariables = canvas.getByRole('tab', {name: 'Vaste variabelen'}); await userEvent.click(staticVariables); - const editIcon = canvas.getByTitle('Registratie-instellingen bewerken') - await userEvent.click(editIcon) + const editIcon = canvas.getByTitle('Registratie-instellingen bewerken'); + await userEvent.click(editIcon); const checkbox = await canvas.findByRole('checkbox'); await expect(checkbox).toBeChecked(); - }) - - + }); }, }; diff --git a/src/openforms/registrations/contrib/json/config.py b/src/openforms/registrations/contrib/json/config.py index 2207fca476..832743732c 100644 --- a/src/openforms/registrations/contrib/json/config.py +++ b/src/openforms/registrations/contrib/json/config.py @@ -21,14 +21,18 @@ class JSONOptionsSerializer(JsonSchemaSerializerMixin, serializers.Serializer): relative_api_endpoint = serializers.CharField( max_length=255, label=_("Relative API endpoint"), - help_text=_("The API endpoint to send the data to (relative to the service API root)."), + help_text=_( + "The API endpoint to send the data to (relative to the service API root)." + ), allow_blank=True, required=False, ) form_variables = serializers.ListField( child=FormioVariableKeyField(max_length=50), label=_("Form variable key list"), - help_text=_("A list of form variables (can also include static variables) to use."), + help_text=_( + "A list of form variables (can also include static variables) to use." + ), required=True, min_length=1, ) @@ -41,6 +45,7 @@ class JSONOptions(TypedDict): This describes the shape of :attr:`JSONOptionsSerializer.validated_data`, after the input data has been cleaned/validated. """ + service: Required[Service] relative_api_endpoint: str form_variables: Required[list[str]] diff --git a/src/openforms/registrations/contrib/json/plugin.py b/src/openforms/registrations/contrib/json/plugin.py index 29016c8758..0b395acedd 100644 --- a/src/openforms/registrations/contrib/json/plugin.py +++ b/src/openforms/registrations/contrib/json/plugin.py @@ -1,7 +1,7 @@ import base64 -from django.utils.translation import gettext_lazy as _ from django.urls import reverse +from django.utils.translation import gettext_lazy as _ from requests import RequestException from zgw_consumers.client import build_client @@ -26,7 +26,7 @@ def register_submission(self, submission: Submission, options: JSONOptions) -> d # Encode (base64) and add attachments to values dict if their form keys were specified in the # form variables list for attachment in submission.attachments: - if not attachment.form_key in options["form_variables"]: + if attachment.form_key not in options["form_variables"]: continue options["form_variables"].remove(attachment.form_key) with attachment.content.open("rb") as f: @@ -54,20 +54,10 @@ def register_submission(self, submission: Submission, options: JSONOptions) -> d "$schema": "https://json-schema.org/draft/2020-12/schema", "type": "object", "properties": { - "static_var_1": { - "type": "string", - "pattern": "^cool_pattern$" - }, - "form_var_1": { - "type": "string" - }, - "form_var_2": { - "type": "string" - }, - "attachment": { - "type": "string", - "contentEncoding": "base64" - }, + "static_var_1": {"type": "string", "pattern": "^cool_pattern$"}, + "form_var_1": {"type": "string"}, + "form_var_2": {"type": "string"}, + "attachment": {"type": "string", "contentEncoding": "base64"}, }, "required": ["static_var_1", "form_var_1", "form_var_2"], "additionalProperties": False, @@ -107,7 +97,7 @@ def get_config_actions(self) -> list[tuple[str, str]]: _("Configuration"), reverse( "admin:registrations_json_jsonconfig_change", - args=(JSONConfig.singleton_instance_id,) - ) + args=(JSONConfig.singleton_instance_id,), + ), ) ] diff --git a/src/openforms/registrations/contrib/json/tests/test_backend.py b/src/openforms/registrations/contrib/json/tests/test_backend.py index d5d80dfb5b..3e8c2e53e1 100644 --- a/src/openforms/registrations/contrib/json/tests/test_backend.py +++ b/src/openforms/registrations/contrib/json/tests/test_backend.py @@ -2,8 +2,8 @@ from pathlib import Path from django.test import TestCase -from requests import RequestException +from requests import RequestException from zgw_consumers.test.factories import ServiceFactory from openforms.submissions.public_references import set_submission_reference @@ -15,7 +15,6 @@ from ..plugin import JSONRegistration - VCR_TEST_FILES = Path(__file__).parent / "files" @@ -75,20 +74,10 @@ def test_submission_with_json_backend(self): "$schema": "https://json-schema.org/draft/2020-12/schema", "type": "object", "properties": { - "static_var_1": { - "type": "string", - "pattern": "^cool_pattern$" - }, - "form_var_1": { - "type": "string" - }, - "form_var_2": { - "type": "string" - }, - "attachment": { - "type": "string", - "contentEncoding": "base64" - }, + "static_var_1": {"type": "string", "pattern": "^cool_pattern$"}, + "form_var_1": {"type": "string"}, + "form_var_2": {"type": "string"}, + "attachment": {"type": "string", "contentEncoding": "base64"}, }, "required": ["static_var_1", "form_var_1", "form_var_2"], "additionalProperties": False, diff --git a/src/openforms/registrations/contrib/json/tests/test_config_checks.py b/src/openforms/registrations/contrib/json/tests/test_config_checks.py index da94c5dbaa..a81fb30c36 100644 --- a/src/openforms/registrations/contrib/json/tests/test_config_checks.py +++ b/src/openforms/registrations/contrib/json/tests/test_config_checks.py @@ -11,7 +11,6 @@ from ..models import JSONConfig from ..plugin import JSONRegistration - VCR_TEST_FILES = Path(__file__).parent / "files" @@ -31,7 +30,7 @@ def test_config_check_happy_flow(self): with patch( "openforms.registrations.contrib.json.plugin.JSONConfig.get_solo", - return_value=config + return_value=config, ): json_plugin.check_config() @@ -41,7 +40,7 @@ def test_no_service_configured(self): with patch( "openforms.registrations.contrib.json.plugin.JSONConfig.get_solo", - return_value=config + return_value=config, ): self.assertRaises(InvalidPluginConfiguration, json_plugin.check_config) @@ -57,6 +56,6 @@ def test_invalid_response_from_api_test_connection_endpoint(self): with patch( "openforms.registrations.contrib.json.plugin.JSONConfig.get_solo", - return_value=config + return_value=config, ): self.assertRaises(InvalidPluginConfiguration, json_plugin.check_config)