Skip to content

A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.

fix: add back bigquery logo, move help into select dropdown (#3852)

Myles Scolnickc9f4f9fc8219
diff --git a/frontend/src/components/databases/icon.tsx b/frontend/src/components/databases/icon.tsx
index 546e045fdf..254754eee3 100644
--- a/frontend/src/components/databases/icon.tsx
+++ b/frontend/src/components/databases/icon.tsx
@@ -10,6 +10,17 @@ import ClickhouseIcon from "./icons/clickhouse.svg";
import GoogleBigQueryIcon from "./icons/googlebigquery.svg";
import { cn } from "@/utils/cn";
+export type DBLogoName =
+ | "sqlite"
+ | "duckdb"
+ | "postgres"
+ | "postgresql"
+ | "mysql"
+ | "snowflake"
+ | "databricks"
+ | "clickhouse"
+ | "bigquery";
+
/**
* Icons are from https://simpleicons.org/
*/
@@ -19,22 +30,22 @@ interface DatabaseLogoProps {
className?: string;
}
+const URLS: Record<DBLogoName, string | undefined> = {
+ sqlite: SQLiteIcon,
+ duckdb: DuckDBIcon,
+ postgres: PostgresQLIcon,
+ postgresql: PostgresQLIcon,
+ mysql: MySQLIcon,
+ snowflake: SnowflakeIcon,
+ databricks: DatabricksIcon,
+ clickhouse: ClickhouseIcon,
+ bigquery: GoogleBigQueryIcon,
+};
+
export const DatabaseLogo: FC<DatabaseLogoProps> = ({ name, className }) => {
const lowerName = name.toLowerCase();
- const URLS: Record<string, string | undefined> = {
- sqlite: SQLiteIcon,
- duckdb: DuckDBIcon,
- postgres: PostgresQLIcon,
- postgresql: PostgresQLIcon,
- mysql: MySQLIcon,
- snowflake: SnowflakeIcon,
- databricks: DatabricksIcon,
- clickhouse: ClickhouseIcon,
- bigquery: GoogleBigQueryIcon,
- };
-
- const url = URLS[lowerName];
+ const url = URLS[lowerName as DBLogoName];
if (!url) {
return null;
diff --git a/frontend/src/components/editor/database/add-database-form.tsx b/frontend/src/components/editor/database/add-database-form.tsx
index a95727206e..c557a05ce5 100644
--- a/frontend/src/components/editor/database/add-database-form.tsx
+++ b/frontend/src/components/editor/database/add-database-form.tsx
@@ -22,7 +22,7 @@ import {
DialogTitle,
DialogTrigger,
} from "@/components/ui/dialog";
-import { DatabaseLogo } from "@/components/databases/icon";
+import { DatabaseLogo, type DBLogoName } from "@/components/databases/icon";
import { useCellActions } from "@/core/cells/cells";
import { useLastFocusedCellId } from "@/core/cells/focus";
import {
@@ -90,9 +90,14 @@ const SCHEMAS = [
name: "BigQuery",
schema: BigQueryConnectionSchema,
color: "#4285F4",
- logo: "googlebigquery",
+ logo: "bigquery",
},
-];
+] satisfies Array<{
+ name: string;
+ schema: z.ZodType;
+ color: string;
+ logo: DBLogoName;
+}>;
const DatabaseSchemaSelector: React.FC<{
onSelect: (schema: z.ZodType) => void;
diff --git a/frontend/src/core/codemirror/language/panel.tsx b/frontend/src/core/codemirror/language/panel.tsx
index e08f2cbb5d..53a203d3de 100644
--- a/frontend/src/core/codemirror/language/panel.tsx
+++ b/frontend/src/core/codemirror/language/panel.tsx
@@ -10,13 +10,13 @@ import {
} from "@/core/datasets/data-source-connections";
import { useAtomValue } from "jotai";
import { AlertCircle, CircleHelpIcon } from "lucide-react";
-import { Tooltip, TooltipProvider } from "@/components/ui/tooltip";
import {
Select,
SelectContent,
SelectGroup,
SelectItem,
SelectLabel,
+ SelectSeparator,
SelectTrigger,
SelectValue,
} from "@/components/ui/select";
@@ -117,6 +117,11 @@ const SQLEngineSelect: React.FC<SelectProps> = ({
selectedEngine && !connectionsMap.has(selectedEngine);
const handleSelectEngine = (value: string) => {
+ if (value === HELP_KEY) {
+ window.open(HELP_URL, "_blank");
+ return;
+ }
+
const nextEngine = connectionsMap.get(value as ConnectionName);
if (nextEngine) {
languageAdapter.selectEngine(nextEngine.name);
@@ -154,23 +159,25 @@ const SQLEngineSelect: React.FC<SelectProps> = ({
</div>
</SelectItem>
))}
+ <SelectSeparator />
+ <SelectItem className="text-muted-foreground" value={HELP_KEY}>
+ <a
+ className="flex items-center gap-1"
+ href={HELP_URL}
+ target="_blank"
+ rel="noreferrer"
+ >
+ <CircleHelpIcon className="h-3 w-3" />
+ <span>How to add a database connection</span>
+ </a>
+ </SelectItem>
</SelectGroup>
</SelectContent>
</Select>
- <TooltipProvider>
- <Tooltip content="How to add a database connection" delayDuration={200}>
- <a
- href="http://docs.marimo.io/guides/working_with_data/sql/#connecting-to-a-custom-database"
- target="_blank"
- rel="noreferrer"
- >
- <CircleHelpIcon
- size={12}
- className="text-[var(--sky-11)] opacity-60 hover:opacity-100"
- />
- </a>
- </Tooltip>
- </TooltipProvider>
</div>
);
};
+
+const HELP_KEY = "__help__";
+const HELP_URL =
+ "http://docs.marimo.io/guides/working_with_data/sql/#connecting-to-a-custom-database";
diff --git a/marimo/_messaging/ops.py b/marimo/_messaging/ops.py
index c98abe925b..9e7c74c69c 100644
--- a/marimo/_messaging/ops.py
+++ b/marimo/_messaging/ops.py
@@ -54,7 +54,7 @@ from marimo._plugins.ui._core.ui_element import UIElement
from marimo._runtime.context import get_context
from marimo._runtime.context.utils import get_mode
from marimo._runtime.layout.layout import LayoutConfig
-from marimo._types.ids import CellId_t
+from marimo._types.ids import CellId_t, RequestId
from marimo._utils.platform import is_pyodide, is_windows
LOGGER = loggers.marimo_logger()
@@ -335,7 +335,7 @@ class FunctionCallResult(Op):
name: ClassVar[str] = "function-call-result"
- function_call_id: str
+ function_call_id: RequestId
return_value: JSONType
status: HumanReadableStatus
@@ -595,7 +595,7 @@ class SQLTablePreview(Op):
"""Preview of a table in a dataset."""
name: ClassVar[str] = "sql-table-preview"
- request_id: str
+ request_id: RequestId
table: Optional[DataTable]
error: Optional[str] = None
diff --git a/marimo/_runtime/requests.py b/marimo/_runtime/requests.py
index a8a3632034..63eec4b655 100644
--- a/marimo/_runtime/requests.py
+++ b/marimo/_runtime/requests.py
@@ -20,14 +20,13 @@ from uuid import uuid4
from marimo._config.config import MarimoConfig
from marimo._data.models import DataTableSource
-from marimo._types.ids import CellId_t, UIElementId
+from marimo._types.ids import CellId_t, RequestId, UIElementId
if TYPE_CHECKING:
from starlette.datastructures import URL
from starlette.requests import HTTPConnection
CompletionRequestId = str
-FunctionCallId = str
T = TypeVar("T")
ListOrValue = Union[T, List[T]]
@@ -223,7 +222,7 @@ class SetUIElementValueRequest:
@dataclass
class FunctionCallRequest:
- function_call_id: FunctionCallId
+ function_call_id: RequestId
namespace: str
function_name: str
args: Dict[str, Any]
@@ -310,7 +309,7 @@ class PreviewDatasetColumnRequest:
class PreviewSQLTableRequest:
"""Preview table details in an SQL database"""
- request_id: str
+ request_id: RequestId
engine: str
database: str
schema: str
diff --git a/marimo/_types/ids.py b/marimo/_types/ids.py
index 57700b4688..38e20d3b73 100644
--- a/marimo/_types/ids.py
+++ b/marimo/_types/ids.py
@@ -11,3 +11,5 @@ SessionId = NewType("SessionId", str)
ConsumerId = NewType("ConsumerId", str)
VariableName = NewType("VariableName", str)
+
+RequestId = NewType("RequestId", str)
diff --git a/tests/_server/api/endpoints/test_datasources.py b/tests/_server/api/endpoints/test_datasources.py
new file mode 100644
index 0000000000..48b484723d
--- /dev/null
+++ b/tests/_server/api/endpoints/test_datasources.py
@@ -0,0 +1,78 @@
+# Copyright 2024 Marimo. All rights reserved.
+from __future__ import annotations
+
+from typing import TYPE_CHECKING
+
+from tests._server.mocks import token_header, with_read_session, with_session
+
+if TYPE_CHECKING:
+ from starlette.testclient import TestClient
+
+SESSION_ID = "session-123"
+HEADERS = {
+ "Marimo-Session-Id": SESSION_ID,
+ **token_header("fake-token"),
+}
+
+
+@with_session(SESSION_ID)
+def test_preview_column(client: TestClient) -> None:
+ response = client.post(
+ "/api/datasources/preview_column",
+ headers=HEADERS,
+ json={
+ "source_type": "connection",
+ "source": "test_source",
+ "table_name": "test_table",
+ "column_name": "test_column",
+ },
+ )
+ assert response.status_code == 200, response.text
+ content = response.json()
+ assert content["success"] is True
+
+
+@with_session(SESSION_ID)
+def test_preview_sql_table(client: TestClient) -> None:
+ response = client.post(
+ "/api/datasources/preview_sql_table",
+ headers=HEADERS,
+ json={
+ "request_id": "test_request_id",
+ "engine": "test_engine",
+ "database": "test_db",
+ "schema": "test_schema",
+ "table_name": "test_table",
+ },
+ )
+ assert response.status_code == 200, response.text
+ content = response.json()
+ assert content["success"] is True
+
+
+@with_read_session(SESSION_ID)
+def test_fails_in_read_mode(client: TestClient) -> None:
+ response = client.post(
+ "/api/datasources/preview_column",
+ headers=HEADERS,
+ json={
+ "source_type": "connection",
+ "source": "test_source",
+ "table_name": "test_table",
+ "column_name": "test_column",
+ },
+ )
+ assert response.status_code == 401
+
+ response = client.post(
+ "/api/datasources/preview_sql_table",
+ headers=HEADERS,
+ json={
+ "request_id": "test_request_id",
+ "engine": "test_engine",
+ "database": "test_db",
+ "schema": "test_schema",
+ "table_name": "test_table",
+ },
+ )
+ assert response.status_code == 401