Skip to content
Merged
Changes from 1 commit
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
21 changes: 7 additions & 14 deletions hotdata_marimo/workspace_selector.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
default_api_key,
default_host,
default_session_id,
explicit_workspace_id,
list_workspaces,
resolve_workspace_selection,
)


Expand All @@ -25,25 +24,19 @@ def __init__(
self._api_key = api_key
self._host = host or default_host()
self._session_id = session_id
self._explicit = explicit_workspace_id()

workspaces = list_workspaces(api_key, self._host, session_id)
if not workspaces:
raise RuntimeError("No Hotdata workspaces found for this API key.")

selection = resolve_workspace_selection(api_key, self._host, session_id)
self._explicit = selection.source == "explicit_env"
if self._explicit:
self._pick = None
self._workspace_id = self._explicit
self._workspace_id = selection.workspace_id
return

workspaces = selection.workspaces
if len(workspaces) == 1:
self._pick = None
self._workspace_id = workspaces[0].public_id
return

active = [w for w in workspaces if w.active]
chosen = active[0] if active else workspaces[0]

labels: list[tuple[str, str]] = []
seen: set[str] = set()
for w in workspaces:
Expand All @@ -52,10 +45,10 @@ def __init__(
seen.add(base)
labels.append((label_text, w.public_id))

labels.sort(key=lambda t: 0 if t[1] == chosen.public_id else 1)
labels.sort(key=lambda t: 0 if t[1] == selection.workspace_id else 1)
options = {k: v for k, v in labels}
self._pick = mo.ui.dropdown(options=options, label=label, full_width=True)
self._workspace_id = chosen.public_id
self._workspace_id = selection.workspace_id
Comment on lines 34 to +51
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: the prior code raised RuntimeError("No Hotdata workspaces found for this API key.") before reaching the picker logic. With this refactor, if resolve_workspace_selection returns source != "explicit_env" with an empty workspaces list, neither branch fires and we fall through to build a dropdown with options={} (and selection.workspace_id is whatever the runtime defaulted it to). Either confirm the runtime contract guarantees a non-empty list / raises for this case, or restore an explicit guard here so the failure mode stays a clear error rather than a broken dropdown. (not blocking)


@property
def workspace_id(self) -> str:
Expand Down
Loading