From f3e4fb9901439021aabd5ccd55f61a5d9e39cbb9 Mon Sep 17 00:00:00 2001 From: Tim Donohue Date: Tue, 21 Jun 2022 16:07:37 -0500 Subject: [PATCH] Fix defaults in Pagination Service --- .../pagination/pagination.service.spec.ts | 23 +++++++++++++++++-- src/app/core/pagination/pagination.service.ts | 6 ++++- .../item-collection-mapper.component.ts | 10 +------- 3 files changed, 27 insertions(+), 12 deletions(-) diff --git a/src/app/core/pagination/pagination.service.spec.ts b/src/app/core/pagination/pagination.service.spec.ts index 94b6b48d59..66349e8a9e 100644 --- a/src/app/core/pagination/pagination.service.spec.ts +++ b/src/app/core/pagination/pagination.service.spec.ts @@ -12,7 +12,7 @@ describe('PaginationService', () => { let routeService; const defaultPagination = new PaginationComponentOptions(); - const defaultSort = new SortOptions('id', SortDirection.DESC); + const defaultSort = new SortOptions('dc.title', SortDirection.ASC); const defaultFindListOptions = new FindListOptions(); beforeEach(() => { @@ -39,7 +39,6 @@ describe('PaginationService', () => { service = new PaginationService(routeService, router); }); - describe('getCurrentPagination', () => { it('should retrieve the current pagination info from the routerService', () => { service.getCurrentPagination('test-id', defaultPagination).subscribe((currentPagination) => { @@ -56,6 +55,26 @@ describe('PaginationService', () => { expect(currentSort).toEqual(Object.assign(new SortOptions('score', SortDirection.ASC ))); }); }); + it('should return default sort when no sort specified', () => { + // This is same as routeService (defined above), but returns no sort field or direction + routeService = { + getQueryParameterValue: (param) => { + let value; + if (param.endsWith('.page')) { + value = 5; + } + if (param.endsWith('.rpp')) { + value = 10; + } + return observableOf(value); + } + }; + service = new PaginationService(routeService, router); + + service.getCurrentSort('test-id', defaultSort).subscribe((currentSort) => { + expect(currentSort).toEqual(defaultSort); + }); + }); }); describe('getFindListOptions', () => { it('should retrieve the current findListOptions info from the routerService', () => { diff --git a/src/app/core/pagination/pagination.service.ts b/src/app/core/pagination/pagination.service.ts index a6f8052c4b..40e13d654f 100644 --- a/src/app/core/pagination/pagination.service.ts +++ b/src/app/core/pagination/pagination.service.ts @@ -24,7 +24,11 @@ import { isNumeric } from '../../shared/numeric.util'; */ export class PaginationService { - private defaultSortOptions = new SortOptions('id', SortDirection.ASC); + /** + * Sort on title ASC by default + * @type {SortOptions} + */ + private defaultSortOptions = new SortOptions('dc.title', SortDirection.ASC); private clearParams = {}; diff --git a/src/app/item-page/edit-item-page/item-collection-mapper/item-collection-mapper.component.ts b/src/app/item-page/edit-item-page/item-collection-mapper/item-collection-mapper.component.ts index f5a9461b5b..a71fe5b385 100644 --- a/src/app/item-page/edit-item-page/item-collection-mapper/item-collection-mapper.component.ts +++ b/src/app/item-page/edit-item-page/item-collection-mapper/item-collection-mapper.component.ts @@ -28,7 +28,6 @@ import { SearchConfigurationService } from '../../../core/shared/search/search-c import { SearchService } from '../../../core/shared/search/search.service'; import { NoContent } from '../../../core/shared/NoContent.model'; import { getItemPageRoute } from '../../item-page-routing-paths'; -import { SortDirection, SortOptions } from '../../../core/cache/models/sort-options.model'; @Component({ selector: 'ds-item-collection-mapper', @@ -74,12 +73,6 @@ export class ItemCollectionMapperComponent implements OnInit { */ mappedCollectionsRD$: Observable>>; - /** - * Sort on title ASC by default - * @type {SortOptions} - */ - defaultSortOptions: SortOptions = new SortOptions('dc.title', SortDirection.ASC); - /** * Firing this observable (shouldUpdate$.next(true)) forces the two lists to reload themselves * Usually fired after the lists their cache is cleared (to force a new request to the REST API) @@ -156,8 +149,7 @@ export class ItemCollectionMapperComponent implements OnInit { switchMap(([itemCollectionsRD, owningCollectionRD, searchOptions]) => { return this.searchService.search(Object.assign(new PaginatedSearchOptions(searchOptions), { query: this.buildQuery([...itemCollectionsRD.payload.page, owningCollectionRD.payload], searchOptions.query), - dsoTypes: [DSpaceObjectType.COLLECTION], - sort: this.defaultSortOptions + dsoTypes: [DSpaceObjectType.COLLECTION] }), 10000).pipe( toDSpaceObjectListRD(), startWith(undefined)