Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Incorrect initial global scoping of cross filters #24642

Merged
merged 1 commit into from
Jul 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading