From 3b45739d0c0933884220b6731291bb9a85fd8956 Mon Sep 17 00:00:00 2001 From: paschalidi Date: Mon, 7 Dec 2020 16:05:24 +0100 Subject: [PATCH] fix: improves perf --- .../capture-core/rules/actionsCreator/inputHelpers.js | 10 ++++------ .../rules/actionsCreator/postProcessRulesEffects.js | 9 ++++++--- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/core_modules/capture-core/rules/actionsCreator/inputHelpers.js b/src/core_modules/capture-core/rules/actionsCreator/inputHelpers.js index 53810f66a9..9a6ec158e9 100644 --- a/src/core_modules/capture-core/rules/actionsCreator/inputHelpers.js +++ b/src/core_modules/capture-core/rules/actionsCreator/inputHelpers.js @@ -31,11 +31,10 @@ function convertFormValuesToClientValues(formValues: {[key: string]: any}, rende function getValidFormValues(formValues: { [key: string]: any }, fieldsValidation: { [key: string]: boolean }) { return Object.keys(formValues) - .reduce((accValidFormValues, key) => { - const isValid = fieldsValidation[key]; - accValidFormValues[key] = isValid ? formValues[key] : null; - return accValidFormValues; - }, {}); + .filter(key => fieldsValidation[key]) + .reduce((accValidFormValues, key) => ( + { ...accValidFormValues, [key]: formValues[key] } + ), {}); } function getFieldsValidationForForm(sectionsFieldsUI: Object, formId: string) { @@ -72,7 +71,6 @@ export function getCurrentClientValues( fieldValidations; const validFormValues = getValidFormValues(updatedCurrentFormData, updatedFieldValidations); - const clientData = convertFormValuesToClientValues(validFormValues, foundation); return clientData; } diff --git a/src/core_modules/capture-core/rules/actionsCreator/postProcessRulesEffects.js b/src/core_modules/capture-core/rules/actionsCreator/postProcessRulesEffects.js index 87782f10bc..16df377a40 100644 --- a/src/core_modules/capture-core/rules/actionsCreator/postProcessRulesEffects.js +++ b/src/core_modules/capture-core/rules/actionsCreator/postProcessRulesEffects.js @@ -116,12 +116,15 @@ function filterFieldsHideEffects( } const elementIds = Object.keys(hideEffects); + const compulsoryElements = foundation.getElements().filter(({ compulsory }) => compulsory); + return elementIds .filter((elementId) => { - const element = foundation.getElement(elementId); - const dataCompulsory = element && element.compulsory; + const { compulsory: elementIsCompulsory } = + compulsoryElements.find(({ id }) => id === elementId) || {}; + const compulsoryEffect = makeCompulsoryEffects[elementId]; - return !(dataCompulsory || compulsoryEffect); + return !(elementIsCompulsory || compulsoryEffect); }) .reduce((accFilteredEffects, elementId) => { accFilteredEffects[elementId] = hideEffects[elementId];