suddjian commented on a change in pull request #15063:
URL: https://github.com/apache/superset/pull/15063#discussion_r649340166



##########
File path: 
superset-frontend/src/dashboard/components/nativeFilters/FilterBar/FilterControls/FilterControls.tsx
##########
@@ -80,11 +80,31 @@ const FilterControls: FC<FilterControlsProps> = ({
     element => element.type === TAB_TYPE,
   );
   const showCollapsePanel = dashboardHasTabs && cascadeFilters.length > 0;
-  if (!lastFocusedTabId || !dashboardHasTabs) {
+
+  // we check native filters scopes only on dashboards with tabs
+  if (!dashboardHasTabs) {
     filtersInScope = cascadeFilters;
   } else {
     cascadeFilters.forEach((filter, index) => {
-      if (cascadeFilters[index].tabsInScope?.includes(lastFocusedTabId)) {
+      // Filter is in scope if any of it's charts is visible.
+      // Chart is visible if it's placed in an active tab tree or if it's not 
attached to any tab.
+      // Chart is in an active tab tree if all of it's ancestors of type TAB 
are active
+      const isFilterInScope = cascadeFilters[index].chartsInScope?.some(
+        chartId => {
+          const chartLayoutItem = Object.values(dashboardLayout).find(
+            layoutItem => layoutItem.meta?.chartId === chartId,
+          );
+          const tabParents = chartLayoutItem?.parents.filter(
+            (parent: string) => dashboardLayout[parent].type === TAB_TYPE,
+          );
+          return (

Review comment:
       I'd love to see this logic moved out of components into a library of 
redux selectors, such as `selectActiveTabbedCharts()`, 
`selectFiltersInScope()`, `selectChartsInScopeByFilter()` etc. That way the 
state logic will be in a central location and easier to manage.
   
   It will also allow calculations to be memoized between different components. 
This is a triple-nested loop, which could become nasty on a dashboard with a 
lot of charts, tabs, and filters with significant numbers of charts in scope. 
And I know similar loops are running elsewhere in the app.




-- 
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:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to