@@ -68,6 +68,7 @@ import {
6868 fetchDbInfoByDatasetId ,
6969} from "redux/neurojson/neurojson.action" ;
7070import { NeurojsonSelector } from "redux/neurojson/neurojson.selector" ;
71+ import { resetDocument } from "redux/neurojson/neurojson.slice" ;
7172// import { NeurojsonService } from "services/neurojson.service";
7273import RoutesEnum from "types/routes.enum" ;
7374
@@ -262,7 +263,7 @@ const UpdatedDatasetDetailPage: React.FC = () => {
262263 const [ searchParams , setSearchParams ] = useSearchParams ( ) ;
263264 const focus = searchParams . get ( "focus" ) || undefined ; // get highlight from url
264265 const rev = searchParams . get ( "rev" ) || undefined ; // get revision from url
265-
266+ const [ chart2DPreviewPath , setChart2DPreviewPath ] = useState < string > ( "" ) ;
266267 const [ externalLinks , setExternalLinks ] = useState < ExternalDataLink [ ] > ( [ ] ) ;
267268 const [ internalLinks , setInternalLinks ] = useState < InternalDataLink [ ] > ( [ ] ) ;
268269 const [ isInternalExpanded , setIsInternalExpanded ] = useState ( true ) ;
@@ -284,6 +285,14 @@ const UpdatedDatasetDetailPage: React.FC = () => {
284285 ? rawSummary
285286 : Object . values ( rawSummary ) . filter ( Boolean ) . join ( "\n\n" ) ;
286287 const readme = datasetDocument ?. [ "README" ] ?? "" ;
288+
289+ useEffect ( ( ) => {
290+ window . __clear2DPath = ( ) => setChart2DPreviewPath ( "" ) ;
291+ return ( ) => {
292+ delete window . __clear2DPath ;
293+ } ;
294+ } , [ ] ) ;
295+
287296 const handleSelectRevision = ( newRev ?: string | null ) => {
288297 setSearchParams ( ( prev ) => {
289298 const p = new URLSearchParams ( prev ) ; // copy of the query url
@@ -335,7 +344,7 @@ const UpdatedDatasetDetailPage: React.FC = () => {
335344 : "Unknown Size" ;
336345
337346 const parts = currentPath . split ( "/" ) ;
338- const subpath = parts . slice ( - 3 ) . join ( "/" ) ;
347+ const subpath = parts . slice ( - 6 ) . join ( "/" ) ;
339348 const label = parentKey || "ExternalData" ;
340349
341350 links . push ( {
@@ -478,6 +487,12 @@ const UpdatedDatasetDetailPage: React.FC = () => {
478487 } ;
479488 } , [ ] ) ;
480489
490+ // clean old dataset detail and metadata panel(include rev)
491+ useEffect ( ( ) => {
492+ dispatch ( resetDocument ( ) ) ; // clear redux state
493+ setRevsList ( [ ] ) ; // clear local state
494+ } , [ dbName , docId , dispatch ] ) ;
495+
481496 useEffect ( ( ) => {
482497 if ( ! dbName || ! docId ) return ;
483498
@@ -493,10 +508,10 @@ const UpdatedDatasetDetailPage: React.FC = () => {
493508 const fromDoc = Array . isArray ( datasetDocument ?. _revs_info )
494509 ? ( datasetDocument . _revs_info as { rev : string } [ ] )
495510 : [ ] ;
496- if ( fromDoc . length && revsList . length === 0 ) {
497- setRevsList ( fromDoc ) ;
511+ if ( fromDoc . length > 0 ) {
512+ setRevsList ( fromDoc ) ; // only update when we have revisions
498513 }
499- } , [ datasetDocument , revsList . length ] ) ;
514+ } , [ datasetDocument ] ) ;
500515
501516 useEffect ( ( ) => {
502517 if ( datasetDocument ) {
@@ -625,7 +640,9 @@ const UpdatedDatasetDetailPage: React.FC = () => {
625640 const handlePreview = (
626641 dataOrUrl : string | any ,
627642 idx : number ,
628- isInternal : boolean = false
643+ isInternal : boolean = false ,
644+ previewPath : string = "" ,
645+ displayNumber ?: number
629646 ) => {
630647 // console.log(
631648 // "🟢 Preview button clicked for:",
@@ -635,6 +652,9 @@ const UpdatedDatasetDetailPage: React.FC = () => {
635652 // "Is Internal:",
636653 // isInternal
637654 // );
655+ setChart2DPreviewPath (
656+ displayNumber ? `[${ displayNumber } ] ${ previewPath } ` : previewPath
657+ ) ;
638658
639659 // Clear any stale preview type from last run
640660 delete ( window as any ) . __previewType ;
@@ -783,14 +803,14 @@ const UpdatedDatasetDetailPage: React.FC = () => {
783803 // Try internal data first
784804 const internal = internalMap . get ( previewPath ) ;
785805 if ( internal ) {
786- handlePreview ( internal . data , internal . index , true ) ;
806+ handlePreview ( internal . data , internal . index , true , previewPath ) ;
787807 return ;
788808 }
789809
790810 // Then try external data by JSON path
791811 const external = linkMap . get ( previewPath ) ;
792812 if ( external ) {
793- handlePreview ( external . url , external . index , false ) ;
813+ handlePreview ( external . url , external . index , false , previewPath ) ;
794814 }
795815 } , [
796816 datasetDocument ,
@@ -1324,7 +1344,12 @@ const UpdatedDatasetDetailPage: React.FC = () => {
13241344 } ,
13251345 } }
13261346 onClick = { ( ) =>
1327- handlePreview ( link . data , link . index , true )
1347+ handlePreview (
1348+ link . data ,
1349+ link . index ,
1350+ true ,
1351+ link . path
1352+ )
13281353 }
13291354 >
13301355 Preview
@@ -1463,7 +1488,7 @@ const UpdatedDatasetDetailPage: React.FC = () => {
14631488 } }
14641489 title = { link . name }
14651490 >
1466- { link . name }
1491+ { index + 1 } . { link . name }
14671492 </ Typography >
14681493 < Box sx = { { display : "flex" , flexShrink : 0 , gap : 1 } } >
14691494 < Button
@@ -1500,7 +1525,13 @@ const UpdatedDatasetDetailPage: React.FC = () => {
15001525 } ,
15011526 } }
15021527 onClick = { ( ) =>
1503- handlePreview ( link . url , link . index , false )
1528+ handlePreview (
1529+ link . url ,
1530+ link . index ,
1531+ false ,
1532+ link . path ,
1533+ index + 1
1534+ )
15041535 }
15051536 >
15061537 Preview
@@ -1563,12 +1594,24 @@ const UpdatedDatasetDetailPage: React.FC = () => {
15631594 </ Box >
15641595 </ Box >
15651596
1597+ { chart2DPreviewPath && (
1598+ < Typography
1599+ sx = { {
1600+ mt : 2 ,
1601+ mb : 0.5 ,
1602+ fontSize : "0.85rem" ,
1603+ color : Colors . lightBlue ,
1604+ } }
1605+ >
1606+ Previewing: { chart2DPreviewPath }
1607+ </ Typography >
1608+ ) }
15661609 < div
15671610 id = "chartpanel"
15681611 style = { {
15691612 display : "none" ,
15701613 marginTop : "16px" ,
1571- background : Colors . darkGray ,
1614+ background : Colors . lightGray ,
15721615 color : Colors . black ,
15731616 padding : "12px" ,
15741617 borderRadius : "8px" ,
0 commit comments