From 01462767fdee943ddb29a2cf5909af4572b88521 Mon Sep 17 00:00:00 2001
From: Viicos <65306057+Viicos@users.noreply.github.com>
Date: Fri, 8 Mar 2024 16:19:52 +0100
Subject: [PATCH] [#3688] Add option to map var to geometry attribute
---
.../objectsapi/ObjectsApiOptionsFormFields.js | 1 +
.../ObjectsApiVariableConfigurationEditor.js | 35 +++++++++++++++++--
2 files changed, 33 insertions(+), 3 deletions(-)
diff --git a/src/openforms/js/components/admin/form_design/registrations/objectsapi/ObjectsApiOptionsFormFields.js b/src/openforms/js/components/admin/form_design/registrations/objectsapi/ObjectsApiOptionsFormFields.js
index e80cb04c91..96b3d2af7e 100644
--- a/src/openforms/js/components/admin/form_design/registrations/objectsapi/ObjectsApiOptionsFormFields.js
+++ b/src/openforms/js/components/admin/form_design/registrations/objectsapi/ObjectsApiOptionsFormFields.js
@@ -43,6 +43,7 @@ const ObjectsApiOptionsFormFields = ({index, name, schema, formData, onChange})
draft.version = realVersion;
if (realVersion === 2) {
draft.variablesMapping = [];
+ draft.geometryVariableKey = '';
} else {
delete draft.variablesMapping;
}
diff --git a/src/openforms/js/components/admin/form_design/registrations/objectsapi/ObjectsApiVariableConfigurationEditor.js b/src/openforms/js/components/admin/form_design/registrations/objectsapi/ObjectsApiVariableConfigurationEditor.js
index 7042ee1b1b..1a9206990f 100644
--- a/src/openforms/js/components/admin/form_design/registrations/objectsapi/ObjectsApiVariableConfigurationEditor.js
+++ b/src/openforms/js/components/admin/form_design/registrations/objectsapi/ObjectsApiVariableConfigurationEditor.js
@@ -10,7 +10,7 @@ import {REGISTRATION_OBJECTS_TARGET_PATHS} from 'components/admin/form_design/co
import Field from 'components/admin/forms/Field';
import Fieldset from 'components/admin/forms/Fieldset';
import FormRow from 'components/admin/forms/FormRow';
-import {TextInput} from 'components/admin/forms/Inputs';
+import {Checkbox, TextInput} from 'components/admin/forms/Inputs';
import Select, {LOADING_OPTION} from 'components/admin/forms/Select';
import ErrorMessage from 'components/errors/ErrorMessage';
import {post} from 'utils/fetch';
@@ -25,6 +25,7 @@ import {asJsonSchema} from './utils';
* objecttype: string;
* objecttypeVersion: number;
* variablesMapping: {variableKey: string, targetPath: string[]}[];
+ * geometryVariableKey: string;
* }} ObjectsAPIRegistrationBackendOptions
*
* @param {Object} p
@@ -35,10 +36,11 @@ const ObjectsApiVariableConfigurationEditor = ({variable}) => {
const {csrftoken} = useContext(APIContext);
const [jsonSchemaVisible, toggleJsonSchemaVisible] = useToggle(false);
- const {values: backendOptions, getFieldProps} = useFormikContext();
+ const {values: backendOptions, getFieldProps, setFieldValue} = useFormikContext();
/** @type {ObjectsAPIRegistrationBackendOptions} */
- const {objecttype, objecttypeVersion, variablesMapping, version} = backendOptions;
+ const {objecttype, objecttypeVersion, geometryVariableKey, variablesMapping, version} =
+ backendOptions;
if (version !== 2) throw new Error('Not supported, must be config version 2.');
// get the index of our variable in the mapping, if it exists
@@ -110,6 +112,32 @@ const ObjectsApiVariableConfigurationEditor = ({variable}) => {
/>
+
+
+ }
+ helpText={
+ record.geometry}}
+ />
+ }
+ name="geometryVariableKey"
+ disabled={!!mappedVariable.targetPath}
+ >
+ {
+ const newValue = event.target.checked ? variable.key : undefined;
+ setFieldValue('geometryVariableKey', newValue);
+ }}
+ />
+
+
{
description="'JSON Schema target' label"
/>
}
+ disabled={!!geometryVariableKey}
>