mirror of https://github.com/apache/superset.git
fix: inability to remove chart filter when dashboard time filter is applied (#25217)
This commit is contained in:
parent
242921bb4c
commit
a9512c1eef
|
@ -59,6 +59,11 @@ const extractAddHocFiltersFromFormData = formDataToHandle =>
|
||||||
{},
|
{},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const hasTemporalRangeFilter = formData =>
|
||||||
|
(formData?.adhoc_filters || []).some(
|
||||||
|
filter => filter.operator === Operators.TEMPORAL_RANGE,
|
||||||
|
);
|
||||||
|
|
||||||
export const getSlicePayload = (
|
export const getSlicePayload = (
|
||||||
sliceName,
|
sliceName,
|
||||||
formDataWithNativeFilters,
|
formDataWithNativeFilters,
|
||||||
|
@ -66,7 +71,7 @@ export const getSlicePayload = (
|
||||||
owners,
|
owners,
|
||||||
formDataFromSlice = {},
|
formDataFromSlice = {},
|
||||||
) => {
|
) => {
|
||||||
let adhocFilters = extractAddHocFiltersFromFormData(
|
const adhocFilters = extractAddHocFiltersFromFormData(
|
||||||
formDataWithNativeFilters,
|
formDataWithNativeFilters,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -76,18 +81,24 @@ export const getSlicePayload = (
|
||||||
// would end up as an extra filter and when overwriting the chart the original
|
// would end up as an extra filter and when overwriting the chart the original
|
||||||
// time range adhoc_filter was lost
|
// time range adhoc_filter was lost
|
||||||
if (isEmpty(adhocFilters?.adhoc_filters) && !isEmpty(formDataFromSlice)) {
|
if (isEmpty(adhocFilters?.adhoc_filters) && !isEmpty(formDataFromSlice)) {
|
||||||
adhocFilters = extractAddHocFiltersFromFormData(formDataFromSlice);
|
formDataFromSlice?.adhoc_filters?.forEach(filter => {
|
||||||
|
if (filter.operator === Operators.TEMPORAL_RANGE && !filter.isExtra) {
|
||||||
|
adhocFilters.adhoc_filters.push({ ...filter, comparator: 'No filter' });
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// This loop iterates through the adhoc_filters array in formDataWithNativeFilters.
|
// This loop iterates through the adhoc_filters array in formDataWithNativeFilters.
|
||||||
// If a filter is of type TEMPORAL_RANGE and isExtra, it sets its comparator to
|
// If a filter is of type TEMPORAL_RANGE and isExtra, it sets its comparator to
|
||||||
// 'No filter' and adds the modified filter to the adhocFilters array. This ensures that all
|
// 'No filter' and adds the modified filter to the adhocFilters array. This ensures that all
|
||||||
// TEMPORAL_RANGE filters are converted to 'No filter' when saving a chart.
|
// TEMPORAL_RANGE filters are converted to 'No filter' when saving a chart.
|
||||||
formDataWithNativeFilters?.adhoc_filters?.forEach(filter => {
|
if (!hasTemporalRangeFilter(adhocFilters)) {
|
||||||
if (filter.operator === Operators.TEMPORAL_RANGE && filter.isExtra) {
|
formDataWithNativeFilters?.adhoc_filters?.forEach(filter => {
|
||||||
adhocFilters.adhoc_filters.push({ ...filter, comparator: 'No filter' });
|
if (filter.operator === Operators.TEMPORAL_RANGE && filter.isExtra) {
|
||||||
}
|
adhocFilters.adhoc_filters.push({ ...filter, comparator: 'No filter' });
|
||||||
});
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
const formData = {
|
const formData = {
|
||||||
...formDataWithNativeFilters,
|
...formDataWithNativeFilters,
|
||||||
|
|
|
@ -302,19 +302,7 @@ describe('getSlicePayload', () => {
|
||||||
formDataWithNativeFilters,
|
formDataWithNativeFilters,
|
||||||
dashboards,
|
dashboards,
|
||||||
owners,
|
owners,
|
||||||
{
|
formDataFromSlice,
|
||||||
datasource: '22__table',
|
|
||||||
viz_type: 'pie',
|
|
||||||
adhoc_filters: [
|
|
||||||
{
|
|
||||||
clause: 'WHERE',
|
|
||||||
subject: 'year',
|
|
||||||
operator: 'TEMPORAL_RANGE',
|
|
||||||
comparator: 'No filter',
|
|
||||||
expressionType: 'SIMPLE',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
);
|
);
|
||||||
expect(result).toHaveProperty('params');
|
expect(result).toHaveProperty('params');
|
||||||
expect(result).toHaveProperty('slice_name', sliceName);
|
expect(result).toHaveProperty('slice_name', sliceName);
|
||||||
|
|
Loading…
Reference in New Issue