@@ -3,12 +3,13 @@ import { UntypedFormBuilder } from '@angular/forms';
33import { Router } from '@angular/router' ;
44import { TranslateService } from '@ngx-translate/core' ;
55import { BehaviorSubject , Observable , Subscription } from 'rxjs' ;
6- import { switchMap , take } from 'rxjs/operators' ;
6+ import { map , switchMap , take } from 'rxjs/operators' ;
77import { PaginatedList } from '../../../../core/data/paginated-list.model' ;
88import { RemoteData } from '../../../../core/data/remote-data' ;
99import { GroupDataService } from '../../../../core/eperson/group-data.service' ;
1010import { Group } from '../../../../core/eperson/models/group.model' ;
1111import {
12+ getAllCompletedRemoteData ,
1213 getFirstCompletedRemoteData
1314} from '../../../../core/shared/operators' ;
1415import { NotificationsService } from '../../../../shared/notifications/notifications.service' ;
@@ -179,24 +180,36 @@ export class SubgroupsListComponent implements OnInit, OnDestroy {
179180 * @param data Contains query param
180181 */
181182 search ( data : any ) {
182- const query : string = data . query ;
183- if ( query != null && this . currentSearchQuery !== query ) {
184- this . router . navigateByUrl ( this . groupDataService . getGroupEditPageRouterLink ( this . groupBeingEdited ) ) ;
185- this . currentSearchQuery = query ;
186- this . configSearch . currentPage = 1 ;
187- }
188- this . searchDone = true ;
189-
190183 this . unsubFrom ( SubKey . SearchResults ) ;
191- this . subs . set ( SubKey . SearchResults , this . paginationService . getCurrentPagination ( this . configSearch . id , this . configSearch ) . pipe (
192- switchMap ( ( config ) => this . groupDataService . searchNonMemberGroups ( this . currentSearchQuery , this . groupBeingEdited . id , {
193- currentPage : config . currentPage ,
194- elementsPerPage : config . pageSize
195- } , false , true , followLink ( 'object' )
196- ) )
197- ) . subscribe ( ( rd : RemoteData < PaginatedList < Group > > ) => {
198- this . searchResults$ . next ( rd ) ;
199- } ) ) ;
184+ this . subs . set ( SubKey . SearchResults ,
185+ this . paginationService . getCurrentPagination ( this . configSearch . id , this . configSearch ) . pipe (
186+ switchMap ( ( paginationOptions ) => {
187+ const query : string = data . query ;
188+ if ( query != null && this . currentSearchQuery !== query && this . groupBeingEdited ) {
189+ this . router . navigate ( [ ] , {
190+ queryParamsHandling : 'merge'
191+ } ) ;
192+ this . currentSearchQuery = query ;
193+ this . paginationService . resetPage ( this . configSearch . id ) ;
194+ }
195+ this . searchDone = true ;
196+
197+ return this . groupDataService . searchNonMemberGroups ( this . currentSearchQuery , this . groupBeingEdited . id , {
198+ currentPage : paginationOptions . currentPage ,
199+ elementsPerPage : paginationOptions . pageSize
200+ } , false , true , followLink ( 'object' ) ) ;
201+ } ) ,
202+ getAllCompletedRemoteData ( ) ,
203+ map ( ( rd : RemoteData < any > ) => {
204+ if ( rd . hasFailed ) {
205+ this . notificationsService . error ( this . translateService . get ( this . messagePrefix + '.notification.failure' , { cause : rd . errorMessage } ) ) ;
206+ } else {
207+ return rd ;
208+ }
209+ } ) )
210+ . subscribe ( ( rd : RemoteData < PaginatedList < Group > > ) => {
211+ this . searchResults$ . next ( rd ) ;
212+ } ) ) ;
200213 }
201214
202215 /**
0 commit comments