From bbffc4c1f8f4eda13517f16ea5e467153c282d4c Mon Sep 17 00:00:00 2001 From: Kamil Gabryjelski Date: Tue, 11 Jul 2023 17:14:55 +0200 Subject: [PATCH] fix: Incorrect initial global scoping of cross filters (#24642) --- .../src/dashboard/util/crossFilters.test.ts | 84 ++++++++++++++++++- .../src/dashboard/util/crossFilters.ts | 9 +- 2 files changed, 90 insertions(+), 3 deletions(-) diff --git a/superset-frontend/src/dashboard/util/crossFilters.test.ts b/superset-frontend/src/dashboard/util/crossFilters.test.ts index 45bcaaf0b6..0e9fc00de8 100644 --- a/superset-frontend/src/dashboard/util/crossFilters.test.ts +++ b/superset-frontend/src/dashboard/util/crossFilters.test.ts @@ -175,7 +175,6 @@ test('Generate correct cross filters configuration without initial configuration chartsInScope: [1, 2], }, }); - metadataRegistryStub.restore(); }); test('Generate correct cross filters configuration with initial configuration', () => { @@ -218,7 +217,6 @@ test('Generate correct cross filters configuration with initial configuration', chartsInScope: [1, 2], }, }); - metadataRegistryStub.restore(); }); test('Return undefined if DASHBOARD_CROSS_FILTERS feature flag is disabled', () => { @@ -234,3 +232,85 @@ test('Return undefined if DASHBOARD_CROSS_FILTERS feature flag is disabled', () ), ).toEqual(undefined); }); + +test('Recalculate charts in global filter scope when charts change', () => { + // @ts-ignore + global.featureFlags = { + [FeatureFlag.DASHBOARD_CROSS_FILTERS]: true, + }; + expect( + getCrossFiltersConfiguration( + { + ...DASHBOARD_LAYOUT, + 'CHART-3': { + children: [], + id: 'CHART-3', + meta: { + chartId: 3, + sliceName: 'Test chart 3', + height: 1, + width: 1, + uuid: '3', + }, + parents: ['ROOT_ID', 'GRID_ID', 'ROW-6XUMf1rV76'], + type: 'CHART', + }, + }, + CHART_CONFIG_METADATA, + { + ...CHARTS, + '3': { + id: 3, + form_data: { + datasource: '3__table', + viz_type: 'echarts_timeseries_line', + }, + chartAlert: null, + chartStatus: 'rendered' as const, + chartUpdateEndTime: 0, + chartUpdateStartTime: 0, + lastRendered: 0, + latestQueryFormData: {}, + sliceFormData: { + datasource: '3__table', + viz_type: 'echarts_timeseries_line', + }, + queryController: null, + queriesResponse: [{}], + triggerQuery: false, + }, + }, + ), + ).toEqual({ + chartConfiguration: { + '1': { + id: 1, + crossFilters: { + scope: { rootPath: ['ROOT_ID'], excluded: [1, 2] }, + chartsInScope: [3], + }, + }, + '2': { + id: 2, + crossFilters: { + scope: 'global', + chartsInScope: [1, 3], + }, + }, + '3': { + id: 3, + crossFilters: { + scope: 'global', + chartsInScope: [1, 2], + }, + }, + }, + globalChartConfiguration: { + scope: { + excluded: [], + rootPath: ['ROOT_ID'], + }, + chartsInScope: [1, 2, 3], + }, + }); +}); diff --git a/superset-frontend/src/dashboard/util/crossFilters.ts b/superset-frontend/src/dashboard/util/crossFilters.ts index 77b2b36f35..425c725989 100644 --- a/superset-frontend/src/dashboard/util/crossFilters.ts +++ b/superset-frontend/src/dashboard/util/crossFilters.ts @@ -53,7 +53,14 @@ export const getCrossFiltersConfiguration = ( } const globalChartConfiguration = metadata.global_chart_configuration - ? cloneDeep(metadata.global_chart_configuration) + ? { + scope: metadata.global_chart_configuration.scope, + chartsInScope: getChartIdsInFilterScope( + metadata.global_chart_configuration.scope, + Object.values(charts).map(chart => chart.id), + dashboardLayout, + ), + } : { scope: DEFAULT_CROSS_FILTER_SCOPING, chartsInScope: Object.values(charts).map(chart => chart.id),