You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by ru...@apache.org on 2026/09/29 04:45:04 UTC
(superset) branch master updated: refactor(dashboard): simplify cross-filter scope resolution (#38762)
This is an automated email from the ASF dual-hosted git repository.
rusackas 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 1e91b933774 refactor(dashboard): simplify cross-filter scope resolution (#38762)
1e91b933774 is described below
commit 1e91b933774ad4efca0ba45d60b72eebdfad5070
Author: Mayank Aggarwal <ag...@gmail.com>
AuthorDate: Tue Sep 29 10:14:57 2026 +0530
refactor(dashboard): simplify cross-filter scope resolution (#38762)
Co-authored-by: Evan Rusackas <ev...@rusackas.com>
Co-authored-by: Evan Rusackas <ev...@preset.io>
Co-authored-by: Claude Sonnet 5 <no...@anthropic.com>
---
.../src/dashboard/util/crossFilters.test.ts | 75 ++++++++++++++++++++++
.../src/dashboard/util/crossFilters.ts | 23 +++----
.../src/dashboard/util/getRelatedCharts.ts | 32 ++-------
3 files changed, 94 insertions(+), 36 deletions(-)
diff --git a/superset-frontend/src/dashboard/util/crossFilters.test.ts b/superset-frontend/src/dashboard/util/crossFilters.test.ts
index d6519dcec64..7389a371fee 100644
--- a/superset-frontend/src/dashboard/util/crossFilters.test.ts
+++ b/superset-frontend/src/dashboard/util/crossFilters.test.ts
@@ -290,3 +290,78 @@ test('Recalculate charts in global filter scope when charts change', () => {
},
});
});
+
+test('Global cross-filter scope includes charts from other tabs (#37665)', () => {
+ // Both charts sit under a different TAB, several layers down from ROOT_ID.
+ // A global-scope cross filter must still see across the tab boundary.
+ const TABBED_LAYOUT = {
+ ROOT_ID: {
+ children: ['TABS-1'],
+ id: 'ROOT_ID',
+ type: 'ROOT',
+ },
+ 'TABS-1': {
+ children: ['TAB-1', 'TAB-2'],
+ id: 'TABS-1',
+ type: 'TABS',
+ },
+ 'TAB-1': {
+ children: ['ROW-1'],
+ id: 'TAB-1',
+ type: 'TAB',
+ },
+ 'TAB-2': {
+ children: ['ROW-2'],
+ id: 'TAB-2',
+ type: 'TAB',
+ },
+ 'ROW-1': {
+ children: ['CHART-1'],
+ id: 'ROW-1',
+ type: 'ROW',
+ },
+ 'ROW-2': {
+ children: ['CHART-2'],
+ id: 'ROW-2',
+ type: 'ROW',
+ },
+ 'CHART-1': {
+ children: [],
+ id: 'CHART-1',
+ meta: {
+ chartId: 1,
+ sliceName: 'Tab 1 chart',
+ height: 1,
+ width: 1,
+ uuid: '1',
+ },
+ parents: ['ROOT_ID', 'TABS-1', 'TAB-1', 'ROW-1'],
+ type: 'CHART',
+ },
+ 'CHART-2': {
+ children: [],
+ id: 'CHART-2',
+ meta: {
+ chartId: 2,
+ sliceName: 'Tab 2 chart',
+ height: 1,
+ width: 1,
+ uuid: '2',
+ },
+ parents: ['ROOT_ID', 'TABS-1', 'TAB-2', 'ROW-2'],
+ type: 'CHART',
+ },
+ };
+
+ const { chartConfiguration } = getCrossFiltersConfiguration(
+ // @ts-expect-error
+ TABBED_LAYOUT,
+ {},
+ CHARTS,
+ );
+
+ // Chart 1 (tab 1)'s global-scope config includes chart 2, in tab 2.
+ expect(chartConfiguration['1'].crossFilters.chartsInScope).toEqual([2]);
+ // ...and vice versa, proving the scope resolution isn't tab-local either way.
+ expect(chartConfiguration['2'].crossFilters.chartsInScope).toEqual([1]);
+});
diff --git a/superset-frontend/src/dashboard/util/crossFilters.ts b/superset-frontend/src/dashboard/util/crossFilters.ts
index f9183f11c6e..6f4286c099f 100644
--- a/superset-frontend/src/dashboard/util/crossFilters.ts
+++ b/superset-frontend/src/dashboard/util/crossFilters.ts
@@ -20,7 +20,7 @@ import { cloneDeep } from 'lodash-es';
import {
Behavior,
getChartMetadataRegistry,
- NativeFilterScope,
+ type NativeFilterScope,
} from '@superset-ui/core';
import {
createChartLayoutItemMap,
@@ -94,17 +94,18 @@ export const getCrossFiltersConfiguration = (
},
};
}
+ const { scope } = chartConfiguration[chartId].crossFilters;
+
+ const effectiveScope: NativeFilterScope = isCrossFilterScopeGlobal(scope)
+ ? globalChartConfiguration.scope
+ : (scope as NativeFilterScope);
+
chartConfiguration[chartId].crossFilters.chartsInScope =
- isCrossFilterScopeGlobal(chartConfiguration[chartId].crossFilters.scope)
- ? globalChartConfiguration.chartsInScope.filter(
- id => id !== Number(chartId),
- )
- : getChartIdsInFilterScope(
- chartConfiguration[chartId].crossFilters
- .scope as NativeFilterScope,
- chartIds,
- chartLayoutItemMap,
- );
+ getChartIdsInFilterScope(
+ effectiveScope,
+ chartIds,
+ chartLayoutItemMap,
+ ).filter(id => id !== Number(chartId));
}
});
diff --git a/superset-frontend/src/dashboard/util/getRelatedCharts.ts b/superset-frontend/src/dashboard/util/getRelatedCharts.ts
index 29045f395f8..2df30928688 100644
--- a/superset-frontend/src/dashboard/util/getRelatedCharts.ts
+++ b/superset-frontend/src/dashboard/util/getRelatedCharts.ts
@@ -55,31 +55,13 @@ function getRelatedChartsForCrossFilter(
slices: Record<string, Slice>,
scope: number[],
): number[] {
- const sourceSlice = slices[filterKey];
-
- if (!sourceSlice) return [];
-
- const fullScope = [
- ...scope.filter(s => String(s) !== filterKey),
- Number(filterKey),
- ];
- const scopeSet = new Set(scope);
-
- return Object.values(slices).reduce((result: number[], slice) => {
- if (slice.slice_id === Number(filterKey)) {
- return result;
- }
- // Check if it's in the global scope
- if (isGlobalScope(fullScope, slices)) {
- result.push(slice.slice_id);
- return result;
- }
- // Check if it's hand-picked in scope
- if (scopeSet.has(slice.slice_id)) {
- result.push(slice.slice_id);
- }
- return result;
- }, []);
+ // `scope` here is already the fully-resolved chartsInScope from
+ // getCrossFiltersConfiguration (global scope pre-expanded to concrete
+ // chart ids there), so no further global-scope re-derivation is needed.
+ const chartsInScopeSet = new Set(scope);
+ return Object.values(slices)
+ .map(slice => slice.slice_id)
+ .filter(id => chartsInScopeSet.has(id) && id !== Number(filterKey));
}
export function getRelatedCharts(