@@ -10,13 +10,14 @@ import flow from 'lodash/flow';
10
10
import getProp from 'lodash/get' ;
11
11
import noop from 'lodash/noop' ;
12
12
import uniqueid from 'lodash/uniqueId' ;
13
- import { withRouter } from 'react-router-dom' ;
13
+ import { matchPath , withRouter } from 'react-router-dom' ;
14
14
import type { Location , RouterHistory } from 'react-router-dom' ;
15
15
import LoadingIndicator from '../../components/loading-indicator/LoadingIndicator' ;
16
16
import LocalStore from '../../utils/LocalStore' ;
17
17
import SidebarNav from './SidebarNav' ;
18
18
import SidebarPanels from './SidebarPanels' ;
19
19
import SidebarUtils from './SidebarUtils' ;
20
+ import { SIDEBAR_PATH_VERSIONS } from '../../constants' ;
20
21
import { withCurrentUser } from '../common/current-user' ;
21
22
import { withFeatureConsumer } from '../common/feature-checking' ;
22
23
import type { FeatureConfig } from '../common/feature-checking' ;
@@ -97,7 +98,7 @@ class Sidebar extends React.Component<Props, State> {
97
98
}
98
99
99
100
componentDidUpdate ( prevProps : Props ) : void {
100
- const { fileId , history , location } : Props = this . props ;
101
+ const { fileId , history , location , onVersionChange } : Props = this . props ;
101
102
const { fileId : prevFileId , location : prevLocation } : Props = prevProps ;
102
103
const { isDirty } : State = this . state ;
103
104
@@ -111,8 +112,18 @@ class Sidebar extends React.Component<Props, State> {
111
112
this . setForcedByLocation ( ) ;
112
113
this . setState ( { isDirty : true } ) ;
113
114
}
115
+
116
+ // Reset the current version id if the wrapping versions route is no longer active
117
+ if ( onVersionChange && this . getVersionsMatchPath ( prevLocation ) && ! this . getVersionsMatchPath ( location ) ) {
118
+ onVersionChange ( null ) ;
119
+ }
114
120
}
115
121
122
+ getVersionsMatchPath = ( location : Location ) => {
123
+ const pathname = getProp ( location , 'pathname' , '' ) ;
124
+ return matchPath ( pathname , SIDEBAR_PATH_VERSIONS ) ;
125
+ } ;
126
+
116
127
getUrlPrefix = ( pathname : string ) => {
117
128
const basePath = pathname . substring ( 1 ) . split ( '/' ) [ 0 ] ;
118
129
return basePath ;
0 commit comments