From 7b24e3bc8e06781d0bb3694a124725c8674a3d5b Mon Sep 17 00:00:00 2001 From: Giuseppe Digilio Date: Fri, 15 Oct 2021 19:04:14 +0200 Subject: [PATCH] [CST-4510] Fix issue with multiple selection in the collection-dropdown.component --- .../collection-dropdown.component.html | 28 ++++++++++--------- .../collection-dropdown.component.spec.ts | 7 ++--- .../collection-dropdown.component.ts | 16 ++++++----- ...nal-source-entry-import-modal.component.ts | 4 +-- 4 files changed, 28 insertions(+), 27 deletions(-) diff --git a/src/app/shared/collection-dropdown/collection-dropdown.component.html b/src/app/shared/collection-dropdown/collection-dropdown.component.html index ccb9cde10d..831c70ad11 100644 --- a/src/app/shared/collection-dropdown/collection-dropdown.component.html +++ b/src/app/shared/collection-dropdown/collection-dropdown.component.html @@ -18,21 +18,23 @@ [scrollWindow]="false" (scrolled)="onScrollDown()"> - - - + + 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 94cb7c857d..2dc1ee433c 100644 --- a/src/app/shared/collection-dropdown/collection-dropdown.component.spec.ts +++ b/src/app/shared/collection-dropdown/collection-dropdown.component.spec.ts @@ -108,9 +108,6 @@ describe('CollectionDropdownComponent', () => { const paginatedCollection = buildPaginatedList(new PageInfo(), collections); const paginatedCollectionRD$ = createSuccessfulRemoteDataObject$(paginatedCollection); - const paginatedEmptyCollection = buildPaginatedList(new PageInfo(), []); - const paginatedEmptyCollectionRD$ = createSuccessfulRemoteDataObject$(paginatedEmptyCollection); - const paginatedOneElementCollection = buildPaginatedList(new PageInfo(), [collections[0]]); const paginatedOneElementCollectionRD$ = createSuccessfulRemoteDataObject$(paginatedOneElementCollection); @@ -203,10 +200,10 @@ describe('CollectionDropdownComponent', () => { }); it('should change loader status', () => { - spyOn(component.isLoadingList, 'next').and.callThrough(); + spyOn(component.isLoading, 'next').and.callThrough(); component.hideShowLoader(true); - expect(component.isLoadingList.next).toHaveBeenCalledWith(true); + expect(component.isLoading.next).toHaveBeenCalledWith(true); }); it('reset pagination fields', () => { diff --git a/src/app/shared/collection-dropdown/collection-dropdown.component.ts b/src/app/shared/collection-dropdown/collection-dropdown.component.ts index 9826c554bb..d7a341d9b6 100644 --- a/src/app/shared/collection-dropdown/collection-dropdown.component.ts +++ b/src/app/shared/collection-dropdown/collection-dropdown.component.ts @@ -87,10 +87,10 @@ export class CollectionDropdownComponent implements OnInit, OnDestroy { /** * A boolean representing if the loader is visible or not */ - isLoadingList: BehaviorSubject = new BehaviorSubject(false); + isLoading: BehaviorSubject = new BehaviorSubject(false); /** - * A numeric representig current page + * A numeric representing current page */ currentPage: number; @@ -100,7 +100,7 @@ export class CollectionDropdownComponent implements OnInit, OnDestroy { hasNextPage: boolean; /** - * Current seach query used to filter collection list + * Current search query used to filter collection list */ currentQuery: string; @@ -145,6 +145,7 @@ export class CollectionDropdownComponent implements OnInit, OnDestroy { * Initialize collection list */ ngOnInit() { + this.isLoading.next(false); this.subs.push(this.searchField.valueChanges.pipe( debounceTime(500), distinctUntilChanged(), @@ -173,7 +174,7 @@ export class CollectionDropdownComponent implements OnInit, OnDestroy { } /** - * Method used from infitity scroll for retrive more data on scroll down + * Method used from infinity scroll for retrieve more data on scroll down */ onScrollDown() { if ( this.hasNextPage ) { @@ -188,6 +189,7 @@ export class CollectionDropdownComponent implements OnInit, OnDestroy { * the selected [CollectionListEntry] */ onSelect(event: CollectionListEntry) { + this.isLoading.next(true); this.selectionChange.emit(event); } @@ -197,13 +199,13 @@ export class CollectionDropdownComponent implements OnInit, OnDestroy { * @param page page number */ populateCollectionList(query: string, page: number) { - this.isLoadingList.next(true); + this.isLoading.next(true); // Set the pagination info const findOptions: FindListOptions = { elementsPerPage: 10, currentPage: page }; - let searchListService$: Observable>> = null; + let searchListService$: Observable>>; if (this.entityType) { searchListService$ = this.collectionDataService .getAuthorizedCollectionByEntityType( @@ -279,7 +281,7 @@ export class CollectionDropdownComponent implements OnInit, OnDestroy { * @param hideShow true for show, false otherwise */ hideShowLoader(hideShow: boolean) { - this.isLoadingList.next(hideShow); + this.isLoading.next(hideShow); } /** diff --git a/src/app/shared/form/builder/ds-dynamic-form-ui/relation-lookup-modal/external-source-tab/external-source-entry-import-modal/external-source-entry-import-modal.component.ts b/src/app/shared/form/builder/ds-dynamic-form-ui/relation-lookup-modal/external-source-tab/external-source-entry-import-modal/external-source-entry-import-modal.component.ts index e1c2bcc3d4..d586520b64 100644 --- a/src/app/shared/form/builder/ds-dynamic-form-ui/relation-lookup-modal/external-source-tab/external-source-entry-import-modal/external-source-entry-import-modal.component.ts +++ b/src/app/shared/form/builder/ds-dynamic-form-ui/relation-lookup-modal/external-source-tab/external-source-entry-import-modal/external-source-entry-import-modal.component.ts @@ -18,7 +18,7 @@ import { ListableObject } from '../../../../../../object-collection/shared/lista import { ItemDataService } from '../../../../../../../core/data/item-data.service'; import { PaginationComponentOptions } from '../../../../../../pagination/pagination-component-options.model'; import { getFirstSucceededRemoteData, getRemoteDataPayload } from '../../../../../../../core/shared/operators'; -import { mergeMap, take } from 'rxjs/operators'; +import { switchMap, take } from 'rxjs/operators'; import { ItemSearchResult } from '../../../../../../object-collection/shared/item-search-result.model'; import { NotificationsService } from '../../../../../../notifications/notifications.service'; import { TranslateService } from '@ngx-translate/core'; @@ -219,7 +219,7 @@ export class ExternalSourceEntryImportModalComponent implements OnInit { this.modalRef.componentInstance.entityType = this.relatedEntityType.label; this.modalRef.componentInstance.selectedEvent.pipe( - mergeMap((collectionListEntry: CollectionListEntry) => { + switchMap((collectionListEntry: CollectionListEntry) => { return this.itemService.importExternalSourceEntry(this.externalSourceEntry, collectionListEntry.collection.id).pipe( getFirstSucceededRemoteData(), getRemoteDataPayload(),