@marimo-team/islands 0.21.2-dev94 → 0.21.2-dev96
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/main.js +3290 -3286
- package/package.json +1 -1
- package/src/components/data-table/TableActions.tsx +1 -8
- package/src/components/data-table/data-table.tsx +0 -2
- package/src/components/data-table/download-actions.tsx +18 -18
- package/src/components/data-table/schemas.ts +7 -2
- package/src/plugins/impl/DataTablePlugin.tsx +0 -4
- package/src/plugins/impl/data-frames/DataFramePlugin.tsx +0 -1
- package/src/stories/dataframe.stories.tsx +1 -1
package/package.json
CHANGED
|
@@ -29,7 +29,6 @@ interface TableActionsProps<TData> {
|
|
|
29
29
|
onRowSelectionChange?: (value: RowSelectionState) => void;
|
|
30
30
|
table: Table<TData>;
|
|
31
31
|
downloadAs?: DownloadActionProps["downloadAs"];
|
|
32
|
-
downloadFileName?: string;
|
|
33
32
|
getRowIds?: GetRowIds;
|
|
34
33
|
toggleDisplayHeader?: () => void;
|
|
35
34
|
showChartBuilder?: boolean;
|
|
@@ -51,7 +50,6 @@ export const TableActions = <TData,>({
|
|
|
51
50
|
onRowSelectionChange,
|
|
52
51
|
table,
|
|
53
52
|
downloadAs,
|
|
54
|
-
downloadFileName,
|
|
55
53
|
getRowIds,
|
|
56
54
|
toggleDisplayHeader,
|
|
57
55
|
showChartBuilder,
|
|
@@ -165,12 +163,7 @@ export const TableActions = <TData,>({
|
|
|
165
163
|
</span>
|
|
166
164
|
)}
|
|
167
165
|
<div className="ml-auto">
|
|
168
|
-
{downloadAs &&
|
|
169
|
-
<DownloadAs
|
|
170
|
-
downloadAs={downloadAs}
|
|
171
|
-
downloadFileName={downloadFileName}
|
|
172
|
-
/>
|
|
173
|
-
)}
|
|
166
|
+
{downloadAs && <DownloadAs downloadAs={downloadAs} />}
|
|
174
167
|
</div>
|
|
175
168
|
</div>
|
|
176
169
|
);
|
|
@@ -127,7 +127,6 @@ const DataTableInternal = <TData,>({
|
|
|
127
127
|
paginationState,
|
|
128
128
|
setPaginationState,
|
|
129
129
|
downloadAs,
|
|
130
|
-
downloadFileName,
|
|
131
130
|
manualPagination = false,
|
|
132
131
|
pagination = false,
|
|
133
132
|
onRowSelectionChange,
|
|
@@ -322,7 +321,6 @@ const DataTableInternal = <TData,>({
|
|
|
322
321
|
onRowSelectionChange={onRowSelectionChange}
|
|
323
322
|
table={table}
|
|
324
323
|
downloadAs={downloadAs}
|
|
325
|
-
downloadFileName={downloadFileName}
|
|
326
324
|
getRowIds={getRowIds}
|
|
327
325
|
toggleDisplayHeader={toggleDisplayHeader}
|
|
328
326
|
showChartBuilder={showChartBuilder}
|
|
@@ -14,7 +14,6 @@ import { logNever } from "@/utils/assertNever";
|
|
|
14
14
|
import { copyToClipboard } from "@/utils/copy";
|
|
15
15
|
import { downloadByURL } from "@/utils/download";
|
|
16
16
|
import { prettyError } from "@/utils/errors";
|
|
17
|
-
import { Filenames } from "@/utils/filenames";
|
|
18
17
|
import {
|
|
19
18
|
jsonParseWithSpecialChar,
|
|
20
19
|
jsonToMarkdown,
|
|
@@ -36,8 +35,9 @@ import { toast } from "../ui/use-toast";
|
|
|
36
35
|
type DownloadFormat = "csv" | "json" | "parquet";
|
|
37
36
|
|
|
38
37
|
export interface DownloadActionProps {
|
|
39
|
-
downloadAs: (req: {
|
|
40
|
-
|
|
38
|
+
downloadAs: (req: {
|
|
39
|
+
format: DownloadFormat;
|
|
40
|
+
}) => Promise<{ url: string; filename: string }>;
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
const options = [
|
|
@@ -99,7 +99,9 @@ export const DownloadAs: React.FC<DownloadActionProps> = (props) => {
|
|
|
99
99
|
</Button>
|
|
100
100
|
);
|
|
101
101
|
|
|
102
|
-
const
|
|
102
|
+
const getDownloadResponse = (
|
|
103
|
+
format: DownloadFormat,
|
|
104
|
+
): Promise<{ url: string; filename: string }> => {
|
|
103
105
|
return props.downloadAs({ format }).catch((error) => {
|
|
104
106
|
toast({
|
|
105
107
|
title: "Failed to download",
|
|
@@ -116,26 +118,26 @@ export const DownloadAs: React.FC<DownloadActionProps> = (props) => {
|
|
|
116
118
|
|
|
117
119
|
switch (format) {
|
|
118
120
|
case "tsv": {
|
|
119
|
-
const
|
|
120
|
-
const json = await fetchJson(
|
|
121
|
+
const { url } = await getDownloadResponse("json");
|
|
122
|
+
const json = await fetchJson(url);
|
|
121
123
|
text = jsonToTSV(json, locale);
|
|
122
124
|
break;
|
|
123
125
|
}
|
|
124
126
|
case "json": {
|
|
125
|
-
const
|
|
126
|
-
const json = await fetchJson(
|
|
127
|
+
const { url } = await getDownloadResponse("json");
|
|
128
|
+
const json = await fetchJson(url);
|
|
127
129
|
text = JSON.stringify(json, null, 2);
|
|
128
130
|
break;
|
|
129
131
|
}
|
|
130
132
|
case "csv": {
|
|
131
|
-
const
|
|
132
|
-
const csv = await fetchText(
|
|
133
|
+
const { url } = await getDownloadResponse("csv");
|
|
134
|
+
const csv = await fetchText(url);
|
|
133
135
|
text = csv;
|
|
134
136
|
break;
|
|
135
137
|
}
|
|
136
138
|
case "markdown": {
|
|
137
|
-
const
|
|
138
|
-
const json = await fetchJson(
|
|
139
|
+
const { url } = await getDownloadResponse("json");
|
|
140
|
+
const json = await fetchJson(url);
|
|
139
141
|
text = jsonToMarkdown(json);
|
|
140
142
|
break;
|
|
141
143
|
}
|
|
@@ -158,12 +160,10 @@ export const DownloadAs: React.FC<DownloadActionProps> = (props) => {
|
|
|
158
160
|
<DropdownMenuItem
|
|
159
161
|
key={option.label}
|
|
160
162
|
onSelect={async () => {
|
|
161
|
-
const
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
Filenames.withoutExtension(rawName) || "download";
|
|
166
|
-
downloadByURL(downloadUrl, `${baseName}.${ext}`);
|
|
163
|
+
const { url, filename } = await getDownloadResponse(
|
|
164
|
+
option.format,
|
|
165
|
+
);
|
|
166
|
+
downloadByURL(url, filename);
|
|
167
167
|
}}
|
|
168
168
|
>
|
|
169
169
|
<option.icon className="mo-dropdown-icon" />
|
|
@@ -5,7 +5,7 @@ import { rpc } from "@/plugins/core/rpc";
|
|
|
5
5
|
|
|
6
6
|
export type DownloadAsArgs = (req: {
|
|
7
7
|
format: "csv" | "json" | "parquet";
|
|
8
|
-
}) => Promise<string>;
|
|
8
|
+
}) => Promise<{ url: string; filename: string }>;
|
|
9
9
|
|
|
10
10
|
export const DownloadAsSchema = rpc
|
|
11
11
|
.input(
|
|
@@ -13,4 +13,9 @@ export const DownloadAsSchema = rpc
|
|
|
13
13
|
format: z.enum(["csv", "json", "parquet"]),
|
|
14
14
|
}),
|
|
15
15
|
)
|
|
16
|
-
.output(
|
|
16
|
+
.output(
|
|
17
|
+
z.object({
|
|
18
|
+
url: z.string(),
|
|
19
|
+
filename: z.string(),
|
|
20
|
+
}),
|
|
21
|
+
);
|
|
@@ -200,7 +200,6 @@ interface Data<T> {
|
|
|
200
200
|
hasStableRowId: boolean;
|
|
201
201
|
lazy: boolean;
|
|
202
202
|
cellHoverTexts?: Record<string, Record<string, string | null>> | null;
|
|
203
|
-
downloadFileName?: string;
|
|
204
203
|
}
|
|
205
204
|
|
|
206
205
|
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
|
|
@@ -286,7 +285,6 @@ export const DataTablePlugin = createPlugin<S>("marimo-table")
|
|
|
286
285
|
// If lazy, this will preload the first page of data
|
|
287
286
|
// without user confirmation.
|
|
288
287
|
preload: z.boolean().default(false),
|
|
289
|
-
downloadFileName: z.string().optional(),
|
|
290
288
|
}),
|
|
291
289
|
)
|
|
292
290
|
.withFunctions<DataTableFunctions>({
|
|
@@ -822,7 +820,6 @@ const DataTableComponent = ({
|
|
|
822
820
|
cellStyles,
|
|
823
821
|
hoverTemplate,
|
|
824
822
|
cellHoverTexts,
|
|
825
|
-
downloadFileName,
|
|
826
823
|
toggleDisplayHeader,
|
|
827
824
|
calculate_top_k_rows,
|
|
828
825
|
preview_column,
|
|
@@ -1077,7 +1074,6 @@ const DataTableComponent = ({
|
|
|
1077
1074
|
hoverTemplate={hoverTemplate}
|
|
1078
1075
|
cellHoverTexts={cellHoverTexts}
|
|
1079
1076
|
downloadAs={showDownload ? downloadAs : undefined}
|
|
1080
|
-
downloadFileName={downloadFileName}
|
|
1081
1077
|
enableSearch={enableSearch}
|
|
1082
1078
|
searchQuery={searchQuery}
|
|
1083
1079
|
onSearchQueryChange={setSearchQuery}
|
|
@@ -329,7 +329,6 @@ export const DataFrameComponent = memo(
|
|
|
329
329
|
fieldTypes={field_types}
|
|
330
330
|
rowHeaders={row_headers || Arrays.EMPTY}
|
|
331
331
|
showDownload={showDownload}
|
|
332
|
-
downloadFileName={dataframeName}
|
|
333
332
|
download_as={download_as}
|
|
334
333
|
enableSearch={false}
|
|
335
334
|
showFilters={false}
|