Revert "Use confirm button for workflow list delete"

This reverts commit 3f0f89498e6fce3ebd63dcee1e1cdf6eb5820419.
This commit is contained in:
shamoon 2024-02-07 07:04:48 -08:00
parent e6c80f6e0d
commit 1b152512d6
3 changed files with 42 additions and 33 deletions

View File

@ -33,21 +33,16 @@
<div class="btn-group"> <div class="btn-group">
<button *pngxIfPermissions="{ action: PermissionAction.Change, type: PermissionType.Workflow }" class="btn btn-sm btn-outline-secondary" type="button" (click)="editWorkflow(workflow)"> <button *pngxIfPermissions="{ action: PermissionAction.Change, type: PermissionType.Workflow }" class="btn btn-sm btn-outline-secondary" type="button" (click)="editWorkflow(workflow)">
<i-bs width="1em" height="1em" name="pencil"></i-bs>&nbsp;<ng-container i18n>Edit</ng-container> <i-bs width="1em" height="1em" name="pencil"></i-bs>&nbsp;<ng-container i18n>Edit</ng-container>
</button> </button>
<pngx-confirm-button <button *pngxIfPermissions="{ action: PermissionAction.Delete, type: PermissionType.Workflow }" class="btn btn-sm btn-outline-danger" type="button" (click)="deleteWorkflow(workflow)">
label="Delete" <i-bs width="1em" height="1em" name="trash"></i-bs>&nbsp;<ng-container i18n>Delete</ng-container>
i18n-label </button>
(confirm)="deleteWorkflow(workflow)" </div>
*pngxIfPermissions="{ action: PermissionAction.Delete, type: PermissionType.Workflow }" </div>
buttonClasses=" btn-sm btn-sm btn-outline-danger"
iconName="trash">
</pngx-confirm-button>
</div> </div>
</div> </li>
</div> }
</li> @if (workflows.length === 0) {
} <li class="list-group-item" i18n>No workflows defined.</li>
@if (workflows.length === 0) { }
<li class="list-group-item" i18n>No workflows defined.</li> </ul>
}
</ul>

View File

@ -25,7 +25,6 @@ import {
} from 'src/app/data/workflow-trigger' } from 'src/app/data/workflow-trigger'
import { WorkflowActionType } from 'src/app/data/workflow-action' import { WorkflowActionType } from 'src/app/data/workflow-action'
import { NgxBootstrapIconsModule, allIcons } from 'ngx-bootstrap-icons' import { NgxBootstrapIconsModule, allIcons } from 'ngx-bootstrap-icons'
import { ConfirmButtonComponent } from '../../common/confirm-button/confirm-button.component'
const workflows: Workflow[] = [ const workflows: Workflow[] = [
{ {
@ -85,7 +84,6 @@ describe('WorkflowsComponent', () => {
IfPermissionsDirective, IfPermissionsDirective,
PageHeaderComponent, PageHeaderComponent,
ConfirmDialogComponent, ConfirmDialogComponent,
ConfirmButtonComponent,
], ],
providers: [ providers: [
{ {
@ -174,23 +172,27 @@ describe('WorkflowsComponent', () => {
}) })
it('should support delete, show notification on error / success', () => { 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 toastErrorSpy = jest.spyOn(toastService, 'showError')
const deleteSpy = jest.spyOn(workflowService, 'delete') const deleteSpy = jest.spyOn(workflowService, 'delete')
const reloadSpy = jest.spyOn(component, 'reload') const reloadSpy = jest.spyOn(component, 'reload')
const deleteButton = fixture.debugElement.query( const deleteButton = fixture.debugElement.queryAll(By.css('button'))[4]
By.directive(ConfirmButtonComponent) deleteButton.triggerEventHandler('click')
)
expect(modal).not.toBeUndefined()
const editDialog = modal.componentInstance as ConfirmDialogComponent
// fail first // fail first
deleteSpy.mockReturnValueOnce(throwError(() => new Error('error deleting'))) deleteSpy.mockReturnValueOnce(throwError(() => new Error('error deleting')))
deleteButton.nativeElement.dispatchEvent(new Event('confirm')) editDialog.confirmClicked.emit()
expect(toastErrorSpy).toHaveBeenCalled() expect(toastErrorSpy).toHaveBeenCalled()
expect(reloadSpy).not.toHaveBeenCalled() expect(reloadSpy).not.toHaveBeenCalled()
// succeed // succeed
deleteSpy.mockReturnValueOnce(of(true)) deleteSpy.mockReturnValueOnce(of(true))
deleteButton.nativeElement.dispatchEvent(new Event('confirm')) editDialog.confirmClicked.emit()
expect(reloadSpy).toHaveBeenCalled() expect(reloadSpy).toHaveBeenCalled()
}) })
}) })

View File

@ -89,15 +89,27 @@ export class WorkflowsComponent
} }
deleteWorkflow(workflow: Workflow) { deleteWorkflow(workflow: Workflow) {
this.workflowService.delete(workflow).subscribe({ const modal = this.modalService.open(ConfirmDialogComponent, {
next: () => { backdrop: 'static',
this.toastService.showInfo($localize`Deleted workflow`) })
this.workflowService.clearCache() modal.componentInstance.title = $localize`Confirm delete workflow`
this.reload() modal.componentInstance.messageBold = $localize`This operation will permanently delete this workflow.`
}, modal.componentInstance.message = $localize`This operation cannot be undone.`
error: (e) => { modal.componentInstance.btnClass = 'btn-danger'
this.toastService.showError($localize`Error deleting workflow.`, e) 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)
},
})
}) })
} }
} }