mirror of
https://github.com/apache/superset.git
synced 2024-09-12 00:29:39 -04:00
fix: Time range filter applied on a dashboard is not persisting to the chart explore (#22920)
This commit is contained in:
parent
30abefb519
commit
e9423c3c87
@ -48,6 +48,14 @@ const getExploreFormData = (overrides: JsonObject = {}) => ({
|
|||||||
sqlExpression: "city = 'Warsaw'",
|
sqlExpression: "city = 'Warsaw'",
|
||||||
filterOptionName: '567',
|
filterOptionName: '567',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
clause: 'WHERE' as const,
|
||||||
|
expressionType: 'SIMPLE' as const,
|
||||||
|
operator: 'TEMPORAL_RANGE' as const,
|
||||||
|
subject: 'ds',
|
||||||
|
comparator: 'No filter',
|
||||||
|
filterOptionName: '678',
|
||||||
|
},
|
||||||
],
|
],
|
||||||
adhoc_filters_b: [
|
adhoc_filters_b: [
|
||||||
{
|
{
|
||||||
@ -158,6 +166,14 @@ const getExpectedResultFormData = (overrides: JsonObject = {}) => ({
|
|||||||
sqlExpression: "city = 'Warsaw'",
|
sqlExpression: "city = 'Warsaw'",
|
||||||
filterOptionName: '567',
|
filterOptionName: '567',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
clause: 'WHERE',
|
||||||
|
expressionType: 'SIMPLE',
|
||||||
|
operator: 'TEMPORAL_RANGE',
|
||||||
|
subject: 'ds',
|
||||||
|
comparator: 'Last month',
|
||||||
|
filterOptionName: expect.any(String),
|
||||||
|
},
|
||||||
{
|
{
|
||||||
clause: 'WHERE',
|
clause: 'WHERE',
|
||||||
expressionType: 'SIMPLE',
|
expressionType: 'SIMPLE',
|
||||||
@ -279,7 +295,7 @@ const getExpectedResultFormData = (overrides: JsonObject = {}) => ({
|
|||||||
...overrides,
|
...overrides,
|
||||||
});
|
});
|
||||||
|
|
||||||
it('merges dashboard context form data with explore form data', () => {
|
test('merges dashboard context form data with explore form data', () => {
|
||||||
const fullFormData = getFormDataWithDashboardContext(
|
const fullFormData = getFormDataWithDashboardContext(
|
||||||
getExploreFormData(),
|
getExploreFormData(),
|
||||||
getDashboardFormData(),
|
getDashboardFormData(),
|
||||||
|
@ -173,6 +173,25 @@ const mergeNativeFiltersToFormData = (
|
|||||||
return nativeFiltersData;
|
return nativeFiltersData;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const applyTimeRangeFilters = (
|
||||||
|
dashboardFormData: JsonObject,
|
||||||
|
adhocFilters: AdhocFilter[],
|
||||||
|
) => {
|
||||||
|
const extraFormData = dashboardFormData.extra_form_data || {};
|
||||||
|
if ('time_range' in extraFormData) {
|
||||||
|
return adhocFilters.map((filter: SimpleAdhocFilter) => {
|
||||||
|
if (filter.operator === 'TEMPORAL_RANGE') {
|
||||||
|
return {
|
||||||
|
...filter,
|
||||||
|
comparator: extraFormData.time_range,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return filter;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return adhocFilters;
|
||||||
|
};
|
||||||
|
|
||||||
export const getFormDataWithDashboardContext = (
|
export const getFormDataWithDashboardContext = (
|
||||||
exploreFormData: QueryFormData,
|
exploreFormData: QueryFormData,
|
||||||
dashboardContextFormData: JsonObject,
|
dashboardContextFormData: JsonObject,
|
||||||
@ -194,14 +213,18 @@ export const getFormDataWithDashboardContext = (
|
|||||||
.reduce(
|
.reduce(
|
||||||
(acc, key) => ({
|
(acc, key) => ({
|
||||||
...acc,
|
...acc,
|
||||||
[key]: removeAdhocFilterDuplicates([
|
[key]: applyTimeRangeFilters(
|
||||||
...ensureIsArray(exploreFormData[key]),
|
dashboardContextFormData,
|
||||||
...ensureIsArray(filterBoxData[key]),
|
removeAdhocFilterDuplicates([
|
||||||
...ensureIsArray(nativeFiltersData[key]),
|
...ensureIsArray(exploreFormData[key]),
|
||||||
]),
|
...ensureIsArray(filterBoxData[key]),
|
||||||
|
...ensureIsArray(nativeFiltersData[key]),
|
||||||
|
]),
|
||||||
|
),
|
||||||
}),
|
}),
|
||||||
{},
|
{},
|
||||||
);
|
);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...exploreFormData,
|
...exploreFormData,
|
||||||
...dashboardContextFormData,
|
...dashboardContextFormData,
|
||||||
|
Loading…
Reference in New Issue
Block a user