@marimo-team/islands 0.23.9-dev34 → 0.23.9-dev37
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-MJy-Ll40.js → ConnectedDataExplorerComponent-BQBH2XAd.js} +4 -4
- package/dist/assets/__vite-browser-external-TaZstNaH.js +1 -0
- package/dist/assets/{worker-BoAkAmaG.js → worker-CZaLU0G8.js} +2 -2
- package/dist/{chat-ui-CpX2YcGy.js → chat-ui-BQqY0W74.js} +60 -60
- package/dist/{code-visibility-y3APpJ-N.js → code-visibility-CHwUF5vX.js} +675 -556
- package/dist/{formats-BIKFEOlR.js → formats-B7_JC7Ba.js} +1 -1
- package/dist/{glide-data-editor-DjQd6fKp.js → glide-data-editor-BmM4MCbn.js} +2 -2
- package/dist/{html-to-image-QL7QveRm.js → html-to-image-BAPmFVwS.js} +2139 -2152
- package/dist/{input-Dh0iMVFM.js → input-Ld3tUgdF.js} +1 -1
- package/dist/main.js +110 -109
- package/dist/{mermaid-CAibas-0.js → mermaid-BrUZ2PpQ.js} +2 -2
- package/dist/{process-output-C657UH7t.js → process-output-B55jxGI5.js} +1 -1
- package/dist/{reveal-component-Cbw9hzrS.js → reveal-component-DQF8h6lC.js} +5 -5
- package/dist/{spec-BKuFJIDz.js → spec-nqxKYdNH.js} +1 -1
- package/dist/{toDate-BeKbrOvs.js → toDate-DLCQY32Y.js} +1 -1
- package/dist/{useAsyncData-yp6n17kh.js → useAsyncData-3f5sSgzf.js} +1 -1
- package/dist/{useDeepCompareMemoize-DJvAHUIC.js → useDeepCompareMemoize-Cu37j2QD.js} +1 -1
- package/dist/{useLifecycle-CsYXf0Ln.js → useLifecycle-DVkMZA_I.js} +1 -1
- package/dist/{useTheme-CK_R9Mn8.js → useTheme-DNcgchnA.js} +11 -2
- package/dist/{vega-component-ikfBfkZO.js → vega-component-7odw1pLZ.js} +5 -5
- package/package.json +1 -1
- package/src/components/app-config/ai-config.tsx +74 -15
- package/src/components/chat/chat-panel.tsx +2 -2
- package/src/components/data-table/__tests__/header-items.test.tsx +220 -10
- package/src/components/data-table/column-header.tsx +17 -12
- package/src/components/data-table/export-actions.tsx +19 -12
- package/src/components/data-table/header-items.tsx +40 -16
- package/src/components/data-table/schemas.ts +2 -2
- package/src/components/editor/actions/useCellActionButton.tsx +3 -3
- package/src/components/editor/cell/code/cell-editor.tsx +7 -4
- package/src/components/editor/chrome/types.ts +13 -6
- package/src/components/editor/chrome/wrapper/app-chrome.tsx +6 -4
- package/src/components/editor/chrome/wrapper/footer-items/ai-status.tsx +10 -1
- package/src/components/editor/chrome/wrapper/sidebar.tsx +7 -5
- package/src/components/editor/errors/auto-fix.tsx +3 -3
- package/src/components/editor/navigation/__tests__/navigation.test.ts +15 -0
- package/src/components/editor/navigation/navigation.ts +5 -0
- package/src/components/editor/output/MarimoTracebackOutput.tsx +4 -3
- package/src/components/editor/renderers/cell-array.tsx +27 -24
- package/src/core/config/__tests__/config-schema.test.ts +2 -0
- package/src/core/config/config-schema.ts +1 -0
- package/src/core/config/config.ts +16 -0
- package/src/utils/__tests__/json-parser.test.ts +1 -69
- package/src/utils/json/json-parser.ts +0 -30
- package/dist/assets/__vite-browser-external-BBEFRPue.js +0 -1
|
@@ -606,6 +606,7 @@ const UserConfigSchema = looseObject({
|
|
|
606
606
|
}).prefault({}),
|
|
607
607
|
package_management: looseObject({ manager: _enum(PackageManagerNames).prefault("pip") }).prefault({}),
|
|
608
608
|
ai: looseObject({
|
|
609
|
+
enabled: boolean().prefault(true),
|
|
609
610
|
rules: string().prefault(""),
|
|
610
611
|
max_tokens: number().int().positive().nullable().optional(),
|
|
611
612
|
mode: _enum(COPILOT_MODES).prefault("manual"),
|
|
@@ -706,13 +707,21 @@ function useResolvedMarimoConfig() {
|
|
|
706
707
|
function getResolvedMarimoConfig() {
|
|
707
708
|
return store.get(resolvedMarimoConfigAtom);
|
|
708
709
|
}
|
|
709
|
-
|
|
710
|
+
atom((e) => isAiEnabled(e(resolvedMarimoConfigAtom))), atom((e) => isAiModelConfigured(e(resolvedMarimoConfigAtom)));
|
|
711
|
+
const aiFeaturesEnabledAtom = atom((e) => isAiFeatureEnabled(e(resolvedMarimoConfigAtom)));
|
|
710
712
|
atom((e) => e(resolvedMarimoConfigAtom).display.code_editor_font_size);
|
|
711
713
|
const localeAtom = atom((e) => e(resolvedMarimoConfigAtom).display.locale);
|
|
712
714
|
function isAiEnabled(e) {
|
|
715
|
+
var _a;
|
|
716
|
+
return ((_a = e.ai) == null ? void 0 : _a.enabled) !== false;
|
|
717
|
+
}
|
|
718
|
+
function isAiModelConfigured(e) {
|
|
713
719
|
var _a, _b, _c, _d, _e, _f;
|
|
714
720
|
return !!((_b = (_a = e.ai) == null ? void 0 : _a.models) == null ? void 0 : _b.chat_model) || !!((_d = (_c = e.ai) == null ? void 0 : _c.models) == null ? void 0 : _d.edit_model) || !!((_f = (_e = e.ai) == null ? void 0 : _e.models) == null ? void 0 : _f.autocomplete_model);
|
|
715
721
|
}
|
|
722
|
+
function isAiFeatureEnabled(e) {
|
|
723
|
+
return isAiEnabled(e) && isAiModelConfigured(e);
|
|
724
|
+
}
|
|
716
725
|
const appConfigAtom = atom(parseAppConfig({}));
|
|
717
726
|
atom((e) => e(appConfigAtom).width), atom((e) => {
|
|
718
727
|
var _a, _b;
|
|
@@ -796,7 +805,7 @@ export {
|
|
|
796
805
|
useTheme as n,
|
|
797
806
|
localeAtom as o,
|
|
798
807
|
waitFor as p,
|
|
799
|
-
|
|
808
|
+
aiFeaturesEnabledAtom as r,
|
|
800
809
|
resolvedMarimoConfigAtom as s,
|
|
801
810
|
resolvedThemeAtom as t,
|
|
802
811
|
createDeepEqualAtom as u,
|
|
@@ -2,23 +2,23 @@ import { s as __toESM } from "./chunk-BNovOVIE.js";
|
|
|
2
2
|
import { _ as Logger, c as Objects, g as cn, h as Events } from "./button-C5K9fIPF.js";
|
|
3
3
|
import { t as require_react } from "./react-DA-nE2FX.js";
|
|
4
4
|
import { t as require_compiler_runtime } from "./compiler-runtime-CEbnTgxf.js";
|
|
5
|
-
import { c as asRemoteURL, v as CircleQuestionMark } from "./toDate-
|
|
5
|
+
import { c as asRemoteURL, v as CircleQuestionMark } from "./toDate-DLCQY32Y.js";
|
|
6
6
|
import "./react-dom-BTJzcVJ9.js";
|
|
7
7
|
import { t as require_jsx_runtime } from "./jsx-runtime-DebpN0FN.js";
|
|
8
8
|
import "./zod-CoBiJ5v4.js";
|
|
9
9
|
import { n as ErrorBanner } from "./error-banner-5bz0L9hS.js";
|
|
10
10
|
import { t as Tooltip } from "./tooltip-C5FYOpQc.js";
|
|
11
11
|
import { i as debounce_default } from "./constants-T20xxyNf.js";
|
|
12
|
-
import { T as useEvent_default, n as useTheme } from "./useTheme-
|
|
12
|
+
import { T as useEvent_default, n as useTheme } from "./useTheme-DNcgchnA.js";
|
|
13
13
|
import { s as uniq } from "./arrays-sEtDRoG4.js";
|
|
14
|
-
import { a as isValid, i as AlertTitle, n as Alert, t as arrow } from "./formats-
|
|
14
|
+
import { a as isValid, i as AlertTitle, n as Alert, t as arrow } from "./formats-B7_JC7Ba.js";
|
|
15
15
|
import { n as formats } from "./vega-loader.browser-CZ-J8Py3.js";
|
|
16
16
|
import { a as getContainerWidth, n as vegaLoadData, s as tooltipHandler } from "./loader-BWLPpjKK.js";
|
|
17
17
|
import { t as j } from "./react-vega-B0sAlDTL.js";
|
|
18
18
|
import "./defaultLocale-u-3osm0P.js";
|
|
19
19
|
import "./defaultLocale-BoHTsDG6.js";
|
|
20
|
-
import { t as useAsyncData } from "./useAsyncData-
|
|
21
|
-
import { t as useDeepCompareMemoize } from "./useDeepCompareMemoize-
|
|
20
|
+
import { t as useAsyncData } from "./useAsyncData-3f5sSgzf.js";
|
|
21
|
+
import { t as useDeepCompareMemoize } from "./useDeepCompareMemoize-Cu37j2QD.js";
|
|
22
22
|
import { t as Semaphore } from "./semaphore-CNDGTzkX.js";
|
|
23
23
|
var import_compiler_runtime = require_compiler_runtime(), import_react = /* @__PURE__ */ __toESM(require_react(), 1);
|
|
24
24
|
function fixRelativeUrl(e) {
|
package/package.json
CHANGED
|
@@ -1849,6 +1849,38 @@ export type AiSettingsSubTab =
|
|
|
1849
1849
|
| "ai-models"
|
|
1850
1850
|
| "mcp";
|
|
1851
1851
|
|
|
1852
|
+
const AiEnabledConfig: React.FC<AiConfigProps> = ({ form, config }) => {
|
|
1853
|
+
return (
|
|
1854
|
+
<SettingGroup>
|
|
1855
|
+
<FormField
|
|
1856
|
+
control={form.control}
|
|
1857
|
+
name="ai.enabled"
|
|
1858
|
+
render={({ field }) => (
|
|
1859
|
+
<div className="flex flex-col gap-y-1">
|
|
1860
|
+
<FormItem className={formItemClasses}>
|
|
1861
|
+
<FormLabel className="font-normal">Enable AI features</FormLabel>
|
|
1862
|
+
<FormControl>
|
|
1863
|
+
<Checkbox
|
|
1864
|
+
data-testid="ai-enabled-checkbox"
|
|
1865
|
+
checked={field.value !== false}
|
|
1866
|
+
onCheckedChange={(checked) =>
|
|
1867
|
+
field.onChange(checked === true)
|
|
1868
|
+
}
|
|
1869
|
+
/>
|
|
1870
|
+
</FormControl>
|
|
1871
|
+
<IsOverridden userConfig={config} name="ai.enabled" />
|
|
1872
|
+
</FormItem>
|
|
1873
|
+
<FormDescription>
|
|
1874
|
+
When disabled, AI actions and panels are hidden from the marimo
|
|
1875
|
+
UI.
|
|
1876
|
+
</FormDescription>
|
|
1877
|
+
</div>
|
|
1878
|
+
)}
|
|
1879
|
+
/>
|
|
1880
|
+
</SettingGroup>
|
|
1881
|
+
);
|
|
1882
|
+
};
|
|
1883
|
+
|
|
1852
1884
|
export const AiConfig: React.FC<AiConfigProps> = ({
|
|
1853
1885
|
form,
|
|
1854
1886
|
config,
|
|
@@ -1857,18 +1889,30 @@ export const AiConfig: React.FC<AiConfigProps> = ({
|
|
|
1857
1889
|
// MCP is not supported in WASM
|
|
1858
1890
|
const wasm = isWasm();
|
|
1859
1891
|
const [activeTab, setActiveTab] = useAtom(aiSettingsSubTabAtom);
|
|
1892
|
+
const aiEnabled = useWatch({
|
|
1893
|
+
control: form.control,
|
|
1894
|
+
name: "ai.enabled",
|
|
1895
|
+
});
|
|
1896
|
+
const activeVisibleTab =
|
|
1897
|
+
aiEnabled === false && activeTab !== "ai-features"
|
|
1898
|
+
? "ai-features"
|
|
1899
|
+
: activeTab;
|
|
1860
1900
|
|
|
1861
1901
|
return (
|
|
1862
1902
|
<Tabs
|
|
1863
|
-
value={
|
|
1903
|
+
value={activeVisibleTab}
|
|
1864
1904
|
onValueChange={(value) => setActiveTab(value as AiSettingsSubTab)}
|
|
1865
1905
|
className="flex-1"
|
|
1866
1906
|
>
|
|
1867
1907
|
<TabsList className="mb-2">
|
|
1868
1908
|
<TabsTrigger value="ai-features">AI Features</TabsTrigger>
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1909
|
+
{aiEnabled !== false && (
|
|
1910
|
+
<>
|
|
1911
|
+
<TabsTrigger value="ai-providers">AI Providers</TabsTrigger>
|
|
1912
|
+
<TabsTrigger value="ai-models">AI Models</TabsTrigger>
|
|
1913
|
+
{!wasm && <TabsTrigger value="mcp">MCP</TabsTrigger>}
|
|
1914
|
+
</>
|
|
1915
|
+
)}
|
|
1872
1916
|
</TabsList>
|
|
1873
1917
|
|
|
1874
1918
|
<TabsContent value="ai-features">
|
|
@@ -1877,18 +1921,33 @@ export const AiConfig: React.FC<AiConfigProps> = ({
|
|
|
1877
1921
|
config={config}
|
|
1878
1922
|
onSubmit={onSubmit}
|
|
1879
1923
|
/>
|
|
1880
|
-
<
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
</TabsContent>
|
|
1885
|
-
<TabsContent value="ai-models">
|
|
1886
|
-
<AiModelDisplayConfig form={form} config={config} onSubmit={onSubmit} />
|
|
1924
|
+
<AiEnabledConfig form={form} config={config} onSubmit={onSubmit} />
|
|
1925
|
+
{aiEnabled !== false && (
|
|
1926
|
+
<AiAssistConfig form={form} config={config} onSubmit={onSubmit} />
|
|
1927
|
+
)}
|
|
1887
1928
|
</TabsContent>
|
|
1888
|
-
{
|
|
1889
|
-
|
|
1890
|
-
<
|
|
1891
|
-
|
|
1929
|
+
{aiEnabled !== false && (
|
|
1930
|
+
<>
|
|
1931
|
+
<TabsContent value="ai-providers">
|
|
1932
|
+
<AiProvidersConfig
|
|
1933
|
+
form={form}
|
|
1934
|
+
config={config}
|
|
1935
|
+
onSubmit={onSubmit}
|
|
1936
|
+
/>
|
|
1937
|
+
</TabsContent>
|
|
1938
|
+
<TabsContent value="ai-models">
|
|
1939
|
+
<AiModelDisplayConfig
|
|
1940
|
+
form={form}
|
|
1941
|
+
config={config}
|
|
1942
|
+
onSubmit={onSubmit}
|
|
1943
|
+
/>
|
|
1944
|
+
</TabsContent>
|
|
1945
|
+
{!wasm && (
|
|
1946
|
+
<TabsContent value="mcp">
|
|
1947
|
+
<MCPConfig form={form} onSubmit={onSubmit} />
|
|
1948
|
+
</TabsContent>
|
|
1949
|
+
)}
|
|
1950
|
+
</>
|
|
1892
1951
|
)}
|
|
1893
1952
|
</Tabs>
|
|
1894
1953
|
);
|
|
@@ -51,7 +51,7 @@ import {
|
|
|
51
51
|
FRONTEND_TOOL_REGISTRY,
|
|
52
52
|
} from "@/core/ai/tools/registry";
|
|
53
53
|
import { useCellActions } from "@/core/cells/cells";
|
|
54
|
-
import { aiAtom,
|
|
54
|
+
import { aiAtom, aiModelConfiguredAtom } from "@/core/config/config";
|
|
55
55
|
import { DEFAULT_AI_MODEL } from "@/core/config/config-schema";
|
|
56
56
|
import { useRequestClient } from "@/core/network/requests";
|
|
57
57
|
import { useRuntimeManager } from "@/core/runtime/config";
|
|
@@ -442,7 +442,7 @@ const PairWithAgentCallout: React.FC<{
|
|
|
442
442
|
};
|
|
443
443
|
|
|
444
444
|
const ChatPanel = () => {
|
|
445
|
-
const aiConfigured = useAtomValue(
|
|
445
|
+
const aiConfigured = useAtomValue(aiModelConfiguredAtom);
|
|
446
446
|
const { handleClick } = useOpenSettingsToTab();
|
|
447
447
|
|
|
448
448
|
if (!aiConfigured) {
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
/* Copyright 2026 Marimo. All rights reserved. */
|
|
2
2
|
|
|
3
|
-
import type {
|
|
3
|
+
import type {
|
|
4
|
+
Column,
|
|
5
|
+
SortDirection,
|
|
6
|
+
SortingState,
|
|
7
|
+
Table,
|
|
8
|
+
} from "@tanstack/react-table";
|
|
4
9
|
import { fireEvent, render, screen } from "@testing-library/react";
|
|
5
10
|
import { describe, expect, it, vi } from "vitest";
|
|
6
11
|
import {
|
|
@@ -8,7 +13,23 @@ import {
|
|
|
8
13
|
DropdownMenuContent,
|
|
9
14
|
DropdownMenuTrigger,
|
|
10
15
|
} from "@/components/ui/dropdown-menu";
|
|
11
|
-
import {
|
|
16
|
+
import {
|
|
17
|
+
ColumnPinning,
|
|
18
|
+
ColumnWrapping,
|
|
19
|
+
CopyColumn,
|
|
20
|
+
DataType,
|
|
21
|
+
FormatOptions,
|
|
22
|
+
HideColumn,
|
|
23
|
+
Sorts,
|
|
24
|
+
} from "../header-items";
|
|
25
|
+
|
|
26
|
+
const renderInMenu = (node: React.ReactNode) =>
|
|
27
|
+
render(
|
|
28
|
+
<DropdownMenu open={true}>
|
|
29
|
+
<DropdownMenuTrigger />
|
|
30
|
+
<DropdownMenuContent>{node}</DropdownMenuContent>
|
|
31
|
+
</DropdownMenu>,
|
|
32
|
+
);
|
|
12
33
|
|
|
13
34
|
describe("multi-column sorting logic", () => {
|
|
14
35
|
// Extract the core sorting logic to test in isolation
|
|
@@ -167,14 +188,6 @@ describe("HideColumn", () => {
|
|
|
167
188
|
toggleVisibility,
|
|
168
189
|
}) as unknown as Column<unknown, unknown>;
|
|
169
190
|
|
|
170
|
-
const renderInMenu = (node: React.ReactNode) =>
|
|
171
|
-
render(
|
|
172
|
-
<DropdownMenu open={true}>
|
|
173
|
-
<DropdownMenuTrigger />
|
|
174
|
-
<DropdownMenuContent>{node}</DropdownMenuContent>
|
|
175
|
-
</DropdownMenu>,
|
|
176
|
-
);
|
|
177
|
-
|
|
178
191
|
it("renders 'Hide column' when canHide is true", () => {
|
|
179
192
|
renderInMenu(<HideColumn column={makeColumn()} />);
|
|
180
193
|
expect(screen.getByText("Hide column")).toBeInTheDocument();
|
|
@@ -192,3 +205,200 @@ describe("HideColumn", () => {
|
|
|
192
205
|
expect(toggleVisibility).toHaveBeenCalledWith(false);
|
|
193
206
|
});
|
|
194
207
|
});
|
|
208
|
+
|
|
209
|
+
describe("DataType", () => {
|
|
210
|
+
const makeColumn = (dtype?: string) =>
|
|
211
|
+
({
|
|
212
|
+
columnDef: { meta: dtype === undefined ? {} : { dtype } },
|
|
213
|
+
}) as unknown as Column<unknown, unknown>;
|
|
214
|
+
|
|
215
|
+
it("renders the dtype label when present", () => {
|
|
216
|
+
renderInMenu(<DataType column={makeColumn("int64")} />);
|
|
217
|
+
expect(screen.getByText("int64")).toBeInTheDocument();
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
it("returns null when dtype is absent", () => {
|
|
221
|
+
renderInMenu(<DataType column={makeColumn()} />);
|
|
222
|
+
expect(screen.queryByText("int64")).toBeNull();
|
|
223
|
+
});
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
describe("Sorts", () => {
|
|
227
|
+
const makeColumn = ({
|
|
228
|
+
canSort = true,
|
|
229
|
+
sorted = false,
|
|
230
|
+
sortIndex = 0,
|
|
231
|
+
}: {
|
|
232
|
+
canSort?: boolean;
|
|
233
|
+
sorted?: false | SortDirection;
|
|
234
|
+
sortIndex?: number;
|
|
235
|
+
} = {}) =>
|
|
236
|
+
({
|
|
237
|
+
getCanSort: () => canSort,
|
|
238
|
+
getIsSorted: () => sorted,
|
|
239
|
+
getSortIndex: () => sortIndex,
|
|
240
|
+
clearSorting: vi.fn(),
|
|
241
|
+
toggleSorting: vi.fn(),
|
|
242
|
+
}) as unknown as Column<unknown, unknown>;
|
|
243
|
+
|
|
244
|
+
const makeTable = (sorting: SortingState) =>
|
|
245
|
+
({
|
|
246
|
+
getState: () => ({ sorting }),
|
|
247
|
+
resetSorting: vi.fn(),
|
|
248
|
+
}) as unknown as Table<unknown>;
|
|
249
|
+
|
|
250
|
+
it("returns null when the column cannot sort", () => {
|
|
251
|
+
renderInMenu(<Sorts column={makeColumn({ canSort: false })} />);
|
|
252
|
+
expect(screen.queryByText("Asc")).toBeNull();
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
it("renders Asc and Desc items", () => {
|
|
256
|
+
renderInMenu(<Sorts column={makeColumn()} />);
|
|
257
|
+
expect(screen.getByText("Asc")).toBeInTheDocument();
|
|
258
|
+
expect(screen.getByText("Desc")).toBeInTheDocument();
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
it("offers single-column 'Clear sort' when sorted without multi-sort", () => {
|
|
262
|
+
renderInMenu(<Sorts column={makeColumn({ sorted: "asc" })} />);
|
|
263
|
+
expect(screen.getByText("Clear sort")).toBeInTheDocument();
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
it("offers 'Clear all sorts' when the table has multiple sorts", () => {
|
|
267
|
+
renderInMenu(
|
|
268
|
+
<Sorts
|
|
269
|
+
column={makeColumn({ sorted: "asc" })}
|
|
270
|
+
table={makeTable([
|
|
271
|
+
{ id: "a", desc: false },
|
|
272
|
+
{ id: "b", desc: true },
|
|
273
|
+
])}
|
|
274
|
+
/>,
|
|
275
|
+
);
|
|
276
|
+
expect(screen.getByText("Clear all sorts")).toBeInTheDocument();
|
|
277
|
+
});
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
describe("CopyColumn", () => {
|
|
281
|
+
const makeColumn = ({
|
|
282
|
+
canCopy = true,
|
|
283
|
+
id = "name",
|
|
284
|
+
}: {
|
|
285
|
+
canCopy?: boolean;
|
|
286
|
+
id?: string;
|
|
287
|
+
} = {}) =>
|
|
288
|
+
({
|
|
289
|
+
id,
|
|
290
|
+
getCanCopy: () => canCopy,
|
|
291
|
+
}) as unknown as Column<unknown, unknown>;
|
|
292
|
+
|
|
293
|
+
it("renders 'Copy column name' when copyable", () => {
|
|
294
|
+
renderInMenu(<CopyColumn column={makeColumn()} />);
|
|
295
|
+
expect(screen.getByText("Copy column name")).toBeInTheDocument();
|
|
296
|
+
});
|
|
297
|
+
|
|
298
|
+
it("returns null when the column cannot be copied", () => {
|
|
299
|
+
renderInMenu(<CopyColumn column={makeColumn({ canCopy: false })} />);
|
|
300
|
+
expect(screen.queryByText("Copy column name")).toBeNull();
|
|
301
|
+
});
|
|
302
|
+
});
|
|
303
|
+
|
|
304
|
+
describe("ColumnPinning", () => {
|
|
305
|
+
const makeColumn = ({
|
|
306
|
+
canPin = true,
|
|
307
|
+
pinned = false,
|
|
308
|
+
}: {
|
|
309
|
+
canPin?: boolean;
|
|
310
|
+
pinned?: false | "left" | "right";
|
|
311
|
+
} = {}) =>
|
|
312
|
+
({
|
|
313
|
+
getCanPin: () => canPin,
|
|
314
|
+
getIsPinned: () => pinned,
|
|
315
|
+
pin: vi.fn(),
|
|
316
|
+
}) as unknown as Column<unknown, unknown>;
|
|
317
|
+
|
|
318
|
+
it("returns null when the column cannot be pinned", () => {
|
|
319
|
+
renderInMenu(<ColumnPinning column={makeColumn({ canPin: false })} />);
|
|
320
|
+
expect(screen.queryByText("Freeze left")).toBeNull();
|
|
321
|
+
});
|
|
322
|
+
|
|
323
|
+
it("offers freeze options when unpinned", () => {
|
|
324
|
+
renderInMenu(<ColumnPinning column={makeColumn()} />);
|
|
325
|
+
expect(screen.getByText("Freeze left")).toBeInTheDocument();
|
|
326
|
+
expect(screen.getByText("Freeze right")).toBeInTheDocument();
|
|
327
|
+
});
|
|
328
|
+
|
|
329
|
+
it("offers 'Unfreeze' when pinned", () => {
|
|
330
|
+
renderInMenu(<ColumnPinning column={makeColumn({ pinned: "left" })} />);
|
|
331
|
+
expect(screen.getByText("Unfreeze")).toBeInTheDocument();
|
|
332
|
+
});
|
|
333
|
+
});
|
|
334
|
+
|
|
335
|
+
describe("ColumnWrapping", () => {
|
|
336
|
+
const makeColumn = ({
|
|
337
|
+
canWrap = true,
|
|
338
|
+
wrapping = "nowrap",
|
|
339
|
+
}: {
|
|
340
|
+
canWrap?: boolean;
|
|
341
|
+
wrapping?: "wrap" | "nowrap";
|
|
342
|
+
} = {}) =>
|
|
343
|
+
({
|
|
344
|
+
getCanWrap: () => canWrap,
|
|
345
|
+
getColumnWrapping: () => wrapping,
|
|
346
|
+
toggleColumnWrapping: vi.fn(),
|
|
347
|
+
}) as unknown as Column<unknown, unknown>;
|
|
348
|
+
|
|
349
|
+
it("returns null when the column cannot wrap", () => {
|
|
350
|
+
renderInMenu(<ColumnWrapping column={makeColumn({ canWrap: false })} />);
|
|
351
|
+
expect(screen.queryByText("Wrap text")).toBeNull();
|
|
352
|
+
});
|
|
353
|
+
|
|
354
|
+
it("offers 'Wrap text' when not wrapping", () => {
|
|
355
|
+
renderInMenu(<ColumnWrapping column={makeColumn()} />);
|
|
356
|
+
expect(screen.getByText("Wrap text")).toBeInTheDocument();
|
|
357
|
+
});
|
|
358
|
+
|
|
359
|
+
it("offers 'No wrap text' when wrapping", () => {
|
|
360
|
+
renderInMenu(<ColumnWrapping column={makeColumn({ wrapping: "wrap" })} />);
|
|
361
|
+
expect(screen.getByText("No wrap text")).toBeInTheDocument();
|
|
362
|
+
});
|
|
363
|
+
});
|
|
364
|
+
|
|
365
|
+
describe("FormatOptions", () => {
|
|
366
|
+
const makeColumn = ({
|
|
367
|
+
dataType = "number",
|
|
368
|
+
canFormat = true,
|
|
369
|
+
}: {
|
|
370
|
+
dataType?: string;
|
|
371
|
+
canFormat?: boolean;
|
|
372
|
+
} = {}) =>
|
|
373
|
+
({
|
|
374
|
+
columnDef: { meta: { dataType } },
|
|
375
|
+
getCanFormat: () => canFormat,
|
|
376
|
+
getColumnFormatting: () => undefined,
|
|
377
|
+
setColumnFormatting: vi.fn(),
|
|
378
|
+
}) as unknown as Column<unknown, unknown>;
|
|
379
|
+
|
|
380
|
+
it("renders the 'Format' submenu trigger for formattable columns", () => {
|
|
381
|
+
renderInMenu(<FormatOptions column={makeColumn()} locale="en-US" />);
|
|
382
|
+
expect(screen.getByText("Format")).toBeInTheDocument();
|
|
383
|
+
});
|
|
384
|
+
|
|
385
|
+
it("returns null when the column cannot be formatted", () => {
|
|
386
|
+
renderInMenu(
|
|
387
|
+
<FormatOptions
|
|
388
|
+
column={makeColumn({ canFormat: false })}
|
|
389
|
+
locale="en-US"
|
|
390
|
+
/>,
|
|
391
|
+
);
|
|
392
|
+
expect(screen.queryByText("Format")).toBeNull();
|
|
393
|
+
});
|
|
394
|
+
|
|
395
|
+
it("returns null when the data type has no format options", () => {
|
|
396
|
+
renderInMenu(
|
|
397
|
+
<FormatOptions
|
|
398
|
+
column={makeColumn({ dataType: "unknown" })}
|
|
399
|
+
locale="en-US"
|
|
400
|
+
/>,
|
|
401
|
+
);
|
|
402
|
+
expect(screen.queryByText("Format")).toBeNull();
|
|
403
|
+
});
|
|
404
|
+
});
|
|
@@ -17,14 +17,14 @@ import { useFilterEditor } from "./filter-editor-context";
|
|
|
17
17
|
import { EDITABLE_FILTER_TYPES, isMembershipFilterType } from "./filters";
|
|
18
18
|
import {
|
|
19
19
|
ClearFilterMenuItem,
|
|
20
|
+
ColumnPinning,
|
|
21
|
+
ColumnWrapping,
|
|
22
|
+
CopyColumn,
|
|
23
|
+
DataType,
|
|
24
|
+
FormatOptions,
|
|
20
25
|
HideColumn,
|
|
21
|
-
renderColumnPinning,
|
|
22
|
-
renderColumnWrapping,
|
|
23
|
-
renderCopyColumn,
|
|
24
|
-
renderDataType,
|
|
25
|
-
renderFormatOptions,
|
|
26
26
|
renderSortIcon,
|
|
27
|
-
|
|
27
|
+
Sorts,
|
|
28
28
|
} from "./header-items";
|
|
29
29
|
|
|
30
30
|
interface DataTableColumnHeaderProps<
|
|
@@ -36,6 +36,11 @@ interface DataTableColumnHeaderProps<
|
|
|
36
36
|
subheader?: React.ReactNode;
|
|
37
37
|
justify?: "left" | "center" | "right";
|
|
38
38
|
calculateTopKRows?: CalculateTopKRows;
|
|
39
|
+
/**
|
|
40
|
+
* Optional: only used to surface multi-column sort actions ("Clear all
|
|
41
|
+
* sorts"). Omitted by call sites that define their header inside column
|
|
42
|
+
* definitions, where the table instance isn't yet available.
|
|
43
|
+
*/
|
|
39
44
|
table?: Table<TData>;
|
|
40
45
|
}
|
|
41
46
|
|
|
@@ -119,12 +124,12 @@ export const DataTableColumnHeader = <TData, TValue>({
|
|
|
119
124
|
</button>
|
|
120
125
|
</DropdownMenuTrigger>
|
|
121
126
|
<DropdownMenuContent align="start">
|
|
122
|
-
{
|
|
123
|
-
{
|
|
124
|
-
{
|
|
125
|
-
{
|
|
126
|
-
{
|
|
127
|
-
{
|
|
127
|
+
<DataType column={column} />
|
|
128
|
+
<Sorts column={column} table={table} />
|
|
129
|
+
<CopyColumn column={column} />
|
|
130
|
+
<ColumnPinning column={column} />
|
|
131
|
+
<ColumnWrapping column={column} />
|
|
132
|
+
<FormatOptions column={column} locale={locale} />
|
|
128
133
|
<HideColumn column={column} />
|
|
129
134
|
{canEditFilter && <DropdownMenuSeparator />}
|
|
130
135
|
{canEditFilter && (
|
|
@@ -9,7 +9,6 @@ import {
|
|
|
9
9
|
TableIcon,
|
|
10
10
|
} from "lucide-react";
|
|
11
11
|
import React from "react";
|
|
12
|
-
import { useLocale } from "react-aria";
|
|
13
12
|
import { downloadSizeLimitAtom } from "./download-policy/atoms";
|
|
14
13
|
import { logNever } from "@/utils/assertNever";
|
|
15
14
|
import { cn } from "@/utils/cn";
|
|
@@ -20,7 +19,6 @@ import { Filenames } from "@/utils/filenames";
|
|
|
20
19
|
import {
|
|
21
20
|
jsonParseWithSpecialChar,
|
|
22
21
|
jsonToMarkdown,
|
|
23
|
-
jsonToTSV,
|
|
24
22
|
} from "@/utils/json/json-parser";
|
|
25
23
|
import { MissingPackagePrompt } from "../datasources/missing-package-prompt";
|
|
26
24
|
import { Button } from "../ui/button";
|
|
@@ -68,7 +66,12 @@ const FILE_TYPES = {
|
|
|
68
66
|
},
|
|
69
67
|
} as const;
|
|
70
68
|
|
|
71
|
-
const downloadOptions = [
|
|
69
|
+
const downloadOptions = [
|
|
70
|
+
FILE_TYPES.CSV,
|
|
71
|
+
FILE_TYPES.TSV,
|
|
72
|
+
FILE_TYPES.JSON,
|
|
73
|
+
FILE_TYPES.PARQUET,
|
|
74
|
+
];
|
|
72
75
|
const copyOptions = [
|
|
73
76
|
FILE_TYPES.TSV,
|
|
74
77
|
FILE_TYPES.JSON,
|
|
@@ -79,6 +82,15 @@ const copyOptions = [
|
|
|
79
82
|
type DownloadFormat = (typeof downloadOptions)[number]["format"];
|
|
80
83
|
type CopyFormat = (typeof copyOptions)[number]["format"];
|
|
81
84
|
|
|
85
|
+
// Each clipboard-copy format fetches from a backend download format, then
|
|
86
|
+
// transforms the payload client-side as needed.
|
|
87
|
+
const COPY_SOURCE_FORMAT: Record<CopyFormat, DownloadFormat> = {
|
|
88
|
+
csv: "csv",
|
|
89
|
+
tsv: "tsv",
|
|
90
|
+
json: "json",
|
|
91
|
+
markdown: "json",
|
|
92
|
+
};
|
|
93
|
+
|
|
82
94
|
export interface ExportActionProps {
|
|
83
95
|
downloadAs: (req: { format: DownloadFormat }) => Promise<{
|
|
84
96
|
url: string;
|
|
@@ -100,7 +112,6 @@ const labelForCopyFormat = (format: CopyFormat): string =>
|
|
|
100
112
|
copyOptions.find((opt) => opt.format === format)?.label ?? format;
|
|
101
113
|
|
|
102
114
|
export const ExportMenu: React.FC<ExportActionProps> = (props) => {
|
|
103
|
-
const { locale } = useLocale();
|
|
104
115
|
const [downloadMenuOpen, setDownloadMenuOpen] = React.useState(false);
|
|
105
116
|
const policy = useAtomValue(downloadSizeLimitAtom);
|
|
106
117
|
const overLimit = !!(
|
|
@@ -213,7 +224,7 @@ export const ExportMenu: React.FC<ExportActionProps> = (props) => {
|
|
|
213
224
|
await withLoadingToast(
|
|
214
225
|
`Preparing ${labelForCopyFormat(format)} for clipboard...`,
|
|
215
226
|
async () => {
|
|
216
|
-
const sourceFormat
|
|
227
|
+
const sourceFormat = COPY_SOURCE_FORMAT[format];
|
|
217
228
|
const result = await resolveDownloadUrl(sourceFormat, () => {
|
|
218
229
|
void handleClipboardCopy(format);
|
|
219
230
|
});
|
|
@@ -223,19 +234,15 @@ export const ExportMenu: React.FC<ExportActionProps> = (props) => {
|
|
|
223
234
|
|
|
224
235
|
let text: string;
|
|
225
236
|
switch (format) {
|
|
226
|
-
case "tsv":
|
|
227
|
-
|
|
228
|
-
text =
|
|
237
|
+
case "tsv":
|
|
238
|
+
case "csv":
|
|
239
|
+
text = await fetchText(result.url);
|
|
229
240
|
break;
|
|
230
|
-
}
|
|
231
241
|
case "json": {
|
|
232
242
|
const json = await fetchJson(result.url);
|
|
233
243
|
text = JSON.stringify(json, null, 2);
|
|
234
244
|
break;
|
|
235
245
|
}
|
|
236
|
-
case "csv":
|
|
237
|
-
text = await fetchText(result.url);
|
|
238
|
-
break;
|
|
239
246
|
case "markdown": {
|
|
240
247
|
const json = await fetchJson(result.url);
|
|
241
248
|
text = jsonToMarkdown(json);
|