Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Port dspace-7_x] Catch and handle unsuccessful "convert rels to items" responses #2418

Merged
merged 1 commit into from
Aug 3, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
import { Relationship } from '../../../../core/shared/item-relationships/relationship.model';
import { Item } from '../../../../core/shared/item.model';
import {
getFirstSucceededRemoteDataPayload,
getFirstSucceededRemoteData
getFirstCompletedRemoteData
} from '../../../../core/shared/operators';
import { hasValue } from '../../../../shared/empty.util';
import { InjectionToken } from '@angular/core';
Expand Down Expand Up @@ -77,24 +76,42 @@
* @param {string} thisId The item's id of which the relations belong to
* @returns {(source: Observable<Relationship[]>) => Observable<Item[]>}
*/
export const paginatedRelationsToItems = (thisId: string) =>
(source: Observable<RemoteData<PaginatedList<Relationship>>>): Observable<RemoteData<PaginatedList<Item>>> =>
export const paginatedRelationsToItems = (thisId: string) => (source: Observable<RemoteData<PaginatedList<Relationship>>>): Observable<RemoteData<PaginatedList<Item>>> =>
source.pipe(
getFirstSucceededRemoteData(),
getFirstCompletedRemoteData(),
switchMap((relationshipsRD: RemoteData<PaginatedList<Relationship>>) => {
return observableCombineLatest(
relationshipsRD.payload.page.map((rel: Relationship) =>
observableCombineLatest([
rel.leftItem.pipe(getFirstSucceededRemoteDataPayload()),
rel.rightItem.pipe(getFirstSucceededRemoteDataPayload())]
rel.leftItem.pipe(
getFirstCompletedRemoteData(),
map((rd: RemoteData<Item>) => {
if (rd.hasSucceeded) {
return rd.payload;

Check warning on line 90 in src/app/item-page/simple/item-types/shared/item-relationships-utils.ts

View check run for this annotation

Codecov / codecov/patch

src/app/item-page/simple/item-types/shared/item-relationships-utils.ts#L90

Added line #L90 was not covered by tests
} else {
return null;

Check warning on line 92 in src/app/item-page/simple/item-types/shared/item-relationships-utils.ts

View check run for this annotation

Codecov / codecov/patch

src/app/item-page/simple/item-types/shared/item-relationships-utils.ts#L92

Added line #L92 was not covered by tests
}
})
),
rel.rightItem.pipe(
getFirstCompletedRemoteData(),
map((rd: RemoteData<Item>) => {
if (rd.hasSucceeded) {
return rd.payload;

Check warning on line 100 in src/app/item-page/simple/item-types/shared/item-relationships-utils.ts

View check run for this annotation

Codecov / codecov/patch

src/app/item-page/simple/item-types/shared/item-relationships-utils.ts#L100

Added line #L100 was not covered by tests
} else {
return null;

Check warning on line 102 in src/app/item-page/simple/item-types/shared/item-relationships-utils.ts

View check run for this annotation

Codecov / codecov/patch

src/app/item-page/simple/item-types/shared/item-relationships-utils.ts#L102

Added line #L102 was not covered by tests
}
})
),
]
)
)).pipe(
)
).pipe(
map((arr) =>
arr
.map(([leftItem, rightItem]) => {
if (leftItem.id === thisId) {
arr.map(([leftItem, rightItem]) => {

Check warning on line 111 in src/app/item-page/simple/item-types/shared/item-relationships-utils.ts

View check run for this annotation

Codecov / codecov/patch

src/app/item-page/simple/item-types/shared/item-relationships-utils.ts#L111

Added line #L111 was not covered by tests
if (hasValue(leftItem) && leftItem.id === thisId) {
return rightItem;
} else if (rightItem.id === thisId) {
} else if (hasValue(rightItem) && rightItem.id === thisId) {
return leftItem;
}
})
Expand Down
Loading