You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by el...@apache.org on 2021/12/06 21:50:13 UTC

[superset] 02/05: Revert "fix(native-filters): Fix update ownState (#17181)" (#17311)

This is an automated email from the ASF dual-hosted git repository.

elizabeth pushed a commit to branch 1.4
in repository https://gitbox.apache.org/repos/asf/superset.git

commit 9818bc5e7a37f3883c4e9581cdeec8561605eea5
Author: Erik Ritter <er...@airbnb.com>
AuthorDate: Tue Nov 2 13:17:29 2021 -0700

    Revert "fix(native-filters): Fix update ownState (#17181)" (#17311)
    
    This reverts commit cf284ba3c72550f64ddb19aeed44de2c5cf0b677.
    
    (cherry picked from commit 7c6d6f47bf71dce15e049f37fe82076bf7cb9c63)
---
 .../src/dashboard/components/Dashboard.jsx         | 81 +++++++---------------
 1 file changed, 24 insertions(+), 57 deletions(-)

diff --git a/superset-frontend/src/dashboard/components/Dashboard.jsx b/superset-frontend/src/dashboard/components/Dashboard.jsx
index 1377789..7e67288 100644
--- a/superset-frontend/src/dashboard/components/Dashboard.jsx
+++ b/superset-frontend/src/dashboard/components/Dashboard.jsx
@@ -220,55 +220,6 @@ class Dashboard extends React.PureComponent {
     return Object.values(this.props.charts);
   }
 
-  isFilterKeyRemoved(filterKey) {
-    const { appliedFilters } = this;
-    const { activeFilters } = this.props;
-
-    // refresh charts if a filter was removed, added, or changed
-    const currFilterKeys = Object.keys(activeFilters);
-    const appliedFilterKeys = Object.keys(appliedFilters);
-
-    return (
-      !currFilterKeys.includes(filterKey) &&
-      appliedFilterKeys.includes(filterKey)
-    );
-  }
-
-  isFilterKeyNewlyAdded(filterKey) {
-    const { appliedFilters } = this;
-    const appliedFilterKeys = Object.keys(appliedFilters);
-
-    return !appliedFilterKeys.includes(filterKey);
-  }
-
-  isFilterKeyChangedValue(filterKey) {
-    const { appliedFilters } = this;
-    const { activeFilters } = this.props;
-
-    return !areObjectsEqual(
-      appliedFilters[filterKey].values,
-      activeFilters[filterKey].values,
-      {
-        ignoreUndefined: true,
-      },
-    );
-  }
-
-  isFilterKeyChangedScope(filterKey) {
-    const { appliedFilters } = this;
-    const { activeFilters } = this.props;
-
-    return !areObjectsEqual(
-      appliedFilters[filterKey].scope,
-      activeFilters[filterKey].scope,
-    );
-  }
-
-  hasFilterKeyValues(filterKey) {
-    const { appliedFilters } = this;
-    return Object.keys(appliedFilters[filterKey]?.values ?? []).length;
-  }
-
   applyFilters() {
     const { appliedFilters } = this;
     const { activeFilters, ownDataCharts } = this.props;
@@ -284,21 +235,37 @@ class Dashboard extends React.PureComponent {
     );
     [...allKeys].forEach(filterKey => {
       if (
-        this.isFilterKeyRemoved(filterKey) ||
-        this.isFilterKeyNewlyAdded(filterKey)
+        !currFilterKeys.includes(filterKey) &&
+        appliedFilterKeys.includes(filterKey)
       ) {
-        // check if there are values in filter, if no, there is was added only ownState, so no need reload other charts
-        if (this.hasFilterKeyValues(filterKey)) {
-          affectedChartIds.push(...appliedFilters[filterKey].scope);
-        }
+        // filterKey is removed?
+        affectedChartIds.push(...appliedFilters[filterKey].scope);
+      } else if (!appliedFilterKeys.includes(filterKey)) {
+        // filterKey is newly added?
+        affectedChartIds.push(...activeFilters[filterKey].scope);
       } else {
+        // if filterKey changes value,
         // update charts in its scope
-        if (this.isFilterKeyChangedValue(filterKey)) {
+        if (
+          !areObjectsEqual(
+            appliedFilters[filterKey].values,
+            activeFilters[filterKey].values,
+            {
+              ignoreUndefined: true,
+            },
+          )
+        ) {
           affectedChartIds.push(...activeFilters[filterKey].scope);
         }
 
+        // if filterKey changes scope,
         // update all charts in its scope
-        if (this.isFilterKeyChangedScope(filterKey)) {
+        if (
+          !areObjectsEqual(
+            appliedFilters[filterKey].scope,
+            activeFilters[filterKey].scope,
+          )
+        ) {
           const chartsInScope = (activeFilters[filterKey].scope || []).concat(
             appliedFilters[filterKey].scope || [],
           );