Skip to content

Commit

Permalink
fix: Native filters cyclic dependency (#16921)
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-s-molina authored Sep 30, 2021
1 parent c5d23fb commit 87290dd
Showing 1 changed file with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export const validateForm = async (
errors: [error],
};
form.setFields([fieldError]);
setCurrentFilterId(filterId);
};

try {
Expand All @@ -57,25 +58,34 @@ export const validateForm = async (
}
}

const validateCycles = (filterId: string, trace: string[] = []) => {
const validateCycles = (
filterId: string,
trace: string[] = [],
): boolean => {
if (trace.includes(filterId)) {
addValidationError(
filterId,
'parentFilter',
'Cannot create cyclic hierarchy',
);
return false;
}
const parentId = formValues.filters?.[filterId]
? formValues.filters[filterId]?.parentFilter?.value
: filterConfigMap[filterId]?.cascadeParentIds?.[0];
if (parentId) {
validateCycles(parentId, [...trace, filterId]);
return validateCycles(parentId, [...trace, filterId]);
}
return true;
};

filterIds
const invalid = filterIds
.filter(id => !removedFilters[id])
.forEach(filterId => validateCycles(filterId));
.some(filterId => !validateCycles(filterId));

if (invalid) {
return null;
}

return formValues;
} catch (error) {
Expand Down

0 comments on commit 87290dd

Please sign in to comment.