mirror of
https://github.com/apache/superset.git
synced 2026-04-19 08:04:53 +00:00
feat(native-filters): Time native filter (#12992)
* Add Time Filter component * Improve Time Filter component * Fix import errors * Display Time Filter * Remove console logs * Change Control Panel * Remove unnecessary files * Use time range override * test: fix tests * feat: re run pipeline * fix: fix some case for Time filter * fix: merge with master * use original time range * fix height * add cross filter behavior * apply filters on initialization * add applied filter to overrides * add unit tests for merge_extra_form_data Co-authored-by: Agata Stawarz-Pastewska <agata.stawarz-pastewska@polidea.com> Co-authored-by: Ville Brofeldt <ville.v.brofeldt@gmail.com>
This commit is contained in:
@@ -1027,8 +1027,41 @@ def to_adhoc(
|
||||
return result
|
||||
|
||||
|
||||
def merge_extra_form_data(form_data: Dict[str, Any]) -> None:
|
||||
"""
|
||||
Merge extra form data (appends and overrides) into the main payload
|
||||
and add applied time extras to the payload.
|
||||
"""
|
||||
time_extras = {
|
||||
"time_range": "__time_range",
|
||||
"granularity_sqla": "__time_col",
|
||||
"time_grain_sqla": "__time_grain",
|
||||
"druid_time_origin": "__time_origin",
|
||||
"granularity": "__granularity",
|
||||
}
|
||||
applied_time_extras = form_data.get("applied_time_extras", {})
|
||||
form_data["applied_time_extras"] = applied_time_extras
|
||||
extra_form_data = form_data.pop("extra_form_data", {})
|
||||
append_form_data = extra_form_data.pop("append_form_data", {})
|
||||
append_filters = append_form_data.get("filters", None)
|
||||
override_form_data = extra_form_data.pop("override_form_data", {})
|
||||
for key, value in override_form_data.items():
|
||||
form_data[key] = value
|
||||
# mark as temporal overrides as applied time extras
|
||||
time_extra = time_extras.get(key)
|
||||
if time_extra:
|
||||
applied_time_extras[time_extra] = value
|
||||
|
||||
adhoc_filters = form_data.get("adhoc_filters", [])
|
||||
form_data["adhoc_filters"] = adhoc_filters
|
||||
if append_filters:
|
||||
adhoc_filters.extend(
|
||||
[to_adhoc({"isExtra": True, **fltr}) for fltr in append_filters if fltr]
|
||||
)
|
||||
|
||||
|
||||
def merge_extra_filters( # pylint: disable=too-many-branches
|
||||
form_data: Dict[str, Any]
|
||||
form_data: Dict[str, Any],
|
||||
) -> None:
|
||||
# extra_filters are temporary/contextual filters (using the legacy constructs)
|
||||
# that are external to the slice definition. We use those for dynamic
|
||||
@@ -1038,16 +1071,7 @@ def merge_extra_filters( # pylint: disable=too-many-branches
|
||||
form_data["applied_time_extras"] = applied_time_extras
|
||||
adhoc_filters = form_data.get("adhoc_filters", [])
|
||||
form_data["adhoc_filters"] = adhoc_filters
|
||||
# extra_overrides contains additional props to be added/overridden in the form_data
|
||||
# and will deprecate `extra_filters`. For now only `filters` is supported,
|
||||
# but additional props will be added later (time grains, groupbys etc)
|
||||
extra_form_data = form_data.pop("extra_form_data", {})
|
||||
append_form_data = extra_form_data.pop("append_form_data", {})
|
||||
append_filters = append_form_data.get("filters", None)
|
||||
if append_filters:
|
||||
adhoc_filters.extend(
|
||||
[to_adhoc({"isExtra": True, **fltr}) for fltr in append_filters if fltr]
|
||||
)
|
||||
merge_extra_form_data(form_data)
|
||||
if "extra_filters" in form_data:
|
||||
# __form and __to are special extra_filters that target time
|
||||
# boundaries. The rest of extra_filters are simple
|
||||
|
||||
Reference in New Issue
Block a user