66 default_api_key ,
77 default_host ,
88 default_session_id ,
9- explicit_workspace_id ,
10- list_workspaces ,
9+ resolve_workspace_selection ,
1110)
1211
1312
@@ -25,25 +24,19 @@ def __init__(
2524 self ._api_key = api_key
2625 self ._host = host or default_host ()
2726 self ._session_id = session_id
28- self ._explicit = explicit_workspace_id ()
29-
30- workspaces = list_workspaces (api_key , self ._host , session_id )
31- if not workspaces :
32- raise RuntimeError ("No Hotdata workspaces found for this API key." )
33-
27+ selection = resolve_workspace_selection (api_key , self ._host , session_id )
28+ self ._explicit = selection .source == "explicit_env"
3429 if self ._explicit :
3530 self ._pick = None
36- self ._workspace_id = self . _explicit
31+ self ._workspace_id = selection . workspace_id
3732 return
3833
34+ workspaces = selection .workspaces
3935 if len (workspaces ) == 1 :
4036 self ._pick = None
4137 self ._workspace_id = workspaces [0 ].public_id
4238 return
4339
44- active = [w for w in workspaces if w .active ]
45- chosen = active [0 ] if active else workspaces [0 ]
46-
4740 labels : list [tuple [str , str ]] = []
4841 seen : set [str ] = set ()
4942 for w in workspaces :
@@ -52,10 +45,10 @@ def __init__(
5245 seen .add (base )
5346 labels .append ((label_text , w .public_id ))
5447
55- labels .sort (key = lambda t : 0 if t [1 ] == chosen . public_id else 1 )
48+ labels .sort (key = lambda t : 0 if t [1 ] == selection . workspace_id else 1 )
5649 options = {k : v for k , v in labels }
5750 self ._pick = mo .ui .dropdown (options = options , label = label , full_width = True )
58- self ._workspace_id = chosen . public_id
51+ self ._workspace_id = selection . workspace_id
5952
6053 @property
6154 def workspace_id (self ) -> str :
0 commit comments