Skip to content

Commit

Permalink
Fixed missing widget name suffixes (#243)
Browse files Browse the repository at this point in the history
  • Loading branch information
nfx authored Jul 30, 2024
1 parent 863708c commit 9fb74ae
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/databricks/labs/lsql/dashboards.py
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ def _get_query_layouts(self) -> Iterable[Layout]:
show_description=len(self.metadata.description) > 0,
)
spec = self._get_query_widget_spec(fields, frame=frame)
widget = Widget(name=self.metadata.id, queries=[named_query], spec=spec)
widget = Widget(name=f"{self.metadata.id}_widget", queries=[named_query], spec=spec)
widget = self._merge_widget_with_overrides(widget)
height = self.position.height
if len(self.metadata.filters) > 0 and self.position.width > 0:
Expand Down
22 changes: 16 additions & 6 deletions tests/unit/test_dashboards.py
Original file line number Diff line number Diff line change
Expand Up @@ -1131,7 +1131,7 @@ def test_dashboard_metadata_sorts_widgets_alphanumerically(tmp_path, query_names
(tmp_path / f"{query_name}.sql").write_text("SELECT 1 AS count")
dashboard_metadata = DashboardMetadata.from_path(tmp_path)
dashboard = dashboard_metadata.as_lakeview()
assert [layout.widget.name for layout in dashboard.pages[0].layout] == query_names
assert [layout.widget.name for layout in dashboard.pages[0].layout] == [f"{_}_widget" for _ in query_names]


def test_dashboard_metadata_orders_widget_using_overwrite(tmp_path):
Expand All @@ -1144,7 +1144,7 @@ def test_dashboard_metadata_orders_widget_using_overwrite(tmp_path):

dashboard = dashboard_metadata.as_lakeview()

assert [layout.widget.name for layout in dashboard.pages[0].layout] == list("abecdf")
assert [layout.widget.name for layout in dashboard.pages[0].layout] == [f"{_}_widget" for _ in list("abecdf")]


def test_dashboard_metadata_orders_widget_with_overwrite_zero(tmp_path):
Expand All @@ -1157,7 +1157,9 @@ def test_dashboard_metadata_orders_widget_with_overwrite_zero(tmp_path):

dashboard = dashboard_metadata.as_lakeview()

assert [layout.widget.name for layout in dashboard.pages[0].layout] == list("aebcdf")
assert sorted([layout.widget.name for layout in dashboard.pages[0].layout]) == sorted(
[f"{_}_widget" for _ in list("abecdf")]
)


def test_dashboard_metadata_orders_widgets_using_id(tmp_path):
Expand All @@ -1168,7 +1170,9 @@ def test_dashboard_metadata_orders_widgets_using_id(tmp_path):

dashboard = dashboard_metadata.as_lakeview()

assert [layout.widget.name for layout in dashboard.pages[0].layout] == list("abcdef")
assert sorted([layout.widget.name for layout in dashboard.pages[0].layout]) == sorted(
[f"{_}_widget" for _ in list("abecdf")]
)


def test_dashboard_metadata_orders_widgets_with_overwrite_from_dashboard_yaml(tmp_path):
Expand All @@ -1186,7 +1190,9 @@ def test_dashboard_metadata_orders_widgets_with_overwrite_from_dashboard_yaml(tm

dashboard = dashboard_metadata.as_lakeview()

assert [layout.widget.name for layout in dashboard.pages[0].layout] == list("eabcdf")
assert sorted([layout.widget.name for layout in dashboard.pages[0].layout]) == sorted(
[f"{_}_widget" for _ in list("abecdf")]
)


def test_dashboard_metadata_orders_widget_where_header_takes_precedence(tmp_path):
Expand All @@ -1204,7 +1210,11 @@ def test_dashboard_metadata_orders_widget_where_header_takes_precedence(tmp_path

dashboard = dashboard_metadata.as_lakeview()

assert [layout.widget.name for layout in dashboard.pages[0].layout] == ["query_0", "query_1", "query_2"]
assert [layout.widget.name for layout in dashboard.pages[0].layout] == [
"query_0_widget",
"query_1_widget",
"query_2_widget",
]


@pytest.mark.parametrize(
Expand Down

0 comments on commit 9fb74ae

Please sign in to comment.