@marimo-team/islands 0.24.1-dev42 → 0.24.1-dev43
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{ConnectedDataExplorerComponent-4UvlnITc.js → ConnectedDataExplorerComponent-CxLgYj_n.js} +1038 -1038
- package/dist/{any-language-editor-ClDhQoll.js → any-language-editor-BrPYtXHK.js} +1 -1
- package/dist/{chat-ui-BzZL5_XE.js → chat-ui-Mjq3lBLn.js} +1335 -1335
- package/dist/{common-DiHZo6cj.js → common-IoLWZR0C.js} +20955 -20975
- package/dist/{input-CIaA2N0m.js → dropdown-menu-DEu759Oe.js} +930 -927
- package/dist/{error-banner-BbxpEiD5.js → error-banner-BT4uIIQ2.js} +190 -192
- package/dist/{glide-data-editor-CgO5z9xu.js → glide-data-editor-C2RTkAgQ.js} +51 -51
- package/dist/{html-to-image-DPAZGZSi.js → html-to-image-hKcfSWj_.js} +5795 -5590
- package/dist/main.js +8696 -8703
- package/dist/{mermaid-BBTUHwCi.js → mermaid-OsTxhZOI.js} +12 -12
- package/dist/{process-output-oZcxC_tq.js → process-output-BkHK-KDc.js} +6 -6
- package/dist/{reveal-component-UCcAUoNH.js → reveal-component-DUBiSLUI.js} +11 -11
- package/dist/{strings-CoQ5sA4r.js → select-Bakm9EUs.js} +50 -53
- package/dist/{spec-6c0_fLYz.js → spec-DqUrBQpS.js} +2 -2
- package/dist/style.css +1 -1
- package/dist/{useDateFormatter-6ImHK1ln.js → useDateFormatter-DjRKOAkR.js} +1 -1
- package/dist/{vega-component-DlnGFDeY.js → vega-component-A2xO4BUa.js} +17 -17
- package/package.json +1 -1
- package/src/components/datasources/datasources.tsx +16 -17
- package/src/components/editor/actions/useNotebookActions.tsx +50 -0
- package/src/components/editor/chrome/panels/components.tsx +1 -1
- package/src/components/editor/connections/__tests__/add-connection-button.test.tsx +129 -0
- package/src/components/editor/connections/add-connection-button.tsx +132 -0
- package/src/components/editor/connections/components.tsx +11 -0
- package/src/components/editor/connections/quick-add-data-sources.tsx +11 -11
- package/src/components/editor/controls/__tests__/notebook-menu-dropdown.test.tsx +109 -1
- package/src/components/storage/storage-inspector.tsx +15 -17
- package/src/core/codemirror/language/panel/sql.test.tsx +69 -0
- package/src/core/codemirror/language/panel/sql.tsx +81 -4
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { a as e } from "./rolldown-runtime-Cb76FRpK.js";
|
|
2
2
|
import { t } from "./react-DMWcHin-.js";
|
|
3
3
|
import { u as n } from "./dist-DTSuOdDc.js";
|
|
4
|
-
import { E as r } from "./
|
|
4
|
+
import { E as r } from "./select-Bakm9EUs.js";
|
|
5
5
|
var i = n("chart-pie", [["path", {
|
|
6
6
|
d: "M21 12c.552 0 1.005-.449.95-.998a10 10 0 0 0-8.953-8.951c-.55-.055-.998.398-.998.95v8a1 1 0 0 0 1 1z",
|
|
7
7
|
key: "pzmjnu"
|
|
@@ -4,17 +4,17 @@ import { t as i } from "./react-DMWcHin-.js";
|
|
|
4
4
|
import { t as a } from "./compiler-runtime-CAH9RLw2.js";
|
|
5
5
|
import { _ as o, c as s } from "./toDate-C4ZHOUTi.js";
|
|
6
6
|
import { t as c } from "./jsx-runtime-CpoKNRgu.js";
|
|
7
|
-
import { n as l } from "./error-banner-
|
|
7
|
+
import { n as l } from "./error-banner-BT4uIIQ2.js";
|
|
8
8
|
import { t as u } from "./tooltip-rwx3Qbw6.js";
|
|
9
9
|
import { t as d } from "./debounce-C3jyATpc.js";
|
|
10
10
|
import { A as f, n as p } from "./useTheme-CLjV5H1i.js";
|
|
11
11
|
import { c as m } from "./arrays-CN1djC4k.js";
|
|
12
12
|
import { t as ee } from "./objects-CzUgoMIF.js";
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
13
|
+
import { t as h } from "./useAsyncData-BPIoRmNG.js";
|
|
14
|
+
import { a as te, i as ne, n as re, t as g } from "./formats-l5hZdDGj.js";
|
|
15
|
+
import { A as ie, n as ae } from "./vega-loader.browser-DEggZzni.js";
|
|
16
|
+
import { t as oe } from "./react-vega-DSD5aT7_.js";
|
|
17
|
+
import { a as se, n as _ } from "./loader-CgRtoLc5.js";
|
|
18
18
|
import { t as ce } from "./useDeepCompareMemoize-rqhnGZ6D.js";
|
|
19
19
|
import { t as le } from "./semaphore-89jsoHtS.js";
|
|
20
20
|
import { t as ue } from "./use-vega-container-remeasure-DUW4tRxq.js";
|
|
@@ -490,7 +490,7 @@ async function U(e) {
|
|
|
490
490
|
} catch {
|
|
491
491
|
return e;
|
|
492
492
|
}
|
|
493
|
-
let a = e.data.format, o = await n.run(() =>
|
|
493
|
+
let a = e.data.format, o = await n.run(() => _(i.href, a));
|
|
494
494
|
return t[i.pathname] = o, {
|
|
495
495
|
...e,
|
|
496
496
|
data: { name: i.pathname }
|
|
@@ -504,11 +504,11 @@ async function U(e) {
|
|
|
504
504
|
//#endregion
|
|
505
505
|
//#region src/plugins/impl/vega/vega-component.tsx
|
|
506
506
|
var W = c();
|
|
507
|
-
|
|
507
|
+
ae("arrow", g);
|
|
508
508
|
var G = (e) => {
|
|
509
509
|
let t = (0, de.c)(12), { value: n, setValue: r, chartSelection: i, fieldSelection: a, spec: o, embedOptions: s } = e, c, u;
|
|
510
510
|
t[0] === o ? (c = t[1], u = t[2]) : (c = async () => U(o), u = [o], t[0] = o, t[1] = c, t[2] = u);
|
|
511
|
-
let { data: d, error: f } =
|
|
511
|
+
let { data: d, error: f } = h(c, u);
|
|
512
512
|
if (f) {
|
|
513
513
|
let e;
|
|
514
514
|
return t[3] === f ? e = t[4] : (e = /* @__PURE__ */ (0, W.jsx)(l, { error: f }), t[3] = f, t[4] = e), e;
|
|
@@ -524,7 +524,7 @@ var G = (e) => {
|
|
|
524
524
|
embedOptions: s
|
|
525
525
|
}), t[5] = i, t[6] = s, t[7] = a, t[8] = d, t[9] = r, t[10] = n, t[11] = p) : p = t[11], p;
|
|
526
526
|
}, K = (e) => {
|
|
527
|
-
let i = (0, de.c)(50), { value: a, setValue: s, chartSelection: c, fieldSelection: l, spec: m, embedOptions: h } = e, { theme:
|
|
527
|
+
let i = (0, de.c)(50), { value: a, setValue: s, chartSelection: c, fieldSelection: l, spec: m, embedOptions: h } = e, { theme: te } = p(), g = (0, v.useRef)(null), ae = (0, v.useRef)(void 0), [_, le] = (0, v.useState)(), y;
|
|
528
528
|
bb0: {
|
|
529
529
|
if (h && "actions" in h) {
|
|
530
530
|
y = h.actions;
|
|
@@ -570,7 +570,7 @@ var G = (e) => {
|
|
|
570
570
|
}, i[17] = w, i[18] = F);
|
|
571
571
|
let I = f(F), L;
|
|
572
572
|
i[19] === Symbol.for("react.memo_cache_sentinel") ? (L = (e) => {
|
|
573
|
-
t.debug("[Vega view] created", e),
|
|
573
|
+
t.debug("[Vega view] created", e), ae.current = e, le(void 0);
|
|
574
574
|
}, i[19] = L) : L = i[19];
|
|
575
575
|
let R = f(L), z;
|
|
576
576
|
i[20] === D ? z = i[21] : (z = () => {
|
|
@@ -585,12 +585,12 @@ var G = (e) => {
|
|
|
585
585
|
children: /* @__PURE__ */ (0, W.jsx)(o, { className: "absolute bottom-1 right-0 m-2 h-4 w-4 cursor-help text-muted-foreground hover:text-foreground" })
|
|
586
586
|
});
|
|
587
587
|
}, i[20] = D, i[21] = z);
|
|
588
|
-
let B = z, V =
|
|
588
|
+
let B = z, V = te === "dark" ? "dark" : void 0, H;
|
|
589
589
|
i[22] !== b || i[23] !== V ? (H = {
|
|
590
590
|
theme: V,
|
|
591
591
|
actions: b,
|
|
592
592
|
mode: "vega-lite",
|
|
593
|
-
tooltip:
|
|
593
|
+
tooltip: se.call,
|
|
594
594
|
renderer: "canvas"
|
|
595
595
|
}, i[22] = b, i[23] = V, i[24] = H) : H = i[24];
|
|
596
596
|
let U;
|
|
@@ -601,7 +601,7 @@ var G = (e) => {
|
|
|
601
601
|
onError: I,
|
|
602
602
|
onEmbed: R
|
|
603
603
|
}, i[25] = I, i[26] = R, i[27] = w, i[28] = H, i[29] = U) : U = i[29];
|
|
604
|
-
let G =
|
|
604
|
+
let G = oe(U), K;
|
|
605
605
|
i[30] === w ? K = i[31] : (K = ie(w), i[30] = w, i[31] = K);
|
|
606
606
|
let q = K;
|
|
607
607
|
ue(g, q === "container");
|
|
@@ -626,9 +626,9 @@ var G = (e) => {
|
|
|
626
626
|
});
|
|
627
627
|
}), Y = [G, P], i[32] = G, i[33] = P, i[34] = J, i[35] = Y) : (J = i[34], Y = i[35]), (0, v.useEffect)(J, Y);
|
|
628
628
|
let X;
|
|
629
|
-
i[36] === _ ? X = i[37] : (X = _ && /* @__PURE__ */ (0, W.jsxs)(
|
|
629
|
+
i[36] === _ ? X = i[37] : (X = _ && /* @__PURE__ */ (0, W.jsxs)(re, {
|
|
630
630
|
variant: "destructive",
|
|
631
|
-
children: [/* @__PURE__ */ (0, W.jsx)(
|
|
631
|
+
children: [/* @__PURE__ */ (0, W.jsx)(ne, { children: _.message }), /* @__PURE__ */ (0, W.jsx)("div", {
|
|
632
632
|
className: "text-md",
|
|
633
633
|
children: _.stack
|
|
634
634
|
})]
|
|
@@ -655,7 +655,7 @@ function me(e) {
|
|
|
655
655
|
return e instanceof Set ? [...e] : e;
|
|
656
656
|
}
|
|
657
657
|
function he(e) {
|
|
658
|
-
return Array.isArray(e) ? e.map((e) => e instanceof Date &&
|
|
658
|
+
return Array.isArray(e) ? e.map((e) => e instanceof Date && te(e) ? new Date(e).getTime() : e) : e;
|
|
659
659
|
}
|
|
660
660
|
function ge(e, t) {
|
|
661
661
|
return /* @__PURE__ */ (0, W.jsxs)("div", { children: [
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import { CommandList } from "cmdk";
|
|
4
4
|
import { atom, useAtom, useAtomValue, useSetAtom } from "jotai";
|
|
5
5
|
import { atomWithStorage } from "jotai/utils";
|
|
6
|
-
import {
|
|
6
|
+
import { PlusSquareIcon, XIcon } from "lucide-react";
|
|
7
7
|
import React from "react";
|
|
8
8
|
import { dbDisplayName } from "@/components/databases/display";
|
|
9
9
|
import { EngineVariable } from "@/components/databases/engine-variable";
|
|
@@ -64,7 +64,7 @@ import { ErrorBoundary } from "../editor/boundary/ErrorBoundary";
|
|
|
64
64
|
import { PythonIcon } from "../editor/cell/code/icons";
|
|
65
65
|
import { useAddCodeToNewCell } from "../editor/cell/useAddCell";
|
|
66
66
|
import { PanelEmptyState } from "../editor/chrome/panels/empty-state";
|
|
67
|
-
import {
|
|
67
|
+
import { AddConnectionButton } from "../editor/connections/add-connection-button";
|
|
68
68
|
import { DatasetColumnPreview } from "./column-preview";
|
|
69
69
|
import {
|
|
70
70
|
ColumnName,
|
|
@@ -250,12 +250,12 @@ export const DataSources: React.FC = () => {
|
|
|
250
250
|
title="No tables found"
|
|
251
251
|
description="Any datasets/dataframes in the global scope will be shown here."
|
|
252
252
|
action={
|
|
253
|
-
<
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
253
|
+
<AddConnectionButton
|
|
254
|
+
group="database"
|
|
255
|
+
label="Add database or catalog"
|
|
256
|
+
variant="outline"
|
|
257
|
+
size="sm"
|
|
258
|
+
/>
|
|
259
259
|
}
|
|
260
260
|
icon={<DatabaseIcon />}
|
|
261
261
|
/>
|
|
@@ -301,15 +301,14 @@ export const DataSources: React.FC = () => {
|
|
|
301
301
|
className="px-2 rounded-none focus-visible:outline-hidden"
|
|
302
302
|
/>
|
|
303
303
|
|
|
304
|
-
<
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
</AddConnectionDialog>
|
|
304
|
+
<AddConnectionButton
|
|
305
|
+
group="database"
|
|
306
|
+
label="Add database or catalog"
|
|
307
|
+
compact={true}
|
|
308
|
+
variant="ghost"
|
|
309
|
+
size="sm"
|
|
310
|
+
className="px-2 rounded-none focus-visible:outline-hidden"
|
|
311
|
+
/>
|
|
313
312
|
</div>
|
|
314
313
|
|
|
315
314
|
<CommandList className="flex flex-col">
|
|
@@ -73,6 +73,7 @@ import { useRequestClient } from "@/core/network/requests";
|
|
|
73
73
|
import { useFilename } from "@/core/saving/filename";
|
|
74
74
|
import { createShareableLink } from "@/core/wasm/share";
|
|
75
75
|
import { isWasm } from "@/core/wasm/utils";
|
|
76
|
+
import { useDetectedDataSources } from "@/hooks/useDataSourceDiscovery";
|
|
76
77
|
import { copyToClipboard } from "@/utils/copy";
|
|
77
78
|
import { Objects } from "@/utils/objects";
|
|
78
79
|
import { Strings } from "@/utils/strings";
|
|
@@ -81,6 +82,7 @@ import { useRunAllCells } from "../cell/useRunCells";
|
|
|
81
82
|
import { useChromeActions, useChromeState } from "../chrome/state";
|
|
82
83
|
import { isPanelHidden, PANELS } from "../chrome/types";
|
|
83
84
|
import { AddConnectionDialogContent } from "../connections/add-connection-dialog";
|
|
85
|
+
import { useAddDetectedDataSource } from "../connections/components";
|
|
84
86
|
import { keyboardShortcutsAtom } from "../controls/keyboard-shortcuts";
|
|
85
87
|
import { commandPaletteAtom } from "../controls/state";
|
|
86
88
|
import { displayLayoutName, getLayoutIcon } from "../renderers/layout-select";
|
|
@@ -135,6 +137,9 @@ export function useNotebookActions({
|
|
|
135
137
|
const setKeyboardShortcutsOpen = useSetAtom(keyboardShortcutsAtom);
|
|
136
138
|
const setExportOptions = useSetAtom(exportOptionsAtom);
|
|
137
139
|
const { readCode, saveCellConfig } = useRequestClient();
|
|
140
|
+
const detectedDatabaseSources = useDetectedDataSources("database");
|
|
141
|
+
const detectedStorageSources = useDetectedDataSources("storage");
|
|
142
|
+
const addDetectedDataSource = useAddDetectedDataSource();
|
|
138
143
|
|
|
139
144
|
const hasDisabledCells = useAtomValue(hasDisabledCellsAtom);
|
|
140
145
|
const canUndoDeletes = useAtomValue(canUndoDeletesAtom);
|
|
@@ -455,6 +460,27 @@ export function useNotebookActions({
|
|
|
455
460
|
handle: () => {
|
|
456
461
|
openModal(<AddConnectionDialogContent onClose={closeModal} />);
|
|
457
462
|
},
|
|
463
|
+
dropdown:
|
|
464
|
+
detectedDatabaseSources.length === 0
|
|
465
|
+
? undefined
|
|
466
|
+
: [
|
|
467
|
+
...detectedDatabaseSources.map((source) => ({
|
|
468
|
+
icon: <SparklesIcon size={14} strokeWidth={1.5} />,
|
|
469
|
+
label: `Add ${source.displayName}`,
|
|
470
|
+
description: "Detected in your environment",
|
|
471
|
+
handle: () => addDetectedDataSource(source),
|
|
472
|
+
})),
|
|
473
|
+
{
|
|
474
|
+
divider: true,
|
|
475
|
+
icon: <DatabaseIcon size={14} strokeWidth={1.5} />,
|
|
476
|
+
label: "Browse all connections",
|
|
477
|
+
handle: () => {
|
|
478
|
+
openModal(
|
|
479
|
+
<AddConnectionDialogContent onClose={closeModal} />,
|
|
480
|
+
);
|
|
481
|
+
},
|
|
482
|
+
},
|
|
483
|
+
],
|
|
458
484
|
},
|
|
459
485
|
{
|
|
460
486
|
icon: <HardDrive size={14} strokeWidth={1.5} />,
|
|
@@ -467,6 +493,30 @@ export function useNotebookActions({
|
|
|
467
493
|
/>,
|
|
468
494
|
);
|
|
469
495
|
},
|
|
496
|
+
dropdown:
|
|
497
|
+
detectedStorageSources.length === 0
|
|
498
|
+
? undefined
|
|
499
|
+
: [
|
|
500
|
+
...detectedStorageSources.map((source) => ({
|
|
501
|
+
icon: <SparklesIcon size={14} strokeWidth={1.5} />,
|
|
502
|
+
label: `Add ${source.displayName}`,
|
|
503
|
+
description: "Detected in your environment",
|
|
504
|
+
handle: () => addDetectedDataSource(source),
|
|
505
|
+
})),
|
|
506
|
+
{
|
|
507
|
+
divider: true,
|
|
508
|
+
icon: <HardDrive size={14} strokeWidth={1.5} />,
|
|
509
|
+
label: "Browse all connections",
|
|
510
|
+
handle: () => {
|
|
511
|
+
openModal(
|
|
512
|
+
<AddConnectionDialogContent
|
|
513
|
+
defaultTab="storage"
|
|
514
|
+
onClose={closeModal}
|
|
515
|
+
/>,
|
|
516
|
+
);
|
|
517
|
+
},
|
|
518
|
+
},
|
|
519
|
+
],
|
|
470
520
|
},
|
|
471
521
|
{
|
|
472
522
|
icon: <Undo2Icon size={14} strokeWidth={1.5} />,
|
|
@@ -105,7 +105,7 @@ const DiscoveredSourcesBadge = ({
|
|
|
105
105
|
return (
|
|
106
106
|
<Tooltip content={content}>
|
|
107
107
|
<span>
|
|
108
|
-
<PanelBadge className="gap-0.5 border-(--blue-6) bg-(--blue-3) text-(--blue-11)">
|
|
108
|
+
<PanelBadge className="gap-0.5 border-(--blue-6) bg-(--blue-3) text-(--blue-11) hover:bg-(--blue-4) dark:border-(--blue-8) dark:bg-(--blue-3) dark:hover:bg-(--blue-4)">
|
|
109
109
|
<SparklesIcon className="h-2.5 w-2.5" />
|
|
110
110
|
{count}
|
|
111
111
|
</PanelBadge>
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/* Copyright 2026 Marimo. All rights reserved. */
|
|
2
|
+
|
|
3
|
+
import { fireEvent, render, screen } from "@testing-library/react";
|
|
4
|
+
import { Provider } from "jotai";
|
|
5
|
+
import type React from "react";
|
|
6
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
7
|
+
import { ModalProvider } from "@/components/modal/ImperativeModal";
|
|
8
|
+
import { TooltipProvider } from "@/components/ui/tooltip";
|
|
9
|
+
import type { DetectedDataSource } from "@/core/datasets/data-source-discovery";
|
|
10
|
+
import { store } from "@/core/state/jotai";
|
|
11
|
+
import { AddConnectionButton } from "../add-connection-button";
|
|
12
|
+
|
|
13
|
+
const mocks = vi.hoisted(() => ({
|
|
14
|
+
addDetectedDataSource: vi.fn(),
|
|
15
|
+
sources: [] as DetectedDataSource[],
|
|
16
|
+
}));
|
|
17
|
+
|
|
18
|
+
const MYSQL_SOURCE: DetectedDataSource = {
|
|
19
|
+
id: "mysql-environment",
|
|
20
|
+
integration: "mysql",
|
|
21
|
+
category: "database",
|
|
22
|
+
displayName: "MySQL",
|
|
23
|
+
confidence: "high",
|
|
24
|
+
origins: [{ type: "environment", label: "Kernel environment" }],
|
|
25
|
+
configuration: [],
|
|
26
|
+
code: "engine = create_engine()",
|
|
27
|
+
hidesWhen: { kind: "dialect", substrings: ["mysql"] },
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
vi.mock("@/hooks/useDataSourceDiscovery", () => ({
|
|
31
|
+
useDetectedDataSources: () => mocks.sources,
|
|
32
|
+
}));
|
|
33
|
+
|
|
34
|
+
vi.mock("../components", async (importOriginal) => ({
|
|
35
|
+
...(await importOriginal<typeof import("../components")>()),
|
|
36
|
+
useAddDetectedDataSource: () => mocks.addDetectedDataSource,
|
|
37
|
+
}));
|
|
38
|
+
|
|
39
|
+
function wrapper({ children }: { children: React.ReactNode }) {
|
|
40
|
+
return (
|
|
41
|
+
<Provider store={store}>
|
|
42
|
+
<TooltipProvider>
|
|
43
|
+
<ModalProvider>{children}</ModalProvider>
|
|
44
|
+
</TooltipProvider>
|
|
45
|
+
</Provider>
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
describe("AddConnectionButton", () => {
|
|
50
|
+
beforeEach(() => {
|
|
51
|
+
mocks.sources = [];
|
|
52
|
+
mocks.addDetectedDataSource.mockClear();
|
|
53
|
+
vi.stubGlobal("PointerEvent", MouseEvent);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
afterEach(() => vi.unstubAllGlobals());
|
|
57
|
+
|
|
58
|
+
it("opens the connection dialog directly without suggestions", () => {
|
|
59
|
+
render(
|
|
60
|
+
<AddConnectionButton
|
|
61
|
+
group="database"
|
|
62
|
+
label="Add database or catalog"
|
|
63
|
+
variant="outline"
|
|
64
|
+
/>,
|
|
65
|
+
{ wrapper },
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
fireEvent.click(
|
|
69
|
+
screen.getByRole("button", { name: "Add database or catalog" }),
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
expect(
|
|
73
|
+
screen.getByRole("dialog", { name: "Add Connection" }),
|
|
74
|
+
).toBeVisible();
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it("opens an ordered suggestion menu when sources are detected", async () => {
|
|
78
|
+
mocks.sources = [MYSQL_SOURCE];
|
|
79
|
+
render(
|
|
80
|
+
<AddConnectionButton
|
|
81
|
+
group="database"
|
|
82
|
+
label="Add database or catalog"
|
|
83
|
+
variant="outline"
|
|
84
|
+
/>,
|
|
85
|
+
{ wrapper },
|
|
86
|
+
);
|
|
87
|
+
|
|
88
|
+
fireEvent.pointerDown(
|
|
89
|
+
screen.getByRole("button", {
|
|
90
|
+
name: "View detected database connections",
|
|
91
|
+
}),
|
|
92
|
+
{ button: 0, ctrlKey: false },
|
|
93
|
+
);
|
|
94
|
+
|
|
95
|
+
const suggestion = await screen.findByRole("menuitem", {
|
|
96
|
+
name: "Add MySQL",
|
|
97
|
+
});
|
|
98
|
+
const browseAll = screen.getByRole("menuitem", {
|
|
99
|
+
name: "Browse all connections",
|
|
100
|
+
});
|
|
101
|
+
expect(
|
|
102
|
+
suggestion.compareDocumentPosition(browseAll) &
|
|
103
|
+
Node.DOCUMENT_POSITION_FOLLOWING,
|
|
104
|
+
).toBeTruthy();
|
|
105
|
+
|
|
106
|
+
fireEvent.click(suggestion);
|
|
107
|
+
expect(mocks.addDetectedDataSource).toHaveBeenCalledWith(MYSQL_SOURCE);
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
it("keeps the primary action direct when sources are detected", () => {
|
|
111
|
+
mocks.sources = [MYSQL_SOURCE];
|
|
112
|
+
render(
|
|
113
|
+
<AddConnectionButton
|
|
114
|
+
group="database"
|
|
115
|
+
label="Add database or catalog"
|
|
116
|
+
variant="outline"
|
|
117
|
+
/>,
|
|
118
|
+
{ wrapper },
|
|
119
|
+
);
|
|
120
|
+
|
|
121
|
+
fireEvent.click(
|
|
122
|
+
screen.getByRole("button", { name: "Add database or catalog" }),
|
|
123
|
+
);
|
|
124
|
+
|
|
125
|
+
expect(
|
|
126
|
+
screen.getByRole("dialog", { name: "Add Connection" }),
|
|
127
|
+
).toBeVisible();
|
|
128
|
+
});
|
|
129
|
+
});
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/* Copyright 2026 Marimo. All rights reserved. */
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
DatabaseIcon,
|
|
5
|
+
HardDriveIcon,
|
|
6
|
+
PlusIcon,
|
|
7
|
+
SparklesIcon,
|
|
8
|
+
} from "lucide-react";
|
|
9
|
+
import type React from "react";
|
|
10
|
+
import { useImperativeModal } from "@/components/modal/ImperativeModal";
|
|
11
|
+
import { Button } from "@/components/ui/button";
|
|
12
|
+
import {
|
|
13
|
+
DropdownMenu,
|
|
14
|
+
DropdownMenuContent,
|
|
15
|
+
DropdownMenuItem,
|
|
16
|
+
DropdownMenuSeparator,
|
|
17
|
+
DropdownMenuTrigger,
|
|
18
|
+
} from "@/components/ui/dropdown-menu";
|
|
19
|
+
import { Tooltip } from "@/components/ui/tooltip";
|
|
20
|
+
import type { DataSourceDiscoveryGroup } from "@/core/datasets/data-source-discovery";
|
|
21
|
+
import { useDetectedDataSources } from "@/hooks/useDataSourceDiscovery";
|
|
22
|
+
import { cn } from "@/utils/cn";
|
|
23
|
+
import {
|
|
24
|
+
AddConnectionDialog,
|
|
25
|
+
AddConnectionDialogContent,
|
|
26
|
+
} from "./add-connection-dialog";
|
|
27
|
+
import { useAddDetectedDataSource } from "./components";
|
|
28
|
+
|
|
29
|
+
type AddConnectionButtonProps = Omit<
|
|
30
|
+
React.ComponentProps<typeof Button>,
|
|
31
|
+
"children"
|
|
32
|
+
> & {
|
|
33
|
+
group: DataSourceDiscoveryGroup;
|
|
34
|
+
label: string;
|
|
35
|
+
compact?: boolean;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Opens the connection dialog directly and, when useful suggestions exist,
|
|
40
|
+
* adds a secondary menu for detected sources.
|
|
41
|
+
*/
|
|
42
|
+
export const AddConnectionButton: React.FC<AddConnectionButtonProps> = ({
|
|
43
|
+
group,
|
|
44
|
+
label,
|
|
45
|
+
compact = false,
|
|
46
|
+
className,
|
|
47
|
+
...buttonProps
|
|
48
|
+
}) => {
|
|
49
|
+
const sources = useDetectedDataSources(group);
|
|
50
|
+
const addDetectedDataSource = useAddDetectedDataSource();
|
|
51
|
+
const { openModal, closeModal } = useImperativeModal();
|
|
52
|
+
const hasSuggestions = sources.length > 0;
|
|
53
|
+
const defaultTab = group === "storage" ? "storage" : "databases";
|
|
54
|
+
|
|
55
|
+
const primaryButton = (
|
|
56
|
+
<Button
|
|
57
|
+
{...buttonProps}
|
|
58
|
+
className={cn(className, hasSuggestions && !compact && "rounded-r-none")}
|
|
59
|
+
aria-label={compact ? label : buttonProps["aria-label"]}
|
|
60
|
+
>
|
|
61
|
+
{!compact && label}
|
|
62
|
+
<PlusIcon className={cn("h-4 w-4", !compact && "ml-2")} />
|
|
63
|
+
</Button>
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
const primaryAction = (
|
|
67
|
+
<AddConnectionDialog defaultTab={defaultTab}>
|
|
68
|
+
{primaryButton}
|
|
69
|
+
</AddConnectionDialog>
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
if (!hasSuggestions) {
|
|
73
|
+
return primaryAction;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const BrowseIcon = group === "storage" ? HardDriveIcon : DatabaseIcon;
|
|
77
|
+
const suggestionsLabel =
|
|
78
|
+
group === "storage"
|
|
79
|
+
? "View detected remote storage connections"
|
|
80
|
+
: "View detected database connections";
|
|
81
|
+
|
|
82
|
+
return (
|
|
83
|
+
<div className="inline-flex">
|
|
84
|
+
{primaryAction}
|
|
85
|
+
<DropdownMenu>
|
|
86
|
+
<Tooltip content={suggestionsLabel}>
|
|
87
|
+
<span className="inline-flex">
|
|
88
|
+
<DropdownMenuTrigger asChild={true}>
|
|
89
|
+
<Button
|
|
90
|
+
variant={buttonProps.variant}
|
|
91
|
+
size={buttonProps.size}
|
|
92
|
+
disabled={buttonProps.disabled}
|
|
93
|
+
className={cn(
|
|
94
|
+
"rounded-l-none border-l-0 px-2 text-(--blue-10) hover:bg-(--blue-3)",
|
|
95
|
+
compact && "rounded-none",
|
|
96
|
+
)}
|
|
97
|
+
aria-label={suggestionsLabel}
|
|
98
|
+
>
|
|
99
|
+
<SparklesIcon className="h-4 w-4" />
|
|
100
|
+
</Button>
|
|
101
|
+
</DropdownMenuTrigger>
|
|
102
|
+
</span>
|
|
103
|
+
</Tooltip>
|
|
104
|
+
<DropdownMenuContent align="end">
|
|
105
|
+
{sources.map((source) => (
|
|
106
|
+
<DropdownMenuItem
|
|
107
|
+
key={source.id}
|
|
108
|
+
onSelect={() => addDetectedDataSource(source)}
|
|
109
|
+
>
|
|
110
|
+
<SparklesIcon className="mr-2 h-4 w-4 text-(--blue-9)" />
|
|
111
|
+
Add {source.displayName}
|
|
112
|
+
</DropdownMenuItem>
|
|
113
|
+
))}
|
|
114
|
+
<DropdownMenuSeparator />
|
|
115
|
+
<DropdownMenuItem
|
|
116
|
+
onSelect={() =>
|
|
117
|
+
openModal(
|
|
118
|
+
<AddConnectionDialogContent
|
|
119
|
+
defaultTab={defaultTab}
|
|
120
|
+
onClose={closeModal}
|
|
121
|
+
/>,
|
|
122
|
+
)
|
|
123
|
+
}
|
|
124
|
+
>
|
|
125
|
+
<BrowseIcon className="mr-2 h-4 w-4" />
|
|
126
|
+
Browse all connections
|
|
127
|
+
</DropdownMenuItem>
|
|
128
|
+
</DropdownMenuContent>
|
|
129
|
+
</DropdownMenu>
|
|
130
|
+
</div>
|
|
131
|
+
);
|
|
132
|
+
};
|
|
@@ -21,6 +21,7 @@ import { maybeAddMarimoImport } from "@/core/cells/add-missing-import";
|
|
|
21
21
|
import { useCellActions } from "@/core/cells/cells";
|
|
22
22
|
import { useLastFocusedCellId } from "@/core/cells/focus";
|
|
23
23
|
import { autoInstantiateAtom } from "@/core/config/config";
|
|
24
|
+
import type { DetectedDataSource } from "@/core/datasets/data-source-discovery";
|
|
24
25
|
import {
|
|
25
26
|
ENV_RENDERER,
|
|
26
27
|
SECRET_TEXTAREA_RENDERER,
|
|
@@ -134,6 +135,16 @@ export function useInsertCode() {
|
|
|
134
135
|
};
|
|
135
136
|
}
|
|
136
137
|
|
|
138
|
+
/** Insert the configured cell supplied by a detected data source. */
|
|
139
|
+
export function useAddDetectedDataSource(onAdd?: () => void) {
|
|
140
|
+
const insertCode = useInsertCode();
|
|
141
|
+
|
|
142
|
+
return (source: DetectedDataSource) => {
|
|
143
|
+
insertCode(source.code);
|
|
144
|
+
onAdd?.();
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
|
|
137
148
|
/**
|
|
138
149
|
* Generic connection form: Zod-driven form with secrets support, a library
|
|
139
150
|
* picker, and Back/Add buttons. Used by both database and storage forms.
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
/* Copyright 2026 Marimo. All rights reserved. */
|
|
2
2
|
|
|
3
3
|
import { PlusIcon, SparklesIcon } from "lucide-react";
|
|
4
|
+
import { useId } from "react";
|
|
4
5
|
import { Tooltip, TooltipProvider } from "@/components/ui/tooltip";
|
|
5
6
|
import type {
|
|
6
7
|
DataSourceDiscoveryGroup,
|
|
7
8
|
DetectedDataSource,
|
|
8
9
|
} from "@/core/datasets/data-source-discovery";
|
|
9
10
|
import { useDetectedDataSources } from "@/hooks/useDataSourceDiscovery";
|
|
10
|
-
import {
|
|
11
|
+
import { useAddDetectedDataSource } from "./components";
|
|
11
12
|
import { cn } from "@/utils/cn";
|
|
12
13
|
|
|
13
14
|
export const QuickAddDataSources: React.FC<{
|
|
@@ -15,22 +16,24 @@ export const QuickAddDataSources: React.FC<{
|
|
|
15
16
|
sources: DetectedDataSource[];
|
|
16
17
|
onAdd: (source: DetectedDataSource) => void;
|
|
17
18
|
}> = ({ className, sources, onAdd }) => {
|
|
19
|
+
const titleId = useId();
|
|
20
|
+
|
|
18
21
|
if (sources.length === 0) {
|
|
19
22
|
return null;
|
|
20
23
|
}
|
|
21
24
|
|
|
22
25
|
return (
|
|
23
26
|
<section
|
|
24
|
-
aria-labelledby=
|
|
27
|
+
aria-labelledby={titleId}
|
|
25
28
|
className={cn(
|
|
26
|
-
"rounded-full bg-[linear-gradient(135deg,var(--blue-2),var(--purple-3))] px-3 py-2",
|
|
29
|
+
"rounded-full bg-[linear-gradient(135deg,var(--blue-2),var(--purple-3))] px-3 py-2 dark:bg-[linear-gradient(135deg,var(--blue-2),var(--purple-2))]",
|
|
27
30
|
className,
|
|
28
31
|
)}
|
|
29
32
|
>
|
|
30
33
|
<div className="flex flex-wrap items-center gap-2">
|
|
31
34
|
<div className="mr-1 flex items-center gap-1.5">
|
|
32
|
-
<SparklesIcon className="h-3.5 w-3.5 text-(--blue-9)" />
|
|
33
|
-
<h3 id=
|
|
35
|
+
<SparklesIcon className="h-3.5 w-3.5 text-(--blue-9) dark:text-(--blue-10)" />
|
|
36
|
+
<h3 id={titleId} className="text-sm">
|
|
34
37
|
Quick add
|
|
35
38
|
</h3>
|
|
36
39
|
</div>
|
|
@@ -44,7 +47,7 @@ export const QuickAddDataSources: React.FC<{
|
|
|
44
47
|
<button
|
|
45
48
|
type="button"
|
|
46
49
|
aria-label={`Add ${source.displayName} connection`}
|
|
47
|
-
className="inline-flex items-center gap-1 rounded-full border border-border/60 bg-background px-2.5 py-1 text-xs font-medium text-foreground/90 transition-colors hover:border-(--blue-7) focus:outline-hidden focus:ring-2 focus:ring-ring focus:ring-offset-2"
|
|
50
|
+
className="inline-flex items-center gap-1 rounded-full border border-border/60 bg-background px-2.5 py-1 text-xs font-medium text-foreground/90 transition-colors hover:border-(--blue-7) focus:outline-hidden focus:ring-2 focus:ring-ring focus:ring-offset-2 dark:border-border dark:bg-background/60 dark:hover:bg-accent/80"
|
|
48
51
|
onClick={() => onAdd(source)}
|
|
49
52
|
>
|
|
50
53
|
<PlusIcon className="h-3 w-3 text-muted-foreground" />
|
|
@@ -101,17 +104,14 @@ export const AutoDiscoveredDataSources: React.FC<{
|
|
|
101
104
|
className?: string;
|
|
102
105
|
group?: DataSourceDiscoveryGroup;
|
|
103
106
|
}> = ({ onSubmit, className, group }) => {
|
|
104
|
-
const
|
|
107
|
+
const addDetectedDataSource = useAddDetectedDataSource(onSubmit);
|
|
105
108
|
const sources = useDetectedDataSources(group);
|
|
106
109
|
|
|
107
110
|
return (
|
|
108
111
|
<QuickAddDataSources
|
|
109
112
|
className={className}
|
|
110
113
|
sources={sources}
|
|
111
|
-
onAdd={
|
|
112
|
-
insertCode(source.code);
|
|
113
|
-
onSubmit?.();
|
|
114
|
-
}}
|
|
114
|
+
onAdd={addDetectedDataSource}
|
|
115
115
|
/>
|
|
116
116
|
);
|
|
117
117
|
};
|