This is an automated email from the ASF dual-hosted git repository.
lilykuang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/superset.git
The following commit(s) were added to refs/heads/master by this push:
new f2523b26fa fix: Applying Dashboard Time Range Filters to Overwritten
Charts (#25156)
f2523b26fa is described below
commit f2523b26fa140febe838624ae8508136d01d1389
Author: Lily Kuang <[email protected]>
AuthorDate: Fri Sep 1 14:30:37 2023 -0700
fix: Applying Dashboard Time Range Filters to Overwritten Charts (#25156)
Co-authored-by: Michael S. Molina
<[email protected]>
---
.../src/explore/actions/saveModalActions.js | 22 +++++++++-------------
.../src/explore/actions/saveModalActions.test.js | 15 +++++++++++++--
2 files changed, 22 insertions(+), 15 deletions(-)
diff --git a/superset-frontend/src/explore/actions/saveModalActions.js
b/superset-frontend/src/explore/actions/saveModalActions.js
index 32b34cbed4..8c864eceac 100644
--- a/superset-frontend/src/explore/actions/saveModalActions.js
+++ b/superset-frontend/src/explore/actions/saveModalActions.js
@@ -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,
diff --git a/superset-frontend/src/explore/actions/saveModalActions.test.js
b/superset-frontend/src/explore/actions/saveModalActions.test.js
index 1662ead63e..dedddfb4cd 100644
--- a/superset-frontend/src/explore/actions/saveModalActions.test.js
+++ b/superset-frontend/src/explore/actions/saveModalActions.test.js
@@ -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);
@@ -366,7 +378,6 @@ describe('getSlicePayload', () => {
operator: 'TEMPORAL_RANGE',
comparator: 'No filter',
expressionType: 'SIMPLE',
- isExtra: true,
},
],
};