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.
Python artificial-intelligencedagdata-sciencedata-visualizationdataflowdeveloper-toolsmachine-learningnotebookspipelinepythonreactivesqlweb-app
add snippet buttons in storage file viewer (#8737)
Shahmir Varqha4a74ce41f677
diff --git a/frontend/src/components/storage/storage-file-viewer.tsx b/frontend/src/components/storage/storage-file-viewer.tsxindex 521a1d2692..0eb587cf6d 100644--- a/frontend/src/components/storage/storage-file-viewer.tsx+++ b/frontend/src/components/storage/storage-file-viewer.tsx@@ -4,27 +4,32 @@ import { FileIcon, LoaderCircle, RefreshCwIcon } from "lucide-react";import type React from "react";import { useCallback } from "react";import { useLocale } from "react-aria";+import { useAddCodeToNewCell } from "@/components/editor/cell/useAddCell";import { FilePreviewHeader } from "@/components/editor/file-tree/file-header";import { renderFileIcon } from "@/components/editor/file-tree/file-icons";import {FileContentRenderer,isMediaMime,} from "@/components/editor/file-tree/renderers";+import { Tooltip } from "@/components/ui/tooltip";import { toast } from "@/components/ui/use-toast";import { DownloadStorage } from "@/core/storage/request-registry";-import type { StorageEntry } from "@/core/storage/types";+import type { StorageEntry, StorageNamespace } from "@/core/storage/types";import { useAsyncData } from "@/hooks/useAsyncData";import { downloadByURL } from "@/utils/download";import { formatBytes } from "@/utils/formatting";import { Logger } from "@/utils/Logger";import { CopyClipboardIcon } from "../icons/copy-icon";import { Button } from "../ui/button";+import { STORAGE_SNIPPETS } from "./storage-snippets";const MAX_MEDIA_PREVIEW_SIZE = 100 * 1024 * 1024; // 100 MBinterface Props {entry: StorageEntry;namespace: string;+ protocol: string;+ backendType: StorageNamespace["backendType"];onBack: () => void;}@@ -41,9 +46,12 @@ type PreviewData =export const StorageFileViewer: React.FC<Props> = ({entry,namespace,+ protocol,+ backendType,onBack,}) => {const { locale } = useLocale();+ const addCodeToNewCell = useAddCodeToNewCell();const name = displayName(entry.path);const mime = entry.mimeType || "text/plain";const isMedia = isMediaMime(mime);@@ -111,12 +119,38 @@ export const StorageFileViewer: React.FC<Props> = ({}}, [namespace, entry.path, name]);+ const snippetActions = STORAGE_SNIPPETS.map((snippet) => {+ const code = snippet.getCode({+ variableName: namespace,+ protocol,+ entry,+ backendType,+ });+ if (code === null) {+ return null;+ }+ const Icon = snippet.icon;+ return (+ <Tooltip key={snippet.id} content={snippet.label}>+ <Button+ variant="text"+ size="xs"+ onClick={() => addCodeToNewCell(code)}+ aria-label={snippet.label}+ >+ <Icon className="h-3.5 w-3.5" />+ </Button>+ </Tooltip>+ );+ });+const header = (<FilePreviewHeaderfilename={name}filenameIcon={renderFileIcon(name)}onBack={onBack}onDownload={handleDownload}+ actions={snippetActions}/>);diff --git a/frontend/src/components/storage/storage-inspector.tsx b/frontend/src/components/storage/storage-inspector.tsxindex 3607d73c89..b7e2c2b3c9 100644--- a/frontend/src/components/storage/storage-inspector.tsx+++ b/frontend/src/components/storage/storage-inspector.tsx@@ -64,6 +64,8 @@ import { STORAGE_SNIPPETS } from "./storage-snippets";interface OpenFileInfo {entry: StorageEntry;namespace: string;+ protocol: string;+ backendType: StorageNamespace["backendType"];}// Pixels per depth level. Applied as paddingLeft on each full-width item@@ -315,7 +317,7 @@ const StorageEntryRow: React.FC<{if (isDir) {setIsExpanded(!effectiveExpanded);} else {- onOpenFile({ entry, namespace });+ onOpenFile({ entry, namespace, protocol, backendType });}}}>@@ -361,7 +363,9 @@ const StorageEntryRow: React.FC<{>{!isDir && (<DropdownMenuItem- onSelect={() => onOpenFile({ entry, namespace })}+ onSelect={() =>+ onOpenFile({ entry, namespace, protocol, backendType })+ }><ViewIcon className={MENU_ITEM_ICON_CLASS} />View@@ -585,6 +589,8 @@ export const StorageInspector: React.FC = () => {<StorageFileViewerentry={openFile.entry}namespace={openFile.namespace}+ protocol={openFile.protocol}+ backendType={openFile.backendType}onBack={() => setOpenFile(null)}/>)}diff --git a/frontend/src/components/storage/storage-snippets.ts b/frontend/src/components/storage/storage-snippets.tsindex 3f8ace9bcb..620fc53c56 100644--- a/frontend/src/components/storage/storage-snippets.ts+++ b/frontend/src/components/storage/storage-snippets.ts@@ -1,7 +1,7 @@/* Copyright 2026 Marimo. All rights reserved. */import type { LucideIcon } from "lucide-react";-import { BookOpenIcon, LinkIcon } from "lucide-react";+import { BookPlusIcon, FileSymlink } from "lucide-react";import type { StorageEntry, StorageNamespace } from "@/core/storage/types";type BackendType = StorageNamespace["backendType"];@@ -31,7 +31,7 @@ export const STORAGE_SNIPPETS: StorageSnippet[] = [{id: "read-file",label: "Insert read snippet",- icon: BookOpenIcon,+ icon: BookPlusIcon,getCode: (ctx) => {if (ctx.entry.kind === "directory") {return null;@@ -46,7 +46,7 @@ export const STORAGE_SNIPPETS: StorageSnippet[] = [{id: "download-file",label: "Insert download snippet",- icon: LinkIcon,+ icon: FileSymlink,getCode: (ctx) => {if (ctx.entry.kind === "directory") {return null;