You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by mi...@apache.org on 2023/04/10 22:01:42 UTC
[superset] branch master updated: fix: Removes Redux state mutations - iteration 3 (#23637)
This is an automated email from the ASF dual-hosted git repository.
michaelsmolina pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/superset.git
The following commit(s) were added to refs/heads/master by this push:
new 8bd8276791 fix: Removes Redux state mutations - iteration 3 (#23637)
8bd8276791 is described below
commit 8bd827679116204aa523c3dd0487104d03ab7376
Author: Michael S. Molina <70...@users.noreply.github.com>
AuthorDate: Mon Apr 10 19:01:34 2023 -0300
fix: Removes Redux state mutations - iteration 3 (#23637)
---
superset-frontend/src/components/Chart/ChartRenderer.jsx | 15 ++++++++++++---
1 file changed, 12 insertions(+), 3 deletions(-)
diff --git a/superset-frontend/src/components/Chart/ChartRenderer.jsx b/superset-frontend/src/components/Chart/ChartRenderer.jsx
index 1b72b4afe1..fa2c0ddc0d 100644
--- a/superset-frontend/src/components/Chart/ChartRenderer.jsx
+++ b/superset-frontend/src/components/Chart/ChartRenderer.jsx
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-import { snakeCase, isEqual } from 'lodash';
+import { snakeCase, isEqual, cloneDeep } from 'lodash';
import PropTypes from 'prop-types';
import React from 'react';
import {
@@ -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) {
@@ -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) ||
@@ -246,7 +256,6 @@ class ChartRenderer extends React.Component {
chartIsStale,
formData,
latestQueryFormData,
- queriesResponse,
postTransformProps,
} = this.props;
@@ -339,7 +348,7 @@ class ChartRenderer extends React.Component {
filterState={filterState}
hooks={this.hooks}
behaviors={behaviors}
- queriesData={queriesResponse}
+ queriesData={this.mutableQueriesResponse}
onRenderSuccess={this.handleRenderSuccess}
onRenderFailure={this.handleRenderFailure}
noResults={noResultsComponent}