1
1
import { SelectionModel } from '@angular/cdk/collections' ;
2
2
import { Directive , inject , Input , OnInit } from '@angular/core' ;
3
+ import { takeUntilDestroyed } from '@angular/core/rxjs-interop' ;
3
4
import { PageEvent } from '@angular/material/paginator' ;
4
5
import { Sort } from '@angular/material/sort' ;
5
- import { ActivatedRoute , Data , NavigationEnd , NavigationExtras , NavigationStart , Router } from '@angular/router' ;
6
+ import { ActivatedRoute , Data , NavigationExtras , Router } from '@angular/router' ;
6
7
import { defaults , isEmpty , isEqual , pick } from 'lodash-es' ;
7
8
import { Observable , Subject } from 'rxjs' ;
8
9
import { NaturalAlertService } from '../modules/alert/alert.service' ;
10
+ import { AvailableColumn } from '../modules/columns-picker/types' ;
9
11
import { NaturalAbstractPanel } from '../modules/panels/abstract-panel' ;
10
12
import { toGraphQLDoctrineFilter } from '../modules/search/classes/graphql-doctrine' ;
11
13
import { fromUrl , toUrl } from '../modules/search/classes/url' ;
12
14
import { NaturalSearchFacets } from '../modules/search/types/facet' ;
13
15
import { NaturalSearchSelections } from '../modules/search/types/values' ;
14
16
import { NaturalAbstractModelService } from '../services/abstract-model.service' ;
15
17
import { NaturalPersistenceService } from '../services/persistence.service' ;
18
+ import { ExtractTall , ExtractVall , Literal } from '../types/types' ;
19
+ import { NavigableItem } from './abstract-navigable-list' ;
16
20
import { NaturalDataSource , PaginatedData } from './data-source' ;
17
21
import {
18
22
NaturalQueryVariablesManager ,
@@ -21,12 +25,7 @@ import {
21
25
Sorting ,
22
26
SortingOrder ,
23
27
} from './query-variable-manager' ;
24
- import { ExtractTall , ExtractVall , Literal } from '../types/types' ;
25
- import { NavigableItem } from './abstract-navigable-list' ;
26
- import { filter } from 'rxjs/operators' ;
27
- import { AvailableColumn } from '../modules/columns-picker/types' ;
28
- import { validateColumns , validatePagination , validateSorting } from './utility' ;
29
- import { takeUntilDestroyed } from '@angular/core/rxjs-interop' ;
28
+ import { onHistoryEvent , validateColumns , validatePagination , validateSorting } from './utility' ;
30
29
31
30
type MaybeNavigable = Literal | NavigableItem < Literal > ;
32
31
@@ -195,35 +194,15 @@ export class NaturalAbstractList<
195
194
}
196
195
197
196
protected handleHistoryNavigation ( ) : void {
198
- // Update natural search when history changes (back/forward buttons)
199
- // History state is detectable only on NavigationStart (popstate trigger)
200
- // But we need parameters from url after NavigationEnd. So proceed in two steps with a flag.
201
- let isPopState = false ;
202
- this . router . events
203
- . pipe (
204
- takeUntilDestroyed ( this . destroyRef ) ,
205
- filter ( event => event instanceof NavigationStart && event . navigationTrigger === 'popstate' ) ,
206
- )
207
- . subscribe ( ( ) => ( isPopState = true ) ) ;
208
-
209
- this . router . events
210
- . pipe (
211
- takeUntilDestroyed ( this . destroyRef ) ,
212
- filter ( event => event instanceof NavigationEnd && isPopState ) ,
213
- filter ( ( ) => this . historyNavigationFilter ( ) ) ,
214
- )
197
+ onHistoryEvent ( this . router )
198
+ . pipe ( takeUntilDestroyed ( this . destroyRef ) )
215
199
. subscribe ( ( ) => {
216
- isPopState = false ; // reset flag
217
200
const selections = fromUrl ( this . persistenceService . getFromUrl ( 'ns' , this . route ) ) ;
218
201
this . naturalSearchSelections = selections ;
219
202
this . search ( selections ) ;
220
203
} ) ;
221
204
}
222
205
223
- protected historyNavigationFilter ( ) : boolean {
224
- return true ;
225
- }
226
-
227
206
/**
228
207
* Persist search and then launch whatever is required to refresh the list
229
208
*/
0 commit comments