From 24c0e648a48d3c6f82c8b926ac4a3fd6f244f44b Mon Sep 17 00:00:00 2001 From: shamoon <4887959+shamoon@users.noreply.github.com> Date: Thu, 13 Aug 2026 09:04:23 -0700 Subject: [PATCH] Avoid double popup when the request actually failed --- .../bulk-editor/bulk-editor.component.spec.ts | 37 +++++++++++++++++++ .../bulk-editor/bulk-editor.component.ts | 15 +++++--- 2 files changed, 47 insertions(+), 5 deletions(-) diff --git a/src-ui/src/app/components/document-list/bulk-editor/bulk-editor.component.spec.ts b/src-ui/src/app/components/document-list/bulk-editor/bulk-editor.component.spec.ts index a2801b7ec..e8a80acb1 100644 --- a/src-ui/src/app/components/document-list/bulk-editor/bulk-editor.component.spec.ts +++ b/src-ui/src/app/components/document-list/bulk-editor/bulk-editor.component.spec.ts @@ -1277,6 +1277,7 @@ describe('BulkEditorComponent', () => { const mergeAsVersionsSpy = jest .spyOn(documentService, 'mergeDocumentsAsVersions') .mockReturnValue(of(true)) + const toastInfoSpy = jest.spyOn(toastService, 'showInfo') fixture.detectChanges() component.mergeSelectedAsVersions() @@ -1292,6 +1293,42 @@ describe('BulkEditorComponent', () => { `${environment.apiBaseUrl}documents/?page=1&page_size=100000&fields=id` ) expect(documentListViewService.selected.size).toEqual(0) + expect(toastInfoSpy).toHaveBeenCalledWith('Documents merged as versions.') + }) + + it('should not report success when merging documents as versions fails', () => { + let modal: NgbModalRef + modalService.activeInstances.subscribe((m) => (modal = m[0])) + jest.spyOn(permissionsService, 'currentUserCan').mockReturnValue(true) + jest + .spyOn(documentListViewService, 'documents', 'get') + .mockReturnValue([{ id: 3 }, { id: 4 }]) + jest.spyOn(documentService, 'getFew').mockReturnValue( + of({ + all: [3, 4], + count: 2, + results: [ + { id: 3, title: 'Document 3' }, + { id: 4, title: 'Document 4' }, + ], + }) + ) + jest + .spyOn(documentListViewService, 'selected', 'get') + .mockReturnValue(new Set([3, 4])) + jest + .spyOn(documentService, 'mergeDocumentsAsVersions') + .mockReturnValue(throwError(() => new Error('failed'))) + const toastInfoSpy = jest.spyOn(toastService, 'showInfo') + const toastErrorSpy = jest.spyOn(toastService, 'showError') + fixture.detectChanges() + + component.mergeSelectedAsVersions() + modal.componentInstance.rootDocumentID.set(4) + modal.componentInstance.confirm() + + expect(toastErrorSpy).toHaveBeenCalled() + expect(toastInfoSpy).not.toHaveBeenCalled() }) it('should support bulk download with archive, originals or both and file formatting', () => { diff --git a/src-ui/src/app/components/document-list/bulk-editor/bulk-editor.component.ts b/src-ui/src/app/components/document-list/bulk-editor/bulk-editor.component.ts index a1a2ee9a2..2009ab06d 100644 --- a/src-ui/src/app/components/document-list/bulk-editor/bulk-editor.component.ts +++ b/src-ui/src/app/components/document-list/bulk-editor/bulk-editor.component.ts @@ -288,14 +288,17 @@ export class BulkEditorComponent private executeDocumentAction( modal: NgbModalRef, request: Observable, - options: { deleteOriginals?: boolean } = {} + options: { clearSelection?: boolean; successMessage?: string } = {} ) { if (modal) { modal.componentInstance.buttonsEnabled.set(false) } request.pipe(first()).subscribe({ next: () => { - this.handleOperationSuccess(modal, options.deleteOriginals ?? false) + this.handleOperationSuccess(modal, options.clearSelection ?? false) + if (options.successMessage) { + this.toastService.showInfo(options.successMessage) + } }, error: (error) => this.handleOperationError(modal, error), }) @@ -986,7 +989,7 @@ export class BulkEditorComponent this.executeDocumentAction( modal, this.documentService.mergeDocuments(mergeDialog.documentIDs(), args), - { deleteOriginals: !!args.delete_originals } + { clearSelection: !!args.delete_originals } ) this.toastService.showInfo( $localize`Merged document will be queued for consumption.` @@ -1016,9 +1019,11 @@ export class BulkEditorComponent mergeDialog.documentIDs(), mergeDialog.rootDocumentID() ), - { deleteOriginals: true } + { + clearSelection: true, + successMessage: $localize`Documents merged as versions.`, + } ) - this.toastService.showInfo($localize`Documents merged as versions.`) }) }