@@ -3,7 +3,6 @@ import CloudDownloadIcon from "@mui/icons-material/CloudDownload";
33import DescriptionIcon from "@mui/icons-material/Description" ;
44import ExpandLess from "@mui/icons-material/ExpandLess" ;
55import ExpandMore from "@mui/icons-material/ExpandMore" ;
6- // import FolderIcon from "@mui/icons-material/Folder";
76import HomeIcon from "@mui/icons-material/Home" ;
87import {
98 Box ,
@@ -27,12 +26,13 @@ import { useAppDispatch } from "hooks/useAppDispatch";
2726import { useAppSelector } from "hooks/useAppSelector" ;
2827import React , { useEffect , useMemo , useState } from "react" ;
2928// import ReactJson from "react-json-view";
30- import { useParams , useNavigate } from "react-router-dom" ;
29+ import { useParams , useNavigate , useSearchParams } from "react-router-dom" ;
3130import {
3231 fetchDocumentDetails ,
3332 fetchDbInfoByDatasetId ,
3433} from "redux/neurojson/neurojson.action" ;
3534import { NeurojsonSelector } from "redux/neurojson/neurojson.selector" ;
35+ import { NeurojsonService } from "services/neurojson.service" ;
3636import RoutesEnum from "types/routes.enum" ;
3737
3838interface ExternalDataLink {
@@ -54,6 +54,19 @@ interface InternalDataLink {
5454const UpdatedDatasetDetailPage : React . FC = ( ) => {
5555 const { dbName, docId } = useParams < { dbName : string ; docId : string } > ( ) ;
5656 const navigate = useNavigate ( ) ;
57+ // for revision
58+ const [ searchParams , setSearchParams ] = useSearchParams ( ) ;
59+ const rev = searchParams . get ( "rev" ) || undefined ;
60+
61+ const handleSelectRevision = ( newRev ?: string | null ) => {
62+ setSearchParams ( ( prev ) => {
63+ const p = new URLSearchParams ( prev ) ;
64+ if ( newRev ) p . set ( "rev" , newRev ) ;
65+ else p . delete ( "rev" ) ;
66+ return p ;
67+ } ) ;
68+ } ;
69+
5770 const dispatch = useAppDispatch ( ) ;
5871 const {
5972 selectedDocument : datasetDocument ,
@@ -257,10 +270,21 @@ const UpdatedDatasetDetailPage: React.FC = () => {
257270 if ( ! dbName || ! docId ) return ;
258271
259272 ( async ( ) => {
260- await dispatch ( fetchDocumentDetails ( { dbName, docId } ) ) ; // render tree ASAP
261- dispatch ( fetchDbInfoByDatasetId ( { dbName, docId } ) ) ; // don't await
273+ await dispatch ( fetchDocumentDetails ( { dbName, docId, rev } ) ) ; // for dataset detail
274+ dispatch ( fetchDbInfoByDatasetId ( { dbName, docId } ) ) ; // for metadata panel (include modality)
262275 } ) ( ) ;
263- } , [ dbName , docId , dispatch ] ) ;
276+ } , [ dbName , docId , rev , dispatch ] ) ;
277+ // for revs list storage
278+ const [ revsList , setRevsList ] = React . useState < { rev : string } [ ] > ( [ ] ) ;
279+
280+ useEffect ( ( ) => {
281+ const fromDoc = Array . isArray ( datasetDocument ?. _revs_info )
282+ ? ( datasetDocument . _revs_info as { rev : string } [ ] )
283+ : [ ] ;
284+ if ( fromDoc . length && revsList . length === 0 ) {
285+ setRevsList ( fromDoc ) ;
286+ }
287+ } , [ datasetDocument , revsList . length ] ) ;
264288
265289 useEffect ( ( ) => {
266290 if ( datasetDocument ) {
@@ -840,6 +864,10 @@ const UpdatedDatasetDetailPage: React.FC = () => {
840864 dbViewInfo = { dbViewInfo }
841865 dbName = { dbName }
842866 docId = { docId }
867+ // new props:
868+ currentRev = { rev } // reflect URL selection
869+ onChangeRev = { handleSelectRevision }
870+ revsList = { revsList }
843871 />
844872 </ Box >
845873 </ Box >
0 commit comments