fix(CrossFilters): Do not reload unrelated filters in global scope (#30252)

Co-authored-by: JUST.in DO IT <justin.park@airbnb.com>
This commit is contained in:
Geido 2024-09-13 15:20:51 +02:00 committed by GitHub
parent c5594f2979
commit dbab2fb955
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 20 additions and 3 deletions

View File

@ -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: [],
},
},
},

View File

@ -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,
@ -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,