From 7fd5d91315bc31c64d7f0a4a9823b59f23198508 Mon Sep 17 00:00:00 2001 From: mikekotikov Date: Thu, 22 Aug 2024 19:17:34 +0300 Subject: [PATCH] FIO-8414: Remove component instance from isEmptyValue execution --- .../conditions/__tests__/conditions.test.ts | 1 + src/utils/conditions.ts | 22 +++++++++---------- src/utils/formUtil.ts | 4 ++-- src/utils/operators/IsEmptyValue.js | 13 +++-------- 4 files changed, 17 insertions(+), 23 deletions(-) diff --git a/src/process/conditions/__tests__/conditions.test.ts b/src/process/conditions/__tests__/conditions.test.ts index 6e418b9d..fda7b9c5 100644 --- a/src/process/conditions/__tests__/conditions.test.ts +++ b/src/process/conditions/__tests__/conditions.test.ts @@ -8,6 +8,7 @@ const processForm = (form: any, submission: any) => { processors: [conditionProcessInfo], components: form.components, data: submission.data, + form, scope: {} }; processSync(context); diff --git a/src/utils/conditions.ts b/src/utils/conditions.ts index d426e396..41a27136 100644 --- a/src/utils/conditions.ts +++ b/src/utils/conditions.ts @@ -50,11 +50,11 @@ export function checkCustomConditional(condition: string, context: ConditionsCon /** * Checks the legacy conditionals. - * - * @param conditional - * @param context - * @param checkDefault - * @returns + * + * @param conditional + * @param context + * @param checkDefault + * @returns */ export function checkLegacyConditional(conditional: LegacyConditional, context: ConditionsContext): boolean | null { const { row, data, component } = context; @@ -75,9 +75,9 @@ export function checkLegacyConditional(conditional: LegacyConditional, context: /** * Checks the JSON Conditionals. - * @param conditional + * @param conditional * @param context - * @returns + * @returns */ export function checkJsonConditional(conditional: JSONConditional, context: ConditionsContext): boolean | null { const { evalContext } = context; @@ -90,9 +90,9 @@ export function checkJsonConditional(conditional: JSONConditional, context: Cond /** * Checks the simple conditionals. - * @param conditional - * @param context - * @returns + * @param conditional + * @param context + * @returns */ export function checkSimpleConditional(conditional: SimpleConditional, context: ConditionsContext): boolean | null { const { component, data, row, instance, form } = context; @@ -116,7 +116,7 @@ export function checkSimpleConditional(conditional: SimpleConditional, context: const ConditionOperator = ConditionOperators[operator]; return ConditionOperator - ? new ConditionOperator().getResult({ value, comparedValue, instance, component, conditionComponentPath }) + ? new ConditionOperator().getResult({ value, comparedValue, instance, component, conditionComponentPath, data, conditionComp }) : true; }), (res) => (res !== null)); diff --git a/src/utils/formUtil.ts b/src/utils/formUtil.ts index 9568b146..e7e77bbd 100644 --- a/src/utils/formUtil.ts +++ b/src/utils/formUtil.ts @@ -1173,8 +1173,8 @@ function isValueEmpty(component: Component, value: any) { return value == null || value === '' || (isArray(value) && value.length === 0) || compValueIsEmptyArray; } -export function isComponentDataEmpty(component: Component, data: any, path: string): boolean { - const value = get(data, path); +export function isComponentDataEmpty(component: Component, data: any, path: string, valueCond?:any): boolean { + const value = isNil(valueCond) ? get(data, path): valueCond; if (isCheckboxComponent(component)) { return isValueEmpty(component, value) || value === false; } else if (isDataGridComponent(component) || isEditGridComponent(component) || isDataTableComponent(component) || hasChildComponents(component)) { diff --git a/src/utils/operators/IsEmptyValue.js b/src/utils/operators/IsEmptyValue.js index 70644fa6..248eefa3 100644 --- a/src/utils/operators/IsEmptyValue.js +++ b/src/utils/operators/IsEmptyValue.js @@ -1,5 +1,5 @@ +import { isComponentDataEmpty } from 'utils/formUtil'; import ConditionOperator from './ConditionOperator'; -import { isEmpty } from 'lodash'; export default class IsEmptyValue extends ConditionOperator { static get operatorKey() { @@ -14,15 +14,8 @@ export default class IsEmptyValue extends ConditionOperator { return false; } - execute({ value, instance, conditionComponentPath }) { - const isEmptyValue = isEmpty(value); - - if (instance && instance.root) { - const conditionTriggerComponent = instance.root.getComponent?.(conditionComponentPath); - return conditionTriggerComponent?.isEmpty ? conditionTriggerComponent.isEmpty() : isEmptyValue; - } - - return isEmptyValue; + execute({ value, conditionComponentPath, data, conditionComp}) { + return isComponentDataEmpty(conditionComp, data, conditionComponentPath, value); } getResult(options) {