mirror of
https://github.com/apache/superset.git
synced 2024-09-12 00:29:39 -04:00
fix: Native filters cyclic dependency (#16921)
This commit is contained in:
parent
c5d23fbcc7
commit
87290ddcc8
@ -42,6 +42,7 @@ export const validateForm = async (
|
|||||||
errors: [error],
|
errors: [error],
|
||||||
};
|
};
|
||||||
form.setFields([fieldError]);
|
form.setFields([fieldError]);
|
||||||
|
setCurrentFilterId(filterId);
|
||||||
};
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -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)) {
|
if (trace.includes(filterId)) {
|
||||||
addValidationError(
|
addValidationError(
|
||||||
filterId,
|
filterId,
|
||||||
'parentFilter',
|
'parentFilter',
|
||||||
'Cannot create cyclic hierarchy',
|
'Cannot create cyclic hierarchy',
|
||||||
);
|
);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
const parentId = formValues.filters?.[filterId]
|
const parentId = formValues.filters?.[filterId]
|
||||||
? formValues.filters[filterId]?.parentFilter?.value
|
? formValues.filters[filterId]?.parentFilter?.value
|
||||||
: filterConfigMap[filterId]?.cascadeParentIds?.[0];
|
: filterConfigMap[filterId]?.cascadeParentIds?.[0];
|
||||||
if (parentId) {
|
if (parentId) {
|
||||||
validateCycles(parentId, [...trace, filterId]);
|
return validateCycles(parentId, [...trace, filterId]);
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
filterIds
|
const invalid = filterIds
|
||||||
.filter(id => !removedFilters[id])
|
.filter(id => !removedFilters[id])
|
||||||
.forEach(filterId => validateCycles(filterId));
|
.some(filterId => !validateCycles(filterId));
|
||||||
|
|
||||||
|
if (invalid) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
return formValues;
|
return formValues;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
Loading…
Reference in New Issue
Block a user