Revert "Use confirm button for custom fields list delete"
This reverts commit 3fd10deadf8bcbc26cd931fee2266c981a1f799e.
This commit is contained in:
parent
200c9f14b8
commit
894f029cb0
@ -29,21 +29,16 @@
|
|||||||
<div class="btn-group">
|
<div class="btn-group">
|
||||||
<button *pngxIfPermissions="{ action: PermissionAction.Change, type: PermissionType.CustomField }" class="btn btn-sm btn-outline-secondary" type="button" (click)="editField(field)">
|
<button *pngxIfPermissions="{ action: PermissionAction.Change, type: PermissionType.CustomField }" class="btn btn-sm btn-outline-secondary" type="button" (click)="editField(field)">
|
||||||
<i-bs width="1em" height="1em" name="pencil"></i-bs> <ng-container i18n>Edit</ng-container>
|
<i-bs width="1em" height="1em" name="pencil"></i-bs> <ng-container i18n>Edit</ng-container>
|
||||||
</button>
|
</button>
|
||||||
<pngx-confirm-button
|
<button *pngxIfPermissions="{ action: PermissionAction.Delete, type: PermissionType.CustomField }" class="btn btn-sm btn-outline-danger" type="button" (click)="deleteField(field)">
|
||||||
label="Delete"
|
<i-bs width="1em" height="1em" name="trash"></i-bs> <ng-container i18n>Delete</ng-container>
|
||||||
i18n-label
|
</button>
|
||||||
(confirm)="deleteField(field)"
|
</div>
|
||||||
*pngxIfPermissions="{ action: PermissionAction.Delete, type: PermissionType.CustomField }"
|
</div>
|
||||||
buttonClasses="btn-sm btn-outline-danger"
|
|
||||||
iconName="trash">
|
|
||||||
</pngx-confirm-button>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</li>
|
||||||
</div>
|
}
|
||||||
</li>
|
@if (fields.length === 0) {
|
||||||
}
|
<li class="list-group-item" i18n>No fields defined.</li>
|
||||||
@if (fields.length === 0) {
|
}
|
||||||
<li class="list-group-item" i18n>No fields defined.</li>
|
</ul>
|
||||||
}
|
|
||||||
</ul>
|
|
||||||
|
@ -21,7 +21,6 @@ import { ConfirmDialogComponent } from '../../common/confirm-dialog/confirm-dial
|
|||||||
import { PageHeaderComponent } from '../../common/page-header/page-header.component'
|
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 { CustomFieldEditDialogComponent } from '../../common/edit-dialog/custom-field-edit-dialog/custom-field-edit-dialog.component'
|
||||||
import { NgxBootstrapIconsModule, allIcons } from 'ngx-bootstrap-icons'
|
import { NgxBootstrapIconsModule, allIcons } from 'ngx-bootstrap-icons'
|
||||||
import { ConfirmButtonComponent } from '../../common/confirm-button/confirm-button.component'
|
|
||||||
|
|
||||||
const fields: CustomField[] = [
|
const fields: CustomField[] = [
|
||||||
{
|
{
|
||||||
@ -50,7 +49,6 @@ describe('CustomFieldsComponent', () => {
|
|||||||
IfPermissionsDirective,
|
IfPermissionsDirective,
|
||||||
PageHeaderComponent,
|
PageHeaderComponent,
|
||||||
ConfirmDialogComponent,
|
ConfirmDialogComponent,
|
||||||
ConfirmButtonComponent,
|
|
||||||
],
|
],
|
||||||
providers: [
|
providers: [
|
||||||
{
|
{
|
||||||
@ -139,22 +137,27 @@ describe('CustomFieldsComponent', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('should support delete, show notification on error / success', () => {
|
it('should support delete, show notification on error / success', () => {
|
||||||
const deleteButton = fixture.debugElement.query(
|
let modal: NgbModalRef
|
||||||
By.directive(ConfirmButtonComponent)
|
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(customFieldsService, 'delete')
|
const deleteSpy = jest.spyOn(customFieldsService, 'delete')
|
||||||
const reloadSpy = jest.spyOn(component, 'reload')
|
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
|
// 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()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -65,15 +65,27 @@ export class CustomFieldsComponent
|
|||||||
}
|
}
|
||||||
|
|
||||||
deleteField(field: CustomField) {
|
deleteField(field: CustomField) {
|
||||||
this.customFieldsService.delete(field).subscribe({
|
const modal = this.modalService.open(ConfirmDialogComponent, {
|
||||||
next: () => {
|
backdrop: 'static',
|
||||||
this.toastService.showInfo($localize`Deleted field`)
|
})
|
||||||
this.customFieldsService.clearCache()
|
modal.componentInstance.title = $localize`Confirm delete field`
|
||||||
this.reload()
|
modal.componentInstance.messageBold = $localize`This operation will permanently delete this field.`
|
||||||
},
|
modal.componentInstance.message = $localize`This operation cannot be undone.`
|
||||||
error: (e) => {
|
modal.componentInstance.btnClass = 'btn-danger'
|
||||||
this.toastService.showError($localize`Error deleting field.`, e)
|
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)
|
||||||
|
},
|
||||||
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user