Skip to content

Commit 2eb1a17

Browse files
committed
Refactor subgroups-list component's "search()" to act same as member-list component's "search()". Avoids reloading the page as frequently.
1 parent 8a10888 commit 2eb1a17

1 file changed

Lines changed: 31 additions & 18 deletions

File tree

src/app/access-control/group-registry/group-form/subgroup-list/subgroups-list.component.ts

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@ import { UntypedFormBuilder } from '@angular/forms';
33
import { Router } from '@angular/router';
44
import { TranslateService } from '@ngx-translate/core';
55
import { BehaviorSubject, Observable, Subscription } from 'rxjs';
6-
import { switchMap, take } from 'rxjs/operators';
6+
import { map, switchMap, take } from 'rxjs/operators';
77
import { PaginatedList } from '../../../../core/data/paginated-list.model';
88
import { RemoteData } from '../../../../core/data/remote-data';
99
import { GroupDataService } from '../../../../core/eperson/group-data.service';
1010
import { Group } from '../../../../core/eperson/models/group.model';
1111
import {
12+
getAllCompletedRemoteData,
1213
getFirstCompletedRemoteData
1314
} from '../../../../core/shared/operators';
1415
import { 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

Comments
 (0)