-
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.
✨ [#4908] Add checkbox to include variables from the variable table
- Loading branch information
1 parent
7ade958
commit 4ddc7f3
Showing
3 changed files
with
110 additions
and
2 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
32 changes: 32 additions & 0 deletions
32
src/openforms/js/components/admin/form_design/registrations/json/JSONSummaryHandler.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,32 @@ | ||
import {FormattedMessage} from 'react-intl'; | ||
import React from 'react'; | ||
|
||
const JSONSummaryHandler = ({variable, backendOptions}) => { | ||
|
||
const isIncluded = backendOptions.formVariables.includes(variable.key); | ||
|
||
if (isIncluded) { | ||
return ( | ||
<FormattedMessage | ||
description="JSON registration summary message" | ||
defaultMessage="Included" | ||
/> | ||
); | ||
} | ||
else { | ||
return ( | ||
<FormattedMessage | ||
description="JSON registration summary message" | ||
defaultMessage="Not included" | ||
/> | ||
); | ||
} | ||
}; | ||
|
||
|
||
// TODO-4098: ?? | ||
JSONSummaryHandler.propTypes = { | ||
|
||
}; | ||
|
||
export default JSONSummaryHandler; |
69 changes: 69 additions & 0 deletions
69
...rms/js/components/admin/form_design/registrations/json/JSONVariableConfigurationEditor.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,69 @@ | ||
// TODO-4908: fix imports | ||
import {Checkbox} from 'components/admin/forms/Inputs'; | ||
import Field from '../../../forms/Field'; | ||
import {FormattedMessage} from 'react-intl'; | ||
import FormRow from '../../../forms/FormRow'; | ||
import React from 'react'; | ||
import {useField, useFormikContext} from 'formik'; | ||
import PropTypes from 'prop-types'; | ||
|
||
|
||
const JSONVariableConfigurationEditor = ({variable}) => { | ||
const [fieldProps, , fieldHelpers] = useField('formVariables'); | ||
const {setValue} = fieldHelpers; | ||
|
||
const formVariables = fieldProps.value | ||
const isIncluded = formVariables.includes(variable.key); | ||
|
||
return ( | ||
<FormRow> | ||
<Field name="includeVariable"> | ||
<Checkbox | ||
name="includeVariableCheckbox" | ||
label={ | ||
<FormattedMessage | ||
description="'Include variable' checkbox label" | ||
defaultMessage="Include variable" | ||
/> | ||
} | ||
helpText={ | ||
<FormattedMessage | ||
description="'Include variable' checkbox help text" | ||
defaultMessage="Whether to include this variable in the data to be sent." | ||
/> | ||
} | ||
checked={isIncluded} | ||
onChange={event => { | ||
const formVariablesNew = formVariables.slice(); | ||
const index = formVariablesNew.indexOf(variable.key); | ||
if (event.target.checked) { | ||
// TODO-4908: remove this when testing is implemented | ||
if (index !== -1) {throw new Error( | ||
"This form variable is already on the list of " + | ||
"form variables to include. This shouldn't happen" | ||
);} | ||
formVariablesNew.push(variable.key); | ||
} else { | ||
if (index === -1) {throw new Error( | ||
"This form variable is not yet on the list of " + | ||
"form variables to include. This shouldn't happen." | ||
);} | ||
formVariablesNew.splice(index, 1); | ||
} | ||
setValue(formVariablesNew); | ||
}} | ||
/> | ||
</Field> | ||
</FormRow> | ||
) | ||
} | ||
|
||
// TODO-4098: ??? | ||
JSONVariableConfigurationEditor.propTypes = { | ||
variable: PropTypes.shape({ | ||
key: PropTypes.string.isRequired, | ||
}).isRequired, | ||
}; | ||
|
||
|
||
export default JSONVariableConfigurationEditor |