diff --git a/src/app/shared/collection-dropdown/collection-dropdown.component.html b/src/app/shared/collection-dropdown/collection-dropdown.component.html index ce5fe0deb8..ccb9cde10d 100644 --- a/src/app/shared/collection-dropdown/collection-dropdown.component.html +++ b/src/app/shared/collection-dropdown/collection-dropdown.component.html @@ -1,42 +1,40 @@ -
- +
+
-
- - + - + + +
diff --git a/src/app/shared/collection-dropdown/collection-dropdown.component.spec.ts b/src/app/shared/collection-dropdown/collection-dropdown.component.spec.ts index 612f5a1733..94cb7c857d 100644 --- a/src/app/shared/collection-dropdown/collection-dropdown.component.spec.ts +++ b/src/app/shared/collection-dropdown/collection-dropdown.component.spec.ts @@ -226,23 +226,11 @@ describe('CollectionDropdownComponent', () => { }); it('should emit hasChoice true when totalElements is greater then one', () => { - spyOn(component.hasChoice, 'emit').and.callThrough(); + spyOn(component.searchComplete, 'emit').and.callThrough(); component.ngOnInit(); fixture.detectChanges(); - expect(component.hasChoice.emit).toHaveBeenCalledWith(true); - }); - - it('should emit hasChoice false when totalElements is not greater then one', () => { - - componentAsAny.collectionDataService.getAuthorizedCollection.and.returnValue(paginatedEmptyCollectionRD$); - componentAsAny.collectionDataService.getAuthorizedCollectionByEntityType.and.returnValue(paginatedEmptyCollectionRD$); - - spyOn(component.hasChoice, 'emit').and.callThrough(); - component.ngOnInit(); - fixture.detectChanges(); - - expect(component.hasChoice.emit).toHaveBeenCalledWith(false); + expect(component.searchComplete.emit).toHaveBeenCalledWith(); }); it('should emit theOnlySelectable when totalElements is equal to one', () => { diff --git a/src/app/shared/collection-dropdown/collection-dropdown.component.ts b/src/app/shared/collection-dropdown/collection-dropdown.component.ts index 6c11613512..9826c554bb 100644 --- a/src/app/shared/collection-dropdown/collection-dropdown.component.ts +++ b/src/app/shared/collection-dropdown/collection-dropdown.component.ts @@ -11,7 +11,7 @@ import { } from '@angular/core'; import { FormControl } from '@angular/forms'; -import { BehaviorSubject, Observable, Subscription } from 'rxjs'; +import { BehaviorSubject, from as observableFrom, Observable, of as observableOf, Subscription } from 'rxjs'; import { debounceTime, distinctUntilChanged, map, mergeMap, reduce, startWith, switchMap, take } from 'rxjs/operators'; import { hasValue } from '../empty.util'; @@ -22,10 +22,7 @@ import { Community } from '../../core/shared/community.model'; import { CollectionDataService } from '../../core/data/collection-data.service'; import { Collection } from '../../core/shared/collection.model'; import { followLink } from '../utils/follow-link-config.model'; -import { - getFirstSucceededRemoteDataPayload, - getFirstSucceededRemoteWithNotEmptyData -} from '../../core/shared/operators'; +import { getFirstCompletedRemoteData, getFirstSucceededRemoteDataPayload } from '../../core/shared/operators'; /** * An interface to represent a collection entry @@ -113,9 +110,9 @@ export class CollectionDropdownComponent implements OnInit, OnDestroy { @Input() entityType: string; /** - * Emit to notify whether collections to choice from are more than one + * Emit to notify whether search is complete */ - @Output() hasChoice = new EventEmitter(); + @Output() searchComplete = new EventEmitter(); /** * Emit to notify the only selectable collection. @@ -213,35 +210,44 @@ export class CollectionDropdownComponent implements OnInit, OnDestroy { query, this.entityType, findOptions, - false, + true, followLink('parentCommunity')); } else { searchListService$ = this.collectionDataService - .getAuthorizedCollection(query, findOptions, true, false, followLink('parentCommunity')); + .getAuthorizedCollection(query, findOptions, true, true, followLink('parentCommunity')); } this.searchListCollection$ = searchListService$.pipe( - getFirstSucceededRemoteWithNotEmptyData(), - switchMap((collections: RemoteData>) => { - if ( (this.searchListCollection.length + findOptions.elementsPerPage) >= collections.payload.totalElements ) { + getFirstCompletedRemoteData(), + switchMap((collectionsRD: RemoteData>) => { + this.searchComplete.emit(); + if (collectionsRD.hasSucceeded && collectionsRD.payload.totalElements > 0) { + if ( (this.searchListCollection.length + findOptions.elementsPerPage) >= collectionsRD.payload.totalElements ) { + this.hasNextPage = false; + this.emitSelectionEvents(collectionsRD); + return observableFrom(collectionsRD.payload.page).pipe( + mergeMap((collection: Collection) => collection.parentCommunity.pipe( + getFirstSucceededRemoteDataPayload(), + map((community: Community) => ({ + communities: [{ id: community.id, name: community.name }], + collection: { id: collection.id, uuid: collection.id, name: collection.name } + }) + ))), + reduce((acc: any, value: any) => [...acc, value], []), + ); + } + } else { this.hasNextPage = false; + return observableOf([]); } - this.emitSelectionEvents(collections); - return collections.payload.page; - }), - mergeMap((collection: Collection) => collection.parentCommunity.pipe( - getFirstSucceededRemoteDataPayload(), - map((community: Community) => ({ - communities: [{ id: community.id, name: community.name }], - collection: { id: collection.id, uuid: collection.id, name: collection.name } - }) - ))), - reduce((acc: any, value: any) => [...acc, value], []), - startWith([]) + }) ); - this.subs.push(this.searchListCollection$.subscribe( - (next) => { this.searchListCollection.push(...next); }, undefined, - () => { this.hideShowLoader(false); this.changeDetectorRef.detectChanges(); } - )); + this.subs.push( + this.searchListCollection$.subscribe((list: CollectionListEntry[]) => { + this.searchListCollection.push(...list); + this.hideShowLoader(false); + this.changeDetectorRef.detectChanges(); + }) + ); } /** @@ -284,7 +290,6 @@ export class CollectionDropdownComponent implements OnInit, OnDestroy { * @private */ private emitSelectionEvents(collections: RemoteData>) { - this.hasChoice.emit(collections.payload.totalElements > 1); if (collections.payload.totalElements === 1) { const collection = collections.payload.page[0]; collections.payload.page[0].parentCommunity.pipe( diff --git a/src/app/submission/import-external/import-external-collection/submission-import-external-collection.component.html b/src/app/submission/import-external/import-external-collection/submission-import-external-collection.component.html index e1f03c40d5..6fb6ab3382 100644 --- a/src/app/submission/import-external/import-external-collection/submission-import-external-collection.component.html +++ b/src/app/submission/import-external/import-external-collection/submission-import-external-collection.component.html @@ -1,5 +1,5 @@
-