Skip to content

Commit

Permalink
Merge pull request #4988 from open-formulieren/issue/4978-empty-varia…
Browse files Browse the repository at this point in the history
…ble-marked-as-geo

Avoid empty variables being marked as geometry fields (objects API registration)
  • Loading branch information
sergei-maertens authored Jan 6, 2025
2 parents 933bc44 + 0c3da88 commit a425cc6
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<FormattedMessage
description="'Mapped to geometry' registration summary message"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const ObjectsApiVariableConfigurationEditor = ({variable}) => {

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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ export const WithObjectsAPIRegistrationBackends = {
targetPath: ['other', 'path'],
},
],
geometryVariableKey: '',
},
},
{
Expand All @@ -301,6 +302,7 @@ export const WithObjectsAPIRegistrationBackends = {
targetPath: ['path', 'to.the', 'target'],
},
],
geometryVariableKey: '',
},
},
{
Expand Down Expand Up @@ -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: [
Expand Down

0 comments on commit a425cc6

Please sign in to comment.