Skip to content

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.

feat: allow deleting file from the file explorer (#1023)

Myles Scolnicked7f6f541a13
diff --git a/frontend/src/components/editor/file-tree/file-explorer.tsx b/frontend/src/components/editor/file-tree/file-explorer.tsx
index 95ef0b6b18..a9282eaa50 100644
--- a/frontend/src/components/editor/file-tree/file-explorer.tsx
+++ b/frontend/src/components/editor/file-tree/file-explorer.tsx
@@ -11,6 +11,7 @@ import {
MoreVerticalIcon,
PlaySquareIcon,
RefreshCcwIcon,
+ Trash2Icon,
UploadIcon,
ViewIcon,
} from "lucide-react";
@@ -25,7 +26,10 @@ import {
} from "./types";
import { toast } from "@/components/ui/use-toast";
import { useImperativeModal } from "@/components/modal/ImperativeModal";
-import { AlertDialogAction } from "@/components/ui/alert-dialog";
+import {
+ AlertDialogAction,
+ AlertDialogDestructiveAction,
+} from "@/components/ui/alert-dialog";
import { useAtom } from "jotai";
import { Button, buttonVariants } from "@/components/ui/button";
@@ -93,6 +97,11 @@ export const FileExplorer: React.FC<{
renderCursor={() => null}
// Disable dropping files into files
disableDrop={({ parentNode }) => !parentNode.data.isDirectory}
+ onDelete={async ({ ids }) => {
+ for (const id of ids) {
+ await tree.delete(id);
+ }
+ }}
onRename={async ({ id, name }) => {
await tree.rename(id, name);
}}
@@ -239,6 +248,25 @@ const Node = ({ node, style, dragHandle }: NodeRendererProps<FileInfo>) => {
});
};
+ const handleDeleteFile = async (evt: Event) => {
+ evt.stopPropagation();
+ evt.preventDefault();
+ openConfirm({
+ title: "Delete file",
+ description: `Are you sure you want to delete ${node.data.name}?`,
+ confirmAction: (
+ <AlertDialogDestructiveAction
+ onClick={async () => {
+ await node.tree.delete(node.id);
+ }}
+ aria-label="Confirm"
+ >
+ Delete
+ </AlertDialogDestructiveAction>
+ ),
+ });
+ };
+
return (
<div
style={style}
@@ -330,6 +358,11 @@ const Node = ({ node, style, dragHandle }: NodeRendererProps<FileInfo>) => {
</DropdownMenuItem>
</>
)}
+ <DropdownMenuSeparator />
+ <DropdownMenuItem onSelect={handleDeleteFile} variant="danger">
+ <Trash2Icon className="mr-2" size={14} strokeWidth={1.5} />
+ Delete
+ </DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
</span>
diff --git a/frontend/src/components/editor/file-tree/requesting-tree.tsx b/frontend/src/components/editor/file-tree/requesting-tree.tsx
index c36ff83ecd..b41354ad1f 100644
--- a/frontend/src/components/editor/file-tree/requesting-tree.tsx
+++ b/frontend/src/components/editor/file-tree/requesting-tree.tsx
@@ -118,6 +118,19 @@ export class RequestingTree {
await this.refreshAll([parentPath]);
}
+ async delete(id: string): Promise<void> {
+ const node = this.delegate.find(id);
+ if (!node) {
+ return;
+ }
+
+ await this.callbacks
+ .deleteFileOrFolder({ path: node.data.path })
+ .then(this.handleResponse);
+ this.delegate.drop({ id });
+ this.onChange(this.delegate.data);
+ }
+
refreshAll = async (ids: string[]): Promise<void> => {
// For each open folder, refresh
const openFolders = [
diff --git a/frontend/src/css/globals.css b/frontend/src/css/globals.css
index b16f339b42..b1ce021102 100644
--- a/frontend/src/css/globals.css
+++ b/frontend/src/css/globals.css
@@ -161,6 +161,8 @@
0px 0px 4px 0px var(--stale-color);
--heavy-shadow-error: 7px 8px 0px 0px var(--red-5),
0px 0px 2px 0px var(--red-5);
+ --light-shadow-accent: 4px 4px 0px 0px hsl(var(--accent)),
+ 0px 0px 2px 0px hsl(var(--accent));
}
}