mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 01:54:15 +00:00
Merge pull request #2418 from DSpace/backport-2344-to-dspace-7_x
[Port dspace-7_x] Catch and handle unsuccessful "convert rels to items" responses
This commit is contained in:
@@ -5,8 +5,7 @@ import { RemoteData } from '../../../../core/data/remote-data';
|
|||||||
import { Relationship } from '../../../../core/shared/item-relationships/relationship.model';
|
import { Relationship } from '../../../../core/shared/item-relationships/relationship.model';
|
||||||
import { Item } from '../../../../core/shared/item.model';
|
import { Item } from '../../../../core/shared/item.model';
|
||||||
import {
|
import {
|
||||||
getFirstSucceededRemoteDataPayload,
|
getFirstCompletedRemoteData
|
||||||
getFirstSucceededRemoteData
|
|
||||||
} from '../../../../core/shared/operators';
|
} from '../../../../core/shared/operators';
|
||||||
import { hasValue } from '../../../../shared/empty.util';
|
import { hasValue } from '../../../../shared/empty.util';
|
||||||
import { InjectionToken } from '@angular/core';
|
import { InjectionToken } from '@angular/core';
|
||||||
@@ -77,24 +76,42 @@ export const relationsToItems = (thisId: string) =>
|
|||||||
* @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[]>}
|
* @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.pipe(
|
source.pipe(
|
||||||
getFirstSucceededRemoteData(),
|
getFirstCompletedRemoteData(),
|
||||||
switchMap((relationshipsRD: RemoteData<PaginatedList<Relationship>>) => {
|
switchMap((relationshipsRD: RemoteData<PaginatedList<Relationship>>) => {
|
||||||
return observableCombineLatest(
|
return observableCombineLatest(
|
||||||
relationshipsRD.payload.page.map((rel: Relationship) =>
|
relationshipsRD.payload.page.map((rel: Relationship) =>
|
||||||
observableCombineLatest([
|
observableCombineLatest([
|
||||||
rel.leftItem.pipe(getFirstSucceededRemoteDataPayload()),
|
rel.leftItem.pipe(
|
||||||
rel.rightItem.pipe(getFirstSucceededRemoteDataPayload())]
|
getFirstCompletedRemoteData(),
|
||||||
|
map((rd: RemoteData<Item>) => {
|
||||||
|
if (rd.hasSucceeded) {
|
||||||
|
return rd.payload;
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
),
|
||||||
|
rel.rightItem.pipe(
|
||||||
|
getFirstCompletedRemoteData(),
|
||||||
|
map((rd: RemoteData<Item>) => {
|
||||||
|
if (rd.hasSucceeded) {
|
||||||
|
return rd.payload;
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
),
|
||||||
|
]
|
||||||
)
|
)
|
||||||
)).pipe(
|
)
|
||||||
|
).pipe(
|
||||||
map((arr) =>
|
map((arr) =>
|
||||||
arr
|
arr.map(([leftItem, rightItem]) => {
|
||||||
.map(([leftItem, rightItem]) => {
|
if (hasValue(leftItem) && leftItem.id === thisId) {
|
||||||
if (leftItem.id === thisId) {
|
|
||||||
return rightItem;
|
return rightItem;
|
||||||
} else if (rightItem.id === thisId) {
|
} else if (hasValue(rightItem) && rightItem.id === thisId) {
|
||||||
return leftItem;
|
return leftItem;
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
Reference in New Issue
Block a user