From ea162e49e7cf2fb8f17e90e64214cc0aaa654eb2 Mon Sep 17 00:00:00 2001 From: "ICX\\Tatsiana.Hashtold" Date: Thu, 10 Oct 2024 15:47:46 +0300 Subject: [PATCH] FIO-9202: fixed an issue where the data for the component inside fieldset insdie wizard is lost after submission --- src/process/__tests__/process.test.ts | 151 ++++++++++++++++++++++++++ src/process/hideChildren.ts | 2 +- 2 files changed, 152 insertions(+), 1 deletion(-) diff --git a/src/process/__tests__/process.test.ts b/src/process/__tests__/process.test.ts index 83680512..a6ed9761 100644 --- a/src/process/__tests__/process.test.ts +++ b/src/process/__tests__/process.test.ts @@ -3759,6 +3759,157 @@ it('Should not unset values for conditionally visible fields with different form assert.equal(context.scope.errors.length, 0); }); + it('Should not unset value of the component inside fieldset inside wizard', () => { + const form = { + _id: '67063bc6094b45c5f33ade96', + title: '8802newOne', + name: '8802NewOne', + path: '8802newone', + type: 'form', + display: 'wizard', + owner: '6707a2f60c037c924c716b54', + components: [ + { + title: 'Basic & Advanced', + breadcrumbClickable: true, + buttonSettings: { + previous: true, + cancel: true, + next: true, + }, + navigateOnEnter: false, + saveOnEnter: false, + scrollToTop: false, + collapsible: false, + key: 'page1', + type: 'panel', + label: 'Page 1', + input: false, + tableView: false, + components: [ + { + label: 'Text Field', + description: 'Hide Text Area when Text Field is Empty', + applyMaskOn: 'change', + tableView: true, + validateWhenHidden: false, + key: 'textField', + type: 'textfield', + input: true, + }, + { + label: 'Text Area', + applyMaskOn: 'change', + autoExpand: false, + tableView: true, + validateWhenHidden: false, + key: 'textArea', + conditional: { + show: false, + conjunction: 'all', + conditions: [ + { + component: 'textField', + operator: 'isEmpty', + }, + ], + }, + type: 'textarea', + input: true, + }, + ], + }, + { + title: 'Advanced & Layout', + breadcrumbClickable: true, + buttonSettings: { + previous: true, + cancel: true, + next: true, + }, + navigateOnEnter: false, + saveOnEnter: false, + scrollToTop: false, + collapsible: false, + key: 'page2', + type: 'panel', + label: 'Page 2', + input: false, + tableView: false, + components: [ + { + key: 'fieldSet', + type: 'fieldset', + label: 'Field Set', + input: false, + tableView: false, + components: [ + { + label: 'Url', + applyMaskOn: 'change', + tableView: true, + validateWhenHidden: false, + key: 'url', + conditional: { + show: true, + conjunction: 'all', + conditions: [ + { + component: 'textAreaFieldSet', + operator: 'isEmpty', + }, + ], + }, + type: 'url', + input: true, + }, + { + label: 'Text Area - Field set', + description: 'Show URL when Text Area - Field set is empty', + applyMaskOn: 'change', + autoExpand: false, + tableView: true, + validateWhenHidden: false, + key: 'textAreaFieldSet', + type: 'textarea', + input: true, + }, + ], + }, + ], + }, + ], + }; + + const submission = { + data: { textField: '', textAreaFieldSet: 'test' }, + state: 'submitted', + }; + + const errors: any = []; + const conditionals: any = []; + const context = { + form, + submission, + data: submission.data, + components: form.components, + processors: ProcessTargets.submission, + scope: { errors, conditionals }, + config: { + server: true, + }, + }; + + processSync(context); + submission.data = context.data; + context.processors = ProcessTargets.evaluator; + processSync(context); + assert.deepEqual(context.data, { textField: '', textAreaFieldSet: 'test' }) + context.scope.conditionals.forEach((cond: any) => { + expect(cond.conditionallyHidden).to.be.true; + }) + }); + describe('Required component validation in nested form in DataGrid/EditGrid', () => { const nestedForm = { key: 'form', diff --git a/src/process/hideChildren.ts b/src/process/hideChildren.ts index 5b80205e..739bc951 100644 --- a/src/process/hideChildren.ts +++ b/src/process/hideChildren.ts @@ -15,7 +15,7 @@ export const hideChildrenProcessor: ProcessorFnSync = (context) const { component, path, parent, scope } = context; // Check if there's a conditional set for the component and if it's marked as conditionally hidden const isConditionallyHidden = scope.conditionals?.find((cond) => { - return path.includes(cond.path) && cond.conditionallyHidden; + return path === cond.path && cond.conditionallyHidden; }); if (!scope.conditionals) {