Revert "Use confirm button for mail account / rule delete"

This reverts commit 5bd1bf37f3ac67abf7a66022768e1a00667224bd.
This commit is contained in:
shamoon 2024-02-07 07:04:45 -08:00
parent 9619c44680
commit e6c80f6e0d
3 changed files with 130 additions and 116 deletions

View File

@ -36,15 +36,9 @@
<button *pngxIfOwner="account" class="btn btn-sm btn-outline-secondary" type="button" (click)="editPermissions(account)"> <button *pngxIfOwner="account" class="btn btn-sm btn-outline-secondary" type="button" (click)="editPermissions(account)">
<i-bs width="1em" height="1em" name="person-lock"></i-bs>&nbsp;<ng-container i18n>Permissions</ng-container> <i-bs width="1em" height="1em" name="person-lock"></i-bs>&nbsp;<ng-container i18n>Permissions</ng-container>
</button> </button>
<pngx-confirm-button <button *pngxIfPermissions="{ action: PermissionAction.Delete, type: PermissionType.MailAccount }" [disabled]="!userIsOwner(account)" class="btn btn-sm btn-outline-danger" type="button" (click)="deleteMailAccount(account)">
label="Delete" <i-bs width="1em" height="1em" name="trash"></i-bs>&nbsp;<ng-container i18n>Delete</ng-container>
i18n-label </button>
(confirm)="deleteMailAccount(account)"
*pngxIfPermissions="{ action: PermissionAction.Delete, type: PermissionType.MailAccount }"
[disabled]="!userIsOwner(account)"
buttonClasses="btn-sm btn-outline-danger"
iconName="trash">
</pngx-confirm-button>
</div> </div>
</div> </div>
</div> </div>
@ -55,9 +49,9 @@
} }
</ul> </ul>
</ng-container> </ng-container>
<ng-container *pngxIfPermissions="{ action: PermissionAction.View, type: PermissionType.MailRule }"> <ng-container *pngxIfPermissions="{ action: PermissionAction.View, type: PermissionType.MailRule }">
<h4 class="mt-4"> <h4 class="mt-4">
<ng-container i18n>Mail rules</ng-container> <ng-container i18n>Mail rules</ng-container>
<button type="button" class="btn btn-sm btn-outline-primary ms-4" (click)="editMailRule()" *pngxIfPermissions="{ action: PermissionAction.Add, type: PermissionType.MailRule }"> <button type="button" class="btn btn-sm btn-outline-primary ms-4" (click)="editMailRule()" *pngxIfPermissions="{ action: PermissionAction.Add, type: PermissionType.MailRule }">
@ -86,15 +80,9 @@
<button *pngxIfOwner="rule" class="btn btn-sm btn-outline-secondary" type="button" (click)="editPermissions(rule)"> <button *pngxIfOwner="rule" class="btn btn-sm btn-outline-secondary" type="button" (click)="editPermissions(rule)">
<i-bs width="1em" height="1em" name="person-lock"></i-bs>&nbsp;<ng-container i18n>Permissions</ng-container> <i-bs width="1em" height="1em" name="person-lock"></i-bs>&nbsp;<ng-container i18n>Permissions</ng-container>
</button> </button>
<pngx-confirm-button <button *pngxIfPermissions="{ action: PermissionAction.Delete, type: PermissionType.MailRule }" [disabled]="!userIsOwner(rule)" class="btn btn-sm btn-outline-danger" type="button" (click)="deleteMailRule(rule)">
label="Delete" <i-bs width="1em" height="1em" name="trash"></i-bs>&nbsp;<ng-container i18n>Delete</ng-container>
i18n-label </button>
(confirm)="deleteMailRule(rule)"
*pngxIfPermissions="{ action: PermissionAction.Delete, type: PermissionType.MailRule }"
[disabled]="!userIsOwner(rule)"
buttonClasses="btn-sm btn-outline-danger"
iconName="trash">
</pngx-confirm-button>
</div> </div>
</div> </div>
</div> </div>
@ -105,11 +93,11 @@
} }
</ul> </ul>
</ng-container> </ng-container>
@if (!mailAccounts || !mailRules) { @if (!mailAccounts || !mailRules) {
<div> <div>
<div class="spinner-border spinner-border-sm fw-normal ms-2 me-auto" role="status"></div> <div class="spinner-border spinner-border-sm fw-normal ms-2 me-auto" role="status"></div>
<div class="visually-hidden" i18n>Loading...</div> <div class="visually-hidden" i18n>Loading...</div>
</div> </div>
} }

View File

@ -42,8 +42,6 @@ import { FormsModule, ReactiveFormsModule } from '@angular/forms'
import { EditDialogMode } from '../../common/edit-dialog/edit-dialog.component' import { EditDialogMode } from '../../common/edit-dialog/edit-dialog.component'
import { NgxBootstrapIconsModule, allIcons } from 'ngx-bootstrap-icons' import { NgxBootstrapIconsModule, allIcons } from 'ngx-bootstrap-icons'
import { SwitchComponent } from '../../common/input/switch/switch.component' import { SwitchComponent } from '../../common/input/switch/switch.component'
import { ConfirmButtonComponent } from '../../common/confirm-button/confirm-button.component'
import { By } from '@angular/platform-browser'
const mailAccounts = [ const mailAccounts = [
{ id: 1, name: 'account1' }, { id: 1, name: 'account1' },
@ -86,7 +84,6 @@ describe('MailComponent', () => {
PermissionsDialogComponent, PermissionsDialogComponent,
PermissionsFormComponent, PermissionsFormComponent,
SwitchComponent, SwitchComponent,
ConfirmButtonComponent,
], ],
providers: [CustomDatePipe, DatePipe, PermissionsGuard], providers: [CustomDatePipe, DatePipe, PermissionsGuard],
imports: [ imports: [
@ -186,9 +183,10 @@ describe('MailComponent', () => {
it('should support delete mail account, show error if needed', () => { it('should support delete mail account, show error if needed', () => {
completeSetup() completeSetup()
const deleteButton = fixture.debugElement.query( let modal: NgbModalRef
By.directive(ConfirmButtonComponent) modalService.activeInstances.subscribe((refs) => (modal = refs[0]))
) component.deleteMailAccount(mailAccounts[0] as MailAccount)
const deleteDialog = modal.componentInstance as ConfirmDialogComponent
const deleteSpy = jest.spyOn(mailAccountService, 'delete') const deleteSpy = jest.spyOn(mailAccountService, 'delete')
const toastErrorSpy = jest.spyOn(toastService, 'showError') const toastErrorSpy = jest.spyOn(toastService, 'showError')
const toastInfoSpy = jest.spyOn(toastService, 'showInfo') const toastInfoSpy = jest.spyOn(toastService, 'showInfo')
@ -196,10 +194,10 @@ describe('MailComponent', () => {
deleteSpy.mockReturnValueOnce( deleteSpy.mockReturnValueOnce(
throwError(() => new Error('error deleting mail account')) throwError(() => new Error('error deleting mail account'))
) )
deleteButton.nativeElement.dispatchEvent(new Event('confirm')) deleteDialog.confirm()
expect(toastErrorSpy).toBeCalled() expect(toastErrorSpy).toBeCalled()
deleteSpy.mockReturnValueOnce(of(true)) deleteSpy.mockReturnValueOnce(of(true))
deleteButton.nativeElement.dispatchEvent(new Event('confirm')) deleteDialog.confirm()
expect(listAllSpy).toHaveBeenCalled() expect(listAllSpy).toHaveBeenCalled()
expect(toastInfoSpy).toHaveBeenCalledWith('Deleted mail account') expect(toastInfoSpy).toHaveBeenCalledWith('Deleted mail account')
}) })
@ -224,9 +222,10 @@ describe('MailComponent', () => {
it('should support delete mail rule, show error if needed', () => { it('should support delete mail rule, show error if needed', () => {
completeSetup() completeSetup()
const deleteButton = fixture.debugElement.queryAll( let modal: NgbModalRef
By.directive(ConfirmButtonComponent) modalService.activeInstances.subscribe((refs) => (modal = refs[0]))
)[2] component.deleteMailRule(mailRules[0] as MailRule)
const deleteDialog = modal.componentInstance as ConfirmDialogComponent
const deleteSpy = jest.spyOn(mailRuleService, 'delete') const deleteSpy = jest.spyOn(mailRuleService, 'delete')
const toastErrorSpy = jest.spyOn(toastService, 'showError') const toastErrorSpy = jest.spyOn(toastService, 'showError')
const toastInfoSpy = jest.spyOn(toastService, 'showInfo') const toastInfoSpy = jest.spyOn(toastService, 'showInfo')
@ -234,10 +233,10 @@ describe('MailComponent', () => {
deleteSpy.mockReturnValueOnce( deleteSpy.mockReturnValueOnce(
throwError(() => new Error('error deleting mail rule')) throwError(() => new Error('error deleting mail rule'))
) )
deleteButton.nativeElement.dispatchEvent(new Event('confirm')) deleteDialog.confirm()
expect(toastErrorSpy).toBeCalled() expect(toastErrorSpy).toBeCalled()
deleteSpy.mockReturnValueOnce(of(true)) deleteSpy.mockReturnValueOnce(of(true))
deleteButton.nativeElement.dispatchEvent(new Event('confirm')) deleteDialog.confirm()
expect(listAllSpy).toHaveBeenCalled() expect(listAllSpy).toHaveBeenCalled()
expect(toastInfoSpy).toHaveBeenCalledWith('Deleted mail rule') expect(toastInfoSpy).toHaveBeenCalledWith('Deleted mail rule')
}) })

View File

@ -106,8 +106,19 @@ export class MailComponent
} }
deleteMailAccount(account: MailAccount) { deleteMailAccount(account: MailAccount) {
const modal = this.modalService.open(ConfirmDialogComponent, {
backdrop: 'static',
})
modal.componentInstance.title = $localize`Confirm delete mail account`
modal.componentInstance.messageBold = $localize`This operation will permanently delete this mail account.`
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.mailAccountService.delete(account).subscribe({ this.mailAccountService.delete(account).subscribe({
next: () => { next: () => {
modal.close()
this.toastService.showInfo($localize`Deleted mail account`) this.toastService.showInfo($localize`Deleted mail account`)
this.mailAccountService.clearCache() this.mailAccountService.clearCache()
this.mailAccountService this.mailAccountService
@ -117,9 +128,13 @@ export class MailComponent
}) })
}, },
error: (e) => { error: (e) => {
this.toastService.showError($localize`Error deleting mail account.`, e) this.toastService.showError(
$localize`Error deleting mail account.`,
e
)
}, },
}) })
})
} }
editMailRule(rule: MailRule = null) { editMailRule(rule: MailRule = null) {
@ -150,8 +165,19 @@ export class MailComponent
} }
deleteMailRule(rule: MailRule) { deleteMailRule(rule: MailRule) {
const modal = this.modalService.open(ConfirmDialogComponent, {
backdrop: 'static',
})
modal.componentInstance.title = $localize`Confirm delete mail rule`
modal.componentInstance.messageBold = $localize`This operation will permanently delete this mail rule.`
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.mailRuleService.delete(rule).subscribe({ this.mailRuleService.delete(rule).subscribe({
next: () => { next: () => {
modal.close()
this.toastService.showInfo($localize`Deleted mail rule`) this.toastService.showInfo($localize`Deleted mail rule`)
this.mailRuleService.clearCache() this.mailRuleService.clearCache()
this.mailRuleService this.mailRuleService
@ -164,6 +190,7 @@ export class MailComponent
this.toastService.showError($localize`Error deleting mail rule.`, e) this.toastService.showError($localize`Error deleting mail rule.`, e)
}, },
}) })
})
} }
editPermissions(object: MailRule | MailAccount) { editPermissions(object: MailRule | MailAccount) {