Skip to content

Commit

Permalink
fix: flow errors
Browse files Browse the repository at this point in the history
  • Loading branch information
simonadomnisoru committed Dec 3, 2024
1 parent ed637cb commit fefbdc6
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const makeMapStateToProps = () => {
const getRulesMessages = makeGetMessages();
const getCompulsory = makeGetCompulsory();
const getDisabled = makeGetDisabled();
const mapStateToProps = (state: Object, props: { formId: string }) => ({
const mapStateToProps = (state: Object, props: { formId: string, fieldsMetaData: any }) => ({
values: getSectionValues(state, props),
rulesHiddenFields: getHiddenFields(state, props),
rulesMessages: getRulesMessages(state, props),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export type FieldCommitOptions = {|
errorCode?: string,
|};

type FieldCommitOptionsExtended = {|
export type FieldCommitOptionsExtended = {|
...FieldCommitOptions,
plugin?: ?boolean,
|};
Expand Down Expand Up @@ -171,12 +171,12 @@ export class FormBuilder extends React.Component<Props> {
let validationData;
try {
const { validators } = field;
validationData = await validateValue(
validationData = await validateValue({
validators,
values[field.id],
value: values[field.id],
validationContext,
handleIsValidatingInternal,
);
postProcessAsyncValidatonInitiation: handleIsValidatingInternal,
});
} catch (reason) {
if (reason && isObject(reason) && reason.isCanceled) {
validationData = null;
Expand Down Expand Up @@ -405,14 +405,13 @@ export class FormBuilder extends React.Component<Props> {
errorMessage: options.error,
errorType: validatorTypes.TYPE_BASE,
errorData: undefined }) :
(await validateValue(
(await validateValue({
validators,
value,
onGetValidationContext && onGetValidationContext(),
handleIsValidatingInternal,
// $FlowFixMe
options,
)
validationContext: onGetValidationContext && onGetValidationContext(),
postProcessAsyncValidatonInitiation: handleIsValidatingInternal,
commitOptions: options,
})
// $FlowFixMe[prop-missing] automated comment
.then(({ valid, errorMessage, errorType, errorData }) => {
updateField({ valid, errorMessage, errorType, errorData });
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// @flow
export { FormBuilder } from './FormBuilder.component';
export type { PostProcessErrorMessage, ErrorData } from './formbuilder.types';
export type { FieldConfig, FieldCommitOptions } from './FormBuilder.component';
export type { FieldConfig, FieldCommitOptionsExtended } from './FormBuilder.component';
2 changes: 1 addition & 1 deletion src/core_modules/capture-core/components/D2Form/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// @flow
export { asyncHandlerActionTypes, asyncUpdateFieldEpic } from './asyncHandlerHOC';
export { D2Form } from './D2Form.container';
export type { FieldCommitOptions } from './FormBuilder';
export type { FieldCommitOptionsExtended } from './FormBuilder';
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export const validateAssignEffects = async ({
const validationContext = onGetValidationContext && onGetValidationContext();

try {
const validatorResult = await validateValue(validators, value, validationContext);
const validatorResult = await validateValue({ validators, value, validationContext });
const effectWithValidation = Object.assign({}, effectsForId[lastIndex], validatorResult);

acc[metaData.id] = [effectWithValidation];
Expand Down
16 changes: 11 additions & 5 deletions src/core_modules/capture-core/utils/validation/validateValue.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @flow
import type { ValidatorContainer } from './getValidators';
import type { FieldCommitOptions } from '../../components/D2Form';
import type { FieldCommitOptionsExtended } from '../../components/D2Form';

export type Validations = {
valid: boolean,
Expand All @@ -9,13 +9,19 @@ export type Validations = {
errorData?: Object,
};

export const validateValue = async (
export const validateValue = async ({
validators,
value,
validationContext,
postProcessAsyncValidatonInitiation,
commitOptions,
}: {
validators?: Array<ValidatorContainer>,
value: any,
validationContext: ?Object,
postProcessAsyncValidatonInitiation: ?Function,
commitOptions?: ?FieldCommitOptions,
): Promise<Validations> => {
postProcessAsyncValidatonInitiation?: Function,
commitOptions?: ?FieldCommitOptionsExtended,
}): Promise<Validations> => {
if (!validators || validators.length === 0) {
return {
valid: true,
Expand Down

0 comments on commit fefbdc6

Please sign in to comment.