From 73d3b7ab9a15a2bdfb8cfa8656d58071d08f19c9 Mon Sep 17 00:00:00 2001 From: Kamil Gabryjelski Date: Mon, 1 May 2023 18:57:20 +0200 Subject: [PATCH] fix: Native time range filter in legacy charts (#23865) --- .../legacy-plugin-chart-calendar/src/controlPanel.ts | 8 ++++++-- superset/utils/core.py | 8 ++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/superset-frontend/plugins/legacy-plugin-chart-calendar/src/controlPanel.ts b/superset-frontend/plugins/legacy-plugin-chart-calendar/src/controlPanel.ts index 9071a278eebae..6cdd79162baef 100644 --- a/superset-frontend/plugins/legacy-plugin-chart-calendar/src/controlPanel.ts +++ b/superset-frontend/plugins/legacy-plugin-chart-calendar/src/controlPanel.ts @@ -22,12 +22,16 @@ import { D3_FORMAT_DOCS, D3_TIME_FORMAT_OPTIONS, getStandardizedControls, - sections, } from '@superset-ui/chart-controls'; const config: ControlPanelConfig = { controlPanelSections: [ - sections.legacyRegularTime, + { + label: t('Time'), + expanded: true, + description: t('Time related form attributes'), + controlSetRows: [['granularity_sqla'], ['time_range']], + }, { label: t('Query'), expanded: true, diff --git a/superset/utils/core.py b/superset/utils/core.py index 22ff3f8be4be2..8cf73b84aa3e1 100644 --- a/superset/utils/core.py +++ b/superset/utils/core.py @@ -1159,6 +1159,14 @@ def merge_extra_form_data(form_data: Dict[str, Any]) -> None: for fltr in append_filters if fltr ) + if ( + form_data.get("time_range") + and not form_data.get("granularity") + and not form_data.get("granularity_sqla") + ): + for adhoc_filter in form_data.get("adhoc_filters", []): + if adhoc_filter.get("operator") == "TEMPORAL_RANGE": + adhoc_filter["comparator"] = form_data["time_range"] def merge_extra_filters(form_data: Dict[str, Any]) -> None: