@@ -14,16 +14,26 @@ import PlainButton from '../../components/plain-button/PlainButton';
1414import messages from '../common/messages' ;
1515import type { BoxItem } from '../../common/types/core' ;
1616import { SIDEBAR_VIEW_METADATA } from '../../constants' ;
17+ import type { InternalSidebarNavigation , InternalSidebarNavigationHandler } from '../common/types/SidebarNavigation' ;
1718
1819type Props = {
1920 collection : Array < string | BoxItem > ,
2021 currentIndex : number ,
2122 intl : IntlShape ,
23+ internalSidebarNavigation ?: InternalSidebarNavigation ,
24+ internalSidebarNavigationHandler ?: InternalSidebarNavigationHandler ,
2225 onNavigateLeft : Function ,
2326 onNavigateRight : Function ,
27+ routerDisabled ?: boolean ,
2428} ;
2529
26- const PreviewNavigation = ( { collection = [ ] , currentIndex, intl, onNavigateLeft, onNavigateRight } : Props ) => {
30+ const PreviewNavigationWithRouter = ( {
31+ collection = [ ] ,
32+ currentIndex,
33+ intl,
34+ onNavigateLeft,
35+ onNavigateRight,
36+ } : Props ) => {
2737 const hasLeftNavigation = collection . length > 1 && currentIndex > 0 && currentIndex < collection . length ;
2838 const hasRightNavigation = collection . length > 1 && currentIndex > - 1 && currentIndex < collection . length - 1 ;
2939
@@ -48,6 +58,7 @@ const PreviewNavigation = ({ collection = [], currentIndex, intl, onNavigateLeft
4858 { hasLeftNavigation && (
4959 < PlainButton
5060 className = "bcpr-navigate-left"
61+ data-testid = "preview-navigation-left"
5162 onClick = { ( ) => {
5263 goToActiveSidebarTab ( match . params , history ) ;
5364 onNavigateLeft ( ) ;
@@ -61,6 +72,7 @@ const PreviewNavigation = ({ collection = [], currentIndex, intl, onNavigateLeft
6172 { hasRightNavigation && (
6273 < PlainButton
6374 className = "bcpr-navigate-right"
75+ data-testid = "preview-navigation-right"
6476 onClick = { ( ) => {
6577 goToActiveSidebarTab ( match . params , history ) ;
6678 onNavigateRight ( ) ;
@@ -77,5 +89,77 @@ const PreviewNavigation = ({ collection = [], currentIndex, intl, onNavigateLeft
7789 ) ;
7890} ;
7991
80- export { PreviewNavigation as PreviewNavigationComponent } ;
92+ const PreviewNavigationWithoutRouter = ( {
93+ collection = [ ] ,
94+ currentIndex,
95+ intl,
96+ internalSidebarNavigation,
97+ internalSidebarNavigationHandler,
98+ onNavigateLeft,
99+ onNavigateRight,
100+ } : Props ) => {
101+ const hasLeftNavigation = collection . length > 1 && currentIndex > 0 && currentIndex < collection . length ;
102+ const hasRightNavigation = collection . length > 1 && currentIndex > - 1 && currentIndex < collection . length - 1 ;
103+
104+ if ( ! hasLeftNavigation && ! hasRightNavigation ) {
105+ return null ;
106+ }
107+
108+ const handleInternalNavigation = ( ) => {
109+ if ( internalSidebarNavigationHandler && internalSidebarNavigation && internalSidebarNavigation . sidebar ) {
110+ const { sidebar, ...rest } = internalSidebarNavigation ;
111+ const hasDeeplink = Object . keys ( rest ) . length > 0 ;
112+
113+ if ( hasDeeplink && sidebar === SIDEBAR_VIEW_METADATA ) {
114+ internalSidebarNavigationHandler ( internalSidebarNavigation ) ;
115+ } else {
116+ internalSidebarNavigationHandler ( { sidebar } ) ;
117+ }
118+ }
119+ } ;
120+
121+ return (
122+ < >
123+ { hasLeftNavigation && (
124+ < PlainButton
125+ className = "bcpr-navigate-left"
126+ data-testid = "preview-navigation-left"
127+ onClick = { ( ) => {
128+ handleInternalNavigation ( ) ;
129+ onNavigateLeft ( ) ;
130+ } }
131+ title = { intl . formatMessage ( messages . previousFile ) }
132+ type = "button"
133+ >
134+ < IconNavigateLeft />
135+ </ PlainButton >
136+ ) }
137+ { hasRightNavigation && (
138+ < PlainButton
139+ className = "bcpr-navigate-right"
140+ data-testid = "preview-navigation-right"
141+ onClick = { ( ) => {
142+ handleInternalNavigation ( ) ;
143+ onNavigateRight ( ) ;
144+ } }
145+ title = { intl . formatMessage ( messages . nextFile ) }
146+ type = "button"
147+ >
148+ < IconNavigateRight />
149+ </ PlainButton >
150+ ) }
151+ </ >
152+ ) ;
153+ } ;
154+
155+ const PreviewNavigation = ( props : Props ) => {
156+ const { routerDisabled = false } = props ;
157+
158+ if ( routerDisabled ) {
159+ return < PreviewNavigationWithoutRouter { ...props } /> ;
160+ }
161+
162+ return < PreviewNavigationWithRouter { ...props } /> ;
163+ } ;
164+
81165export default injectIntl ( PreviewNavigation ) ;
0 commit comments