Skip to content

Commit c963c69

Browse files
Merge branch 'w2p-136580_Replace-plaintext-relationship-7.6' into w2p-136580_Replace-plaintext-relationship-main
2 parents acabb5a + b7f47bc commit c963c69

3 files changed

Lines changed: 32 additions & 5 deletions

File tree

src/app/shared/form/builder/ds-dynamic-form-ui/relation-lookup-modal/dynamic-lookup-relation-modal.component.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ <h4 class="modal-title" id="modal-title">{{ ('submission.sections.describe.relat
55
</button>
66
</div>
77
<div class="modal-body">
8-
@if (!item || !collection) {
8+
@if (!item || !collection || isSubmitting) {
99
<ds-loading></ds-loading>
1010
}
11-
@if (item && collection) {
11+
@if (item && collection && !isSubmitting) {
1212
<ul ngbNav #nav="ngbNav" class="nav-tabs">
1313
<li ngbNavItem role="presentation">
1414
<a ngbNavLink>{{'submission.sections.describe.relationship-lookup.search-tab.tab-title.' + relationshipOptions.relationshipType | translate : { count: (totalInternal$ | async)} }}</a>
@@ -78,18 +78,18 @@ <h4 class="modal-title" id="modal-title">{{ ('submission.sections.describe.relat
7878
<small>{{ ('submission.sections.describe.relationship-lookup.selected' | translate: {size: (selection$ | async)?.length || 0}) }}</small>
7979
<div class="d-flex float-end space-children-mr">
8080
<div class="close-button">
81-
<button type="button" [dsBtnDisabled]="isPending" class="btn btn-outline-secondary" (click)="close()">
81+
<button type="button" [dsBtnDisabled]="isPending || isSubmitting" class="btn btn-outline-secondary" (click)="close()">
8282
{{ ('submission.sections.describe.relationship-lookup.close' | translate) }}</button>
8383
</div>
8484
@if (isEditRelationship) {
8585
<button class="btn btn-danger discard"
86-
[dsBtnDisabled]="(toAdd.length === 0 && toRemove.length === 0) || isPending"
86+
[dsBtnDisabled]="(toAdd.length === 0 && toRemove.length === 0) || isPending || isSubmitting"
8787
(click)="discardEv()">
8888
<i class="fas fa-times"></i>
8989
<span class="d-none d-sm-inline">&nbsp;{{"item.edit.metadata.discard-button" | translate}}</span>
9090
</button>
9191
<button class="btn btn-primary submit"
92-
[dsBtnDisabled]="(toAdd.length === 0 && toRemove.length === 0) || isPending"
92+
[dsBtnDisabled]="(toAdd.length === 0 && toRemove.length === 0) || isPending || isSubmitting"
9393
(click)="submitEv()">
9494
@if (isPending) {
9595
<span class="spinner-border spinner-border-sm me-1" role="status"

src/app/shared/form/builder/ds-dynamic-form-ui/relation-lookup-modal/dynamic-lookup-relation-modal.component.spec.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ import {
4747
RemoveRelationshipAction,
4848
ReplaceRelationshipAction,
4949
} from './relationship.actions';
50+
import { SubmissionService } from '../../../../../submission/submission.service';
5051

5152
describe('DsDynamicLookupRelationModalComponent', () => {
5253
let component: DsDynamicLookupRelationModalComponent;
@@ -71,6 +72,7 @@ describe('DsDynamicLookupRelationModalComponent', () => {
7172
let lookupRelationService;
7273
let rdbService;
7374
let submissionId;
75+
let submissionService;
7476

7577
const externalSources = [
7678
Object.assign(new ExternalSource(), {
@@ -125,6 +127,9 @@ describe('DsDynamicLookupRelationModalComponent', () => {
125127
aggregate: createSuccessfulRemoteDataObject$(externalSources),
126128
});
127129
submissionId = '1234';
130+
submissionService = jasmine.createSpyObj('submissionService', {
131+
getSubmissionSaveProcessingStatus: observableOf(false),
132+
});
128133
}
129134

130135
beforeEach(waitForAsync(() => {
@@ -156,6 +161,7 @@ describe('DsDynamicLookupRelationModalComponent', () => {
156161
},
157162
{ provide: XSRFService, useValue: {} },
158163
{ provide: NgZone, useValue: new NgZone({}) },
164+
{ provide: SubmissionService, useValue: submissionService },
159165
{ provide: APP_DATA_SERVICES_MAP, useValue: {} },
160166
{ provide: APP_CONFIG, useValue: { cache: { msToLive: { default: 15 * 60 * 1000 } } } },
161167
NgbActiveModal,

src/app/shared/form/builder/ds-dynamic-form-ui/relation-lookup-modal/dynamic-lookup-relation-modal.component.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ import {
7272
} from './relationship.actions';
7373
import { ThemedDynamicLookupRelationSearchTabComponent } from './search-tab/themed-dynamic-lookup-relation-search-tab.component';
7474
import { DsDynamicLookupRelationSelectionTabComponent } from './selection-tab/dynamic-lookup-relation-selection-tab.component';
75+
import { SubmissionService } from '../../../../../submission/submission.service';
7576

7677
@Component({
7778
selector: 'ds-dynamic-lookup-relation-modal',
@@ -231,6 +232,16 @@ export class DsDynamicLookupRelationModalComponent implements OnInit, OnDestroy
231232
*/
232233
isPending = false;
233234

235+
/**
236+
* Show a loading indicator if the form is currently submitting to avoid race conditions between requests
237+
*/
238+
isSubmitting = false;
239+
240+
/**
241+
* Open subscriptions
242+
*/
243+
subs = [];
244+
234245
constructor(
235246
public modal: NgbActiveModal,
236247
private selectableListService: SelectableListService,
@@ -242,6 +253,7 @@ export class DsDynamicLookupRelationModalComponent implements OnInit, OnDestroy
242253
private zone: NgZone,
243254
private store: Store<AppState>,
244255
private router: Router,
256+
protected submissionService: SubmissionService,
245257
) {
246258

247259
}
@@ -294,6 +306,14 @@ export class DsDynamicLookupRelationModalComponent implements OnInit, OnDestroy
294306
}));
295307
}
296308

309+
if (hasValue(this.submissionId)) {
310+
this.subs.push(
311+
this.submissionService.getSubmissionSaveProcessingStatus(this.submissionId).subscribe((isSubmitting) => {
312+
this.isSubmitting = isSubmitting;
313+
}),
314+
);
315+
}
316+
297317
this.setTotals();
298318
}
299319

@@ -407,6 +427,7 @@ export class DsDynamicLookupRelationModalComponent implements OnInit, OnDestroy
407427
ngOnDestroy() {
408428
this.router.navigate([], {});
409429
Object.values(this.subMap).forEach((subscription) => subscription.unsubscribe());
430+
this.subs.filter((sub) => hasValue(sub)).forEach((sub) => sub.unsubscribe());
410431
}
411432

412433
/* eslint-disable no-empty,@typescript-eslint/no-empty-function */

0 commit comments

Comments
 (0)