Skip to content

Commit

Permalink
fix: [DHIS2-17883] revert validate values assigned from the rules eng…
Browse files Browse the repository at this point in the history
…ine (#3758)

Revert "fix: [BETA-116][DHIS2-15896] validate values assigned from the rules …"

This reverts commit 459ab9a.
  • Loading branch information
simonadomnisoru authored Aug 14, 2024
1 parent 4461efa commit ea0e675
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 33 deletions.
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -41,7 +40,6 @@ type FieldUI = {
errorType?: ?string,
errorData?: ErrorData,
validatingMessage?: ?string,
pendingValidation?: ?boolean,
};

type RenderDividerFn = (index: number, fieldsCount: number, field: FieldConfig) => React.Node;
Expand Down Expand Up @@ -110,7 +108,6 @@ export class FormBuilder extends React.Component<Props> {
if (!validators || validators.length === 0) {
return {
valid: true,
pendingValidation: false,
};
}

Expand Down Expand Up @@ -142,16 +139,11 @@ export class FormBuilder extends React.Component<Props> {
errorMessage: validatorResult.message,
errorType: validatorResult.type,
errorData: validatorResult.data,
pendingValidation: false,
};
}

return {
valid: true,
errorMessage: null,
errorType: null,
errorData: null,
pendingValidation: false,
};
}

Expand Down Expand Up @@ -188,19 +180,17 @@ export class FormBuilder extends React.Component<Props> {
}, asyncUIState);
}

static executeValidateFields(
static executeValidateAllFields(
props: Props,
fieldsValidatingPromiseContainer: FieldsValidatingPromiseContainer,
customFields?: Array<FieldConfig>,
) {
const {
id,
fields: allFields,
fields,
values,
onGetValidationContext,
onIsValidating,
} = props;
const fields = customFields || allFields || [];
const validationContext = onGetValidationContext && onGetValidationContext();
const validationPromises = fields
.map(async (field) => {
Expand Down Expand Up @@ -243,7 +233,6 @@ export class FormBuilder extends React.Component<Props> {
valid: false,
errorMessage: [i18n.t('error encountered during field validation')],
errorType: i18n.t('error'),
pendingValidation: false,
};
log.error({ reason, field });
}
Expand Down Expand Up @@ -279,7 +268,7 @@ export class FormBuilder extends React.Component<Props> {
this.commitUpdateTriggeredForFields = {};

if (this.props.validateIfNoUIData) {
this.validateFields(this.props);
this.validateAllFields(this.props);
}
}

Expand All @@ -288,27 +277,14 @@ export class FormBuilder extends React.Component<Props> {
this.asyncUIState = FormBuilder.getAsyncUIState(this.props.fieldsUI);
this.commitUpdateTriggeredForFields = {};
if (this.props.validateIfNoUIData) {
this.validateFields(newProps);
this.validateAllFields(newProps);
}
} else {
this.asyncUIState =
FormBuilder.updateAsyncUIState(this.props.fieldsUI, newProps.fieldsUI, this.asyncUIState);
}
}

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<string> = Object
.keys(this.fieldsValidatingPromiseContainer)
Expand All @@ -324,13 +300,12 @@ export class FormBuilder extends React.Component<Props> {
return remainingCompleteUids;
}

validateFields(
validateAllFields(
props: Props,
customFields?: Array<FieldConfig>,
) {
this.validateAllCancelablePromise && this.validateAllCancelablePromise.cancel();
this.validateAllCancelablePromise = makeCancelablePromise(
FormBuilder.executeValidateFields(props, this.fieldsValidatingPromiseContainer, customFields),
FormBuilder.executeValidateAllFields(props, this.fieldsValidatingPromiseContainer),
);

this.validateAllCancelablePromise
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit ea0e675

Please sign in to comment.