Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: missing orderby in query on the nvd3 timeseries chart #15343

Merged
merged 1 commit into from
Jun 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions superset/utils/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1269,6 +1269,11 @@ def get_metric_names(metrics: Sequence[Metric]) -> List[str]:
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:
try:
os.makedirs(path)
Expand Down
8 changes: 5 additions & 3 deletions superset/viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -1228,13 +1228,15 @@ class NVD3TimeSeriesViz(NVD3Viz):

def query_obj(self) -> QueryObjectDict:
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:
sort_by_label = utils.get_metric_name(sort_by)
if sort_by_label not in utils.get_metric_names(d["metrics"]):
d["metrics"].append(sort_by)
if self.form_data.get("order_desc"):
d["orderby"] = [(sort_by, not self.form_data.get("order_desc", True))]
d["orderby"] = [(sort_by, not self.form_data.get("order_desc", is_asc))]
return d

def to_series(
Expand Down