@@ -28,6 +28,7 @@ interface ExternalDataLink {
2828 size : string ;
2929 path : string ;
3030 url : string ;
31+ index : number ;
3132}
3233
3334const DatasetDetailPage : React . FC = ( ) => {
@@ -74,6 +75,7 @@ const DatasetDetailPage: React.FC = () => {
7475 size,
7576 path : subPath ,
7677 url : correctedUrl ,
78+ index : links . length ,
7779 } ) ;
7880 } else if ( typeof obj [ key ] === "object" ) {
7981 links . push ( ...extractDataLinks ( obj [ key ] , `${ path } /${ key } ` ) ) ;
@@ -95,14 +97,28 @@ const DatasetDetailPage: React.FC = () => {
9597 fetchData ( ) ;
9698 } , [ dbName , docId , dispatch ] ) ;
9799
100+ // useEffect(() => {
101+ // if (datasetDocument) {
102+ // // Extract external links
103+ // const links = extractDataLinks(datasetDocument, "");
104+ // setExternalLinks(links);
105+ // }
106+ // }, [datasetDocument]);
107+
98108 useEffect ( ( ) => {
99109 if ( datasetDocument ) {
100- // Extract external links
101- const links = extractDataLinks ( datasetDocument , "" ) ;
110+ // ✅ Extract links and ensure each link gets a proper `index`
111+ const links = extractDataLinks ( datasetDocument , "" ) . map ( ( link , index ) => ( {
112+ ...link ,
113+ index, // ✅ Assign index correctly
114+ } ) ) ;
115+
116+ console . log ( "🟢 Extracted external links with index:" , links ) ; // Debugging
102117 setExternalLinks ( links ) ;
103118 }
104119 } , [ datasetDocument ] ) ;
105120
121+
106122
107123 // Function to handle the "Preview" functionality
108124 // const handlePreview = (url: string) => {
@@ -127,22 +143,42 @@ const DatasetDetailPage: React.FC = () => {
127143 // setPreviewOpen(true);
128144 // };
129145
130- const handlePreview = ( url : string ) => {
146+ // const handlePreview = (url: string) => {
147+
148+ // // Check if the file is NIfTI (.nii, .nii.gz), JData (.jdt, .jdb), or Mesh (.bmsh, .jmsh)
149+ // if (/\.(nii|nii\.gz|jdt|jdb|bmsh|jmsh|bnii)$/i.test(url)) {
150+ // if (typeof (window as any).previewdataurl === "function") {
151+ // (window as any).previewdataurl(url, 0); // Calls preview immediately
152+ // } else {
153+ // console.error("❌ previewdataurl() is not defined!");
154+ // }
155+ // } else {
156+ // console.warn("⚠️ Unsupported file format for preview:", url);
157+ // }
158+
159+ // setPreviewDataKey(url); // Store the preview key
160+ // setPreviewOpen(true); // Open the preview modal
161+ // };
162+
163+ const handlePreview = ( url : string , idx : number ) => {
164+ console . log ( "🟢 Preview button clicked for:" , url , "Index:" , idx ) ;
131165
132- // Check if the file is NIfTI (.nii, .nii.gz), JData (.jdt, .jdb), or Mesh (.bmsh, .jmsh)
166+ // ✅ Check if the file type is supported
133167 if ( / \. ( n i i | n i i \. g z | j d t | j d b | b m s h | j m s h | b n i i ) $ / i. test ( url ) ) {
134168 if ( typeof ( window as any ) . previewdataurl === "function" ) {
135- ( window as any ) . previewdataurl ( url , 0 ) ; // Calls preview immediately
169+ console . log ( "✅ Calling previewdataurl() for:" , url , "Index:" , idx ) ;
170+ ( window as any ) . previewdataurl ( url , idx ) ; // ✅ Correctly passing `idx`
136171 } else {
137172 console . error ( "❌ previewdataurl() is not defined!" ) ;
138173 }
139174 } else {
140175 console . warn ( "⚠️ Unsupported file format for preview:" , url ) ;
141176 }
142177
143- setPreviewDataKey ( url ) ; // Store the preview key
144- setPreviewOpen ( true ) ; // Open the preview modal
178+ setPreviewDataKey ( url ) ; // ✅ Store the preview key
179+ setPreviewOpen ( true ) ; // ✅ Open the preview modal
145180 } ;
181+
146182
147183 // const handleClosePreview = () => {
148184 // setPreviewOpen(false);
@@ -535,7 +571,8 @@ const DatasetDetailPage: React.FC = () => {
535571 color : Colors . primary . dark ,
536572 } ,
537573 } }
538- onClick = { ( ) => handlePreview ( link . url ) }
574+ onClick = { ( ) => handlePreview ( link . url , link . index ) } // ✅ Ensure `idx` is dynamically set
575+
539576 >
540577 Preview
541578 </ Button >
0 commit comments