Skip to content

Commit

Permalink
fix: Incorrect initial global scoping of cross filters (#24642)
Browse files Browse the repository at this point in the history
  • Loading branch information
kgabryje authored Jul 11, 2023
1 parent 0efb884 commit bbffc4c
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 3 deletions.
84 changes: 82 additions & 2 deletions superset-frontend/src/dashboard/util/crossFilters.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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', () => {
Expand All @@ -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],
},
});
});
9 changes: 8 additions & 1 deletion superset-frontend/src/dashboard/util/crossFilters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down

0 comments on commit bbffc4c

Please sign in to comment.