Skip to content

Commit

Permalink
♻️ [#4908] Use VariableSelection component
Browse files Browse the repository at this point in the history
Now supports multi selection, so we can use it here
  • Loading branch information
viktorvanwijk committed Jan 16, 2025
1 parent 0edf9bc commit 1766a87
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 84 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import PropTypes from 'prop-types';
import React, {useContext} from 'react';
import {FormattedMessage} from 'react-intl';

import {FormContext} from 'components/admin/form_design/Context';
import Fieldset from 'components/admin/forms/Fieldset';
import ModalOptionsConfiguration from 'components/admin/forms/ModalOptionsConfiguration';
import {
Expand All @@ -12,23 +11,12 @@ import {
} from 'components/admin/forms/ValidationErrors';
import {getChoicesFromSchema} from 'utils/json-schema';

import {FormVariablesSelect, Path, ServiceSelect} from './fields';
import {Variables, Path, ServiceSelect} from './fields';

const JSONDumpOptionsForm = ({name, label, schema, formData, onChange}) => {
const validationErrors = useContext(ValidationErrorContext);
const relevantErrors = filterErrors(name, validationErrors);

// Get form variables and create form variable options
const formContext = useContext(FormContext);
const formVariables = formContext.formVariables ?? [];
const staticVariables = formContext.staticVariables ?? [];
const allVariables = staticVariables.concat(formVariables);

const variableOptions = [];
for (const variable of allVariables) {
variableOptions.push({value: variable.key, label: variable.name});
}

// Create service options
const {service} = schema.properties;
const serviceOptions = getChoicesFromSchema(service.enum, service.enumNames).map(
Expand All @@ -53,13 +41,13 @@ const JSONDumpOptionsForm = ({name, label, schema, formData, onChange}) => {
...formData,
}}
onSubmit={values => onChange({formData: values})}
modalSize="medium"
modalSize="large"
>
<ValidationErrorsProvider errors={relevantErrors}>
<Fieldset>
<ServiceSelect options={serviceOptions} />
<Path />
<FormVariablesSelect options={variableOptions} />
<Variables />
</Fieldset>
</ValidationErrorsProvider>
</ModalOptionsConfiguration>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const JSONDumpVariableConfigurationEditor = ({variable}) => {
const newVariables = shouldBeIncluded
? [...variables, variable.key] // add the variable to the array
: variables.filter(key => key !== variable.key); // remove the variable from the array
setFieldValue('variables', variables);
setFieldValue('variables', newVariables);
}}
/>
</Field>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import {useField} from 'formik';
import React from 'react';
import {FormattedMessage} from 'react-intl';

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');

return (
<FormRow>
<Field
name="variables"
label={
<FormattedMessage
description="JSON registration options 'variables' label"
defaultMessage="Variables"
/>
}
helpText={
<FormattedMessage
description="JSON registration options 'variables' helpText"
defaultMessage="Which variables to include in the data to be sent"
/>
}
required
noManageChildProps
>
<VariableSelection
{...fieldProps}
isMulti
required
closeMenuOnSelect={false}
includeStaticVariables={true}
/>
</Field>
</FormRow>
);
};

export default Variables;
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import FormVariablesSelect from './FormVariablesSelect';
import Variables from './Variables';
import Path from './Path';
import ServiceSelect from './ServiceSelect';

export {FormVariablesSelect, Path, ServiceSelect};
export {Path, ServiceSelect, Variables};

0 comments on commit 1766a87

Please sign in to comment.