From 549a13a5dae7987a923f32be53d3442112065d69 Mon Sep 17 00:00:00 2001 From: andreastanderen Date: Mon, 4 Mar 2024 09:47:56 +0100 Subject: [PATCH 1/2] Add check for formItem[key] before fetching formItem[key][subKey] --- .../ux-editor/src/components/config/Expressions/utils/utils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/packages/ux-editor/src/components/config/Expressions/utils/utils.ts b/frontend/packages/ux-editor/src/components/config/Expressions/utils/utils.ts index aeefc3c180a..8e44ad411e6 100644 --- a/frontend/packages/ux-editor/src/components/config/Expressions/utils/utils.ts +++ b/frontend/packages/ux-editor/src/components/config/Expressions/utils/utils.ts @@ -107,7 +107,7 @@ export const getPropertyValue = ( property: FormItemProperty, ): Expression => { const { key, subKey } = property; - if (subKey) { + if (subKey && formItem[key]) { return formItem[key][subKey] as BooleanExpression | undefined; } return formItem[key] as BooleanExpression | undefined; From ca38c4f23582831667db049c9613cf0c6036f50d Mon Sep 17 00:00:00 2001 From: andreastanderen Date: Mon, 4 Mar 2024 10:03:37 +0100 Subject: [PATCH 2/2] Add test --- .../config/Expressions/utils/utils.test.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/frontend/packages/ux-editor/src/components/config/Expressions/utils/utils.test.ts b/frontend/packages/ux-editor/src/components/config/Expressions/utils/utils.test.ts index dc566b7d3a7..282a9965e17 100644 --- a/frontend/packages/ux-editor/src/components/config/Expressions/utils/utils.test.ts +++ b/frontend/packages/ux-editor/src/components/config/Expressions/utils/utils.test.ts @@ -224,8 +224,23 @@ describe('utils', () => { pageIndex: null, type: ComponentType.Input, }; + const repeatingGroupWithoutEditProp: FormContainer = { + id: 'repeatingGroup', + itemType: 'CONTAINER', + type: ComponentType.RepeatingGroup, + }; const hiddenProp: FormItemProperty = { key: 'hidden' }; + const addButtonProp: FormItemProperty = { + key: 'edit', + subKey: 'addButton', + }; expect(getPropertyValue(inputComponent, hiddenProp)).toBeUndefined(); + expect( + getPropertyValue( + repeatingGroupWithoutEditProp, + addButtonProp, + ), + ).toBeUndefined(); }); }); });