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

Added save-dashboard command #300

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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 .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
8 changes: 8 additions & 0 deletions labs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,11 @@ 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: remote-path
description: The path to fetch dashboard from.
- name: local-path
description: The path to save files to.
15 changes: 15 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,19 @@ def create_dashboard(
print(sdk_dashboard.dashboard_id)


@lsql.command
def save_dashboard(w: WorkspaceClient, prompts: Prompts, remote_path: str = '~', local_path: Path = Path.cwd()):
"""Save a dashboard to a folder"""
workspace_path = WorkspacePath(w, remote_path).expanduser()
if workspace_path.is_dir():
dashboards = {_.name: _ for _ in workspace_path.glob('*.lvdash.json')}
workspace_path = prompts.choice_from_dict('Select existing dashboard', dashboards)
lakeview_dashboards = Dashboards(w)
remote_dashboard = lakeview_dashboards.get_dashboard(workspace_path)
lakeview_dashboards.save_to_folder(remote_dashboard, Path(local_path))



@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
Loading