From ebc9ce17b5cbbe6edacf6d1e2ed24eb3ab84bd80 Mon Sep 17 00:00:00 2001 From: shamoon <4887959+shamoon@users.noreply.github.com> Date: Wed, 21 Feb 2024 15:27:15 -0800 Subject: [PATCH] Fix: accidentally retained confirm button for management lists --- src-ui/messages.xlf | 53 +++++++++------ .../management-list.component.html | 64 +++++++++---------- .../management-list.component.spec.ts | 18 +++--- .../management-list.component.ts | 48 +++++++++----- 4 files changed, 104 insertions(+), 79 deletions(-) diff --git a/src-ui/messages.xlf b/src-ui/messages.xlf index 3a6d6f8df..b102e9567 100644 --- a/src-ui/messages.xlf +++ b/src-ui/messages.xlf @@ -1491,6 +1491,10 @@ src/app/components/manage/management-list/management-list.component.html 96 + + src/app/components/manage/management-list/management-list.component.ts + 208 + src/app/components/manage/workflows/workflows.component.html 38 @@ -2017,7 +2021,7 @@ src/app/components/manage/management-list/management-list.component.ts - 304 + 320 src/app/components/manage/workflows/workflows.component.ts @@ -2056,7 +2060,7 @@ src/app/components/manage/management-list/management-list.component.ts - 306 + 322 src/app/components/manage/workflows/workflows.component.ts @@ -5025,7 +5029,11 @@ src/app/components/manage/management-list/management-list.component.ts - 302 + 204 + + + src/app/components/manage/management-list/management-list.component.ts + 318 @@ -6219,7 +6227,7 @@ src/app/components/manage/management-list/management-list.component.ts - 289 + 305 @@ -6302,26 +6310,26 @@ {VAR_PLURAL, plural, =1 {One } other { total }} src/app/components/manage/management-list/management-list.component.html - 116 + 110 src/app/components/manage/management-list/management-list.component.html - 116 + 110 src/app/components/manage/management-list/management-list.component.html - 116 + 110 src/app/components/manage/management-list/management-list.component.html - 116 + 110 Automatic src/app/components/manage/management-list/management-list.component.ts - 113 + 116 src/app/data/matching-model.ts @@ -6332,7 +6340,7 @@ None src/app/components/manage/management-list/management-list.component.ts - 115 + 118 src/app/data/matching-model.ts @@ -6343,63 +6351,70 @@ Successfully created . src/app/components/manage/management-list/management-list.component.ts - 158 + 161 Error occurred while creating . src/app/components/manage/management-list/management-list.component.ts - 163 + 166 Successfully updated . src/app/components/manage/management-list/management-list.component.ts - 178 + 181 Error occurred while saving . src/app/components/manage/management-list/management-list.component.ts - 183 + 186 + + + + Associated documents will not be deleted. + + src/app/components/manage/management-list/management-list.component.ts + 206 Error while deleting element src/app/components/manage/management-list/management-list.component.ts - 207 + 222 Permissions updated successfully src/app/components/manage/management-list/management-list.component.ts - 282 + 298 This operation will permanently delete all objects. src/app/components/manage/management-list/management-list.component.ts - 303 + 319 Objects deleted successfully src/app/components/manage/management-list/management-list.component.ts - 317 + 333 Error deleting objects src/app/components/manage/management-list/management-list.component.ts - 323 + 339 diff --git a/src-ui/src/app/components/manage/management-list/management-list.component.html b/src-ui/src/app/components/manage/management-list/management-list.component.html index d627a1540..58101c388 100644 --- a/src-ui/src/app/components/manage/management-list/management-list.component.html +++ b/src-ui/src/app/components/manage/management-list/management-list.component.html @@ -88,39 +88,33 @@
- - - -
- - - } - - - - - @if (!isLoading) { -
- @if (collectionSize > 0) { -
- {collectionSize, plural, =1 {One {{typeName}}} other {{{collectionSize || 0}} total {{typeNamePlural}}}} - @if (selectedObjects.size > 0) { -  ({{selectedObjects.size}} selected) - } + + + +
+ + + } + +
- } - @if (collectionSize > 20) { - - } - - } + + @if (!isLoading) { +
+ @if (collectionSize > 0) { +
+ {collectionSize, plural, =1 {One {{typeName}}} other {{{collectionSize || 0}} total {{typeNamePlural}}}} + @if (selectedObjects.size > 0) { +  ({{selectedObjects.size}} selected) + } +
+ } + @if (collectionSize > 20) { + + } +
+ } diff --git a/src-ui/src/app/components/manage/management-list/management-list.component.spec.ts b/src-ui/src/app/components/manage/management-list/management-list.component.spec.ts index 280c40ca8..710d3018a 100644 --- a/src-ui/src/app/components/manage/management-list/management-list.component.spec.ts +++ b/src-ui/src/app/components/manage/management-list/management-list.component.spec.ts @@ -13,7 +13,6 @@ import { NgbModalModule, NgbModalRef, NgbPaginationModule, - NgbPopoverModule, } from '@ng-bootstrap/ng-bootstrap' import { of, throwError } from 'rxjs' import { Tag } from 'src/app/data/tag' @@ -38,7 +37,6 @@ import { MATCH_NONE } from 'src/app/data/matching-model' import { MATCH_LITERAL } from 'src/app/data/matching-model' import { PermissionsDialogComponent } from '../../common/permissions-dialog/permissions-dialog.component' import { NgxBootstrapIconsModule, allIcons } from 'ngx-bootstrap-icons' -import { ConfirmButtonComponent } from '../../common/confirm-button/confirm-button.component' import { BulkEditObjectOperation } from 'src/app/services/rest/abstract-name-filter-service' const tags: Tag[] = [ @@ -78,7 +76,6 @@ describe('ManagementListComponent', () => { SafeHtmlPipe, ConfirmDialogComponent, PermissionsDialogComponent, - ConfirmButtonComponent, ], providers: [ { @@ -100,7 +97,6 @@ describe('ManagementListComponent', () => { NgbModalModule, RouterTestingModule.withRoutes(routes), NgxBootstrapIconsModule.pick(allIcons), - NgbPopoverModule, ], }).compileComponents() @@ -197,23 +193,27 @@ describe('ManagementListComponent', () => { }) 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(tagService, 'delete') const reloadSpy = jest.spyOn(component, 'reloadData') - const deleteButton = fixture.debugElement.query( - By.directive(ConfirmButtonComponent) - ) + const deleteButton = fixture.debugElement.queryAll(By.css('button'))[8] + 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/management-list/management-list.component.ts b/src-ui/src/app/components/manage/management-list/management-list.component.ts index 8f0947f1c..0b0365f06 100644 --- a/src-ui/src/app/components/manage/management-list/management-list.component.ts +++ b/src-ui/src/app/components/manage/management-list/management-list.component.ts @@ -15,7 +15,10 @@ import { MATCH_NONE, } from 'src/app/data/matching-model' import { ObjectWithId } from 'src/app/data/object-with-id' -import { ObjectWithPermissions } from 'src/app/data/object-with-permissions' +import { + ObjectWithPermissions, + PermissionsObject, +} from 'src/app/data/object-with-permissions' import { SortableDirective, SortEvent, @@ -194,21 +197,34 @@ export abstract class ManagementListComponent ]) } - deleteObject(object: T) { - this.service - .delete(object) - .pipe(takeUntil(this.unsubscribeNotifier)) - .subscribe({ - next: () => { - this.reloadData() - }, - error: (error) => { - this.toastService.showError( - $localize`Error while deleting element`, - error - ) - }, - }) + openDeleteDialog(object: T) { + var activeModal = this.modalService.open(ConfirmDialogComponent, { + backdrop: 'static', + }) + activeModal.componentInstance.title = $localize`Confirm delete` + activeModal.componentInstance.messageBold = this.getDeleteMessage(object) + activeModal.componentInstance.message = $localize`Associated documents will not be deleted.` + activeModal.componentInstance.btnClass = 'btn-danger' + activeModal.componentInstance.btnCaption = $localize`Delete` + activeModal.componentInstance.confirmClicked.subscribe(() => { + activeModal.componentInstance.buttonsEnabled = false + this.service + .delete(object) + .pipe(takeUntil(this.unsubscribeNotifier)) + .subscribe({ + next: () => { + activeModal.close() + this.reloadData() + }, + error: (error) => { + activeModal.componentInstance.buttonsEnabled = true + this.toastService.showError( + $localize`Error while deleting element`, + error + ) + }, + }) + }) } get nameFilter() {