Skip to content

Commit

Permalink
fix: Removes Redux state mutations - iteration 1 (#23522)
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-s-molina authored Mar 31, 2023
1 parent ee9ef24 commit 1ced7cd
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
4 changes: 2 additions & 2 deletions superset-frontend/src/components/Chart/chartReducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
/* eslint camelcase: 0 */
import { t } from '@superset-ui/core';
import { omit } from 'lodash';
import { HYDRATE_DASHBOARD } from 'src/dashboard/actions/hydrate';
import { DatasourcesAction } from 'src/dashboard/actions/datasources';
import { ChartState } from 'src/explore/types';
Expand Down Expand Up @@ -180,8 +181,7 @@ export default function chartReducer(

/* eslint-disable no-param-reassign */
if (action.type === actions.REMOVE_CHART) {
delete charts[action.key];
return charts;
return omit(charts, [action.key]);
}
if (action.type === actions.UPDATE_CHART_ID) {
const { newId, key } = action;
Expand Down
5 changes: 3 additions & 2 deletions superset-frontend/src/dashboard/util/crossFilters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/

import { cloneDeep } from 'lodash';
import {
Behavior,
FeatureFlag,
Expand Down Expand Up @@ -60,7 +60,8 @@ export const getCrossFiltersConfiguration = (

if (behaviors.includes(Behavior.INTERACTIVE_CHART)) {
if (initialConfig[chartId]) {
chartConfiguration[chartId] = initialConfig[chartId];
// We need to clone to avoid mutating Redux state
chartConfiguration[chartId] = cloneDeep(initialConfig[chartId]);
}
if (!chartConfiguration[chartId]) {
chartConfiguration[chartId] = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { logging } from '@superset-ui/core';

/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
Expand All @@ -18,6 +16,8 @@ import { logging } from '@superset-ui/core';
* specific language governing permissions and limitations
* under the License.
*/
import { logging } from '@superset-ui/core';

export default function updateComponentParentsList({
currentComponent,
layout = {},
Expand All @@ -32,11 +32,14 @@ export default function updateComponentParentsList({

if (Array.isArray(currentComponent.children)) {
currentComponent.children.forEach(childId => {
const child = layout[childId];
if (child) {
child.parents = parentsList; // eslint-disable-line no-param-reassign
if (layout[childId]) {
// eslint-disable-next-line no-param-reassign
layout[childId] = {
...layout[childId],
parents: parentsList,
};
updateComponentParentsList({
currentComponent: child,
currentComponent: layout[childId],
layout,
});
} else {
Expand Down

0 comments on commit 1ced7cd

Please sign in to comment.