From 287d35cb2639f8915c12773ac1c73c2051b52ded Mon Sep 17 00:00:00 2001 From: Kristof De Langhe Date: Mon, 28 Apr 2025 13:04:44 +0200 Subject: [PATCH] 127655: Fix submission infinite loading --- .../submission/submission-rest.service.ts | 32 ++++++++++++------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/src/app/core/submission/submission-rest.service.ts b/src/app/core/submission/submission-rest.service.ts index cf4b741af2..7676bfb141 100644 --- a/src/app/core/submission/submission-rest.service.ts +++ b/src/app/core/submission/submission-rest.service.ts @@ -23,6 +23,23 @@ import { RemoteData } from '../data/remote-data'; import { SubmissionResponse } from './submission-response.model'; import { RestRequest } from '../data/rest-request.model'; +/** + * Retrieve the first emitting payload's dataDefinition, or throw an error if the request failed + */ +export const getFirstDataDefinition = () => + (source: Observable>): Observable => + source.pipe( + getFirstCompletedRemoteData(), + map((response: RemoteData) => { + if (response.hasFailed) { + throw new Error(response.errorMessage); + } else { + return hasValue(response.payload) ? response.payload.dataDefinition : response.payload; + } + }), + distinctUntilChanged(), + ); + /** * The service handling all submission REST requests */ @@ -46,15 +63,7 @@ export class SubmissionRestService { */ protected fetchRequest(requestId: string): Observable { return this.rdbService.buildFromRequestUUID(requestId).pipe( - getFirstCompletedRemoteData(), - map((response: RemoteData) => { - if (response.hasFailed) { - throw new Error(response.errorMessage); - } else { - return hasValue(response.payload) ? response.payload.dataDefinition : response.payload; - } - }), - distinctUntilChanged() + getFirstDataDefinition(), ); } @@ -119,8 +128,9 @@ export class SubmissionRestService { tap((request: RestRequest) => { this.requestService.send(request); }), - mergeMap(() => this.fetchRequest(requestId)), - distinctUntilChanged()); + mergeMap((request) => this.rdbService.buildSingle(request.href)), + getFirstDataDefinition(), + ); } /**