diff --git a/superset-frontend/src/dashboard/util/crossFilters.test.ts b/superset-frontend/src/dashboard/util/crossFilters.test.ts index b88579cc843a0..e811856a4a39c 100644 --- a/superset-frontend/src/dashboard/util/crossFilters.test.ts +++ b/superset-frontend/src/dashboard/util/crossFilters.test.ts @@ -294,14 +294,14 @@ test('Recalculate charts in global filter scope when charts change', () => { id: 2, crossFilters: { scope: 'global', - chartsInScope: [1, 3], + chartsInScope: [1], }, }, '3': { id: 3, crossFilters: { scope: 'global', - chartsInScope: [1, 2], + chartsInScope: [], }, }, }, diff --git a/superset-frontend/src/dashboard/util/crossFilters.ts b/superset-frontend/src/dashboard/util/crossFilters.ts index 903a1f74fbe55..880b826870a1a 100644 --- a/superset-frontend/src/dashboard/util/crossFilters.ts +++ b/superset-frontend/src/dashboard/util/crossFilters.ts @@ -52,6 +52,20 @@ export const getCrossFiltersConfiguration = ( return undefined; } + const chartsByDataSource: Record> = Object.values( + charts, + ).reduce((acc: Record>, chart) => { + if (!chart.form_data) { + return acc; + } + const { datasource } = chart.form_data; + if (!acc[datasource]) { + acc[datasource] = new Set(); + } + acc[datasource].add(chart.id); + return acc; + }, {}); + const globalChartConfiguration = metadata.global_chart_configuration?.scope ? { scope: metadata.global_chart_configuration.scope, @@ -97,10 +111,13 @@ export const getCrossFiltersConfiguration = ( }, }; } + const chartDataSource = charts[chartId].form_data.datasource; chartConfiguration[chartId].crossFilters.chartsInScope = isCrossFilterScopeGlobal(chartConfiguration[chartId].crossFilters.scope) ? globalChartConfiguration.chartsInScope.filter( - id => id !== Number(chartId), + id => + id !== Number(chartId) && + chartsByDataSource[chartDataSource]?.has(id), ) : getChartIdsInFilterScope( chartConfiguration[chartId].crossFilters.scope,