@@ -14,12 +14,10 @@ import React from "react";
1414type 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
2523const 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