[CST-4510] Fix issue with multiple selection in the collection-dropdown.component

This commit is contained in:
Giuseppe Digilio
2021-10-15 19:04:14 +02:00
parent 096a1d8427
commit 7b24e3bc8e
4 changed files with 28 additions and 27 deletions

View File

@@ -18,21 +18,23 @@
[scrollWindow]="false"
(scrolled)="onScrollDown()">
<button class="dropdown-item disabled" *ngIf="searchListCollection?.length == 0 && !(isLoadingList | async)">
<button class="dropdown-item disabled" *ngIf="searchListCollection?.length == 0 && !(isLoading | async)">
{{'submission.sections.general.no-collection' | translate}}
</button>
<button *ngFor="let listItem of searchListCollection"
class="dropdown-item collection-item"
title="{{ listItem.collection.name }}"
(click)="onSelect(listItem)">
<ul class="list-unstyled mb-0">
<li class="list-item text-truncate text-secondary" *ngFor="let item of listItem.communities">
{{ item.name}} <i class="fa fa-level-down" aria-hidden="true"></i>
</li>
<li class="list-item text-truncate text-primary font-weight-bold">{{ listItem.collection.name}}</li>
</ul>
</button>
<button class="dropdown-item disabled" *ngIf="(isLoadingList | async)">
<ng-container *ngIf="searchListCollection?.length > 0 && !(isLoading | async)">
<button *ngFor="let listItem of searchListCollection"
class="dropdown-item collection-item"
title="{{ listItem.collection.name }}"
(click)="onSelect(listItem)">
<ul class="list-unstyled mb-0">
<li class="list-item text-truncate text-secondary" *ngFor="let item of listItem.communities">
{{ item.name}} <i class="fa fa-level-down" aria-hidden="true"></i>
</li>
<li class="list-item text-truncate text-primary font-weight-bold">{{ listItem.collection.name}}</li>
</ul>
</button>
</ng-container>
<button class="dropdown-item disabled" *ngIf="(isLoading | async)">
<ds-loading message="{{'loading.default' | translate}}">
</ds-loading>
</button>

View File

@@ -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', () => {

View File

@@ -87,10 +87,10 @@ export class CollectionDropdownComponent implements OnInit, OnDestroy {
/**
* A boolean representing if the loader is visible or not
*/
isLoadingList: BehaviorSubject<boolean> = new BehaviorSubject(false);
isLoading: BehaviorSubject<boolean> = 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<RemoteData<PaginatedList<Collection>>> = null;
let searchListService$: Observable<RemoteData<PaginatedList<Collection>>>;
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);
}
/**

View File

@@ -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(),