1- import React , { useEffect , useMemo , useState } from 'react' ;
1+ import React , { useEffect , useMemo , useRef , useState } from 'react' ;
22import {
33 apiClient ,
44 DoiContextProvider ,
@@ -25,7 +25,7 @@ import {
2525 FileTypeIcon ,
2626 TFileListingColumns ,
2727} from '@client/common-components' ;
28- import { Link , useParams } from 'react-router-dom' ;
28+ import { Link , useLocation , useParams } from 'react-router-dom' ;
2929import { PublishedEntityDetails } from '../PublishedEntityDetails' ;
3030import { PreviewModalBody } from '../../DatafilesModal/PreviewModal' ;
3131import { SubEntityDetails } from '../SubEntityDetails' ;
@@ -225,6 +225,14 @@ export const PublishedEntityDisplay: React.FC<{
225225 : '' ;
226226 const { data : citationMetrics } = useDataciteMetrics ( dois , ! preview ) ;
227227
228+ const publishedRef = useRef < HTMLElement > ( null ) ;
229+ const location = useLocation ( ) ;
230+ useEffect ( ( ) => {
231+ if ( location . hash === `#detail-${ treeData . uuid } ` ) {
232+ publishedRef . current ?. scrollIntoView ( ) ;
233+ }
234+ } , [ publishedRef , location , treeData . uuid ] ) ;
235+
228236 useEffect ( ( ) => {
229237 if ( active && ! preview ) {
230238 const identifier = dois ?? treeData . uuid ;
@@ -237,7 +245,11 @@ export const PublishedEntityDisplay: React.FC<{
237245 } , [ active , preview , dois , projectId , treeData . name , treeData . uuid ] ) ;
238246
239247 return (
240- < section >
248+ < section
249+ id = { `#detail-${ treeData . uuid } ` }
250+ ref = { publishedRef }
251+ style = { { scrollMargin : '70px' } }
252+ >
241253 < div
242254 className = { styles [ 'pub-show-button' ] }
243255 style = { {
@@ -399,6 +411,8 @@ export const PublicationView: React.FC<{
399411 const { children } = data ?. tree ?? { } ;
400412
401413 const { selectedVersion } = usePublicationVersions ( projectId ) ;
414+ const { hash } = useLocation ( ) ;
415+ const openUuid = hash . split ( '#detail-' ) . slice ( - 1 ) [ 0 ] ;
402416
403417 const sortedChildren = useMemo (
404418 ( ) => [ ...( children ?? [ ] ) ] . sort ( ( a , b ) => ( a . order ?? 0 ) - ( b . order ?? 0 ) ) ,
@@ -420,7 +434,10 @@ export const PublicationView: React.FC<{
420434 license = { data . baseProject . license }
421435 projectId = { projectId }
422436 treeData = { child }
423- defaultOpen = { idx === 0 && sortedChildren . length === 1 }
437+ defaultOpen = {
438+ ( idx === 0 && sortedChildren . length === 1 ) ||
439+ child . uuid === openUuid
440+ }
424441 key = { child . id }
425442 />
426443 </ DoiContextProvider >
0 commit comments