During submission retrieve collection list only at first load

This commit is contained in:
Giuseppe Digilio
2019-07-25 19:16:08 +02:00
parent 2ff1b88bac
commit 50024c8c55

View File

@@ -209,43 +209,46 @@ export class SubmissionFormCollectionComponent implements OnChanges, OnInit {
elementsPerPage: 100 elementsPerPage: 100
}; };
// @TODO replace with search/top browse endpoint // Retrieve collection list only when is the first change
// @TODO implement community/subcommunity hierarchy if (changes.currentCollectionId.isFirstChange()) {
const communities$ = this.communityDataService.findAll(findOptions).pipe( // @TODO replace with search/top browse endpoint
find((communities: RemoteData<PaginatedList<Community>>) => isNotEmpty(communities.payload)), // @TODO implement community/subcommunity hierarchy
mergeMap((communities: RemoteData<PaginatedList<Community>>) => communities.payload.page)); const communities$ = this.communityDataService.findAll(findOptions).pipe(
find((communities: RemoteData<PaginatedList<Community>>) => isNotEmpty(communities.payload)),
mergeMap((communities: RemoteData<PaginatedList<Community>>) => communities.payload.page));
const listCollection$ = communities$.pipe( const listCollection$ = communities$.pipe(
flatMap((communityData: Community) => { flatMap((communityData: Community) => {
return this.collectionDataService.getAuthorizedCollectionByCommunity(communityData.uuid).pipe( return this.collectionDataService.getAuthorizedCollectionByCommunity(communityData.uuid).pipe(
find((collections: RemoteData<PaginatedList<Collection>>) => !collections.isResponsePending && collections.hasSucceeded), find((collections: RemoteData<PaginatedList<Collection>>) => !collections.isResponsePending && collections.hasSucceeded),
mergeMap((collections: RemoteData<PaginatedList<Collection>>) => collections.payload.page), mergeMap((collections: RemoteData<PaginatedList<Collection>>) => collections.payload.page),
filter((collectionData: Collection) => isNotEmpty(collectionData)), filter((collectionData: Collection) => isNotEmpty(collectionData)),
map((collectionData: Collection) => ({ map((collectionData: Collection) => ({
communities: [{ id: communityData.id, name: communityData.name }], communities: [{ id: communityData.id, name: communityData.name }],
collection: { id: collectionData.id, name: collectionData.name } collection: { id: collectionData.id, name: collectionData.name }
})) }))
); );
}), }),
reduce((acc: any, value: any) => [...acc, ...value], []), reduce((acc: any, value: any) => [...acc, ...value], []),
startWith([]) startWith([])
); );
const searchTerm$ = this.searchField.valueChanges.pipe( const searchTerm$ = this.searchField.valueChanges.pipe(
debounceTime(200), debounceTime(200),
distinctUntilChanged(), distinctUntilChanged(),
startWith('') startWith('')
); );
this.searchListCollection$ = combineLatest(searchTerm$, listCollection$).pipe( this.searchListCollection$ = combineLatest(searchTerm$, listCollection$).pipe(
map(([searchTerm, listCollection]) => { map(([searchTerm, listCollection]) => {
this.disabled$.next(isEmpty(listCollection)); this.disabled$.next(isEmpty(listCollection));
if (isEmpty(searchTerm)) { if (isEmpty(searchTerm)) {
return listCollection; return listCollection;
} else { } else {
return listCollection.filter((v) => v.collection.name.toLowerCase().indexOf(searchTerm.toLowerCase()) > -1).slice(0, 5); return listCollection.filter((v) => v.collection.name.toLowerCase().indexOf(searchTerm.toLowerCase()) > -1).slice(0, 5);
} }
})); }));
}
} }
} }