Skip to content

Commit a7c61fd

Browse files
authored
Merge pull request #91 from NeuroJSON/staging
Dataset Detail Page refinements (tree, metadata panel, layout adjustment)
2 parents 3af6b27 + 6b211d8 commit a7c61fd

File tree

15 files changed

+1051
-796
lines changed

15 files changed

+1051
-796
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import CheckIcon from "@mui/icons-material/Check";
2+
import ContentCopyIcon from "@mui/icons-material/ContentCopy";
3+
import { IconButton, Tooltip } from "@mui/material";
4+
import React from "react";
5+
6+
const write = async (text: string) => {
7+
try {
8+
await navigator.clipboard.writeText(text);
9+
return true;
10+
} catch {
11+
// Fallback
12+
const ta = document.createElement("textarea");
13+
ta.value = text;
14+
ta.style.position = "fixed";
15+
ta.style.opacity = "0";
16+
document.body.appendChild(ta);
17+
ta.focus();
18+
ta.select();
19+
const ok = document.execCommand("copy");
20+
document.body.removeChild(ta);
21+
return ok;
22+
}
23+
};
24+
25+
export default function CopyButton({
26+
text,
27+
title = "Copy",
28+
size = "small",
29+
}: {
30+
text: string;
31+
title?: string;
32+
size?: "small" | "medium" | "large";
33+
}) {
34+
const [ok, setOk] = React.useState(false);
35+
36+
const onClick = async (e: React.MouseEvent) => {
37+
e.stopPropagation();
38+
if (await write(text)) {
39+
setOk(true);
40+
setTimeout(() => setOk(false), 1200);
41+
}
42+
};
43+
44+
return (
45+
<Tooltip title={ok ? "Copied!" : title} arrow>
46+
<IconButton size={size} onClick={onClick} sx={{ ml: 0.5 }}>
47+
{ok ? (
48+
<CheckIcon fontSize="inherit" />
49+
) : (
50+
<ContentCopyIcon fontSize="inherit" />
51+
)}
52+
</IconButton>
53+
</Tooltip>
54+
);
55+
}

src/components/DatasetDetailPage/FileTree/FileTree.tsx

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//renders the header (title, counts, total size) and the scrollable area.
12
import FileTreeRow from "./FileTreeRow";
23
import type { TreeNode } from "./types";
34
import FolderIcon from "@mui/icons-material/Folder";
@@ -9,7 +10,10 @@ type Props = {
910
tree: TreeNode[];
1011
filesCount: number;
1112
totalBytes: number;
12-
onPreview: (url: string, index: number) => void;
13+
// for preview in tree row
14+
onPreview: (src: string | any, index: number, isInternal?: boolean) => void;
15+
getInternalByPath: (path: string) => { data: any; index: number } | undefined;
16+
getJsonByPath?: (path: string) => any;
1317
};
1418

1519
const formatSize = (n: number) => {
@@ -26,6 +30,8 @@ const FileTree: React.FC<Props> = ({
2630
filesCount,
2731
totalBytes,
2832
onPreview,
33+
getInternalByPath,
34+
getJsonByPath,
2935
}) => (
3036
<Box
3137
sx={{
@@ -49,16 +55,23 @@ const FileTree: React.FC<Props> = ({
4955
flexShrink: 0,
5056
}}
5157
>
52-
<FolderIcon />
58+
{/* <FolderIcon /> */}
5359
<Typography sx={{ fontWeight: 700, flex: 1 }}>{title}</Typography>
54-
<Typography variant="body2" sx={{ color: "text.secondary" }}>
60+
{/* <Typography variant="body2" sx={{ color: "text.secondary" }}>
5561
Files: {filesCount} &nbsp; Size: {formatSize(totalBytes)}
56-
</Typography>
62+
</Typography> */}
5763
</Box>
5864

5965
<Box sx={{ flex: 1, minHeight: 0, overflowY: "auto", py: 0.5 }}>
6066
{tree.map((n) => (
61-
<FileTreeRow key={n.path} node={n} level={0} onPreview={onPreview} />
67+
<FileTreeRow
68+
key={n.path}
69+
node={n}
70+
level={0}
71+
onPreview={onPreview}
72+
getInternalByPath={getInternalByPath}
73+
getJsonByPath={getJsonByPath}
74+
/> // pass the handlePreview(onPreview = handlePreview) function to FileTreeRow
6275
))}
6376
</Box>
6477
</Box>

0 commit comments

Comments
 (0)