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

Merged
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
42 changes: 42 additions & 0 deletions docs/developers/frontend/admin-styling.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
.. _developers_frontend_admin_styling:

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

Adding a custom style
---------------------
The steps below describe how to add custom styling for a component in the admin, with the
help of an example ``div`` component:

.. code-block:: html

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

1. Create a new file called ``_component-file-name.scss`` in ``src/openforms/scss/components/admin``,
where ``component-file-name`` reflects the class name of the component. For example: ``_json-dump-variables.scss``

2. Add the custom styling. For example:

.. code-block:: scss

.json-dump-variables {
display: flex;

@include bem.modifier('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. For example, in ``src/openforms/scss/components/admin/_index.scss``):

.. code-block:: scss

...
@import './json-dump-variables';
...
9 changes: 9 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?

Copy link
Contributor

Choose a reason for hiding this comment

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

No this would be the correct place. (S)CSS is frontend stuff :)
I would suggest moving this to a separate file, instead of added it to the index.rst, just to give some structure.

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 was a bit confused by the definition of frontend here. If you look at the frontend documentation, it only mentions the repos related to the form frontend, not the admin styling. I guess it depends on what is meant exactly by Backend and Frontend here:
image

Copy link
Contributor

Choose a reason for hiding this comment

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

Mhh, yeah.. it's a bit confusing.. I assume 'Frontend' contains all things related to frontend code (including the frontend of the open-forms project). I think this is fine, otherwise you can blame me 😉

Original file line number Diff line number Diff line change
Expand Up @@ -145,3 +145,12 @@ 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


Topics
======

.. toctree::
:maxdepth: 1

admin-styling
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 @@ -2311,6 +2311,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 @@ -2332,6 +2332,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 @@ -1085,7 +1085,7 @@ export const JSONDump = {
options: {
service: 1,
path: 'example/endpoint',
variables: [],
variables: ['firstName', 'lastName', 'foo'],
fixedMetadataVariables: ['form_name', 'form_version', 'public_reference'],
additionalMetadataVariables: ['auth_bsn'],
},
Expand All @@ -1097,7 +1097,7 @@ export const JSONDump = {
formDefinition: null,
name: 'First name',
key: 'firstName',
source: 'user_defined',
source: 'component',
prefillPlugin: '',
prefillAttribute: '',
prefillIdentifierRole: '',
Expand All @@ -1113,7 +1113,7 @@ export const JSONDump = {
formDefinition: null,
name: 'Last name',
key: 'lastName',
source: 'user_defined',
source: 'component',
prefillPlugin: '',
prefillAttribute: '',
prefillIdentifierRole: '',
Expand All @@ -1129,7 +1129,7 @@ export const JSONDump = {
formDefinition: null,
name: 'Attachment',
key: 'attachment',
source: 'user_defined',
source: 'component',
prefillPlugin: '',
prefillAttribute: '',
prefillIdentifierRole: '',
Expand All @@ -1140,6 +1140,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 Expand Up @@ -1177,9 +1193,28 @@ export const JSONDump = {
],
},

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

await userEvent.click(canvas.getByRole('button', {name: 'Opties instellen'}));

const modalForm = await screen.findByTestId('modal-form');
await expect(modalForm).toBeVisible();
const modal = within(modalForm);

await step('Add form variables', async () => {
await expect(...modal.queryAllByText('Attachment')).toBeFalsy(); // Ensure component variable 'Attachment' IS NOT selected
await expect(modal.getByText('Foo')).toBeVisible(); // Ensure user-defined variable 'Foo' IS selected

await userEvent.click(modal.getByRole('button', {name: 'Add all form variables'}));
await expect(modal.getByText('Attachment')).toBeVisible(); // Ensure 'Attachment' IS selected
await expect(modal.getByText('Foo')).toBeVisible(); // Ensure user-defined variable 'Foo' IS STILL selected

// Close modal
await userEvent.click(modal.getByRole('button', {name: 'Opslaan'}));
});

// Re-open modal for visual regression testing
await userEvent.click(canvas.getByRole('button', {name: 'Opties instellen'}));
},
};
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
import {useField} from 'formik';
import React from 'react';
import {FormattedMessage} from 'react-intl';
import {useContext} from 'react';
import {FormattedMessage, useIntl} from 'react-intl';

import {FormContext} from 'components/admin/form_design/Context';
import {VARIABLE_SOURCES} from 'components/admin/form_design/variables/constants';
import ActionButton from 'components/admin/forms/ActionButton';
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 intl = useIntl();

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

const {formVariables} = useContext(FormContext);

return (
<FormRow>
Expand All @@ -28,13 +35,31 @@ 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
/>

<ActionButton
name="addAllFormVariables"
type="button"
text={intl.formatMessage({
description: "JSON registration options 'add all form variables' label",
defaultMessage: 'Add all form variables',
})}
onClick={() => {
const componentVariables = formVariables.filter(
v => v.source === VARIABLE_SOURCES.component
);
const newVariables = [...fieldProps.value, ...componentVariables.map(v => v.key)];
setValue([...new Set(newVariables)]); // Use a Set to ensure they are unique
}}
/>
</div>
</Field>
</FormRow>
);
Expand Down
5 changes: 5 additions & 0 deletions src/openforms/js/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1089,6 +1089,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 @@ -1098,6 +1098,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';
@import './fieldset';

// Form design UI
Expand Down
10 changes: 10 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,10 @@
@use 'microscope-sass/lib/bem';

.json-dump-variables {
display: flex;

@include bem.modifier('horizontal') {
align-items: center;
gap: 0.5em;
}
}
Loading