@marimo-team/islands 0.23.10-dev13 → 0.23.10-dev15
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/{chat-ui-BD7DNRSw.js → chat-ui-C7ZYD6Uw.js} +2 -2
- package/dist/{code-visibility-Db0yh3sI.js → code-visibility-QvdSqBSm.js} +2 -2
- package/dist/{html-to-image-DU8Qw0nX.js → html-to-image-BqJ4c852.js} +4 -2
- package/dist/main.js +5 -5
- package/dist/{process-output-Bxz3AalF.js → process-output-DzDBuKrN.js} +1 -1
- package/dist/{reveal-component-CrJz4IhC.js → reveal-component-qiH93aYL.js} +2 -2
- package/dist/style.css +1 -1
- package/package.json +1 -1
- package/src/components/datasources/__tests__/filter-empty.test.ts +183 -0
- package/src/components/datasources/datasources.tsx +107 -3
- package/src/components/editor/documentation.css +16 -0
- package/src/core/datasets/data-source-connections.ts +2 -0
package/package.json
CHANGED
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
/* Copyright 2026 Marimo. All rights reserved. */
|
|
2
|
+
|
|
3
|
+
import { describe, expect, it } from "vitest";
|
|
4
|
+
import type {
|
|
5
|
+
Database,
|
|
6
|
+
DatabaseSchema,
|
|
7
|
+
DataTable,
|
|
8
|
+
} from "@/core/kernel/messages";
|
|
9
|
+
import { filterEmptyDatabases } from "../datasources";
|
|
10
|
+
|
|
11
|
+
function makeTable(name: string): DataTable {
|
|
12
|
+
return {
|
|
13
|
+
name,
|
|
14
|
+
columns: [],
|
|
15
|
+
source: "memory",
|
|
16
|
+
source_type: "local",
|
|
17
|
+
type: "table",
|
|
18
|
+
engine: null,
|
|
19
|
+
indexes: null,
|
|
20
|
+
num_columns: null,
|
|
21
|
+
num_rows: null,
|
|
22
|
+
variable_name: null,
|
|
23
|
+
primary_keys: null,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function makeSchema(opts: {
|
|
28
|
+
name: string;
|
|
29
|
+
tables: DataTable[];
|
|
30
|
+
tables_resolved?: boolean;
|
|
31
|
+
}): DatabaseSchema {
|
|
32
|
+
return {
|
|
33
|
+
name: opts.name,
|
|
34
|
+
tables: opts.tables,
|
|
35
|
+
tables_resolved: opts.tables_resolved ?? true,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function makeDatabase(
|
|
40
|
+
name: string,
|
|
41
|
+
schemas: DatabaseSchema[],
|
|
42
|
+
schemas_resolved = true,
|
|
43
|
+
): Database {
|
|
44
|
+
return {
|
|
45
|
+
name,
|
|
46
|
+
dialect: "duckdb",
|
|
47
|
+
schemas,
|
|
48
|
+
schemas_resolved,
|
|
49
|
+
engine: null,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
describe("filterEmptyDatabases", () => {
|
|
54
|
+
it("hides schemas whose tables are resolved and empty", () => {
|
|
55
|
+
const databases = [
|
|
56
|
+
makeDatabase("memory", [
|
|
57
|
+
makeSchema({ name: "main", tables: [makeTable("t1")] }),
|
|
58
|
+
makeSchema({ name: "empty_schema", tables: [] }),
|
|
59
|
+
]),
|
|
60
|
+
];
|
|
61
|
+
|
|
62
|
+
expect(filterEmptyDatabases(databases)).toEqual([
|
|
63
|
+
makeDatabase("memory", [
|
|
64
|
+
makeSchema({ name: "main", tables: [makeTable("t1")] }),
|
|
65
|
+
]),
|
|
66
|
+
]);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it("preserves databases whose schemas have not been resolved yet (lazy state)", () => {
|
|
70
|
+
const databases = [
|
|
71
|
+
makeDatabase("not_loaded_yet", [], /* schemas_resolved */ false),
|
|
72
|
+
];
|
|
73
|
+
|
|
74
|
+
expect(filterEmptyDatabases(databases)).toEqual([
|
|
75
|
+
makeDatabase("not_loaded_yet", [], false),
|
|
76
|
+
]);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it("hides databases that have been resolved as empty", () => {
|
|
80
|
+
const databases = [
|
|
81
|
+
makeDatabase("really_empty", [], /* schemas_resolved */ true),
|
|
82
|
+
makeDatabase("has_tables", [
|
|
83
|
+
makeSchema({ name: "main", tables: [makeTable("t1")] }),
|
|
84
|
+
]),
|
|
85
|
+
];
|
|
86
|
+
|
|
87
|
+
expect(filterEmptyDatabases(databases)).toEqual([
|
|
88
|
+
makeDatabase("has_tables", [
|
|
89
|
+
makeSchema({ name: "main", tables: [makeTable("t1")] }),
|
|
90
|
+
]),
|
|
91
|
+
]);
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
it("hides databases whose schemas all filtered to empty", () => {
|
|
95
|
+
const databases = [
|
|
96
|
+
makeDatabase("only_empty", [
|
|
97
|
+
makeSchema({ name: "a", tables: [] }),
|
|
98
|
+
makeSchema({ name: "b", tables: [] }),
|
|
99
|
+
]),
|
|
100
|
+
makeDatabase("has_tables", [
|
|
101
|
+
makeSchema({ name: "main", tables: [makeTable("t1")] }),
|
|
102
|
+
]),
|
|
103
|
+
];
|
|
104
|
+
|
|
105
|
+
expect(filterEmptyDatabases(databases)).toEqual([
|
|
106
|
+
makeDatabase("has_tables", [
|
|
107
|
+
makeSchema({ name: "main", tables: [makeTable("t1")] }),
|
|
108
|
+
]),
|
|
109
|
+
]);
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
it("treats missing schemas_resolved as resolved (backward compatible)", () => {
|
|
113
|
+
const databases = [
|
|
114
|
+
{ name: "memory", dialect: "duckdb", schemas: [], engine: null },
|
|
115
|
+
] as Database[];
|
|
116
|
+
|
|
117
|
+
expect(filterEmptyDatabases(databases)).toEqual([]);
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it("preserves schemas whose tables have not been resolved yet", () => {
|
|
121
|
+
const databases = [
|
|
122
|
+
makeDatabase("snowflake_db", [
|
|
123
|
+
// include_tables=False was used; the schema is not actually empty,
|
|
124
|
+
// tables will be fetched lazily on expand.
|
|
125
|
+
makeSchema({ name: "public", tables: [], tables_resolved: false }),
|
|
126
|
+
makeSchema({ name: "audit", tables: [], tables_resolved: false }),
|
|
127
|
+
makeSchema({
|
|
128
|
+
name: "really_empty",
|
|
129
|
+
tables: [],
|
|
130
|
+
tables_resolved: true,
|
|
131
|
+
}),
|
|
132
|
+
]),
|
|
133
|
+
];
|
|
134
|
+
|
|
135
|
+
expect(filterEmptyDatabases(databases)).toEqual([
|
|
136
|
+
makeDatabase("snowflake_db", [
|
|
137
|
+
makeSchema({ name: "public", tables: [], tables_resolved: false }),
|
|
138
|
+
makeSchema({ name: "audit", tables: [], tables_resolved: false }),
|
|
139
|
+
]),
|
|
140
|
+
]);
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
it("treats missing tables_resolved as resolved (backward compatible)", () => {
|
|
144
|
+
// Older payloads predating the new flag may omit it; default semantics
|
|
145
|
+
// treat the schema as resolved/authoritative.
|
|
146
|
+
const databases = [
|
|
147
|
+
makeDatabase("memory", [
|
|
148
|
+
{ name: "main", tables: [makeTable("t1")] },
|
|
149
|
+
{ name: "empty_schema", tables: [] },
|
|
150
|
+
] as DatabaseSchema[]),
|
|
151
|
+
];
|
|
152
|
+
|
|
153
|
+
expect(filterEmptyDatabases(databases)).toEqual([
|
|
154
|
+
makeDatabase("memory", [
|
|
155
|
+
{ name: "main", tables: [makeTable("t1")] },
|
|
156
|
+
] as DatabaseSchema[]),
|
|
157
|
+
]);
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
it("returns the same reference when nothing was filtered", () => {
|
|
161
|
+
const databases = [
|
|
162
|
+
makeDatabase("memory", [
|
|
163
|
+
makeSchema({ name: "main", tables: [makeTable("t1")] }),
|
|
164
|
+
]),
|
|
165
|
+
];
|
|
166
|
+
|
|
167
|
+
expect(filterEmptyDatabases(databases)).toBe(databases);
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
it("does not mutate the input", () => {
|
|
171
|
+
const databases = [
|
|
172
|
+
makeDatabase("memory", [
|
|
173
|
+
makeSchema({ name: "main", tables: [makeTable("t1")] }),
|
|
174
|
+
makeSchema({ name: "empty_schema", tables: [] }),
|
|
175
|
+
]),
|
|
176
|
+
];
|
|
177
|
+
const snapshot = JSON.parse(JSON.stringify(databases));
|
|
178
|
+
|
|
179
|
+
filterEmptyDatabases(databases);
|
|
180
|
+
|
|
181
|
+
expect(databases).toEqual(snapshot);
|
|
182
|
+
});
|
|
183
|
+
});
|
|
@@ -1,8 +1,15 @@
|
|
|
1
1
|
/* Copyright 2026 Marimo. All rights reserved. */
|
|
2
2
|
|
|
3
3
|
import { CommandList } from "cmdk";
|
|
4
|
-
import { atom, useAtomValue, useSetAtom } from "jotai";
|
|
5
|
-
import {
|
|
4
|
+
import { atom, useAtom, useAtomValue, useSetAtom } from "jotai";
|
|
5
|
+
import { atomWithStorage } from "jotai/utils";
|
|
6
|
+
import {
|
|
7
|
+
EyeIcon,
|
|
8
|
+
EyeOffIcon,
|
|
9
|
+
PlusIcon,
|
|
10
|
+
PlusSquareIcon,
|
|
11
|
+
XIcon,
|
|
12
|
+
} from "lucide-react";
|
|
6
13
|
import React from "react";
|
|
7
14
|
import { dbDisplayName } from "@/components/databases/display";
|
|
8
15
|
import { EngineVariable } from "@/components/databases/engine-variable";
|
|
@@ -52,6 +59,7 @@ import { sortBy } from "@/utils/arrays";
|
|
|
52
59
|
import { logNever } from "@/utils/assertNever";
|
|
53
60
|
import { cn } from "@/utils/cn";
|
|
54
61
|
import { Events } from "@/utils/events";
|
|
62
|
+
import { jotaiJsonStorage } from "@/utils/storage/jotai";
|
|
55
63
|
import {
|
|
56
64
|
DatabaseIcon,
|
|
57
65
|
SchemaIcon,
|
|
@@ -116,6 +124,63 @@ const sortedTablesAtom = atom((get) => {
|
|
|
116
124
|
});
|
|
117
125
|
});
|
|
118
126
|
|
|
127
|
+
/**
|
|
128
|
+
* Whether to hide empty schemas and databases (those with no tables) in the
|
|
129
|
+
* datasources panel.
|
|
130
|
+
*/
|
|
131
|
+
export const hideEmptyDatasourcesAtom = atomWithStorage<boolean>(
|
|
132
|
+
"marimo:datasources:hideEmpty",
|
|
133
|
+
false,
|
|
134
|
+
jotaiJsonStorage,
|
|
135
|
+
{ getOnInit: true },
|
|
136
|
+
);
|
|
137
|
+
|
|
138
|
+
function isKnownEmptySchema(schema: DatabaseSchema): boolean {
|
|
139
|
+
return schema.tables_resolved !== false && schema.tables.length === 0;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Apply the "hide empty" filter to a connection's databases.
|
|
144
|
+
*
|
|
145
|
+
* - Schemas with confirmed-empty table lists are hidden.
|
|
146
|
+
* - Databases are hidden when either (a) their schemas have been enumerated
|
|
147
|
+
* and the list is empty, or (b) every schema in them was hidden by the
|
|
148
|
+
* schema-level filter.
|
|
149
|
+
* - Databases / schemas whose contents haven't been resolved yet (deferred
|
|
150
|
+
* discovery — `schemas_resolved === false` or `tables_resolved === false`)
|
|
151
|
+
* are preserved so the user can expand them to trigger a fetch.
|
|
152
|
+
*/
|
|
153
|
+
export function filterEmptyDatabases(databases: Database[]): Database[] {
|
|
154
|
+
let changed = false;
|
|
155
|
+
const result: Database[] = [];
|
|
156
|
+
for (const database of databases) {
|
|
157
|
+
// Known-empty database: schema list was enumerated and is empty.
|
|
158
|
+
if (database.schemas_resolved !== false && database.schemas.length === 0) {
|
|
159
|
+
changed = true;
|
|
160
|
+
continue;
|
|
161
|
+
}
|
|
162
|
+
// Deferred schema discovery — keep so the user can expand and load.
|
|
163
|
+
if (database.schemas.length === 0) {
|
|
164
|
+
result.push(database);
|
|
165
|
+
continue;
|
|
166
|
+
}
|
|
167
|
+
const visibleSchemas = database.schemas.filter(
|
|
168
|
+
(schema) => !isKnownEmptySchema(schema),
|
|
169
|
+
);
|
|
170
|
+
if (visibleSchemas.length === 0) {
|
|
171
|
+
changed = true;
|
|
172
|
+
continue;
|
|
173
|
+
}
|
|
174
|
+
if (visibleSchemas.length === database.schemas.length) {
|
|
175
|
+
result.push(database);
|
|
176
|
+
continue;
|
|
177
|
+
}
|
|
178
|
+
changed = true;
|
|
179
|
+
result.push({ ...database, schemas: visibleSchemas });
|
|
180
|
+
}
|
|
181
|
+
return changed ? result : databases;
|
|
182
|
+
}
|
|
183
|
+
|
|
119
184
|
/**
|
|
120
185
|
* This atom is used to get the data connections that are available to the user.
|
|
121
186
|
* It filters out the internal engines if it has no databases or if it has only the in-memory database and no schemas.
|
|
@@ -152,10 +217,27 @@ export const connectionsAtom = atom((get) => {
|
|
|
152
217
|
|
|
153
218
|
export const DataSources: React.FC = () => {
|
|
154
219
|
const [searchValue, setSearchValue] = React.useState<string>("");
|
|
220
|
+
const [hideEmpty, setHideEmpty] = useAtom(hideEmptyDatasourcesAtom);
|
|
155
221
|
|
|
156
222
|
const closeAllColumns = useSetAtom(closeAllColumnsAtom);
|
|
157
223
|
const tables = useAtomValue(sortedTablesAtom);
|
|
158
|
-
const
|
|
224
|
+
const rawConnections = useAtomValue(connectionsAtom);
|
|
225
|
+
|
|
226
|
+
const dataConnections = React.useMemo(() => {
|
|
227
|
+
if (!hideEmpty) {
|
|
228
|
+
return rawConnections;
|
|
229
|
+
}
|
|
230
|
+
let changed = false;
|
|
231
|
+
const filtered = rawConnections.map((connection) => {
|
|
232
|
+
const databases = filterEmptyDatabases(connection.databases);
|
|
233
|
+
if (databases === connection.databases) {
|
|
234
|
+
return connection;
|
|
235
|
+
}
|
|
236
|
+
changed = true;
|
|
237
|
+
return { ...connection, databases };
|
|
238
|
+
});
|
|
239
|
+
return changed ? filtered : rawConnections;
|
|
240
|
+
}, [rawConnections, hideEmpty]);
|
|
159
241
|
|
|
160
242
|
if (tables.length === 0 && dataConnections.length === 0) {
|
|
161
243
|
return (
|
|
@@ -204,6 +286,28 @@ export const DataSources: React.FC = () => {
|
|
|
204
286
|
</button>
|
|
205
287
|
)}
|
|
206
288
|
|
|
289
|
+
<Tooltip
|
|
290
|
+
content={
|
|
291
|
+
hideEmpty
|
|
292
|
+
? "Show empty schemas and databases"
|
|
293
|
+
: "Hide empty schemas and databases"
|
|
294
|
+
}
|
|
295
|
+
>
|
|
296
|
+
<Button
|
|
297
|
+
data-testid="datasources-hide-empty-button"
|
|
298
|
+
variant="ghost"
|
|
299
|
+
size="sm"
|
|
300
|
+
className="px-2 rounded-none focus-visible:outline-hidden"
|
|
301
|
+
onClick={() => setHideEmpty(!hideEmpty)}
|
|
302
|
+
>
|
|
303
|
+
{hideEmpty ? (
|
|
304
|
+
<EyeOffIcon className="h-4 w-4" />
|
|
305
|
+
) : (
|
|
306
|
+
<EyeIcon className="h-4 w-4" />
|
|
307
|
+
)}
|
|
308
|
+
</Button>
|
|
309
|
+
</Tooltip>
|
|
310
|
+
|
|
207
311
|
<AddConnectionDialog>
|
|
208
312
|
<Button
|
|
209
313
|
variant="ghost"
|
|
@@ -51,6 +51,22 @@
|
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
+
a {
|
|
55
|
+
cursor: pointer;
|
|
56
|
+
text-decoration: inherit;
|
|
57
|
+
|
|
58
|
+
@apply text-link;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
a:hover,
|
|
62
|
+
a:active {
|
|
63
|
+
text-decoration: underline;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
a:visited {
|
|
67
|
+
@apply text-link-visited;
|
|
68
|
+
}
|
|
69
|
+
|
|
54
70
|
code {
|
|
55
71
|
@apply border px-1 rounded font-mono bg-[var(--slate-2)] text-sm mb-4 mt-2;
|
|
56
72
|
}
|
|
@@ -169,6 +169,7 @@ const {
|
|
|
169
169
|
return {
|
|
170
170
|
...db,
|
|
171
171
|
schemas: schemas,
|
|
172
|
+
schemas_resolved: true,
|
|
172
173
|
};
|
|
173
174
|
}),
|
|
174
175
|
};
|
|
@@ -213,6 +214,7 @@ const {
|
|
|
213
214
|
return {
|
|
214
215
|
...schema,
|
|
215
216
|
tables: tables,
|
|
217
|
+
tables_resolved: true,
|
|
216
218
|
};
|
|
217
219
|
}),
|
|
218
220
|
};
|