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: toggle hidden files file explorer (#7192)

Francis Shonubic081cc696656
diff --git a/frontend/src/components/editor/file-tree/__tests__/file-expolorer.test.ts b/frontend/src/components/editor/file-tree/__tests__/file-expolorer.test.ts
new file mode 100644
index 0000000000..3b700bb3a3
--- /dev/null
+++ b/frontend/src/components/editor/file-tree/__tests__/file-expolorer.test.ts
@@ -0,0 +1,178 @@
+import { describe, it, expect } from "vitest";
+import { isDirectoryOrFileHidden, filterHiddenTree } from "../file-explorer";
+import type { FileInfo } from "@/core/network/types";
+
+// Helpers to build FileInfo objects for tests
+const file = (name: string, path: string): FileInfo => ({
+ id: path,
+ name,
+ path,
+ isDirectory: false,
+ isMarimoFile: false,
+ children: [],
+});
+
+const dir = (
+ name: string,
+ path: string,
+ children: FileInfo[] = [],
+): FileInfo => ({
+ id: path,
+ name,
+ path,
+ isDirectory: true,
+ isMarimoFile: false,
+ children,
+});
+
+describe("isDirectoryOrFileHidden", () => {
+ it("should return true for files starting with dot", () => {
+ expect(isDirectoryOrFileHidden(".git")).toBe(true);
+ expect(isDirectoryOrFileHidden(".env")).toBe(true);
+ expect(isDirectoryOrFileHidden(".gitignore")).toBe(true);
+ });
+
+ it("should return false for normal files", () => {
+ expect(isDirectoryOrFileHidden("README.md")).toBe(false);
+ expect(isDirectoryOrFileHidden("package.json")).toBe(false);
+ expect(isDirectoryOrFileHidden("index.ts")).toBe(false);
+ });
+
+ it("should return false for files with dots in the middle", () => {
+ expect(isDirectoryOrFileHidden("file.test.ts")).toBe(false);
+ expect(isDirectoryOrFileHidden("my.config.js")).toBe(false);
+ });
+});
+
+describe("filterHiddenTree", () => {
+ it("should return all items when showHidden is true", () => {
+ const list: FileInfo[] = [
+ dir(".git", "/.git", []),
+ file("README.md", "/README.md"),
+ file(".env", "/.env"),
+ ];
+
+ const result = filterHiddenTree(list, true);
+
+ expect(result).toBe(list); // should be the exact same reference
+ expect(result).toHaveLength(3);
+ });
+
+ it("should filter out hidden files when showHidden is false", () => {
+ const list: FileInfo[] = [
+ dir(".git", "/.git"),
+ file("README.md", "/README.md"),
+ file(".env", "/.env"),
+ file("package.json", "/package.json"),
+ ];
+
+ const result = filterHiddenTree(list, false);
+
+ expect(result).toHaveLength(2);
+ expect(result[0].name).toBe("README.md");
+ expect(result[1].name).toBe("package.json");
+ });
+
+ it("should filter hidden directories recursively", () => {
+ const list: FileInfo[] = [
+ dir("src", "/src", [
+ file("index.ts", "/src/index.ts"),
+ file(".DS_Store", "/src/.DS_Store"),
+ file("utils.ts", "/src/utils.ts"),
+ ]),
+ dir(".git", "/.git", [file("config", "/.git/config")]),
+ ];
+
+ const result = filterHiddenTree(list, false);
+
+ expect(result).toHaveLength(1);
+ expect(result[0].name).toBe("src");
+ expect(result[0].children).toHaveLength(2);
+ expect(result[0].children?.[0].name).toBe("index.ts");
+ expect(result[0].children?.[1].name).toBe("utils.ts");
+ });
+
+ it("should handle nested hidden files", () => {
+ const list: FileInfo[] = [
+ dir("project", "/project", [
+ dir("src", "/project/src", [
+ file("index.ts", "/project/src/index.ts"),
+ file(".backup", "/project/src/.backup"),
+ ]),
+ file(".env", "/project/.env"),
+ ]),
+ ];
+
+ const result = filterHiddenTree(list, false);
+
+ expect(result).toHaveLength(1);
+ expect(result[0].children).toHaveLength(1);
+ expect(result[0].children?.[0].name).toBe("src");
+ expect(result[0].children?.[0].children).toHaveLength(1);
+ expect(result[0].children?.[0].children?.[0].name).toBe("index.ts");
+ });
+
+ it("should preserve directory structure when no children are filtered", () => {
+ const list: FileInfo[] = [
+ dir("src", "/src", [
+ file("index.ts", "/src/index.ts"),
+ file("utils.ts", "/src/utils.ts"),
+ ]),
+ ];
+
+ const result = filterHiddenTree(list, true);
+
+ // Should return the same reference since nothing changed
+ expect(result[0]).toBe(list[0]);
+ });
+
+ it("should create new object only when children are filtered", () => {
+ const list: FileInfo[] = [
+ dir("src", "/src", [
+ file("index.ts", "/src/index.ts"),
+ file(".hidden", "/src/.hidden"),
+ ]),
+ ];
+
+ const result = filterHiddenTree(list, false);
+
+ // Should be a new object since children changed
+ expect(result[0]).not.toBe(list[0]);
+ expect(result[0].children).not.toBe(list[0].children);
+ });
+
+ it("should handle empty list", () => {
+ const result = filterHiddenTree([], false);
+ expect(result).toEqual([]);
+ });
+
+ it("should handle empty children arrays", () => {
+ const list: FileInfo[] = [dir("empty-dir", "/empty-dir", [])];
+
+ const result = filterHiddenTree(list, false);
+
+ expect(result).toHaveLength(1);
+ expect(result[0].children).toEqual([]);
+ });
+
+ it("should handle deeply nested structures", () => {
+ const list: FileInfo[] = [
+ dir("level1", "/level1", [
+ dir("level2", "/level1/level2", [
+ dir("level3", "/level1/level2/level3", [
+ file("file.ts", "/level1/level2/level3/file.ts"),
+ file(".hidden", "/level1/level2/level3/.hidden"),
+ ]),
+ ]),
+ file(".ignore", "/level1/.ignore"),
+ ]),
+ ];
+
+ const result = filterHiddenTree(list, false);
+
+ expect(result[0].children?.[0].children?.[0].children).toHaveLength(1);
+ expect(result[0].children?.[0].children?.[0].children?.[0].name).toBe(
+ "file.ts",
+ );
+ });
+});
diff --git a/frontend/src/components/editor/file-tree/file-explorer.tsx b/frontend/src/components/editor/file-tree/file-explorer.tsx
index da3e30383e..00c836332f 100644
--- a/frontend/src/components/editor/file-tree/file-explorer.tsx
+++ b/frontend/src/components/editor/file-tree/file-explorer.tsx
@@ -12,6 +12,7 @@ import {
DownloadIcon,
Edit3Icon,
ExternalLinkIcon,
+ EyeOffIcon,
FilePlus2Icon,
FolderPlusIcon,
ListTreeIcon,
@@ -67,6 +68,15 @@ import {
PYTHON_CODE_FOR_FILE_TYPE,
} from "./types";
import { useFileExplorerUpload } from "./upload";
+import { atomWithStorage } from "jotai/utils";
+import { jotaiJsonStorage } from "@/utils/storage/jotai";
+
+const hiddenFilesState = atomWithStorage("marimo:showHiddenFiles", true,
+ jotaiJsonStorage,
+ {
+ getOnInit: true,
+ },
+)
const RequestingTreeContext = React.createContext<RequestingTree | null>(null);
@@ -77,6 +87,9 @@ export const FileExplorer: React.FC<{
const [tree] = useAtom(treeAtom);
const [data, setData] = useState<FileInfo[]>([]);
const [openFile, setOpenFile] = useState<FileInfo | null>(null);
+ const [showHiddenFiles, setShowHiddenFiles] = useAtom<boolean>(hiddenFilesState);
+
+
const { openPrompt } = useImperativeModal();
// Keep external state to remember which folders are open
// when this component is unmounted
@@ -87,6 +100,11 @@ export const FileExplorer: React.FC<{
tree.refreshAll(Object.keys(openState).filter((id) => openState[id]));
});
+ const handleHiddenFilesToggle = useEvent(() => {
+ const newValue = !showHiddenFiles;
+ setShowHiddenFiles(newValue);
+ });
+
const handleCreateFolder = useEvent(async () => {
openPrompt({
title: "Folder name",
@@ -148,10 +166,12 @@ export const FileExplorer: React.FC<{
);
}
+ const visibleData = React.useMemo(() => filterHiddenTree(data, showHiddenFiles), [data, showHiddenFiles]);
return (
<>
<Toolbar
onRefresh={handleRefresh}
+ onHidden={handleHiddenFilesToggle}
onCreateFile={handleCreateFile}
onCreateFolder={handleCreateFolder}
onCollapseAll={handleCollapseAll}
@@ -163,7 +183,7 @@ export const FileExplorer: React.FC<{
ref={treeRef}
height={height - 33}
className="h-full"
- data={data}
+ data={visibleData}
initialOpenState={openState}
openByDefault={false}
// Hide the drop cursor
@@ -215,6 +235,7 @@ const INDENT_STEP = 15;
interface ToolbarProps {
onRefresh: () => void;
+ onHidden: () => void;
onCreateFile: () => void;
onCreateFolder: () => void;
onCollapseAll: () => void;
@@ -223,6 +244,7 @@ interface ToolbarProps {
const Toolbar = ({
onRefresh,
+ onHidden,
onCreateFile,
onCreateFolder,
onCollapseAll,
@@ -277,6 +299,16 @@ const Toolbar = ({
<RefreshCcwIcon size={16} />
</Button>
</Tooltip>
+ <Tooltip content="Toggle hidden files">
+ <Button
+ data-testid="file-explorer-hidden-files-button"
+ onClick={onHidden}
+ variant="text"
+ size="xs"
+ >
+ <EyeOffIcon size={16} />
+ </Button>
+ </Tooltip>
<Tooltip content="Collapse all folders">
<Button
data-testid="file-explorer-collapse-button"
@@ -612,8 +644,8 @@ const Node = ({ node, style, dragHandle }: NodeRendererProps<FileInfo>) => {
className={cn(
"flex items-center pl-1 py-1 cursor-pointer hover:bg-accent/50 hover:text-accent-foreground rounded-l flex-1 overflow-hidden group",
node.willReceiveDrop &&
- node.data.isDirectory &&
- "bg-accent/80 hover:bg-accent/80 text-accent-foreground",
+ node.data.isDirectory &&
+ "bg-accent/80 hover:bg-accent/80 text-accent-foreground",
)}
>
{node.data.isMarimoFile ? (
@@ -677,3 +709,33 @@ function openMarimoNotebook(
event.preventDefault();
openNotebook(path);
}
+
+export function filterHiddenTree(list: FileInfo[], showHidden: boolean): FileInfo[] {
+ if (showHidden) {
+ return list
+ }
+
+ const out: FileInfo[] = [];
+ for (const item of list) {
+ if (isDirectoryOrFileHidden(item.name)) {
+ continue
+ };
+ let next = item;
+ if (item.children && item.children.length) {
+ const kids = filterHiddenTree(item.children, showHidden);
+ if (kids !== item.children) {
+ next = { ...item, children: kids }
+
+ };
+ }
+ out.push(next);
+ }
+ return out;
+}
+
+export function isDirectoryOrFileHidden(filename: string): boolean {
+ if (filename.startsWith('.')) {
+ return true
+ }
+ return false
+}