Skip to content

Commit 5f48c1e

Browse files
committed
test: add mesh preview in the tree row
1 parent 0f997d7 commit 5f48c1e

File tree

4 files changed

+245
-51
lines changed

4 files changed

+245
-51
lines changed

src/components/DatasetDetailPage/FileTree/FileTree.tsx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@ type Props = {
1010
tree: TreeNode[];
1111
filesCount: number;
1212
totalBytes: number;
13-
onPreview: (url: string, index: number) => void;
13+
// 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;
1419
};
1520

1621
const formatSize = (n: number) => {
@@ -27,6 +32,7 @@ const FileTree: React.FC<Props> = ({
2732
filesCount,
2833
totalBytes,
2934
onPreview,
35+
getInternalByPath,
3036
}) => (
3137
<Box
3238
sx={{
@@ -59,7 +65,13 @@ const FileTree: React.FC<Props> = ({
5965

6066
<Box sx={{ flex: 1, minHeight: 0, overflowY: "auto", py: 0.5 }}>
6167
{tree.map((n) => (
62-
<FileTreeRow key={n.path} node={n} level={0} onPreview={onPreview} /> // pass the handlePreview(onPreview = handlePreview) function to FileTreeRow
68+
<FileTreeRow
69+
key={n.path}
70+
node={n}
71+
level={0}
72+
onPreview={onPreview}
73+
getInternalByPath={getInternalByPath}
74+
/> // pass the handlePreview(onPreview = handlePreview) function to FileTreeRow
6375
))}
6476
</Box>
6577
</Box>

src/components/DatasetDetailPage/FileTree/FileTreeRow.tsx

Lines changed: 59 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,23 @@ import React from "react";
1414
type Props = {
1515
node: TreeNode;
1616
level: number;
17-
onPreview: (url: string, index: number) => void;
17+
// onPreview: (url: string, index: number) => void;
18+
// for preview in the tree row
19+
onPreview: (src: string | any, index: number, isInternal?: boolean) => void;
20+
getInternalByPath?: (
21+
path: string
22+
) => { data: any; index: number } | undefined;
1823
};
1924

20-
const FileTreeRow: React.FC<Props> = ({ node, level, onPreview }) => {
25+
const FileTreeRow: React.FC<Props> = ({
26+
node,
27+
level,
28+
onPreview,
29+
getInternalByPath,
30+
}) => {
2131
const [open, setOpen] = React.useState(false);
32+
const internal = getInternalByPath?.(node.path); // 👈 resolve by path
33+
const externalUrl = node.link?.url;
2234

2335
// if (node.kind === "folder") {
2436
// return (
@@ -131,6 +143,7 @@ const FileTreeRow: React.FC<Props> = ({ node, level, onPreview }) => {
131143
node={child}
132144
level={level + 1}
133145
onPreview={onPreview}
146+
getInternalByPath={getInternalByPath}
134147
/>
135148
))}
136149
</Collapse>
@@ -188,7 +201,49 @@ const FileTreeRow: React.FC<Props> = ({ node, level, onPreview }) => {
188201
)}
189202
</Box>
190203

191-
{node.link?.url && (
204+
{(externalUrl || internal) && (
205+
<Box
206+
sx={{ display: "flex", gap: 1, flexShrink: 0 }}
207+
onClick={(e) => e.stopPropagation()}
208+
>
209+
{externalUrl && (
210+
<>
211+
<Button
212+
size="small"
213+
variant="text"
214+
onClick={() => window.open(externalUrl, "_blank")}
215+
>
216+
Download
217+
</Button>
218+
{isPreviewable(externalUrl) && (
219+
<Button
220+
size="small"
221+
variant="text"
222+
onClick={() =>
223+
onPreview(externalUrl, node.link!.index, false)
224+
}
225+
>
226+
Preview
227+
</Button>
228+
)}
229+
</>
230+
)}
231+
232+
{internal && (
233+
<Button
234+
size="small"
235+
variant="text"
236+
startIcon={<VisibilityIcon fontSize="small" />}
237+
onClick={(e) => {
238+
e.stopPropagation();
239+
onPreview(internal.data, internal.index, true);
240+
}}
241+
sx={{ color: Colors.purple }}
242+
>
243+
Preview
244+
</Button>
245+
)}
246+
{/* {node.link?.url && (
192247
<Box sx={{ display: "flex", gap: 1, flexShrink: 0 }}>
193248
<Button
194249
size="small"
@@ -207,7 +262,7 @@ const FileTreeRow: React.FC<Props> = ({ node, level, onPreview }) => {
207262
>
208263
Preview
209264
</Button>
210-
)}
265+
)} */}
211266
</Box>
212267
)}
213268
</Box>

src/components/DatasetDetailPage/FileTree/utils.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,7 @@ export const buildTreeFromDoc = (
9191
// For primitive items, show "1: value" in the *name*
9292
const isPrimitive =
9393
item === null || ["string", "number", "boolean"].includes(typeof item);
94-
const label = isPrimitive
95-
? `${i + 1}: ${formatLeafValue(item)}`
96-
: String(i + 1); // objects/arrays just show "1", "2", ...
94+
const label = isPrimitive ? `${i}: ${formatLeafValue(item)}` : String(i); // objects/arrays just show "1", "2", ...
9795

9896
if (item && typeof item === "object" && !isPrimitive) {
9997
out.push({

0 commit comments

Comments
 (0)