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

Add method to dashboards to get dashboard url #211

Merged
merged 8 commits into from
Jul 10, 2024
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
3 changes: 2 additions & 1 deletion src/databricks/labs/lsql/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ def create_dashboard(
replace_database_in_query = functools.partial(dashboards.replace_database_in_query, database=database)
lakeview_dashboard = lakeview_dashboards.create_dashboard(folder, query_transformer=replace_database_in_query)
sdk_dashboard = lakeview_dashboards.deploy_dashboard(lakeview_dashboard)
dashboard_url = f"{w.config.host}/sql/dashboardsv3/{sdk_dashboard.dashboard_id}"
if not no_open:
assert sdk_dashboard.dashboard_id is not None
dashboard_url = lakeview_dashboards.get_url(sdk_dashboard.dashboard_id)
webbrowser.open(dashboard_url)
print(sdk_dashboard.dashboard_id)

Expand Down
14 changes: 14 additions & 0 deletions src/databricks/labs/lsql/dashboards.py
Original file line number Diff line number Diff line change
Expand Up @@ -919,3 +919,17 @@ def _replace_names(self, node: T, better_names: dict[str, str]) -> T:
if node.spec is not None:
node.name = node.spec.as_dict().get("widgetType", node.name)
return node

def get_url(self, dashboard_id: str) -> str:
"""Get the dashboard URL.

Parameters :
dashboard_id : str
The dashboard id to get the URL for

Returns :
The dashboard URL
"""
# The /published redirects to the draft if the dashboard is not published
dashboard_url = f"{self._ws.config.host}/dashboardsv3/{dashboard_id}/published"
return dashboard_url
8 changes: 8 additions & 0 deletions tests/unit/test_dashboards.py
Original file line number Diff line number Diff line change
Expand Up @@ -1367,3 +1367,11 @@ def test_dashboards_save_to_folder_replaces_counter_names(ugly_dashboard, tmp_pa

assert all(counter.name == "counter" for counter in counters)
ws.assert_not_called()


def test_dashboards_get_dashboard_url():
dashboard_url_expected = "https://adb-0123456789.12.azuredatabricks.net/dashboardsv3/1234/published"
ws = create_autospec(WorkspaceClient)
ws.config.host = "https://adb-0123456789.12.azuredatabricks.net"
dashboard_url = Dashboards(ws).get_url("1234")
assert dashboard_url == dashboard_url_expected
Loading