Skip to content

Commit 287d35c

Browse files
127655: Fix submission infinite loading
1 parent 404ccd9 commit 287d35c

File tree

1 file changed

+21
-11
lines changed

1 file changed

+21
-11
lines changed

src/app/core/submission/submission-rest.service.ts

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,23 @@ import { RemoteData } from '../data/remote-data';
2323
import { SubmissionResponse } from './submission-response.model';
2424
import { RestRequest } from '../data/rest-request.model';
2525

26+
/**
27+
* Retrieve the first emitting payload's dataDefinition, or throw an error if the request failed
28+
*/
29+
export const getFirstDataDefinition = () =>
30+
(source: Observable<RemoteData<SubmissionResponse>>): Observable<SubmitDataResponseDefinitionObject> =>
31+
source.pipe(
32+
getFirstCompletedRemoteData(),
33+
map((response: RemoteData<SubmissionResponse>) => {
34+
if (response.hasFailed) {
35+
throw new Error(response.errorMessage);
36+
} else {
37+
return hasValue(response.payload) ? response.payload.dataDefinition : response.payload;
38+
}
39+
}),
40+
distinctUntilChanged(),
41+
);
42+
2643
/**
2744
* The service handling all submission REST requests
2845
*/
@@ -46,15 +63,7 @@ export class SubmissionRestService {
4663
*/
4764
protected fetchRequest(requestId: string): Observable<SubmitDataResponseDefinitionObject> {
4865
return this.rdbService.buildFromRequestUUID<SubmissionResponse>(requestId).pipe(
49-
getFirstCompletedRemoteData(),
50-
map((response: RemoteData<SubmissionResponse>) => {
51-
if (response.hasFailed) {
52-
throw new Error(response.errorMessage);
53-
} else {
54-
return hasValue(response.payload) ? response.payload.dataDefinition : response.payload;
55-
}
56-
}),
57-
distinctUntilChanged()
66+
getFirstDataDefinition(),
5867
);
5968
}
6069

@@ -119,8 +128,9 @@ export class SubmissionRestService {
119128
tap((request: RestRequest) => {
120129
this.requestService.send(request);
121130
}),
122-
mergeMap(() => this.fetchRequest(requestId)),
123-
distinctUntilChanged());
131+
mergeMap((request) => this.rdbService.buildSingle(request.href)),
132+
getFirstDataDefinition(),
133+
);
124134
}
125135

126136
/**

0 commit comments

Comments
 (0)