Skip to content
Snippets Groups Projects
Commit a2180c19 authored by Giuseppe Digilio's avatar Giuseppe Digilio
Browse files

during submission retrieve surrent collection name by current collection id

parent 062ff5b8
No related branches found
No related tags found
No related merge requests found
......@@ -12,8 +12,7 @@
(click)="onClose()"
[disabled]="(disabled$ | async)"
ngbDropdownToggle>
<span *ngIf="(disabled$ | async)"><i class='fas fa-circle-notch fa-spin'></i></span>
<span *ngIf="!(disabled$ | async)">{{ selectedCollectionName$ | async }}</span>
<span>{{ selectedCollectionName$ | async }}</span>
</button>
<div ngbDropdownMenu
......
......@@ -123,6 +123,9 @@ const mockCommunity2 = Object.assign(new Community(), {
undefined, new PaginatedList(new PageInfo(), []))),
});
const mockCommunity1Collection1Rd = observableOf(new RemoteData(true, true, true,
undefined, mockCommunity1Collection1));
const mockCommunityList = observableOf(new RemoteData(true, true, true,
undefined, new PaginatedList(new PageInfo(), [mockCommunity, mockCommunity2])));
......@@ -202,6 +205,7 @@ describe('SubmissionFormCollectionComponent Component', () => {
});
const collectionDataService: any = jasmine.createSpyObj('collectionDataService', {
findById: jasmine.createSpy('findById'),
getAuthorizedCollectionByCommunity: jasmine.createSpy('getAuthorizedCollectionByCommunity')
});
......@@ -297,6 +301,7 @@ describe('SubmissionFormCollectionComponent Component', () => {
it('should init collection list properly', () => {
communityDataService.findAll.and.returnValue(mockCommunityList);
collectionDataService.findById.and.returnValue(mockCommunity1Collection1Rd);
collectionDataService.getAuthorizedCollectionByCommunity.and.returnValues(mockCommunityCollectionList, mockCommunity2CollectionList);
comp.ngOnChanges({
......@@ -308,9 +313,8 @@ describe('SubmissionFormCollectionComponent Component', () => {
b: mockCollectionList
}));
expect(comp.selectedCollectionName$).toBeObservable(cold('(ab|)', {
a: '',
b: 'Community 1-Collection 1'
expect(comp.selectedCollectionName$).toBeObservable(cold('(a|)', {
a: 'Community 1-Collection 1'
}));
});
......
......@@ -193,6 +193,12 @@ export class SubmissionFormCollectionComponent implements OnChanges, OnInit {
if (hasValue(changes.currentCollectionId)
&& hasValue(changes.currentCollectionId.currentValue)) {
this.selectedCollectionId = this.currentCollectionId;
this.selectedCollectionName$ = this.collectionDataService.findById(this.currentCollectionId).pipe(
find((collectionRD: RemoteData<Collection>) => isNotEmpty(collectionRD.payload)),
map((collectionRD: RemoteData<Collection>) => collectionRD.payload.name)
);
const findOptions: FindAllOptions = {
elementsPerPage: 100
};
......@@ -219,19 +225,6 @@ export class SubmissionFormCollectionComponent implements OnChanges, OnInit {
startWith([])
);
this.selectedCollectionName$ = communities$.pipe(
flatMap((communityData: Community) => {
return communityData.collections.pipe(
find((collections: RemoteData<PaginatedList<Collection>>) => !collections.isResponsePending && collections.hasSucceeded),
mergeMap((collections: RemoteData<PaginatedList<Collection>>) => collections.payload.page),
filter((collectionData: Collection) => isNotEmpty(collectionData)),
filter((collectionData: Collection) => collectionData.id === this.selectedCollectionId),
map((collectionData: Collection) => collectionData.name)
);
}),
startWith('')
);
const searchTerm$ = this.searchField.valueChanges.pipe(
debounceTime(200),
distinctUntilChanged(),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment