mirror of
https://github.com/apache/superset.git
synced 2024-09-12 08:39:45 -04:00
fix: missing orderby in query on the nvd3 timeseries chart (#15343)
This commit is contained in:
parent
b3cdff4995
commit
fae4531f1e
@ -1269,6 +1269,11 @@ def get_metric_names(metrics: Sequence[Metric]) -> List[str]:
|
|||||||
return [get_metric_name(metric) for metric in metrics]
|
return [get_metric_name(metric) for metric in metrics]
|
||||||
|
|
||||||
|
|
||||||
|
def get_main_metric_name(metrics: Sequence[Metric]) -> Optional[str]:
|
||||||
|
metric_labels = get_metric_names(metrics)
|
||||||
|
return metric_labels[0] if metric_labels else None
|
||||||
|
|
||||||
|
|
||||||
def ensure_path_exists(path: str) -> None:
|
def ensure_path_exists(path: str) -> None:
|
||||||
try:
|
try:
|
||||||
os.makedirs(path)
|
os.makedirs(path)
|
||||||
|
@ -1228,13 +1228,15 @@ class NVD3TimeSeriesViz(NVD3Viz):
|
|||||||
|
|
||||||
def query_obj(self) -> QueryObjectDict:
|
def query_obj(self) -> QueryObjectDict:
|
||||||
d = super().query_obj()
|
d = super().query_obj()
|
||||||
sort_by = self.form_data.get("timeseries_limit_metric")
|
sort_by = self.form_data.get(
|
||||||
|
"timeseries_limit_metric"
|
||||||
|
) or utils.get_main_metric_name(d.get("metrics") or [])
|
||||||
|
is_asc = not self.form_data.get("order_desc")
|
||||||
if sort_by:
|
if sort_by:
|
||||||
sort_by_label = utils.get_metric_name(sort_by)
|
sort_by_label = utils.get_metric_name(sort_by)
|
||||||
if sort_by_label not in utils.get_metric_names(d["metrics"]):
|
if sort_by_label not in utils.get_metric_names(d["metrics"]):
|
||||||
d["metrics"].append(sort_by)
|
d["metrics"].append(sort_by)
|
||||||
if self.form_data.get("order_desc"):
|
d["orderby"] = [(sort_by, not self.form_data.get("order_desc", is_asc))]
|
||||||
d["orderby"] = [(sort_by, not self.form_data.get("order_desc", True))]
|
|
||||||
return d
|
return d
|
||||||
|
|
||||||
def to_series(
|
def to_series(
|
||||||
|
Loading…
Reference in New Issue
Block a user