From 3617aaeded719d74bf372bbe7d0192cccbbecf7e Mon Sep 17 00:00:00 2001 From: mikekotikov Date: Tue, 29 Oct 2024 16:15:53 +0300 Subject: [PATCH 1/3] FIO-8690: Add migrate changes --- src/utils/conditions.ts | 220 +++++++++++++++++++++---------- src/utils/formUtil/index.ts | 16 ++- src/utils/operators/IsEqualTo.js | 6 +- 3 files changed, 165 insertions(+), 77 deletions(-) diff --git a/src/utils/conditions.ts b/src/utils/conditions.ts index d1d4cd78..0508af09 100644 --- a/src/utils/conditions.ts +++ b/src/utils/conditions.ts @@ -3,6 +3,7 @@ import { EvaluatorFn, evaluate, JSONLogicEvaluator } from 'modules/jsonlogic'; import { flattenComponents, getComponent, getComponentActualValue } from './formUtil'; import { has, isObject, map, every, some, find, filter, isBoolean, split } from 'lodash'; import ConditionOperators from './operators'; +import _ from 'lodash'; export const isJSONConditional = (conditional: any): conditional is JSONConditional => { return conditional && conditional.json && isObject(conditional.json); @@ -117,97 +118,174 @@ function isConditionPotentiallyBasedOnValuePath(condition: any = {}) { ); } +function getConditionalPathsRecursive(conditionPaths: any, data: any): any { + let currentGlobalIndex = 0; + const conditionalPathsArray: string[] = []; + const getConditionalPaths = (data: any, currentPath = '', localIndex = 0) => { + currentPath = currentPath.replace(/^\.+|\.+$/g, ''); + const currentLocalIndex = localIndex; + const currentData = _.get(data, currentPath); + if (Array.isArray(currentData) && currentData.filter(Boolean).length > 0) { + if (currentData.some(element => typeof element !== 'object')) { + return; + } + const hasInnerDataArray = currentData.find(x => Array.isArray(x[conditionPaths[currentLocalIndex]])); + if (hasInnerDataArray) { + currentData.forEach((_, indexOutside) => { + const innerCompDataPath = `${currentPath}[${indexOutside}].${conditionPaths[currentLocalIndex]}`; + getConditionalPaths(data, innerCompDataPath, currentLocalIndex + 1); + }); + } + else { + currentData.forEach((x, index) => { + if (!_.isNil(x[conditionPaths[currentLocalIndex]])) { + const compDataPath = `${currentPath}[${index}].${conditionPaths[currentLocalIndex]}`; + conditionalPathsArray.push(compDataPath); + } + }); + } + } + else { + if (!conditionPaths[currentGlobalIndex]) { + return; + } + currentGlobalIndex = currentGlobalIndex + 1; + getConditionalPaths(data, `${currentPath}.${conditionPaths[currentGlobalIndex - 1]}`, currentGlobalIndex); + } + }; + getConditionalPaths(data); + return conditionalPathsArray; +} + /** * Checks the simple conditionals. * @param conditional * @param context * @returns */ +// @ts-ignore export function checkSimpleConditional( conditional: SimpleConditional, context: ConditionsContext, -): boolean | null { +): any { const { component, data, row, instance, form } = context; if (!conditional || !isSimpleConditional(conditional)) { return null; } - const { conditions = [], conjunction = 'all', show = true } = conditional; - if (!conditions.length) { - return null; + // @ts-ignore + if (conditional.when) { + // // @ts-ignore + // const value = getComponentActualValue(conditional!.when, data, row); + // // @ts-ignore + // const eq = String(conditional.eq); + // const show = String(conditional.show); + + // // Special check for selectboxes component. + // // @ts-ignore + // if (_.isObject(value) && _.has(value, conditional.eq)) { + // // @ts-ignore + // return String(value[conditional.eq]) === show; + // } + // // FOR-179 - Check for multiple values. + // if (Array.isArray(value) && value.map(String).includes(eq)) { + // return show === 'true'; + // } + + // return (String(value) === eq) === (show === 'true'); } + else { + const { conditions = [], conjunction = 'all', show = true } = conditional; + if (!conditions.length) { + return null; + } - const conditionsResult = filter( - map(conditions, (cond) => { - const { operator } = cond; - let { value: comparedValue, component: conditionComponentPath } = cond; - if (!conditionComponentPath) { - // Ignore conditions if there is no component path. - return null; - } - const formComponents = form?.components || []; - let conditionComponent = getComponent(formComponents, conditionComponentPath, true); - // If condition componenet is not found, check if conditionComponentPath is value path. - // Need to handle condtions like: - // { - // "component": "selectBoxes.a", - // "operator": "isEqual", - // "value": "true" - // } - if ( - !conditionComponent && - isConditionPotentiallyBasedOnValuePath(cond) && - formComponents.length - ) { - const flattenedComponents = flattenComponents(formComponents, true); - const pathParts = split(conditionComponentPath, '.'); - const valuePathParts = []; - - while (!conditionComponent && pathParts.length) { - conditionComponent = flattenedComponents[`${pathParts.join('.')}`]; - if (!conditionComponent) { - valuePathParts.unshift(pathParts.pop()); - } + const conditionsResult = filter( + map(conditions, (cond) => { + const { operator } = cond; + let { value: comparedValue, component: conditionComponentPath } = cond; + if (!conditionComponentPath) { + // Ignore conditions if there is no component path. + return null; } + const formComponents = form?.components || []; + let conditionComponent = getComponent(formComponents, conditionComponentPath, true); + // If condition componenet is not found, check if conditionComponentPath is value path. + // Need to handle condtions like: + // { + // "component": "selectBoxes.a", + // "operator": "isEqual", + // "value": "true" + // } if ( - conditionComponent && - conditionComponent.type === 'selectboxes' && - valuePathParts.length + !conditionComponent && + isConditionPotentiallyBasedOnValuePath(cond) && + formComponents.length ) { - console.warn( - 'Condition based on selectboxes has wrong format. Resave the form in the form builder to fix it.', - ); - conditionComponentPath = pathParts.join('.'); - comparedValue = valuePathParts.join('.'); + const flattenedComponents = flattenComponents(formComponents, true); + const pathParts = split(conditionComponentPath, '.'); + const valuePathParts = []; + + while (!conditionComponent && pathParts.length) { + conditionComponent = flattenedComponents[`${pathParts.join('.')}`]; + if (!conditionComponent) { + valuePathParts.unshift(pathParts.pop()); + } + } + if ( + conditionComponent && + conditionComponent.type === 'selectboxes' && + valuePathParts.length + ) { + console.warn( + 'Condition based on selectboxes has wrong format. Resave the form in the form builder to fix it.', + ); + conditionComponentPath = pathParts.join('.'); + comparedValue = valuePathParts.join('.'); + } } - } - const value = conditionComponent - ? getComponentActualValue(conditionComponent, conditionComponentPath, data, row) - : null; - - const ConditionOperator = ConditionOperators[operator]; - return ConditionOperator - ? new ConditionOperator().getResult({ - value, - comparedValue, - instance, - component, - conditionComponent, - conditionComponentPath, - data, - }) - : true; - }), - (res) => res !== null, - ); + const splittedConditionPath = conditionComponentPath.split('.'); + // @ts-ignore + const conditionalPaths = (component?.parent?.type || instance?.parent?.type) === 'datagrid' || (component?.parent?.type || instance?.parent?.type) === 'editgrid' ? [] : getConditionalPathsRecursive(splittedConditionPath, data); + // @ts-ignore + if(conditionComponent?.component?.type === "checkbox") { + if(typeof comparedValue === 'string') { + comparedValue = comparedValue === 'true'? true: false //!!!! replace just on: compared = compared === 'value' + } + } + if (conditionalPaths.length > 0) { + return conditionalPaths.map((path: string) => { + const value = getComponentActualValue(conditionComponent, path, data, row); - let result = false; - switch (conjunction) { - case 'any': - result = some(conditionsResult, (res) => !!res); - break; - default: - result = every(conditionsResult, (res) => !!res); + const ConditionOperator = ConditionOperators[operator]; + return ConditionOperator + ? new ConditionOperator().getResult({ value, comparedValue, instance, component, conditionComponentPath }) + : true; + }); + } + + else { + + const value = getComponentActualValue(conditionComponent, conditionComponentPath, data, row); + const СonditionOperator = ConditionOperators[operator]; + return СonditionOperator + ? new СonditionOperator().getResult({ value, comparedValue, instance, component, conditionComponentPath, conditionComponent }) + : true; + + } + }), + (res) => res !== null, + ); + + let result = false; + switch (conjunction) { + case 'any': + result = some(conditionsResult.flat(), (res) => !!res); + break; + default: + result = every(conditionsResult.flat(), (res) => !!res); + } + return show ? result : !result; } - return show ? result : !result; } + diff --git a/src/utils/formUtil/index.ts b/src/utils/formUtil/index.ts index a15ae3bc..e615b2f8 100644 --- a/src/utils/formUtil/index.ts +++ b/src/utils/formUtil/index.ts @@ -290,8 +290,8 @@ export function getContextualRowData(component: Component, path: string, data: a } export function componentInfo(component: any) { - const hasColumns = component.columns && Array.isArray(component.columns); - const hasRows = component.rows && Array.isArray(component.rows); + const hasColumns = component.columns && Array.isArray(component.columns)&& component?.component?.type !=="datagrid"; + const hasRows = component.rows && Array.isArray(component.rows) const hasComps = component.components && Array.isArray(component.components); const isContent = getModelType(component) === 'content'; const isLayout = getModelType(component) === 'none'; @@ -323,7 +323,7 @@ export function getComponentData(components: Component[], data: DataObject, path } export function getComponentActualValue( - component: Component, + component: Component | undefined, compPath: string, data: any, row: any, @@ -341,6 +341,9 @@ export function getComponentActualValue( let parent = component; let rowPath = ''; + const compPathModified = compPath.split("."); + rowPath = (compPathModified.length > 1)? compPathModified[compPathModified.length-1]: compPath; + while (parent?.parent?.path && !parentInputComponent) { parent = parent.parent; if (parent.input) { @@ -357,6 +360,13 @@ export function getComponentActualValue( let value = null; if (data) { value = get(data, compPath); + if(component?.type === 'address') { + const addressIgnoreProperties = ['mode', 'address']; + const result = Object.values(omit(value, addressIgnoreProperties)).some(Boolean); + if(!result) { + value = '' + } + } } if (rowPath && row && isNil(value)) { value = get(row, rowPath); diff --git a/src/utils/operators/IsEqualTo.js b/src/utils/operators/IsEqualTo.js index c7ad34e9..8ecadbc3 100644 --- a/src/utils/operators/IsEqualTo.js +++ b/src/utils/operators/IsEqualTo.js @@ -35,10 +35,10 @@ export default class IsEqualTo extends ConditionOperator { if ( conditionComponent && - isSelectResourceWithObjectValue(conditionComponent) && - conditionComponent.template + isSelectResourceWithObjectValue(conditionComponent.component) && + conditionComponent?.component?.template ) { - return compareSelectResourceWithObjectTypeValues(value, comparedValue, conditionComponent); + return compareSelectResourceWithObjectTypeValues(value, comparedValue, conditionComponent.component); } return isEqual(value, comparedValue); From 78114ae087c764f22f3511283a42fb551125561f Mon Sep 17 00:00:00 2001 From: mikekotikov Date: Wed, 30 Oct 2024 14:59:36 +0300 Subject: [PATCH 2/3] FIO-8690: Add fixes --- src/types/BaseComponent.ts | 1 + src/types/PassedComponentInstance.ts | 1 + src/utils/conditions.ts | 236 ++++++++++++--------------- src/utils/operators/IsEqualTo.js | 6 +- 4 files changed, 111 insertions(+), 133 deletions(-) diff --git a/src/types/BaseComponent.ts b/src/types/BaseComponent.ts index 4b976a44..926e988a 100644 --- a/src/types/BaseComponent.ts +++ b/src/types/BaseComponent.ts @@ -16,6 +16,7 @@ export type SimpleConditional = { export type BaseComponent = { input: boolean; + component?: BaseComponent type: string; key: string; path?: string; diff --git a/src/types/PassedComponentInstance.ts b/src/types/PassedComponentInstance.ts index e0f9e5d1..abd4a4dd 100644 --- a/src/types/PassedComponentInstance.ts +++ b/src/types/PassedComponentInstance.ts @@ -16,6 +16,7 @@ export type PassedComponentInstance = { form: Form; options: Record; }; + parent?: Component; evaluate: (expression: string, additionalContext?: Record) => any; interpolate: (text: string, additionalContext?: Record) => string; shouldSkipValidation: (data?: DataObject, row?: DataObject) => boolean; diff --git a/src/utils/conditions.ts b/src/utils/conditions.ts index 0508af09..b06b50d5 100644 --- a/src/utils/conditions.ts +++ b/src/utils/conditions.ts @@ -122,36 +122,36 @@ function getConditionalPathsRecursive(conditionPaths: any, data: any): any { let currentGlobalIndex = 0; const conditionalPathsArray: string[] = []; const getConditionalPaths = (data: any, currentPath = '', localIndex = 0) => { - currentPath = currentPath.replace(/^\.+|\.+$/g, ''); - const currentLocalIndex = localIndex; - const currentData = _.get(data, currentPath); - if (Array.isArray(currentData) && currentData.filter(Boolean).length > 0) { - if (currentData.some(element => typeof element !== 'object')) { - return; - } - const hasInnerDataArray = currentData.find(x => Array.isArray(x[conditionPaths[currentLocalIndex]])); - if (hasInnerDataArray) { - currentData.forEach((_, indexOutside) => { - const innerCompDataPath = `${currentPath}[${indexOutside}].${conditionPaths[currentLocalIndex]}`; - getConditionalPaths(data, innerCompDataPath, currentLocalIndex + 1); - }); - } - else { - currentData.forEach((x, index) => { - if (!_.isNil(x[conditionPaths[currentLocalIndex]])) { - const compDataPath = `${currentPath}[${index}].${conditionPaths[currentLocalIndex]}`; - conditionalPathsArray.push(compDataPath); - } - }); - } + currentPath = currentPath.replace(/^\.+|\.+$/g, ''); + const currentLocalIndex = localIndex; + const currentData = _.get(data, currentPath); + if (Array.isArray(currentData) && currentData.filter(Boolean).length > 0) { + if (currentData.some(element => typeof element !== 'object')) { + return; + } + const hasInnerDataArray = currentData.find(x => Array.isArray(x[conditionPaths[currentLocalIndex]])); + if (hasInnerDataArray) { + currentData.forEach((_, indexOutside) => { + const innerCompDataPath = `${currentPath}[${indexOutside}].${conditionPaths[currentLocalIndex]}`; + getConditionalPaths(data, innerCompDataPath, currentLocalIndex + 1); + }); } else { - if (!conditionPaths[currentGlobalIndex]) { - return; + currentData.forEach((x, index) => { + if (!_.isNil(x[conditionPaths[currentLocalIndex]])) { + const compDataPath = `${currentPath}[${index}].${conditionPaths[currentLocalIndex]}`; + conditionalPathsArray.push(compDataPath); } - currentGlobalIndex = currentGlobalIndex + 1; - getConditionalPaths(data, `${currentPath}.${conditionPaths[currentGlobalIndex - 1]}`, currentGlobalIndex); + }); } + } + else { + if (!conditionPaths[currentGlobalIndex]) { + return; + } + currentGlobalIndex = currentGlobalIndex + 1; + getConditionalPaths(data, `${currentPath}.${conditionPaths[currentGlobalIndex - 1]}`, currentGlobalIndex); + } }; getConditionalPaths(data); return conditionalPathsArray; @@ -163,129 +163,105 @@ function getConditionalPathsRecursive(conditionPaths: any, data: any): any { * @param context * @returns */ -// @ts-ignore export function checkSimpleConditional( conditional: SimpleConditional, context: ConditionsContext, -): any { +): boolean | null { const { component, data, row, instance, form } = context; if (!conditional || !isSimpleConditional(conditional)) { return null; } - // @ts-ignore - if (conditional.when) { - // // @ts-ignore - // const value = getComponentActualValue(conditional!.when, data, row); - // // @ts-ignore - // const eq = String(conditional.eq); - // const show = String(conditional.show); - - // // Special check for selectboxes component. - // // @ts-ignore - // if (_.isObject(value) && _.has(value, conditional.eq)) { - // // @ts-ignore - // return String(value[conditional.eq]) === show; - // } - // // FOR-179 - Check for multiple values. - // if (Array.isArray(value) && value.map(String).includes(eq)) { - // return show === 'true'; - // } - - // return (String(value) === eq) === (show === 'true'); + const { conditions = [], conjunction = 'all', show = true } = conditional; + if (!conditions.length) { + return null; } - else { - const { conditions = [], conjunction = 'all', show = true } = conditional; - if (!conditions.length) { - return null; - } - const conditionsResult = filter( - map(conditions, (cond) => { - const { operator } = cond; - let { value: comparedValue, component: conditionComponentPath } = cond; - if (!conditionComponentPath) { - // Ignore conditions if there is no component path. - return null; + const conditionsResult = filter( + map(conditions, (cond) => { + const { operator } = cond; + let { value: comparedValue, component: conditionComponentPath } = cond; + if (!conditionComponentPath) { + // Ignore conditions if there is no component path. + return null; + } + const formComponents = form?.components || []; + let conditionComponent = getComponent(formComponents, conditionComponentPath, true); + // If condition componenet is not found, check if conditionComponentPath is value path. + // Need to handle condtions like: + // { + // "component": "selectBoxes.a", + // "operator": "isEqual", + // "value": "true" + // } + if ( + !conditionComponent && + isConditionPotentiallyBasedOnValuePath(cond) && + formComponents.length + ) { + const flattenedComponents = flattenComponents(formComponents, true); + const pathParts = split(conditionComponentPath, '.'); + const valuePathParts = []; + + while (!conditionComponent && pathParts.length) { + conditionComponent = flattenedComponents[`${pathParts.join('.')}`]; + if (!conditionComponent) { + valuePathParts.unshift(pathParts.pop()); + } } - const formComponents = form?.components || []; - let conditionComponent = getComponent(formComponents, conditionComponentPath, true); - // If condition componenet is not found, check if conditionComponentPath is value path. - // Need to handle condtions like: - // { - // "component": "selectBoxes.a", - // "operator": "isEqual", - // "value": "true" - // } if ( - !conditionComponent && - isConditionPotentiallyBasedOnValuePath(cond) && - formComponents.length + conditionComponent && + conditionComponent.type === 'selectboxes' && + valuePathParts.length ) { - const flattenedComponents = flattenComponents(formComponents, true); - const pathParts = split(conditionComponentPath, '.'); - const valuePathParts = []; - - while (!conditionComponent && pathParts.length) { - conditionComponent = flattenedComponents[`${pathParts.join('.')}`]; - if (!conditionComponent) { - valuePathParts.unshift(pathParts.pop()); - } - } - if ( - conditionComponent && - conditionComponent.type === 'selectboxes' && - valuePathParts.length - ) { - console.warn( - 'Condition based on selectboxes has wrong format. Resave the form in the form builder to fix it.', - ); - conditionComponentPath = pathParts.join('.'); - comparedValue = valuePathParts.join('.'); - } + console.warn( + 'Condition based on selectboxes has wrong format. Resave the form in the form builder to fix it.', + ); + conditionComponentPath = pathParts.join('.'); + comparedValue = valuePathParts.join('.'); } + } - const splittedConditionPath = conditionComponentPath.split('.'); - // @ts-ignore - const conditionalPaths = (component?.parent?.type || instance?.parent?.type) === 'datagrid' || (component?.parent?.type || instance?.parent?.type) === 'editgrid' ? [] : getConditionalPathsRecursive(splittedConditionPath, data); - // @ts-ignore - if(conditionComponent?.component?.type === "checkbox") { - if(typeof comparedValue === 'string') { - comparedValue = comparedValue === 'true'? true: false //!!!! replace just on: compared = compared === 'value' - } - } - if (conditionalPaths.length > 0) { - return conditionalPaths.map((path: string) => { - const value = getComponentActualValue(conditionComponent, path, data, row); + const splittedConditionPath = conditionComponentPath.split('.'); + const isParentGrid = (component?.parent?.type || instance?.parent?.type) === 'datagrid' || (component?.parent?.type || instance?.parent?.type) === 'editgrid' + const conditionalPaths = isParentGrid ? [] : getConditionalPathsRecursive(splittedConditionPath, data); - const ConditionOperator = ConditionOperators[operator]; - return ConditionOperator - ? new ConditionOperator().getResult({ value, comparedValue, instance, component, conditionComponentPath }) - : true; - }); + if (conditionComponent?.component?.type === "checkbox") { + if (typeof comparedValue === 'string') { + comparedValue = comparedValue === 'true' } + } + if (conditionComponent?.type === 'select') { + conditionComponent = conditionComponent?.component || conditionComponent; + } + if (conditionalPaths.length > 0) { + return conditionalPaths.map((path: string) => { + const value = getComponentActualValue(conditionComponent, path, data, row); - else { - - const value = getComponentActualValue(conditionComponent, conditionComponentPath, data, row); - const СonditionOperator = ConditionOperators[operator]; - return СonditionOperator - ? new СonditionOperator().getResult({ value, comparedValue, instance, component, conditionComponentPath, conditionComponent }) + const ConditionOperator = ConditionOperators[operator]; + return ConditionOperator + ? new ConditionOperator().getResult({ value, comparedValue, instance, component, conditionComponentPath }) : true; + }); + } + else { + const value = getComponentActualValue(conditionComponent, conditionComponentPath, data, row); + const СonditionOperator = ConditionOperators[operator]; + return СonditionOperator + ? new СonditionOperator().getResult({ value, comparedValue, instance, component, conditionComponentPath, conditionComponent }) + : true; + } + }), + (res) => res !== null, + ); - } - }), - (res) => res !== null, - ); - - let result = false; - switch (conjunction) { - case 'any': - result = some(conditionsResult.flat(), (res) => !!res); - break; - default: - result = every(conditionsResult.flat(), (res) => !!res); - } - return show ? result : !result; + let result = false; + switch (conjunction) { + case 'any': + result = some(conditionsResult.flat(), (res) => !!res); + break; + default: + result = every(conditionsResult.flat(), (res) => !!res); } + return show ? result : !result; } diff --git a/src/utils/operators/IsEqualTo.js b/src/utils/operators/IsEqualTo.js index 8ecadbc3..ed1ed7b8 100644 --- a/src/utils/operators/IsEqualTo.js +++ b/src/utils/operators/IsEqualTo.js @@ -35,10 +35,10 @@ export default class IsEqualTo extends ConditionOperator { if ( conditionComponent && - isSelectResourceWithObjectValue(conditionComponent.component) && - conditionComponent?.component?.template + isSelectResourceWithObjectValue(conditionComponent) && + conditionComponent?.template ) { - return compareSelectResourceWithObjectTypeValues(value, comparedValue, conditionComponent.component); + return compareSelectResourceWithObjectTypeValues(value, comparedValue, conditionComponent); } return isEqual(value, comparedValue); From b3387fcafc507117eca1afd3f6f6cdce8e6ad78c Mon Sep 17 00:00:00 2001 From: mikekotikov Date: Wed, 30 Oct 2024 18:11:11 +0300 Subject: [PATCH 3/3] FIO-8690: Add small fixes --- src/utils/conditions.ts | 7 ++++--- src/utils/formUtil/index.ts | 3 ++- src/utils/utils.ts | 4 ++++ 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/utils/conditions.ts b/src/utils/conditions.ts index b06b50d5..93aab0be 100644 --- a/src/utils/conditions.ts +++ b/src/utils/conditions.ts @@ -4,6 +4,7 @@ import { flattenComponents, getComponent, getComponentActualValue } from './form import { has, isObject, map, every, some, find, filter, isBoolean, split } from 'lodash'; import ConditionOperators from './operators'; import _ from 'lodash'; +import { checkComponentType } from './utils'; export const isJSONConditional = (conditional: any): conditional is JSONConditional => { return conditional && conditional.json && isObject(conditional.json); @@ -118,7 +119,7 @@ function isConditionPotentiallyBasedOnValuePath(condition: any = {}) { ); } -function getConditionalPathsRecursive(conditionPaths: any, data: any): any { +function getConditionalPathsRecursive(conditionPaths: string[], data: any): any { let currentGlobalIndex = 0; const conditionalPathsArray: string[] = []; const getConditionalPaths = (data: any, currentPath = '', localIndex = 0) => { @@ -225,12 +226,12 @@ export function checkSimpleConditional( const isParentGrid = (component?.parent?.type || instance?.parent?.type) === 'datagrid' || (component?.parent?.type || instance?.parent?.type) === 'editgrid' const conditionalPaths = isParentGrid ? [] : getConditionalPathsRecursive(splittedConditionPath, data); - if (conditionComponent?.component?.type === "checkbox") { + if (checkComponentType(conditionComponent, "checkbox")) { if (typeof comparedValue === 'string') { comparedValue = comparedValue === 'true' } } - if (conditionComponent?.type === 'select') { + if (checkComponentType(conditionComponent, "select")) { conditionComponent = conditionComponent?.component || conditionComponent; } if (conditionalPaths.length > 0) { diff --git a/src/utils/formUtil/index.ts b/src/utils/formUtil/index.ts index e615b2f8..df68b288 100644 --- a/src/utils/formUtil/index.ts +++ b/src/utils/formUtil/index.ts @@ -46,6 +46,7 @@ import { eachComponent } from './eachComponent'; import { eachComponentData } from './eachComponentData'; import { eachComponentAsync } from './eachComponentAsync'; import { eachComponentDataAsync } from './eachComponentDataAsync'; +import { checkComponentType } from 'utils/utils'; /** * Flatten the form components for data manipulation. @@ -360,7 +361,7 @@ export function getComponentActualValue( let value = null; if (data) { value = get(data, compPath); - if(component?.type === 'address') { + if(checkComponentType(component, "address")) { const addressIgnoreProperties = ['mode', 'address']; const result = Object.values(omit(value, addressIgnoreProperties)).some(Boolean); if(!result) { diff --git a/src/utils/utils.ts b/src/utils/utils.ts index b78ad80a..8d2506a1 100644 --- a/src/utils/utils.ts +++ b/src/utils/utils.ts @@ -126,3 +126,7 @@ export function resetEphemeralState(component: Component) { delete component.ephemeralState; } } + +export function checkComponentType(component: Component | undefined, type:string) { + return component?.type === type; +}