mirror of
https://github.com/apache/superset.git
synced 2026-04-18 15:44:57 +00:00
fix(native-filter): infinite filter loading by deps (#39175)
This commit is contained in:
@@ -46,7 +46,7 @@ import { useDispatch, useSelector } from 'react-redux';
|
||||
import { isEqual, isEqualWith } from 'lodash';
|
||||
import { getChartDataRequest } from 'src/components/Chart/chartAction';
|
||||
import { ErrorAlert, ErrorMessageWithStackTrace } from 'src/components';
|
||||
import { Loading, Constants } from '@superset-ui/core/components';
|
||||
import { Loading, Constants, Flex } from '@superset-ui/core/components';
|
||||
import { waitForAsyncData } from 'src/middleware/asyncEvent';
|
||||
import { FilterBarOrientation, RootState } from 'src/dashboard/types';
|
||||
import {
|
||||
@@ -128,6 +128,8 @@ const FilterValue: FC<FilterValueProps> = ({
|
||||
[isCustomization],
|
||||
);
|
||||
const [state, setState] = useState<ChartDataResponseResult[]>([]);
|
||||
const hasDeps = Boolean(filter.cascadeParentIds?.length);
|
||||
const [hasDepsFilterValue, setHasDepsFilterValue] = useState(hasDeps);
|
||||
const dashboardId = useSelector<RootState, number>(
|
||||
state => state.dashboardInfo.id,
|
||||
);
|
||||
@@ -160,6 +162,10 @@ const FilterValue: FC<FilterValueProps> = ({
|
||||
}
|
||||
}, [dispatch, shouldRefresh]);
|
||||
|
||||
useEffect(() => {
|
||||
setHasDepsFilterValue(hasDeps);
|
||||
}, [hasDeps]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!inViewFirstTime && inView) {
|
||||
setInViewFirstTime(true);
|
||||
@@ -185,28 +191,31 @@ const FilterValue: FC<FilterValueProps> = ({
|
||||
// Prevent unnecessary backend requests by validating parent filter selections first
|
||||
|
||||
let selectedParentFilterValueCounts = 0;
|
||||
|
||||
let isTimeRangeSelected = false;
|
||||
(filter.cascadeParentIds ?? []).forEach(pId => {
|
||||
const extraFormData = dataMaskSelected?.[pId]?.extraFormData;
|
||||
if (extraFormData?.filters?.length) {
|
||||
selectedParentFilterValueCounts += extraFormData.filters.length;
|
||||
} else if (extraFormData?.time_range) {
|
||||
selectedParentFilterValueCounts += 1;
|
||||
}
|
||||
if (extraFormData?.time_range) {
|
||||
isTimeRangeSelected = true;
|
||||
}
|
||||
});
|
||||
|
||||
// check if all parent filters with defaults have a value selected
|
||||
|
||||
let depsCount = dependencies.filters?.length ?? 0;
|
||||
const depsCount = dependencies.filters?.length ?? 0;
|
||||
const hasTimeRangeDeps = Boolean(dependencies?.time_range);
|
||||
|
||||
if (dependencies?.time_range) {
|
||||
depsCount += 1;
|
||||
}
|
||||
if (selectedParentFilterValueCounts !== depsCount) {
|
||||
if (
|
||||
selectedParentFilterValueCounts !== depsCount ||
|
||||
(hasTimeRangeDeps && !isTimeRangeSelected)
|
||||
) {
|
||||
// child filter should not request backend until it
|
||||
// has all the required information from parent filters
|
||||
return;
|
||||
}
|
||||
setHasDepsFilterValue(false);
|
||||
}
|
||||
|
||||
// TODO: We should try to improve our useEffect hooks to depend more on
|
||||
@@ -281,6 +290,7 @@ const FilterValue: FC<FilterValueProps> = ({
|
||||
isRefreshing,
|
||||
shouldRefresh,
|
||||
dataMaskSelected,
|
||||
setHasDepsFilterValue,
|
||||
]);
|
||||
|
||||
useEffect(() => {
|
||||
@@ -397,7 +407,12 @@ const FilterValue: FC<FilterValueProps> = ({
|
||||
overflow={overflow}
|
||||
>
|
||||
{isLoading ? (
|
||||
<Loading position="inline-centered" size="s" muted />
|
||||
<Flex align="center">
|
||||
<Loading position="inline" size="s" muted />
|
||||
{hasDepsFilterValue
|
||||
? t('Awaiting filter selection')
|
||||
: t('Loading filter values')}
|
||||
</Flex>
|
||||
) : (
|
||||
<SuperChart
|
||||
height={HEIGHT}
|
||||
|
||||
Reference in New Issue
Block a user