-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileTree.tsx
More file actions
83 lines (78 loc) · 2.26 KB
/
FileTree.tsx
File metadata and controls
83 lines (78 loc) · 2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
//renders the header (title, counts, total size) and the scrollable area.
import FileTreeRow from "./FileTreeRow";
import type { TreeNode } from "./types";
import FolderIcon from "@mui/icons-material/Folder";
import { Box, Typography } from "@mui/material";
import React from "react";
type Props = {
title: string;
tree: TreeNode[];
// filesCount: number;
// totalBytes: number;
// for preview in tree row
onPreview: (src: string | any, index: number, isInternal?: boolean) => void;
getInternalByPath: (path: string) => { data: any; index: number } | undefined;
getJsonByPath?: (path: string) => any;
highlightText?: string;
};
// const formatSize = (n: number) => {
// if (n < 1024) return `${n} B`;
// if (n < 1024 ** 2) return `${(n / 1024).toFixed(1)} KB`;
// if (n < 1024 ** 3) return `${(n / 1024 ** 2).toFixed(2)} MB`;
// if (n < 1024 ** 4) return `${(n / 1024 ** 3).toFixed(2)} GB`;
// return `${(n / 1024 ** 4).toFixed(2)} TB`;
// };
const FileTree: React.FC<Props> = ({
title,
tree,
// filesCount,
// totalBytes,
onPreview,
getInternalByPath,
getJsonByPath,
highlightText,
}) => (
<Box
sx={{
backgroundColor: "#fff",
borderRadius: 2,
border: "1px solid #e0e0e0",
height: "100%",
display: "flex",
flexDirection: "column",
minHeight: 0,
}}
>
<Box
sx={{
px: 2,
py: 1.5,
borderBottom: "1px solid #eee",
display: "flex",
alignItems: "center",
gap: 1,
flexShrink: 0,
}}
>
{/* <FolderIcon /> */}
<Typography sx={{ fontWeight: 700, flex: 1 }}>{title}</Typography>
{/* <Typography variant="body2" sx={{ color: "text.secondary" }}>
Files: {filesCount} Size: {formatSize(totalBytes)}
</Typography> */}
</Box>
<Box sx={{ flex: 1, minHeight: 0, overflowY: "auto", py: 0.5 }}>
{tree.map((n) => (
<FileTreeRow
key={n.path}
node={n}
level={0}
onPreview={onPreview}
getInternalByPath={getInternalByPath}
getJsonByPath={getJsonByPath}
highlightText={highlightText}
/> // pass the handlePreview(onPreview = handlePreview) function to FileTreeRow
))}
</Box>
</Box>
);
export default FileTree;