Skip to content

Commit

Permalink
Added save-dashboard command
Browse files Browse the repository at this point in the history
  • Loading branch information
nfx committed Sep 27, 2024
1 parent dbfc823 commit 6f652d9
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -161,4 +161,5 @@ cython_debug/
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

*.out
*.out
/.databricks-login.json
10 changes: 10 additions & 0 deletions labs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,13 @@ commands:
description: Publish the dashboard after creating by setting to `yes` or `y`.
- name: open-browser
description: Open the dashboard in the browser after creating by setting to `yes` or `y`.

- name: save-dashboard
description: Save the dashboard to the given path.
flags:
- name: dashboard-id
description: The dashboard ID to save.
- name: path
description: The path to save the dashboard to.
- name: overwrite
description: Overwrite the existing file if it exists.
12 changes: 12 additions & 0 deletions src/databricks/labs/lsql/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

from databricks.labs.blueprint.cli import App
from databricks.labs.blueprint.entrypoint import get_logger
from databricks.labs.blueprint.tui import Prompts
from databricks.labs.blueprint.paths import WorkspacePath
from databricks.sdk import WorkspaceClient

from databricks.labs.lsql.dashboards import DashboardMetadata, Dashboards, QueryTile
Expand Down Expand Up @@ -43,6 +45,16 @@ def create_dashboard(
print(sdk_dashboard.dashboard_id)


@lsql.command
def save_dashboard(w: WorkspaceClient, prompts: Prompts, remote_folder: str = '~'):
"""Save a dashboard to a folder"""
workspace_path = WorkspacePath(w, remote_folder).expanduser()
dashboards = {_.name: _ for _ in workspace_path.glob('*.lvdash.json')}
selected = prompts.choice_from_dict('Select existing dashboard', dashboards)
print(selected)



@lsql.command(is_unauthenticated=True)
def fmt(folder: Path = Path.cwd(), *, normalize_case: str = "true", exclude: Iterable[str] = ()):
"""Format SQL files in a folder"""
Expand Down

0 comments on commit 6f652d9

Please sign in to comment.