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 varianles in JSON dump plugin #5070

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
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;
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