Skip to content

Commit

Permalink
fix: Applying Dashboard Time Range Filters to Overwritten Charts (apa…
Browse files Browse the repository at this point in the history
…che#25156)

Co-authored-by: Michael S. Molina <70410625+michael-s-molina@users.noreply.github.com>
  • Loading branch information
Lily Kuang and michael-s-molina committed Sep 1, 2023
1 parent 8b2a408 commit f2523b2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 15 deletions.
22 changes: 9 additions & 13 deletions superset-frontend/src/explore/actions/saveModalActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,19 +79,15 @@ export const getSlicePayload = (
adhocFilters = extractAddHocFiltersFromFormData(formDataFromSlice);
}

if (
isEmpty(adhocFilters?.adhoc_filters) &&
isEmpty(formDataFromSlice) &&
formDataWithNativeFilters?.adhoc_filters?.[0]?.operator ===
Operators.TEMPORAL_RANGE
) {
adhocFilters.adhoc_filters = [
{
...formDataWithNativeFilters.adhoc_filters[0],
comparator: 'No filter',
},
];
}
// 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
// '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.
formDataWithNativeFilters?.adhoc_filters?.forEach(filter => {
if (filter.operator === Operators.TEMPORAL_RANGE && filter.isExtra) {
adhocFilters.adhoc_filters.push({ ...filter, comparator: 'No filter' });
}
});

const formData = {
...formDataWithNativeFilters,
Expand Down
15 changes: 13 additions & 2 deletions superset-frontend/src/explore/actions/saveModalActions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,19 @@ describe('getSlicePayload', () => {
formDataWithNativeFilters,
dashboards,
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('slice_name', sliceName);
Expand Down Expand Up @@ -366,7 +378,6 @@ describe('getSlicePayload', () => {
operator: 'TEMPORAL_RANGE',
comparator: 'No filter',
expressionType: 'SIMPLE',
isExtra: true,
},
],
};
Expand Down

0 comments on commit f2523b2

Please sign in to comment.