Skip to content

Commit

Permalink
fix(CrossFilters): Do not reload unrelated filters in global scope (a…
Browse files Browse the repository at this point in the history
…pache#30252)

Co-authored-by: JUST.in DO IT <justin.park@airbnb.com>
(cherry picked from commit dbab2fb)
  • Loading branch information
geido authored and sadpandajoe committed Sep 13, 2024
1 parent 4a6dd94 commit 90ce1b5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
4 changes: 2 additions & 2 deletions superset-frontend/src/dashboard/util/crossFilters.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [],
},
},
},
Expand Down
19 changes: 18 additions & 1 deletion superset-frontend/src/dashboard/util/crossFilters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,20 @@ export const getCrossFiltersConfiguration = (
return undefined;
}

const chartsByDataSource: Record<string, Set<number>> = Object.values(
charts,
).reduce((acc: Record<string, Set<number>>, 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,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 90ce1b5

Please sign in to comment.