Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid empty variables being marked as geometry fields (objects API registration) #4988

Merged
merged 2 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading