From fb93f81c4b3efa757ac20a0f90811fcc7498381a Mon Sep 17 00:00:00 2001 From: Roman Letsuk Date: Mon, 22 Jul 2024 15:59:40 +0300 Subject: [PATCH] FIO-8626: updated conditionally hidden logic --- src/process/__tests__/process.test.ts | 79 +++++++++++++++++++++++++++ src/utils/logic.ts | 7 +-- 2 files changed, 82 insertions(+), 4 deletions(-) diff --git a/src/process/__tests__/process.test.ts b/src/process/__tests__/process.test.ts index 4e5ed176..c69933b3 100644 --- a/src/process/__tests__/process.test.ts +++ b/src/process/__tests__/process.test.ts @@ -2702,6 +2702,85 @@ describe('Process Tests', () => { }); }); + it('Should include submission data for logically visible fields', async () => { + const form = { + display: 'form', + components: [ + { + type: 'textfield', + key: 'textField', + label: 'Text Field', + input: true, + }, + { + type: 'textarea', + key: 'textArea', + label: 'Text Area', + input: true, + hidden: true, + logic: [ + { + name: 'Show When Not Empty', + trigger: { + type: 'simple' as const, + simple: { + show: true, + conjunction: 'all', + conditions: [ + { + component: 'textField', + operator: 'isNotEmpty', + }, + ], + }, + }, + actions: [ + { + name: 'Show', + type: 'property' as const, + property: { + label: 'Hidden', + value: 'hidden', + type: 'boolean' as const, + }, + state: false, + }, + ], + }, + ], + }, + ], + }; + + const submission = { + data: { + textField: 'not empty', + textArea: 'should be conditionally visible', + }, + }; + + const context = { + form, + submission, + data: submission.data, + components: form.components, + processors: ProcessTargets.evaluator, + scope: {}, + config: { + server: true, + }, + }; + processSync(context); + expect((context.scope as any).conditionals).to.deep.equal([{ + path: 'textArea', + conditionallyHidden: false, + }]); + expect(context.data).to.deep.equal({ + textArea: 'should be conditionally visible', + textField: 'not empty', + }); + }); + describe('Required component validation in nested form in DataGrid/EditGrid', () => { const nestedForm = { key: 'form', diff --git a/src/utils/logic.ts b/src/utils/logic.ts index 3cf641d8..2dc7efce 100644 --- a/src/utils/logic.ts +++ b/src/utils/logic.ts @@ -48,11 +48,10 @@ export function setActionBooleanProperty(context: LogicContext, action: LogicAct if (currentValue !== newValue) { set(component, property, newValue === 'true'); - // If this is "logic" forcing a component to be hidden, then we will set the "conditionallyHidden" + // If this is "logic" forcing a component to set hidden property, then we will set the "conditionallyHidden" // flag which will trigger the clearOnHide functionality. if ( property === 'hidden' && - component.hidden && path ) { if (!(scope as any).conditionals) { @@ -62,12 +61,12 @@ export function setActionBooleanProperty(context: LogicContext, action: LogicAct return cond.path === path }); if (conditionalyHidden) { - conditionalyHidden.conditionallyHidden = true; + conditionalyHidden.conditionallyHidden = component.hidden; } else { (scope as any).conditionals.push({ path, - conditionallyHidden: true + conditionallyHidden: component.hidden, }); } }