-
Notifications
You must be signed in to change notification settings - Fork 0
refactor: dedupe marimo dropdown and connection helpers #3
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
Merged
Merged
Changes from 7 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
17a32c5
refactor: dedupe marimo dropdown and connection helpers
eddietejeda 1360cbc
fix: avoid duplicate list_connections in resolve_connection_picker
eddietejeda f18450a
feat: reorganize demo with tabbed explorer layout
eddietejeda eb50371
fix: pass .ui components to mo.ui.tabs in demo
eddietejeda a18b11c
chore: simplify demo watcher cells for tabbed layout
eddietejeda f9a1ed7
feat: show connection table in connections_panel
eddietejeda bc4828b
fix: reload dataset tables when connection changes in tabs
eddietejeda 0a11268
fix: name browser_ui explicitly for marimo cell export
eddietejeda c494a18
fix: show SQL and recent query results in demo tabs
eddietejeda a48fe3c
refactor: simplify demo and improve recent results table UI
eddietejeda a060ade
chore: polish demo and SQL editor UI
eddietejeda File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| """Shared dropdown option helpers for Marimo UI widgets.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from collections.abc import Callable | ||
| from typing import Any | ||
|
|
||
| import marimo as mo | ||
|
|
||
| from hotdata_runtime import HotdataClient | ||
|
|
||
|
|
||
| def unique_label_options( | ||
| pairs: list[tuple[str, str]], | ||
| *, | ||
| disambiguate: Callable[[str, str, int], str] | None = None, | ||
| ) -> dict[str, str]: | ||
| """Build a label→value map, suffixing repeated labels when needed.""" | ||
| counts: dict[str, int] = {} | ||
| options: dict[str, str] = {} | ||
| for label, value in pairs: | ||
| count = counts.get(label, 0) | ||
| counts[label] = count + 1 | ||
| if count == 0: | ||
| key = label | ||
| elif disambiguate is not None: | ||
| key = disambiguate(label, value, count) | ||
| else: | ||
| key = f"{label} ({count + 1})" | ||
| options[key] = value | ||
| return options | ||
|
|
||
|
|
||
| def empty_dropdown( | ||
| *, | ||
| label: str, | ||
| message: str, | ||
| full_width: bool = True, | ||
| ): | ||
| return mo.ui.dropdown( | ||
| options={message: ""}, | ||
| label=label, | ||
| full_width=full_width, | ||
| ) | ||
|
|
||
|
|
||
| def connection_options(conns: list[Any]) -> dict[str, str]: | ||
| pairs = [(str(c.name), str(c.id)) for c in conns] | ||
| return unique_label_options( | ||
| pairs, | ||
| disambiguate=lambda label, value, count: f"{label} ({value})", | ||
| ) | ||
|
|
||
|
|
||
| def connection_picker_from_connections( | ||
| conns: list[Any], | ||
| *, | ||
| label: str = "Connection", | ||
| full_width: bool = True, | ||
| ): | ||
| if not conns: | ||
| return empty_dropdown( | ||
| label=label, | ||
| message="(no connections)", | ||
| full_width=full_width, | ||
| ) | ||
| return mo.ui.dropdown( | ||
| options=connection_options(conns), | ||
| label=label, | ||
| full_width=full_width, | ||
| ) | ||
|
|
||
|
|
||
| def connection_picker( | ||
| client: HotdataClient, | ||
| *, | ||
| label: str = "Connection", | ||
| full_width: bool = True, | ||
| ): | ||
| conns = client.connections().list_connections().connections | ||
| return connection_picker_from_connections( | ||
| conns, | ||
| label=label, | ||
| full_width=full_width, | ||
| ) | ||
|
|
||
|
|
||
| def resolve_connection_picker( | ||
| client: HotdataClient, | ||
| *, | ||
| label: str = "Connection", | ||
| full_width: bool = True, | ||
| ) -> tuple[Any | None, str | None]: | ||
| """Return ``(dropdown_or_none, implicit_connection_id)`` for table browsers.""" | ||
| conns = client.connections().list_connections().connections | ||
| if not conns: | ||
| return None, "" | ||
| if len(conns) == 1: | ||
| return None, conns[0].id | ||
| return ( | ||
| connection_picker_from_connections( | ||
| conns, | ||
| label=label, | ||
| full_width=full_width, | ||
| ), | ||
| None, | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: this drops the local
_connection_id_cacheand now callsself._connection.connection_id_by_name()on every invocation._connection_idis hit fromget_schemas,get_tables_in_schema, andget_table_details— each of which can fire several times per render — so unlessconnection_id_by_name()is cheap or memoized on the runtime side, this will multiply backend calls during catalog browsing. Worth confirming the runtime caches the mapping, or memoize locally (e.g., one cached dict reused alongside_connections_cache). (not blocking)