diff --git a/src-ui/src/app/components/manage/workflows/workflows.component.html b/src-ui/src/app/components/manage/workflows/workflows.component.html index 01302e069..9dc214af4 100644 --- a/src-ui/src/app/components/manage/workflows/workflows.component.html +++ b/src-ui/src/app/components/manage/workflows/workflows.component.html @@ -33,21 +33,16 @@
- - + + +
+ - - - - } - @if (workflows.length === 0) { -
  • No workflows defined.
  • - } - + + } + @if (workflows.length === 0) { +
  • No workflows defined.
  • + } + diff --git a/src-ui/src/app/components/manage/workflows/workflows.component.spec.ts b/src-ui/src/app/components/manage/workflows/workflows.component.spec.ts index 3c96d84bd..51e0eda72 100644 --- a/src-ui/src/app/components/manage/workflows/workflows.component.spec.ts +++ b/src-ui/src/app/components/manage/workflows/workflows.component.spec.ts @@ -25,7 +25,6 @@ import { } from 'src/app/data/workflow-trigger' import { WorkflowActionType } from 'src/app/data/workflow-action' import { NgxBootstrapIconsModule, allIcons } from 'ngx-bootstrap-icons' -import { ConfirmButtonComponent } from '../../common/confirm-button/confirm-button.component' const workflows: Workflow[] = [ { @@ -85,7 +84,6 @@ describe('WorkflowsComponent', () => { IfPermissionsDirective, PageHeaderComponent, ConfirmDialogComponent, - ConfirmButtonComponent, ], providers: [ { @@ -174,23 +172,27 @@ describe('WorkflowsComponent', () => { }) it('should support delete, show notification on error / success', () => { + let modal: NgbModalRef + modalService.activeInstances.subscribe((m) => (modal = m[m.length - 1])) const toastErrorSpy = jest.spyOn(toastService, 'showError') const deleteSpy = jest.spyOn(workflowService, 'delete') const reloadSpy = jest.spyOn(component, 'reload') - const deleteButton = fixture.debugElement.query( - By.directive(ConfirmButtonComponent) - ) + 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'))) - deleteButton.nativeElement.dispatchEvent(new Event('confirm')) + editDialog.confirmClicked.emit() expect(toastErrorSpy).toHaveBeenCalled() expect(reloadSpy).not.toHaveBeenCalled() // succeed deleteSpy.mockReturnValueOnce(of(true)) - deleteButton.nativeElement.dispatchEvent(new Event('confirm')) + editDialog.confirmClicked.emit() expect(reloadSpy).toHaveBeenCalled() }) }) diff --git a/src-ui/src/app/components/manage/workflows/workflows.component.ts b/src-ui/src/app/components/manage/workflows/workflows.component.ts index 742fa8a6d..a80f03577 100644 --- a/src-ui/src/app/components/manage/workflows/workflows.component.ts +++ b/src-ui/src/app/components/manage/workflows/workflows.component.ts @@ -89,15 +89,27 @@ export class WorkflowsComponent } deleteWorkflow(workflow: Workflow) { - this.workflowService.delete(workflow).subscribe({ - next: () => { - this.toastService.showInfo($localize`Deleted workflow`) - this.workflowService.clearCache() - this.reload() - }, - error: (e) => { - this.toastService.showError($localize`Error deleting workflow.`, e) - }, + const modal = this.modalService.open(ConfirmDialogComponent, { + backdrop: 'static', + }) + modal.componentInstance.title = $localize`Confirm delete workflow` + modal.componentInstance.messageBold = $localize`This operation will permanently delete this workflow.` + 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.workflowService.delete(workflow).subscribe({ + next: () => { + modal.close() + this.toastService.showInfo($localize`Deleted workflow`) + this.workflowService.clearCache() + this.reload() + }, + error: (e) => { + this.toastService.showError($localize`Error deleting workflow.`, e) + }, + }) }) } }