Skip to content

Commit

Permalink
Moves cloning logic
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-s-molina committed Apr 10, 2023
1 parent 3a8aaa7 commit d3d7797
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions superset-frontend/src/components/Chart/ChartRenderer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ class ChartRenderer extends React.Component {
this.props.actions?.updateDataMask(this.props.chartId, dataMask);
},
};

// TODO: queriesResponse comes from Redux store but it's being edited by
// the plugins, hence we need to clone it to avoid state mutation
// until we change the reducers to use Redux Toolkit with Immer
this.mutableQueriesResponse = cloneDeep(this.props.queriesResponse);
}

shouldComponentUpdate(nextProps, nextState) {
Expand All @@ -131,6 +136,11 @@ class ChartRenderer extends React.Component {
}
this.hasQueryResponseChange =
nextProps.queriesResponse !== this.props.queriesResponse;

if (this.hasQueryResponseChange) {
this.mutableQueriesResponse = cloneDeep(nextProps.queriesResponse);
}

return (
this.hasQueryResponseChange ||
!isEqual(nextProps.datasource, this.props.datasource) ||
Expand Down Expand Up @@ -246,15 +256,9 @@ class ChartRenderer extends React.Component {
chartIsStale,
formData,
latestQueryFormData,
queriesResponse,
postTransformProps,
} = this.props;

// TODO: queriesResponse comes from Redux store but it's being edited by
// the plugins, hence we need to clone it to avoid state mutation
// until we change the reducers to use Redux Toolkit with Immer
const mutableQueriesResponse = cloneDeep(queriesResponse);

const currentFormData =
chartIsStale && latestQueryFormData ? latestQueryFormData : formData;
const vizType = currentFormData.viz_type || this.props.vizType;
Expand Down Expand Up @@ -344,7 +348,7 @@ class ChartRenderer extends React.Component {
filterState={filterState}
hooks={this.hooks}
behaviors={behaviors}
queriesData={mutableQueriesResponse}
queriesData={this.mutableQueriesResponse}
onRenderSuccess={this.handleRenderSuccess}
onRenderFailure={this.handleRenderFailure}
noResults={noResultsComponent}
Expand Down

0 comments on commit d3d7797

Please sign in to comment.