Skip to content

Commit 443d38b

Browse files
committed
feat: add preview for embedded internal data in file tree; refs #88
1 parent 5f48c1e commit 443d38b

File tree

3 files changed

+109
-307
lines changed

3 files changed

+109
-307
lines changed

src/components/DatasetDetailPage/FileTree/FileTree.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,8 @@ type Props = {
1111
filesCount: number;
1212
totalBytes: number;
1313
// for preview in tree row
14-
// onPreview: (url: string, index: number) => void;
15-
onPreview: (src: string | any, index: number, isInternal?: boolean) => void; // ← type it
16-
getInternalByPath?: (
17-
path: string
18-
) => { data: any; index: number } | undefined;
14+
onPreview: (src: string | any, index: number, isInternal?: boolean) => void;
15+
getInternalByPath: (path: string) => { data: any; index: number } | undefined;
1916
};
2017

2118
const formatSize = (n: number) => {

src/components/DatasetDetailPage/FileTree/FileTreeRow.tsx

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,10 @@ import React from "react";
1414
type Props = {
1515
node: TreeNode;
1616
level: number;
17-
// onPreview: (url: string, index: number) => void;
18-
// for preview in the tree row
17+
18+
// src is either an external URL(string) or the internal object
1919
onPreview: (src: string | any, index: number, isInternal?: boolean) => void;
20-
getInternalByPath?: (
21-
path: string
22-
) => { data: any; index: number } | undefined;
20+
getInternalByPath: (path: string) => { data: any; index: number } | undefined;
2321
};
2422

2523
const FileTreeRow: React.FC<Props> = ({
@@ -29,7 +27,9 @@ const FileTreeRow: React.FC<Props> = ({
2927
getInternalByPath,
3028
}) => {
3129
const [open, setOpen] = React.useState(false);
32-
const internal = getInternalByPath?.(node.path); // 👈 resolve by path
30+
// const internal = getInternalByPath?.(node.path);
31+
// const internal = getInternalByPath ? getInternalByPath(node.path) : undefined;
32+
const internal = getInternalByPath(node.path);
3333
const externalUrl = node.link?.url;
3434

3535
// if (node.kind === "folder") {
@@ -132,6 +132,24 @@ const FileTreeRow: React.FC<Props> = ({
132132
</Box>
133133
)}
134134

135+
{/* internal preview action for folders */}
136+
{internal && (
137+
<Box
138+
sx={{ display: "flex", gap: 1, mr: 0.5, flexShrink: 0 }}
139+
onClick={(e) => e.stopPropagation()}
140+
>
141+
<Button
142+
size="small"
143+
variant="text"
144+
startIcon={<VisibilityIcon fontSize="small" />}
145+
onClick={() => onPreview(internal.data, internal.index, true)}
146+
sx={{ color: Colors.purple }}
147+
>
148+
Preview
149+
</Button>
150+
</Box>
151+
)}
152+
135153
{open ? <ExpandLess /> : <ExpandMore />}
136154
</Box>
137155

0 commit comments

Comments
 (0)