mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-18 15:33:04 +00:00
fix an issue where the state of an aggregated RD would be wrong when some of the RDs it's based on were still pending
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
|
|
||||||
import { combineLatest as observableCombineLatest, Observable, of as observableOf, race as observableRace } from 'rxjs';
|
import { combineLatest as observableCombineLatest, Observable, of as observableOf, race as observableRace } from 'rxjs';
|
||||||
import { distinctUntilChanged, flatMap, map, startWith, switchMap } from 'rxjs/operators';
|
import { distinctUntilChanged, flatMap, map, startWith, switchMap, tap } from 'rxjs/operators';
|
||||||
|
|
||||||
import { hasValue, hasValueOperator, isEmpty, isNotEmpty, isNotUndefined } from '../../../shared/empty.util';
|
import { hasValue, hasValueOperator, isEmpty, isNotEmpty, isNotUndefined } from '../../../shared/empty.util';
|
||||||
import { PaginatedList } from '../../data/paginated-list';
|
import { PaginatedList } from '../../data/paginated-list';
|
||||||
@@ -205,17 +205,29 @@ export class RemoteDataBuildService {
|
|||||||
|
|
||||||
return observableCombineLatest(...input).pipe(
|
return observableCombineLatest(...input).pipe(
|
||||||
map((arr) => {
|
map((arr) => {
|
||||||
|
// The request of an aggregate RD should be pending if at least one
|
||||||
|
// of the RDs it's based on is still in the state RequestPending
|
||||||
const requestPending: boolean = arr
|
const requestPending: boolean = arr
|
||||||
.map((d: RemoteData<T>) => d.isRequestPending)
|
.map((d: RemoteData<T>) => d.isRequestPending)
|
||||||
.every((b: boolean) => b === true);
|
.find((b: boolean) => b === true);
|
||||||
|
|
||||||
const responsePending: boolean = arr
|
// The response of an aggregate RD should be pending if no requests
|
||||||
|
// are still pending and at least one of the RDs it's based
|
||||||
|
// on is still in the state ResponsePending
|
||||||
|
const responsePending: boolean = !requestPending && arr
|
||||||
.map((d: RemoteData<T>) => d.isResponsePending)
|
.map((d: RemoteData<T>) => d.isResponsePending)
|
||||||
.every((b: boolean) => b === true);
|
.find((b: boolean) => b === true);
|
||||||
|
|
||||||
const isSuccessful: boolean = arr
|
|
||||||
.map((d: RemoteData<T>) => d.hasSucceeded)
|
let isSuccessful: boolean = undefined;
|
||||||
.every((b: boolean) => b === true);
|
// isSuccessful should be undefined until all responses have come in.
|
||||||
|
// We can't know its state beforehand. We also can't say it's false
|
||||||
|
// because that would imply a request failed.
|
||||||
|
if (!(requestPending || responsePending)) {
|
||||||
|
isSuccessful = arr
|
||||||
|
.map((d: RemoteData<T>) => d.hasSucceeded)
|
||||||
|
.every((b: boolean) => b === true);
|
||||||
|
}
|
||||||
|
|
||||||
const errorMessage: string = arr
|
const errorMessage: string = arr
|
||||||
.map((d: RemoteData<T>) => d.error)
|
.map((d: RemoteData<T>) => d.error)
|
||||||
|
Reference in New Issue
Block a user