ktmud commented on a change in pull request #9891:
URL: 
https://github.com/apache/incubator-superset/pull/9891#discussion_r430052816



##########
File path: superset-frontend/src/dashboard/components/Dashboard.jsx
##########
@@ -205,6 +181,56 @@ class Dashboard extends React.PureComponent {
     return Object.values(this.props.charts);
   }
 
+  applyFilters() {
+    const appliedFilters = this.appliedFilters;
+    const { activeFilters } = this.props;
+
+    // refresh charts if a filter was removed, added, or changed
+    const currFilterKeys = Object.keys(activeFilters);
+    const appliedFilterKeys = Object.keys(appliedFilters);
+
+    const allKeys = new Set(currFilterKeys.concat(appliedFilterKeys));
+    const affectedChartIds = [];
+    [...allKeys].forEach(filterKey => {
+      if (!currFilterKeys.includes(filterKey)) {
+        // removed filter?
+        affectedChartIds.push(...appliedFilters[filterKey].scope);
+      } else if (!appliedFilterKeys.includes(filterKey)) {
+        // added filter?
+        affectedChartIds.push(...activeFilters[filterKey].scope);
+      } else {
+        // if filter changes value
+        // update charts in its scope
+        if (
+          !areObjectsEqual(
+            appliedFilters[filterKey].values,
+            activeFilters[filterKey].values,
+          )
+        ) {
+          affectedChartIds.push(...activeFilters[filterKey].scope);
+        }
+
+        // if filter change scope
+        // update all charts in its scope
+        if (
+          !areObjectsEqual(
+            appliedFilters[filterKey].scope,
+            activeFilters[filterKey].scope,
+          )
+        ) {
+          const chartsInScope = (activeFilters[filterKey].scope || []).concat(
+            appliedFilters[filterKey].scope || [],
+          );
+          affectedChartIds.push(...chartsInScope);
+        }
+      }
+    });
+
+    const idSet = new Set(affectedChartIds);
+    this.refreshCharts([...idSet]);

Review comment:
       Nit:
   
   ```
   this.refreshCharts([...new Set(affectedChartIds)]);
   ```




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscr...@superset.apache.org
For additional commands, e-mail: notifications-h...@superset.apache.org

Reply via email to