From ea0e67572d3edf5bee4adc19a3a845260cfa2abd Mon Sep 17 00:00:00 2001 From: Simona Domnisoru Date: Wed, 14 Aug 2024 14:45:36 +0200 Subject: [PATCH] fix: [DHIS2-17883] revert validate values assigned from the rules engine (#3758) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Revert "fix: [BETA-116][DHIS2-15896] validate values assigned from the rules …" This reverts commit 459ab9a7fc0b0f3c3ce98e19a7acf213b35eb6e8. --- .../FormBuilder/FormBuilder.component.js | 37 +++---------------- .../descriptions/form.reducerDescription.js | 6 ++- 2 files changed, 10 insertions(+), 33 deletions(-) diff --git a/src/core_modules/capture-core/components/D2Form/FormBuilder/FormBuilder.component.js b/src/core_modules/capture-core/components/D2Form/FormBuilder/FormBuilder.component.js index 532c6ea560..f62a5c32f0 100644 --- a/src/core_modules/capture-core/components/D2Form/FormBuilder/FormBuilder.component.js +++ b/src/core_modules/capture-core/components/D2Form/FormBuilder/FormBuilder.component.js @@ -1,7 +1,6 @@ // @flow /* eslint-disable complexity */ import i18n from '@dhis2/d2-i18n'; -import { isEqual } from 'lodash'; import log from 'loglevel'; import { v4 as uuid } from 'uuid'; import * as React from 'react'; @@ -41,7 +40,6 @@ type FieldUI = { errorType?: ?string, errorData?: ErrorData, validatingMessage?: ?string, - pendingValidation?: ?boolean, }; type RenderDividerFn = (index: number, fieldsCount: number, field: FieldConfig) => React.Node; @@ -110,7 +108,6 @@ export class FormBuilder extends React.Component { if (!validators || validators.length === 0) { return { valid: true, - pendingValidation: false, }; } @@ -142,16 +139,11 @@ export class FormBuilder extends React.Component { errorMessage: validatorResult.message, errorType: validatorResult.type, errorData: validatorResult.data, - pendingValidation: false, }; } return { valid: true, - errorMessage: null, - errorType: null, - errorData: null, - pendingValidation: false, }; } @@ -188,19 +180,17 @@ export class FormBuilder extends React.Component { }, asyncUIState); } - static executeValidateFields( + static executeValidateAllFields( props: Props, fieldsValidatingPromiseContainer: FieldsValidatingPromiseContainer, - customFields?: Array, ) { const { id, - fields: allFields, + fields, values, onGetValidationContext, onIsValidating, } = props; - const fields = customFields || allFields || []; const validationContext = onGetValidationContext && onGetValidationContext(); const validationPromises = fields .map(async (field) => { @@ -243,7 +233,6 @@ export class FormBuilder extends React.Component { valid: false, errorMessage: [i18n.t('error encountered during field validation')], errorType: i18n.t('error'), - pendingValidation: false, }; log.error({ reason, field }); } @@ -279,7 +268,7 @@ export class FormBuilder extends React.Component { this.commitUpdateTriggeredForFields = {}; if (this.props.validateIfNoUIData) { - this.validateFields(this.props); + this.validateAllFields(this.props); } } @@ -288,7 +277,7 @@ export class FormBuilder extends React.Component { this.asyncUIState = FormBuilder.getAsyncUIState(this.props.fieldsUI); this.commitUpdateTriggeredForFields = {}; if (this.props.validateIfNoUIData) { - this.validateFields(newProps); + this.validateAllFields(newProps); } } else { this.asyncUIState = @@ -296,19 +285,6 @@ export class FormBuilder extends React.Component { } } - componentDidUpdate(prevProps: Props) { - const { fieldsUI, fields } = this.props; - - if (!isEqual(prevProps.fieldsUI, fieldsUI)) { - const pendingValidationFields = Object.keys(fieldsUI).filter(key => fieldsUI[key].pendingValidation); - - if (pendingValidationFields.length !== 0 && !this.validateAllCancelablePromise) { - const fieldsToValidate = fields.filter(field => pendingValidationFields.includes(field.id)); - this.validateFields(this.props, fieldsToValidate); - } - } - } - getCleanUpData() { const remainingCompleteUids: Array = Object .keys(this.fieldsValidatingPromiseContainer) @@ -324,13 +300,12 @@ export class FormBuilder extends React.Component { return remainingCompleteUids; } - validateFields( + validateAllFields( props: Props, - customFields?: Array, ) { this.validateAllCancelablePromise && this.validateAllCancelablePromise.cancel(); this.validateAllCancelablePromise = makeCancelablePromise( - FormBuilder.executeValidateFields(props, this.fieldsValidatingPromiseContainer, customFields), + FormBuilder.executeValidateAllFields(props, this.fieldsValidatingPromiseContainer), ); this.validateAllCancelablePromise diff --git a/src/core_modules/capture-core/reducers/descriptions/form.reducerDescription.js b/src/core_modules/capture-core/reducers/descriptions/form.reducerDescription.js index b0d3bd5231..30dd29a15f 100644 --- a/src/core_modules/capture-core/reducers/descriptions/form.reducerDescription.js +++ b/src/core_modules/capture-core/reducers/descriptions/form.reducerDescription.js @@ -216,11 +216,13 @@ export const formsSectionsFieldsUIDesc = createReducerDescription({ const updatedFields = Object.keys(assignEffects).reduce((acc, id) => { if (formSectionFields[id]) { acc[id] = { - ...state[formId][id], + valid: true, + errorData: undefined, + errorMessage: undefined, + errorType: undefined, modified: true, touched: true, validatingMessage: null, - pendingValidation: true, }; } return acc;