Skip to content

Commit

Permalink
fix: use useEffect to trigger ingestQueries only when submitting the …
Browse files Browse the repository at this point in the history
…form
  • Loading branch information
Eliav-Maimon committed Jan 12, 2025
1 parent d82e49a commit 8af5f54
Showing 1 changed file with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ export const EntityRasterDialog: React.FC<EntityRasterDialogProps> = observer(
const [vestValidationResults, setVestValidationResults] = useState<
Record<string,DraftResult>
>({} as Record<string,DraftResult>);
const [isSubmittedForm, setIsSubmittedForm] = useState(false);

const [descriptors, setDescriptors] = useState<unknown[]>([]);
const [schema, setSchema] = useState<Record<string, Yup.AnySchema>>({});
const [inputValues, setInputValues] = useState<FormikValues>({});
Expand Down Expand Up @@ -369,7 +371,10 @@ export const EntityRasterDialog: React.FC<EntityRasterDialogProps> = observer(
break;
}
});


const { topLevelEntityVestErrors ,...rest} = vestValidationResults;
removePrevNested && setVestValidationResults({topLevelEntityVestErrors});

const newSchema = removePrevNested ? removePropertiesWithPrefix(schema, NESTED_FORMS_PRFIX) : {...schema};

for(let i=0; i < partsNumber; i++ ){
Expand All @@ -381,6 +386,9 @@ export const EntityRasterDialog: React.FC<EntityRasterDialogProps> = observer(
const removePolygonPart = (polygonPartKey: string) => {
delete schema[polygonPartKey];
setSchema({...schema});

const { [polygonPartKey]: polygonPartValue, ...rest } = vestValidationResults;
setVestValidationResults(rest)
};

useEffect(() => {
Expand Down Expand Up @@ -449,7 +457,7 @@ export const EntityRasterDialog: React.FC<EntityRasterDialogProps> = observer(
break;
}
}
}, [vestValidationResults]);
}, [isSubmittedForm]);

const closeDialog = useCallback(() => {
onSetOpen(false);
Expand Down Expand Up @@ -550,7 +558,9 @@ export const EntityRasterDialog: React.FC<EntityRasterDialogProps> = observer(
vestSuite[nestedFieldName] = get(vestSuiteNested, "get")();
});

setVestValidationResults(vestSuite) ;
setVestValidationResults(vestSuite);

setIsSubmittedForm(!isSubmittedForm);
// setVestValidationResults(get(vestSuiteTopLevel, "get")()) ;
}}
vestValidationResults={vestValidationResults}
Expand Down

0 comments on commit 8af5f54

Please sign in to comment.