Skip to content

Commit 6223d6b

Browse files
committed
fix removing a new/unsaved profile, add duplicate profile error handling
1 parent 94199df commit 6223d6b

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

src/frontend/src/app/settings/quality-profiles.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ <h4 class="modal-title">Quality Profiles</h4>
55
<div class="modal-body" [formGroup]="form">
66
<ngx-loading [show]="isLoading" [config]="{fullScreenBackdrop: true}"></ngx-loading>
77
<div class="text-end">
8-
<button type="button" class="btn btn-sm btn-outline-success" (click)="add()"><span class="oi oi-plus"></span></button>
8+
<button type="button" class="btn btn-sm btn-outline-success" (click)="add()">New <span class="oi oi-plus"></span></button>
99
</div>
1010
<form class="was-validated" [formArrayName]="'profiles'">
1111
<div class="card my-2" *ngFor="let profile of form.controls.profiles.controls; let i = index" [formGroupName]="i">

src/frontend/src/app/settings/quality-profiles.component.ts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,36 @@ export class QualityProfilesComponent implements OnInit {
5555
},
5656
error: (error) => {
5757
console.error(error);
58-
this.toastr.error('An unknown error occurred updating the quality profile');
58+
let msg: string;
59+
// display specific error
60+
if (error.error) {
61+
msg = Object.entries(error.error).map(([key,value]: [k: string, v: string[]]) => {
62+
return `${key}: ${value.join(', ')}`;
63+
}).join(', ');
64+
}
65+
// display generic error
66+
else {
67+
msg = 'An unknown error occurred updating the quality profile'
68+
}
69+
this.toastr.error(msg);
5970
this.isLoading = false;
6071
}
6172
})
6273
}
6374

6475
public delete(formArrayIndex: number) {
6576
const profileFormGroup = this.form.controls.profiles.controls[formArrayIndex];
66-
this.isLoading = true;
6777
const data = profileFormGroup.value;
78+
79+
// remove unsaved form control
80+
if (!data.id) {
81+
this.form.controls.profiles.removeAt(formArrayIndex);
82+
return;
83+
}
84+
85+
this.isLoading = true;
86+
87+
// delete existing record
6888
this.apiService.deleteQualityProfile(data.id).subscribe({
6989
next: () => {
7090
// remove form group

0 commit comments

Comments
 (0)