From 280aeb036954699d7de281ff0373ee9bb9a4cb88 Mon Sep 17 00:00:00 2001 From: Sergei Maertens Date: Mon, 6 Jan 2025 15:51:11 +0100 Subject: [PATCH 1/2] :test_tube: [#4978] Add regression test for incorrect geometry summary --- .../variables/VariablesEditor.stories.js | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/src/openforms/js/components/admin/form_design/variables/VariablesEditor.stories.js b/src/openforms/js/components/admin/form_design/variables/VariablesEditor.stories.js index 629bd8fe21..94498595cb 100644 --- a/src/openforms/js/components/admin/form_design/variables/VariablesEditor.stories.js +++ b/src/openforms/js/components/admin/form_design/variables/VariablesEditor.stories.js @@ -284,6 +284,7 @@ export const WithObjectsAPIRegistrationBackends = { targetPath: ['other', 'path'], }, ], + geometryVariableKey: '', }, }, { @@ -301,6 +302,7 @@ export const WithObjectsAPIRegistrationBackends = { targetPath: ['path', 'to.the', 'target'], }, ], + geometryVariableKey: '', }, }, { @@ -375,6 +377,62 @@ export const WithObjectsAPIRegistrationBackends = { }, }; +// gh-4978 regression for geometry field on empty variable +export const EmptyUserDefinedVariableWithObjectsAPIRegistration = { + args: { + registrationBackends: [ + { + backend: 'objects_api', + key: 'objects_api_1', + name: 'Example Objects API reg.', + options: { + version: 2, + objectsApiGroup: 1, + objecttype: '2c77babf-a967-4057-9969-0200320d23f1', + objecttypeVersion: 2, + variablesMapping: [ + { + variableKey: 'formioComponent', + targetPath: ['path', 'to.the', 'target'], + }, + { + variableKey: 'userDefined', + targetPath: ['other', 'path'], + }, + ], + geometryVariableKey: '', + }, + }, + ], + variables: [ + // add a variable as if the user clicked "add new user defined variable" + { + form: 'http://localhost:8000/api/v2/forms/36612390', + formDefinition: undefined, + name: '', + key: '', + source: 'user_defined', + prefillPlugin: '', + prefillAttribute: '', + prefillIdentifierRole: 'main', + dataType: 'string', + dataFormat: undefined, + isSensitiveData: false, + serviceFetchConfiguration: undefined, + initialValue: '', + prefillOptions: {}, + }, + ], + }, + play: async ({canvasElement}) => { + const canvas = within(canvasElement); + + const userDefinedVarsTab = canvas.getByRole('tab', {name: 'Gebruikersvariabelen'}); + await userEvent.click(userDefinedVarsTab); + expect(canvas.queryAllByText('record.geometry')).toHaveLength(0); + }, +}; + export const FilesMappingAndObjectAPIRegistration = { args: { registrationBackends: [ From 0c3da88c2c66d660a14b069ec24735a6162ab832 Mon Sep 17 00:00:00 2001 From: Sergei Maertens Date: Mon, 6 Jan 2025 15:54:17 +0100 Subject: [PATCH 2/2] :bug: [#4978] Only mark variable as geometry if the key is not empty The empty string as key for a variable incorrectly marked a variable as geometry variable because the empty values match. Now we only consider non-empty values as valid, as a variable *must* have a non-empty key to be valid and mappable. --- .../registrations/objectsapi/ObjectsApiSummaryHandler.js | 2 +- .../objectsapi/ObjectsApiVariableConfigurationEditor.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/openforms/js/components/admin/form_design/registrations/objectsapi/ObjectsApiSummaryHandler.js b/src/openforms/js/components/admin/form_design/registrations/objectsapi/ObjectsApiSummaryHandler.js index a1b5b5f493..d8f21cc090 100644 --- a/src/openforms/js/components/admin/form_design/registrations/objectsapi/ObjectsApiSummaryHandler.js +++ b/src/openforms/js/components/admin/form_design/registrations/objectsapi/ObjectsApiSummaryHandler.js @@ -17,7 +17,7 @@ import {FormattedMessage} from 'react-intl'; const ObjectsApiSummaryHandler = ({variable, backendOptions}) => { const geometryVariableKey = backendOptions.geometryVariableKey; - if (geometryVariableKey === variable.key) { + if (geometryVariableKey && geometryVariableKey === variable.key) { return ( { if (version !== 2) throw new Error('Not supported, must be config version 2.'); - const isGeometry = geometryVariableKey === variable.key; + const isGeometry = geometryVariableKey && geometryVariableKey === variable.key; // get the index of our variable in the mapping, if it exists let index = variablesMapping.findIndex(