fix: Incorrect initial global scoping of cross filters (#24642)

This commit is contained in:
Kamil Gabryjelski 2023-07-11 17:14:55 +02:00 committed by GitHub
parent 0efb88479e
commit bbffc4c1f8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 90 additions and 3 deletions

View File

@ -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],
},
});
});

View File

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