mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 18:14:17 +00:00
115046: Fixed issue where relationsToItems would never emit when an empty array was passed to it
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { combineLatest as observableCombineLatest, Observable, zip as observableZip } from 'rxjs';
|
import { combineLatest as observableCombineLatest, Observable, of as observableOf, zip as observableZip } from 'rxjs';
|
||||||
import { distinctUntilChanged, map, mergeMap, switchMap } from 'rxjs/operators';
|
import { distinctUntilChanged, map, mergeMap, switchMap } from 'rxjs/operators';
|
||||||
import { PaginatedList } from '../../../../core/data/paginated-list.model';
|
import { PaginatedList } from '../../../../core/data/paginated-list.model';
|
||||||
import { RemoteData } from '../../../../core/data/remote-data';
|
import { RemoteData } from '../../../../core/data/remote-data';
|
||||||
@@ -46,17 +46,19 @@ export const compareArraysUsingIds = <T extends { id: string }>() =>
|
|||||||
/**
|
/**
|
||||||
* Operator for turning a list of relationships into a list of the relevant items
|
* Operator for turning a list of relationships into a list of the relevant items
|
||||||
* @param {string} thisId The item's id of which the relations belong to
|
* @param {string} thisId The item's id of which the relations belong to
|
||||||
* @returns {(source: Observable<Relationship[]>) => Observable<Item[]>}
|
|
||||||
*/
|
*/
|
||||||
export const relationsToItems = (thisId: string) =>
|
export const relationsToItems = (thisId: string): (source: Observable<Relationship[]>) => Observable<Item[]> =>
|
||||||
(source: Observable<Relationship[]>): Observable<Item[]> =>
|
(source: Observable<Relationship[]>): Observable<Item[]> =>
|
||||||
source.pipe(
|
source.pipe(
|
||||||
mergeMap((rels: Relationship[]) =>
|
mergeMap((relationships: Relationship[]) => {
|
||||||
observableZip(
|
if (relationships.length === 0) {
|
||||||
...rels.map((rel: Relationship) => observableCombineLatest(rel.leftItem, rel.rightItem))
|
return observableOf([]);
|
||||||
)
|
}
|
||||||
),
|
return observableZip(
|
||||||
map((arr) =>
|
...relationships.map((rel: Relationship) => observableCombineLatest([rel.leftItem, rel.rightItem])),
|
||||||
|
);
|
||||||
|
}),
|
||||||
|
map((arr: [RemoteData<Item>, RemoteData<Item>][]) =>
|
||||||
arr
|
arr
|
||||||
.filter(([leftItem, rightItem]) => leftItem.hasSucceeded && rightItem.hasSucceeded)
|
.filter(([leftItem, rightItem]) => leftItem.hasSucceeded && rightItem.hasSucceeded)
|
||||||
.map(([leftItem, rightItem]) => {
|
.map(([leftItem, rightItem]) => {
|
||||||
@@ -75,9 +77,8 @@ export const relationsToItems = (thisId: string) =>
|
|||||||
* Operator for turning a paginated list of relationships into a paginated list of the relevant items
|
* Operator for turning a paginated list of relationships into a paginated list of the relevant items
|
||||||
* The result is wrapped in the original RemoteData and PaginatedList
|
* The result is wrapped in the original RemoteData and PaginatedList
|
||||||
* @param {string} thisId The item's id of which the relations belong to
|
* @param {string} thisId The item's id of which the relations belong to
|
||||||
* @returns {(source: Observable<Relationship[]>) => Observable<Item[]>}
|
|
||||||
*/
|
*/
|
||||||
export const paginatedRelationsToItems = (thisId: string) =>
|
export const paginatedRelationsToItems = (thisId: string): (source: Observable<RemoteData<PaginatedList<Relationship>>>) => Observable<RemoteData<PaginatedList<Item>>> =>
|
||||||
(source: Observable<RemoteData<PaginatedList<Relationship>>>): Observable<RemoteData<PaginatedList<Item>>> =>
|
(source: Observable<RemoteData<PaginatedList<Relationship>>>): Observable<RemoteData<PaginatedList<Item>>> =>
|
||||||
source.pipe(
|
source.pipe(
|
||||||
getFirstSucceededRemoteData(),
|
getFirstSucceededRemoteData(),
|
||||||
|
Reference in New Issue
Block a user