@@ -100,6 +100,8 @@ class Browser extends DashboardView {
100
100
processedScripts : 0 ,
101
101
} ;
102
102
103
+ this . addLocation = this . addLocation . bind ( this ) ;
104
+ this . removeLocation = this . removeLocation . bind ( this ) ;
103
105
this . prefetchData = this . prefetchData . bind ( this ) ;
104
106
this . fetchData = this . fetchData . bind ( this ) ;
105
107
this . fetchRelation = this . fetchRelation . bind ( this ) ;
@@ -186,29 +188,18 @@ class Browser extends DashboardView {
186
188
}
187
189
188
190
componentDidMount ( ) {
189
- if ( window . localStorage ) {
190
- const pathname = window . localStorage . getItem ( BROWSER_LAST_LOCATION ) ;
191
- window . localStorage . removeItem ( BROWSER_LAST_LOCATION ) ;
192
- if ( pathname ) {
193
- setTimeout (
194
- function ( ) {
195
- this . props . navigate ( pathname ) ;
196
- } . bind ( this )
197
- ) ;
198
- }
199
- }
191
+ this . addLocation ( this . props . params . appId ) ;
200
192
}
201
193
202
194
componentWillUnmount ( ) {
203
- if ( window . localStorage ) {
204
- window . localStorage . setItem (
205
- BROWSER_LAST_LOCATION ,
206
- this . props . location . pathname + this . props . location . search
207
- ) ;
208
- }
195
+ this . removeLocation ( ) ;
209
196
}
210
197
211
198
componentWillReceiveProps ( nextProps , nextContext ) {
199
+ if ( nextProps . params . appId !== this . props . params . appId ) {
200
+ this . removeLocation ( ) ;
201
+ this . addLocation ( nextProps . params . appId ) ;
202
+ }
212
203
if (
213
204
this . props . params . appId !== nextProps . params . appId ||
214
205
this . props . params . className !== nextProps . params . className ||
@@ -228,6 +219,43 @@ class Browser extends DashboardView {
228
219
}
229
220
}
230
221
222
+ addLocation ( appId ) {
223
+ if ( window . localStorage ) {
224
+ let pathname = null ;
225
+ const newLastLocations = [ ] ;
226
+
227
+ const lastLocations = JSON . parse ( window . localStorage . getItem ( BROWSER_LAST_LOCATION ) ) ;
228
+ lastLocations ?. forEach ( lastLocation => {
229
+ if ( lastLocation . appId !== appId ) {
230
+ newLastLocations . push ( lastLocation ) ;
231
+ } else {
232
+ pathname = lastLocation . location ;
233
+ }
234
+ } ) ;
235
+
236
+ window . localStorage . setItem ( BROWSER_LAST_LOCATION , JSON . stringify ( newLastLocations ) ) ;
237
+ if ( pathname ) {
238
+ setTimeout (
239
+ function ( ) {
240
+ this . props . navigate ( pathname ) ;
241
+ } . bind ( this )
242
+ ) ;
243
+ }
244
+ }
245
+ }
246
+
247
+ removeLocation ( ) {
248
+ if ( window . localStorage ) {
249
+ const lastLocation = {
250
+ appId : this . props . params . appId ,
251
+ location : `${ this . props . location . pathname } ${ this . props . location . search } ` ,
252
+ } ;
253
+ const currentLastLocation = JSON . parse ( window . localStorage . getItem ( BROWSER_LAST_LOCATION ) ) ;
254
+ const updatedLastLocation = [ ...( currentLastLocation || [ ] ) , lastLocation ] ;
255
+ window . localStorage . setItem ( BROWSER_LAST_LOCATION , JSON . stringify ( updatedLastLocation ) ) ;
256
+ }
257
+ }
258
+
231
259
async prefetchData ( props , context ) {
232
260
const filters = this . extractFiltersFromQuery ( props ) ;
233
261
const { className, entityId, relationName } = props . params ;
0 commit comments