55} from '@angular/common' ;
66import {
77 Component ,
8+ Inject ,
89 Input ,
910 OnDestroy ,
1011 OnInit ,
@@ -33,6 +34,10 @@ import {
3334 take ,
3435} from 'rxjs/operators' ;
3536
37+ import {
38+ APP_CONFIG ,
39+ AppConfig ,
40+ } from '../../../../config/app-config.interface' ;
3641import { getCollectionPageRoute } from '../../../collection-page/collection-page-routing-paths' ;
3742import { getCommunityPageRoute } from '../../../community-page/community-page-routing-paths' ;
3843import { BrowseService } from '../../../core/browse/browse.service' ;
@@ -82,6 +87,7 @@ export class ComcolPageBrowseByComponent implements OnDestroy, OnInit {
8287 subs : Subscription [ ] = [ ] ;
8388
8489 constructor (
90+ @Inject ( APP_CONFIG ) public appConfig : AppConfig ,
8591 public router : Router ,
8692 private browseService : BrowseService ,
8793 ) {
@@ -99,14 +105,14 @@ export class ComcolPageBrowseByComponent implements OnDestroy, OnInit {
99105 allOptions . push ( {
100106 id : 'search' ,
101107 label : 'collection.page.browse.search.head' ,
102- routerLink : comColRoute ,
108+ routerLink : ` ${ comColRoute } /search` ,
103109 } ) ;
104110 } else if ( this . contentType === 'community' ) {
105111 comColRoute = getCommunityPageRoute ( this . id ) ;
106112 allOptions . push ( {
107113 id : 'search' ,
108114 label : 'collection.page.browse.search.head' ,
109- routerLink : comColRoute ,
115+ routerLink : ` ${ comColRoute } /search` ,
110116 } ) ;
111117 allOptions . push ( {
112118 id : 'comcols' ,
@@ -120,11 +126,24 @@ export class ComcolPageBrowseByComponent implements OnDestroy, OnInit {
120126 label : `browse.comcol.by.${ config . id } ` ,
121127 routerLink : `${ comColRoute } /browse/${ config . id } ` ,
122128 } ) ) ) ;
129+
130+ // When the default tab is not the "search" tab, the "search" tab is moved
131+ // at the end of the tabs ribbon for aesthetics purposes.
132+ if ( this . appConfig [ this . contentType ] . defaultBrowseTab !== 'search' ) {
133+ allOptions . push ( allOptions . shift ( ) ) ;
134+ }
123135 }
124136 return allOptions ;
125137 } ) ,
126138 ) ;
127139
140+ let comColRoute : string ;
141+ if ( this . contentType === 'collection' ) {
142+ comColRoute = getCollectionPageRoute ( this . id ) ;
143+ } else if ( this . contentType === 'community' ) {
144+ comColRoute = getCommunityPageRoute ( this . id ) ;
145+ }
146+
128147 this . subs . push ( combineLatest ( [
129148 this . allOptions$ ,
130149 this . router . events . pipe (
@@ -135,11 +154,29 @@ export class ComcolPageBrowseByComponent implements OnDestroy, OnInit {
135154 ) ,
136155 ] ) . subscribe ( ( [ navOptions , url ] : [ ComColPageNavOption [ ] , string ] ) => {
137156 for ( const option of navOptions ) {
138- if ( option . routerLink === url ?. split ( '?' ) [ 0 ] ) {
157+ if ( url ?. split ( '?' ) [ 0 ] === comColRoute && option . id === this . appConfig [ this . contentType ] . defaultBrowseTab ) {
158+ void this . router . navigate ( [ option . routerLink ] , { queryParams : option . params } ) ;
159+ break ;
160+ } else if ( option . routerLink === url ?. split ( '?' ) [ 0 ] ) {
139161 this . currentOption$ . next ( option ) ;
162+ break ;
140163 }
141164 }
142165 } ) ) ;
166+
167+ if ( this . router . url ?. split ( '?' ) [ 0 ] === comColRoute ) {
168+ this . allOptions$ . pipe (
169+ take ( 1 ) ,
170+ ) . subscribe ( ( allOptions : ComColPageNavOption [ ] ) => {
171+ for ( const option of allOptions ) {
172+ if ( option . id === this . appConfig [ this . contentType ] . defaultBrowseTab ) {
173+ this . currentOption$ . next ( option [ 0 ] ) ;
174+ void this . router . navigate ( [ option . routerLink ] , { queryParams : option . params } ) ;
175+ break ;
176+ }
177+ }
178+ } ) ;
179+ }
143180 }
144181
145182 ngOnDestroy ( ) : void {
0 commit comments