mirror of
https://github.com/apache/superset.git
synced 2024-09-12 00:29:39 -04:00
fix: Removes Redux state mutations - iteration 2 (#23535)
This commit is contained in:
parent
117360cd57
commit
3cff2b0a58
@ -25,6 +25,7 @@ import {
|
|||||||
makeApi,
|
makeApi,
|
||||||
} from '@superset-ui/core';
|
} from '@superset-ui/core';
|
||||||
import { Dispatch } from 'redux';
|
import { Dispatch } from 'redux';
|
||||||
|
import { cloneDeep } from 'lodash';
|
||||||
import {
|
import {
|
||||||
SET_DATA_MASK_FOR_FILTER_CONFIG_FAIL,
|
SET_DATA_MASK_FOR_FILTER_CONFIG_FAIL,
|
||||||
setDataMaskForFilterConfigComplete,
|
setDataMaskForFilterConfigComplete,
|
||||||
@ -189,7 +190,7 @@ export const setInScopeStatusOfFilters =
|
|||||||
filterConfig: filtersWithScopes,
|
filterConfig: filtersWithScopes,
|
||||||
});
|
});
|
||||||
// need to update native_filter_configuration in the dashboard metadata
|
// need to update native_filter_configuration in the dashboard metadata
|
||||||
const { metadata } = getState().dashboardInfo;
|
const metadata = cloneDeep(getState().dashboardInfo.metadata);
|
||||||
const filterConfig: FilterConfiguration =
|
const filterConfig: FilterConfiguration =
|
||||||
metadata.native_filter_configuration;
|
metadata.native_filter_configuration;
|
||||||
const mergedFilterConfig = filterConfig.map(filter => {
|
const mergedFilterConfig = filterConfig.map(filter => {
|
||||||
@ -394,6 +395,23 @@ export function unsetHoveredNativeFilter(): UnsetHoveredNativeFilter {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const UPDATE_CASCADE_PARENT_IDS = 'UPDATE_CASCADE_PARENT_IDS';
|
||||||
|
export interface UpdateCascadeParentIds {
|
||||||
|
type: typeof UPDATE_CASCADE_PARENT_IDS;
|
||||||
|
id: string;
|
||||||
|
parentIds: string[];
|
||||||
|
}
|
||||||
|
export function updateCascadeParentIds(
|
||||||
|
id: string,
|
||||||
|
parentIds: string[],
|
||||||
|
): UpdateCascadeParentIds {
|
||||||
|
return {
|
||||||
|
type: UPDATE_CASCADE_PARENT_IDS,
|
||||||
|
id,
|
||||||
|
parentIds,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
export type AnyFilterAction =
|
export type AnyFilterAction =
|
||||||
| SetFilterConfigBegin
|
| SetFilterConfigBegin
|
||||||
| SetFilterConfigComplete
|
| SetFilterConfigComplete
|
||||||
@ -415,4 +433,5 @@ export type AnyFilterAction =
|
|||||||
| DeleteFilterSetFail
|
| DeleteFilterSetFail
|
||||||
| UpdateFilterSetBegin
|
| UpdateFilterSetBegin
|
||||||
| UpdateFilterSetComplete
|
| UpdateFilterSetComplete
|
||||||
| UpdateFilterSetFail;
|
| UpdateFilterSetFail
|
||||||
|
| UpdateCascadeParentIds;
|
||||||
|
@ -33,10 +33,12 @@ import {
|
|||||||
SLOW_DEBOUNCE,
|
SLOW_DEBOUNCE,
|
||||||
t,
|
t,
|
||||||
} from '@superset-ui/core';
|
} from '@superset-ui/core';
|
||||||
|
import { useDispatch } from 'react-redux';
|
||||||
import { AntdForm } from 'src/components';
|
import { AntdForm } from 'src/components';
|
||||||
import ErrorBoundary from 'src/components/ErrorBoundary';
|
import ErrorBoundary from 'src/components/ErrorBoundary';
|
||||||
import { StyledModal } from 'src/components/Modal';
|
import { StyledModal } from 'src/components/Modal';
|
||||||
import { testWithId } from 'src/utils/testUtils';
|
import { testWithId } from 'src/utils/testUtils';
|
||||||
|
import { updateCascadeParentIds } from 'src/dashboard/actions/nativeFilters';
|
||||||
import { useFilterConfigMap, useFilterConfiguration } from '../state';
|
import { useFilterConfigMap, useFilterConfiguration } from '../state';
|
||||||
import FilterConfigurePane from './FilterConfigurePane';
|
import FilterConfigurePane from './FilterConfigurePane';
|
||||||
import FiltersConfigForm, {
|
import FiltersConfigForm, {
|
||||||
@ -116,6 +118,8 @@ function FiltersConfigModal({
|
|||||||
onSave,
|
onSave,
|
||||||
onCancel,
|
onCancel,
|
||||||
}: FiltersConfigModalProps) {
|
}: FiltersConfigModalProps) {
|
||||||
|
const dispatch = useDispatch();
|
||||||
|
|
||||||
const [form] = AntdForm.useForm<NativeFiltersForm>();
|
const [form] = AntdForm.useForm<NativeFiltersForm>();
|
||||||
|
|
||||||
const configFormRef = useRef<any>();
|
const configFormRef = useRef<any>();
|
||||||
@ -309,8 +313,11 @@ function FiltersConfigModal({
|
|||||||
}
|
}
|
||||||
const { cascadeParentIds } = filter;
|
const { cascadeParentIds } = filter;
|
||||||
if (cascadeParentIds) {
|
if (cascadeParentIds) {
|
||||||
filter.cascadeParentIds = cascadeParentIds.filter(id =>
|
dispatch(
|
||||||
canBeUsedAsDependency(id),
|
updateCascadeParentIds(
|
||||||
|
key,
|
||||||
|
cascadeParentIds.filter(id => canBeUsedAsDependency(id)),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -25,6 +25,7 @@ import {
|
|||||||
UNSET_FOCUSED_NATIVE_FILTER,
|
UNSET_FOCUSED_NATIVE_FILTER,
|
||||||
SET_HOVERED_NATIVE_FILTER,
|
SET_HOVERED_NATIVE_FILTER,
|
||||||
UNSET_HOVERED_NATIVE_FILTER,
|
UNSET_HOVERED_NATIVE_FILTER,
|
||||||
|
UPDATE_CASCADE_PARENT_IDS,
|
||||||
} from 'src/dashboard/actions/nativeFilters';
|
} from 'src/dashboard/actions/nativeFilters';
|
||||||
import {
|
import {
|
||||||
FilterSet,
|
FilterSet,
|
||||||
@ -116,6 +117,18 @@ export default function nativeFilterReducer(
|
|||||||
...state,
|
...state,
|
||||||
hoveredFilterId: undefined,
|
hoveredFilterId: undefined,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
case UPDATE_CASCADE_PARENT_IDS:
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
filters: {
|
||||||
|
...state.filters,
|
||||||
|
[action.id]: {
|
||||||
|
...state.filters[action.id],
|
||||||
|
cascadeParentIds: action.parentIds,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
// TODO handle SET_FILTER_CONFIG_FAIL action
|
// TODO handle SET_FILTER_CONFIG_FAIL action
|
||||||
default:
|
default:
|
||||||
return state;
|
return state;
|
||||||
|
Loading…
Reference in New Issue
Block a user