Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Removes Redux state mutations - iteration 2 #23535

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions superset-frontend/src/dashboard/actions/nativeFilters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
makeApi,
} from '@superset-ui/core';
import { Dispatch } from 'redux';
import { cloneDeep } from 'lodash';
import {
SET_DATA_MASK_FOR_FILTER_CONFIG_FAIL,
setDataMaskForFilterConfigComplete,
Expand Down Expand Up @@ -189,7 +190,7 @@ export const setInScopeStatusOfFilters =
filterConfig: filtersWithScopes,
});
// need to update native_filter_configuration in the dashboard metadata
const { metadata } = getState().dashboardInfo;
const metadata = cloneDeep(getState().dashboardInfo.metadata);
const filterConfig: FilterConfiguration =
metadata.native_filter_configuration;
const mergedFilterConfig = filterConfig.map(filter => {
Expand Down Expand Up @@ -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 =
| SetFilterConfigBegin
| SetFilterConfigComplete
Expand All @@ -415,4 +433,5 @@ export type AnyFilterAction =
| DeleteFilterSetFail
| UpdateFilterSetBegin
| UpdateFilterSetComplete
| UpdateFilterSetFail;
| UpdateFilterSetFail
| UpdateCascadeParentIds;
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,12 @@ import {
SLOW_DEBOUNCE,
t,
} from '@superset-ui/core';
import { useDispatch } from 'react-redux';
import { AntdForm } from 'src/components';
import ErrorBoundary from 'src/components/ErrorBoundary';
import { StyledModal } from 'src/components/Modal';
import { testWithId } from 'src/utils/testUtils';
import { updateCascadeParentIds } from 'src/dashboard/actions/nativeFilters';
import { useFilterConfigMap, useFilterConfiguration } from '../state';
import FilterConfigurePane from './FilterConfigurePane';
import FiltersConfigForm, {
Expand Down Expand Up @@ -116,6 +118,8 @@ function FiltersConfigModal({
onSave,
onCancel,
}: FiltersConfigModalProps) {
const dispatch = useDispatch();

const [form] = AntdForm.useForm<NativeFiltersForm>();

const configFormRef = useRef<any>();
Expand Down Expand Up @@ -309,8 +313,11 @@ function FiltersConfigModal({
}
const { cascadeParentIds } = filter;
if (cascadeParentIds) {
filter.cascadeParentIds = cascadeParentIds.filter(id =>
canBeUsedAsDependency(id),
dispatch(
updateCascadeParentIds(
key,
cascadeParentIds.filter(id => canBeUsedAsDependency(id)),
),
);
}
});
Expand Down
13 changes: 13 additions & 0 deletions superset-frontend/src/dashboard/reducers/nativeFilters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
UNSET_FOCUSED_NATIVE_FILTER,
SET_HOVERED_NATIVE_FILTER,
UNSET_HOVERED_NATIVE_FILTER,
UPDATE_CASCADE_PARENT_IDS,
} from 'src/dashboard/actions/nativeFilters';
import {
FilterSet,
Expand Down Expand Up @@ -116,6 +117,18 @@ export default function nativeFilterReducer(
...state,
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
default:
return state;
Expand Down