-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ac7be79
commit 8a3e039
Showing
9 changed files
with
186 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
src/openforms/js/components/admin/form_design/registrations/json/JSONOptionsForm.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
3 changes: 3 additions & 0 deletions
3
src/openforms/js/components/admin/form_design/registrations/json/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import JSONOptionsForm from './JSONOptionsForm'; | ||
|
||
export default JSONOptionsForm; |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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." | ||
) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |