Skip to content

Commit

Permalink
🚧 [#4908] WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
viktorvanwijk committed Dec 19, 2024
1 parent eedffb3 commit a6c3e5d
Show file tree
Hide file tree
Showing 9 changed files with 186 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/openforms/conf/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@
"openforms.registrations.contrib.objects_api",
"openforms.registrations.contrib.microsoft_graph.apps.MicrosoftGraphApp",
"openforms.registrations.contrib.camunda.apps.CamundaApp",
"openforms.registrations.contrib.new_plugin",
"openforms.prefill",
"openforms.prefill.contrib.demo.apps.DemoApp",
"openforms.prefill.contrib.kvk.apps.KVKPrefillApp",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,21 @@ export default {
type: 'object',
},
},
{
id: 'json',
label: 'JSON',
schema: {
properties: {
// TODO-4098: add actual relevant properties
extraLine: {
minLength: 1,
title: 'Extra print statement',
type: 'string',
},
},
type: 'object',
},
},
],
configuredBackends: [],
onChange: fn(),
Expand Down Expand Up @@ -663,6 +678,12 @@ export const ConfiguredBackends = {
],
},
},
{
key: 'backend11',
name: 'JSON',
backend: 'json',
options: {extraLine: 'We are checking.'},
},
],
validationErrors: [
['form.registrationBackends.1.options.zgwApiGroup', 'You sure about this?'],
Expand Down Expand Up @@ -910,3 +931,25 @@ export const STUFZDS = {
await userEvent.click(canvas.getByRole('button', {name: 'Opties instellen'}));
},
};


export const JSON = {
args: {
configuredBackends: [
{
key: 'backend11',
name: 'JSON',
backend: 'json',
options: {
extraLine: 'We are checking.',
},
},
],
},

play: async ({canvasElement}) => {
const canvas = within(canvasElement);

await userEvent.click(canvas.getByRole('button', {name: 'Opties instellen'}));
},
};
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import CamundaOptionsForm from './camunda';
import DemoOptionsForm from './demo';
import EmailOptionsForm from './email';
import JSONOptionsForm from './json';
import MSGraphOptionsForm from './ms_graph';
import ObjectsApiOptionsForm from './objectsapi/ObjectsApiOptionsForm';
import ObjectsApiSummaryHandler from './objectsapi/ObjectsApiSummaryHandler';
Expand Down Expand Up @@ -46,6 +47,7 @@ export const BACKEND_OPTIONS_FORMS = {
form: StufZDSOptionsForm,
},
'microsoft-graph': {form: MSGraphOptionsForm},
'json': {form: JSONOptionsForm},
// demo plugins
demo: {form: DemoOptionsForm},
'failing-demo': {form: DemoOptionsForm},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import {useField} from 'formik';
import PropTypes from 'prop-types';
import React, {useContext} from 'react';
import {FormattedMessage} from 'react-intl';

import Field from 'components/admin/forms/Field';
import Fieldset from 'components/admin/forms/Fieldset';
import FormRow from 'components/admin/forms/FormRow';
import {TextInput} from 'components/admin/forms/Inputs';
import ModalOptionsConfiguration from 'components/admin/forms/ModalOptionsConfiguration';
import {
ValidationErrorContext,
ValidationErrorsProvider,
filterErrors,
} from 'components/admin/forms/ValidationErrors';


const ExtraLine = () => {
const [fieldProps] = useField('extraLine');
return (
<FormRow>
<Field
name="extraLine"
label={
<FormattedMessage
description="Demo registration options 'extraLine' label"
defaultMessage="Extra print statement"
/>
}
>
<TextInput id="id_extraLine" {...fieldProps} />
</Field>
</FormRow>
);
};


const JSONOptionsForm = ({name, label, formData, onChange}) => {
const validationErrors = useContext(ValidationErrorContext);
const relevantErrors = filterErrors(name, validationErrors);
return (
<ModalOptionsConfiguration
name={name}
label={label}
numErrors={relevantErrors.length}
modalTitle={
<FormattedMessage
description="JSON registration options modal title"
defaultMessage="Plugin configuration: JSON"
/>
}
initialFormData={{extraLine: '', ...formData}}
onSubmit={values => onChange({formData: values})}
modalSize="small"
>
<ValidationErrorsProvider errors={relevantErrors}>
<Fieldset>
<ExtraLine />
</Fieldset>
</ValidationErrorsProvider>
</ModalOptionsConfiguration>
);
};

JSONOptionsForm.propTypes = {
name: PropTypes.string.isRequired,
label: PropTypes.node.isRequired,
formData: PropTypes.shape({
extraLine: PropTypes.string,
}),
onChange: PropTypes.func.isRequired,
};

export default JSONOptionsForm;
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import JSONOptionsForm from './JSONOptionsForm';

export default JSONOptionsForm;
Empty file.
12 changes: 12 additions & 0 deletions src/openforms/registrations/contrib/new_plugin/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from django.apps import AppConfig
from django.utils.translation import gettext_lazy as _


# TODO-4908: come up with good name: 'JSON' or '(Form) Variables API'?
class NewPluginConfig(AppConfig):
name = "openforms.registrations.contrib.new_plugin"
label = "registrations_new_plugin"
verbose_name = _("New plugin")

def ready(self):
from . import plugin # noqa
33 changes: 33 additions & 0 deletions src/openforms/registrations/contrib/new_plugin/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from django.utils.translation import gettext_lazy as _

from rest_framework import serializers
from zgw_consumers.models import Service

from openforms.api.fields import PrimaryKeyRelatedAsChoicesField
from openforms.formio.api.fields import FormioVariableKeyField
from openforms.utils.mixins import JsonSchemaSerializerMixin


class NewPluginOptionsSerializer(JsonSchemaSerializerMixin, serializers.Serializer):
# TODO-4098: is service enough, or do we need an API group like the ObjectsAPI?
service = PrimaryKeyRelatedAsChoicesField(
queryset=Service.objects.all(),
label=_("Service"),
help_text=_("Which service to use."),
)
# TODO-4098: show the complete API endpoint as a (tooltip) hint after user entry?
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)."),
)
# TODO-4098: should be linked to the checkboxes in the form variable table
# TODO-4098: is it possible to have a choices field of variable keys, where you can select them
# from a drop-down list?
form_variables = serializers.ListField(
child=FormioVariableKeyField(max_length=50),
label=_("Form variable key list"),
help_text=_(
"A comma-separated list of form variables (can also include static variables) to use."
)
)
18 changes: 18 additions & 0 deletions src/openforms/registrations/contrib/new_plugin/plugin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from django.utils.translation import gettext_lazy as _

from openforms.submissions.models import Submission
from ...base import BasePlugin, OptionsT # openforms.registrations.base
from ...registry import register # openforms.registrations.registry
from .config import NewPluginOptionsSerializer


@register("new_plugin")
class NewPlugin(BasePlugin):
verbose_name = _("New fancy plugin")
configuration_options = NewPluginOptionsSerializer

def register_submission(self, submission: Submission, options: OptionsT) -> None:
print(options)

def check_config(self):
pass

0 comments on commit a6c3e5d

Please sign in to comment.