Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add button to quickly include all form variables in JSON dump plugin #5070

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions docs/developers/frontend/index.rst
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm thinking now this might be better placed in Backend -> Admin styling?

Original file line number Diff line number Diff line change
Expand Up @@ -145,3 +145,42 @@ This script can handle current and future NPM packages published in the
.. _FormatJS: https://formatjs.github.io/
.. _react-intl: https://formatjs.github.io/docs/getting-started/installation
.. _react-intl storybook addon: https://storybook.js.org/addons/storybook-react-intl

Admin styling
=============
Custom styling of admin components can be realized by adding/updating .scss files,
which are located in ``path/to/open-forms/src/openforms/scss``.

Adding a custom style
---------------------
See below for an example on adding custom styling for a ``div`` component in the admin:

.. code-block:: html

<div className="json-dump-variables json-dump-variables--horizontal">
...
</div>

1. Create a file called ``_json-dump-variables.scss`` in ``../scss/components/admin``

2. Add styling, for example:

.. code-block:: scss

.json-dump-variables {
display: flex;

&--horizontal {
align-items: center;
gap: 0.5em;
}
}

3. To ensure it gets picked up, add an import of the file name (without underscore) to the ``_index.scss``
file of the parent directory (in this case ``../scss/components/admin/_index.scss``):

.. code-block:: scss

...
@import './json-dump-variables';
...
6 changes: 6 additions & 0 deletions src/openforms/js/compiled-lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -2305,6 +2305,12 @@
"value": "Text with (embedded) form field(s)"
}
],
"Is9K3/": [
{
"type": 0,
"value": "Add all form variables"
}
],
"ItH6EY": [
{
"type": 0,
Expand Down
6 changes: 6 additions & 0 deletions src/openforms/js/compiled-lang/nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -2326,6 +2326,12 @@
"value": "Tekst met (ingesloten) formulierveldwaarde(n)"
}
],
"Is9K3/": [
{
"type": 0,
"value": "Add all form variables"
}
],
"ItH6EY": [
{
"type": 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1029,7 +1029,7 @@ export const JSONDump = {
options: {
service: 1,
path: 'example/endpoint',
variables: [],
variables: ['firstName', 'lastName'],
},
},
],
Expand All @@ -1039,7 +1039,7 @@ export const JSONDump = {
formDefinition: null,
name: 'First name',
key: 'firstName',
source: 'user_defined',
source: 'component',
prefillPlugin: '',
prefillAttribute: '',
prefillIdentifierRole: '',
Expand All @@ -1055,7 +1055,7 @@ export const JSONDump = {
formDefinition: null,
name: 'Last name',
key: 'lastName',
source: 'user_defined',
source: 'component',
prefillPlugin: '',
prefillAttribute: '',
prefillIdentifierRole: '',
Expand All @@ -1071,7 +1071,7 @@ export const JSONDump = {
formDefinition: null,
name: 'Attachment',
key: 'attachment',
source: 'user_defined',
source: 'component',
prefillPlugin: '',
prefillAttribute: '',
prefillIdentifierRole: '',
Expand All @@ -1082,6 +1082,22 @@ export const JSONDump = {
serviceFetchConfiguration: undefined,
initialValue: '',
},
{
form: null,
formDefinition: null,
name: 'Foo',
key: 'foo',
source: 'user_defined',
prefillPlugin: '',
prefillAttribute: '',
prefillIdentifierRole: '',
prefillOptions: {},
dataType: 'string',
dataFormat: '',
isSensitiveData: false,
serviceFetchConfiguration: undefined,
initialValue: 'Bar',
},
],
availableStaticVariables: [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import {useField} from 'formik';
import React from 'react';
import React, {useContext} from 'react';
import {FormattedMessage} from 'react-intl';

import {FormContext} from 'components/admin/form_design/Context';
import {VARIABLE_SOURCES} from 'components/admin/form_design/variables/constants';
import Field from 'components/admin/forms/Field';
import FormRow from 'components/admin/forms/FormRow';
import VariableSelection from 'components/admin/forms/VariableSelection';

const Variables = () => {
const [fieldProps] = useField('variables');
const [fieldProps, , {setValue}] = useField('variables');

const {formVariables} = useContext(FormContext);

return (
<FormRow>
Expand All @@ -28,16 +32,34 @@ const Variables = () => {
required
noManageChildProps
>
<VariableSelection
{...fieldProps}
isMulti
required
closeMenuOnSelect={false}
includeStaticVariables
/>
<div className="json-dump-variables json-dump-variables--horizontal">
<VariableSelection
{...fieldProps}
isMulti
required
closeMenuOnSelect={false}
includeStaticVariables
/>

<button
type="button"
className="button button--padded"
onClick={() => onAddAllComponentVariables(formVariables, setValue)}
>
<FormattedMessage
description="JSON registration options 'add all form variables' label"
defaultMessage="Add all form variables"
/>
</button>
</div>
</Field>
</FormRow>
);
};

function onAddAllComponentVariables(formVariables, setValue) {
const componentVariables = formVariables.filter(v => v.source === VARIABLE_SOURCES.component);
setValue(componentVariables.map(v => v.key));
}

export default Variables;
5 changes: 5 additions & 0 deletions src/openforms/js/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1084,6 +1084,11 @@
"description": "JSON editor: \"interpolate\" variable source label",
"originalDefault": "Text with (embedded) form field(s)"
},
"Is9K3/": {
"defaultMessage": "Add all form variables",
"description": "JSON registration options 'add all form variables' label",
"originalDefault": "Add all form variables"
},
"ItH6EY": {
"defaultMessage": "Time",
"description": "data type time",
Expand Down
5 changes: 5 additions & 0 deletions src/openforms/js/lang/nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -1093,6 +1093,11 @@
"description": "JSON editor: \"interpolate\" variable source label",
"originalDefault": "Text with (embedded) form field(s)"
},
"Is9K3/": {
"defaultMessage": "Add all form variables",
"description": "JSON registration options 'add all form variables' label",
"originalDefault": "Add all form variables"
},
"ItH6EY": {
"defaultMessage": "Tijd (time)",
"description": "data type time",
Expand Down
1 change: 1 addition & 0 deletions src/openforms/scss/components/admin/_index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
@import './column-field-value';
@import './confirmation-email-template';
@import './variablemapping';
@import './json-dump-variables';

// Form design UI
@import './select';
Expand Down
8 changes: 8 additions & 0 deletions src/openforms/scss/components/admin/_json-dump-variables.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.json-dump-variables {
display: flex;

&--horizontal {
align-items: center;
gap: 0.5em;
}
}
Loading