From 3fd10deadf8bcbc26cd931fee2266c981a1f799e Mon Sep 17 00:00:00 2001
From: shamoon <4887959+shamoon@users.noreply.github.com>
Date: Tue, 6 Feb 2024 22:22:33 -0800
Subject: [PATCH] Use confirm button for custom fields list delete
---
.../custom-fields.component.html | 29 ++++++++++--------
.../custom-fields.component.spec.ts | 17 +++++------
.../custom-fields/custom-fields.component.ts | 30 ++++++-------------
3 files changed, 33 insertions(+), 43 deletions(-)
diff --git a/src-ui/src/app/components/manage/custom-fields/custom-fields.component.html b/src-ui/src/app/components/manage/custom-fields/custom-fields.component.html
index a803aae9c..acf5bf980 100644
--- a/src-ui/src/app/components/manage/custom-fields/custom-fields.component.html
+++ b/src-ui/src/app/components/manage/custom-fields/custom-fields.component.html
@@ -29,16 +29,21 @@
-
-
-
+
+
+
-
- }
- @if (fields.length === 0) {
- No fields defined.
- }
-
+
+
+
+ }
+ @if (fields.length === 0) {
+ No fields defined.
+ }
+
diff --git a/src-ui/src/app/components/manage/custom-fields/custom-fields.component.spec.ts b/src-ui/src/app/components/manage/custom-fields/custom-fields.component.spec.ts
index 8797d6803..bde7bf964 100644
--- a/src-ui/src/app/components/manage/custom-fields/custom-fields.component.spec.ts
+++ b/src-ui/src/app/components/manage/custom-fields/custom-fields.component.spec.ts
@@ -21,6 +21,7 @@ import { ConfirmDialogComponent } from '../../common/confirm-dialog/confirm-dial
import { PageHeaderComponent } from '../../common/page-header/page-header.component'
import { CustomFieldEditDialogComponent } from '../../common/edit-dialog/custom-field-edit-dialog/custom-field-edit-dialog.component'
import { NgxBootstrapIconsModule, allIcons } from 'ngx-bootstrap-icons'
+import { ConfirmButtonComponent } from '../../common/confirm-button/confirm-button.component'
const fields: CustomField[] = [
{
@@ -49,6 +50,7 @@ describe('CustomFieldsComponent', () => {
IfPermissionsDirective,
PageHeaderComponent,
ConfirmDialogComponent,
+ ConfirmButtonComponent,
],
providers: [
{
@@ -137,27 +139,22 @@ describe('CustomFieldsComponent', () => {
})
it('should support delete, show notification on error / success', () => {
- let modal: NgbModalRef
- modalService.activeInstances.subscribe((m) => (modal = m[m.length - 1]))
+ const deleteButton = fixture.debugElement.query(
+ By.directive(ConfirmButtonComponent)
+ )
const toastErrorSpy = jest.spyOn(toastService, 'showError')
const deleteSpy = jest.spyOn(customFieldsService, 'delete')
const reloadSpy = jest.spyOn(component, 'reload')
- const deleteButton = fixture.debugElement.queryAll(By.css('button'))[4]
- deleteButton.triggerEventHandler('click')
-
- expect(modal).not.toBeUndefined()
- const editDialog = modal.componentInstance as ConfirmDialogComponent
-
// fail first
deleteSpy.mockReturnValueOnce(throwError(() => new Error('error deleting')))
- editDialog.confirmClicked.emit()
+ deleteButton.nativeElement.dispatchEvent(new Event('confirm'))
expect(toastErrorSpy).toHaveBeenCalled()
expect(reloadSpy).not.toHaveBeenCalled()
// succeed
deleteSpy.mockReturnValueOnce(of(true))
- editDialog.confirmClicked.emit()
+ deleteButton.nativeElement.dispatchEvent(new Event('confirm'))
expect(reloadSpy).toHaveBeenCalled()
})
})
diff --git a/src-ui/src/app/components/manage/custom-fields/custom-fields.component.ts b/src-ui/src/app/components/manage/custom-fields/custom-fields.component.ts
index 33f2751a9..b427b8c2b 100644
--- a/src-ui/src/app/components/manage/custom-fields/custom-fields.component.ts
+++ b/src-ui/src/app/components/manage/custom-fields/custom-fields.component.ts
@@ -65,27 +65,15 @@ export class CustomFieldsComponent
}
deleteField(field: CustomField) {
- const modal = this.modalService.open(ConfirmDialogComponent, {
- backdrop: 'static',
- })
- modal.componentInstance.title = $localize`Confirm delete field`
- modal.componentInstance.messageBold = $localize`This operation will permanently delete this field.`
- modal.componentInstance.message = $localize`This operation cannot be undone.`
- modal.componentInstance.btnClass = 'btn-danger'
- modal.componentInstance.btnCaption = $localize`Proceed`
- modal.componentInstance.confirmClicked.subscribe(() => {
- modal.componentInstance.buttonsEnabled = false
- this.customFieldsService.delete(field).subscribe({
- next: () => {
- modal.close()
- this.toastService.showInfo($localize`Deleted field`)
- this.customFieldsService.clearCache()
- this.reload()
- },
- error: (e) => {
- this.toastService.showError($localize`Error deleting field.`, e)
- },
- })
+ this.customFieldsService.delete(field).subscribe({
+ next: () => {
+ this.toastService.showInfo($localize`Deleted field`)
+ this.customFieldsService.clearCache()
+ this.reload()
+ },
+ error: (e) => {
+ this.toastService.showError($localize`Error deleting field.`, e)
+ },
})
}