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

feat(TimeTableViz): sort by first metric #18896

Merged
merged 2 commits into from
Feb 28, 2022
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/viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -854,6 +854,11 @@ def query_obj(self) -> QueryObjectDict:
raise QueryObjectValidationError(
_("When using 'Group By' you are limited to use a single metric")
)

sort_by = utils.get_first_metric_name(query_obj["metrics"])
is_asc = not query_obj.get("order_desc")
query_obj["orderby"] = [(sort_by, is_asc)]

return query_obj

def get_data(self, df: pd.DataFrame) -> VizData:
Expand Down
7 changes: 7 additions & 0 deletions tests/integration_tests/viz_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1067,6 +1067,13 @@ def test_query_obj_throws_metrics_and_groupby(self, super_query_obj):
with self.assertRaises(Exception):
test_viz.query_obj()

def test_query_obj_order_by(self):
test_viz = viz.TimeTableViz(
self.get_datasource_mock(), {"metrics": ["sum__A", "count"], "groupby": []}
)
query_obj = test_viz.query_obj()
self.assertEqual(query_obj["orderby"], [("sum__A", False)])


class TestBaseDeckGLViz(SupersetTestCase):
def test_get_metrics(self):
Expand Down