From 5d5c45542100f632a17862bfa6b835a31af889f5 Mon Sep 17 00:00:00 2001 From: shamoon <4887959+shamoon@users.noreply.github.com> Date: Tue, 15 Sep 2026 07:48:39 -0700 Subject: [PATCH] Now use the excluded to route to getting fresh counts --- .../bulk-editor/bulk-editor.component.spec.ts | 77 +++++++++++++++++++ .../bulk-editor/bulk-editor.component.ts | 21 ++--- 2 files changed, 88 insertions(+), 10 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 c3f258c10d..fb5ac400fe 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 @@ -387,6 +387,42 @@ describe('BulkEditorComponent', () => { expect(component.tagSelectionModel.selectionSize()).toEqual(1) }) + it('should request selection data for tags when documents are excluded from an all-filtered selection', () => { + jest.spyOn(permissionsService, 'currentUserCan').mockReturnValue(true) + fixture.detectChanges() + jest + .spyOn(documentListViewService, 'allSelected', 'get') + .mockReturnValue(true) + jest + .spyOn(documentListViewService, 'excluded', 'get') + .mockReturnValue(new Set([4])) + jest + .spyOn(documentListViewService, 'filterRules', 'get') + .mockReturnValue([{ rule_type: FILTER_TITLE, value: 'apple' }]) + jest + .spyOn(documentListViewService, 'selectedCount', 'get') + .mockReturnValue(2) + const adjustedSelectionData: SelectionData = { + ...selectionData, + selected_tags: [{ id: 12, document_count: 2 }], + } + const getSelectionDataSpy = jest + .spyOn(documentService, 'getSelectionData') + .mockReturnValue(of(adjustedSelectionData)) + + component.openTagsDropdown() + + expect(getSelectionDataSpy).toHaveBeenCalledWith({ + all: true, + filters: { title_search: 'apple' }, + excluded_documents: [4], + }) + expect(component.tagDocumentCounts()).toEqual( + adjustedSelectionData.selected_tags + ) + expect(component.tagSelectionModel.selectionSize()).toEqual(1) + }) + it('should apply list selection data to document types menu when all filtered documents are selected', () => { jest.spyOn(permissionsService, 'currentUserCan').mockReturnValue(true) fixture.detectChanges() @@ -455,6 +491,47 @@ describe('BulkEditorComponent', () => { ) }) + it('should request selection data for the other metadata menus when documents are excluded', () => { + jest.spyOn(permissionsService, 'currentUserCan').mockReturnValue(true) + fixture.detectChanges() + jest + .spyOn(documentListViewService, 'allSelected', 'get') + .mockReturnValue(true) + jest + .spyOn(documentListViewService, 'excluded', 'get') + .mockReturnValue(new Set([4])) + jest + .spyOn(documentListViewService, 'filterRules', 'get') + .mockReturnValue([{ rule_type: FILTER_TITLE, value: 'apple' }]) + const getSelectionDataSpy = jest + .spyOn(documentService, 'getSelectionData') + .mockReturnValue(of(selectionData)) + + component.openDocumentTypeDropdown() + component.openCorrespondentDropdown() + component.openStoragePathDropdown() + component.openCustomFieldsDropdown() + + expect(getSelectionDataSpy).toHaveBeenCalledTimes(4) + expect(getSelectionDataSpy).toHaveBeenCalledWith({ + all: true, + filters: { title_search: 'apple' }, + excluded_documents: [4], + }) + expect(component.documentTypeDocumentCounts()).toEqual( + selectionData.selected_document_types + ) + expect(component.correspondentDocumentCounts()).toEqual( + selectionData.selected_correspondents + ) + expect(component.storagePathDocumentCounts()).toEqual( + selectionData.selected_storage_paths + ) + expect(component.customFieldDocumentCounts()).toEqual( + selectionData.selected_custom_fields + ) + }) + it('should execute modify tags bulk operation', () => { jest.spyOn(permissionsService, 'currentUserCan').mockReturnValue(true) jest 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 8644eb617f..f76be66c63 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 @@ -374,7 +374,8 @@ export class BulkEditorComponent } openTagsDropdown() { - if (this.list.allSelected) { + // If none excluded, use the selection data already available in the list view, otherwise fetch + if (this.list.allSelected && this.list.excluded.size === 0) { const selectionData = this.list.selectionData this.tagDocumentCounts.set(selectionData?.selected_tags ?? []) this.applySelectionData(this.tagDocumentCounts(), this.tagSelectionModel) @@ -382,7 +383,7 @@ export class BulkEditorComponent } this.documentService - .getSelectionData({ documents: Array.from(this.list.selected) }) + .getSelectionData(this.getSelectionQuery()) .pipe(first()) .subscribe((s) => { this.tagDocumentCounts.set(s.selected_tags) @@ -391,7 +392,7 @@ export class BulkEditorComponent } openDocumentTypeDropdown() { - if (this.list.allSelected) { + if (this.list.allSelected && this.list.excluded.size === 0) { const selectionData = this.list.selectionData this.documentTypeDocumentCounts.set( selectionData?.selected_document_types ?? [] @@ -404,7 +405,7 @@ export class BulkEditorComponent } this.documentService - .getSelectionData({ documents: Array.from(this.list.selected) }) + .getSelectionData(this.getSelectionQuery()) .pipe(first()) .subscribe((s) => { this.documentTypeDocumentCounts.set(s.selected_document_types) @@ -416,7 +417,7 @@ export class BulkEditorComponent } openCorrespondentDropdown() { - if (this.list.allSelected) { + if (this.list.allSelected && this.list.excluded.size === 0) { const selectionData = this.list.selectionData this.correspondentDocumentCounts.set( selectionData?.selected_correspondents ?? [] @@ -429,7 +430,7 @@ export class BulkEditorComponent } this.documentService - .getSelectionData({ documents: Array.from(this.list.selected) }) + .getSelectionData(this.getSelectionQuery()) .pipe(first()) .subscribe((s) => { this.correspondentDocumentCounts.set(s.selected_correspondents) @@ -441,7 +442,7 @@ export class BulkEditorComponent } openStoragePathDropdown() { - if (this.list.allSelected) { + if (this.list.allSelected && this.list.excluded.size === 0) { const selectionData = this.list.selectionData this.storagePathDocumentCounts.set( selectionData?.selected_storage_paths ?? [] @@ -454,7 +455,7 @@ export class BulkEditorComponent } this.documentService - .getSelectionData({ documents: Array.from(this.list.selected) }) + .getSelectionData(this.getSelectionQuery()) .pipe(first()) .subscribe((s) => { this.storagePathDocumentCounts.set(s.selected_storage_paths) @@ -466,7 +467,7 @@ export class BulkEditorComponent } openCustomFieldsDropdown() { - if (this.list.allSelected) { + if (this.list.allSelected && this.list.excluded.size === 0) { const selectionData = this.list.selectionData this.customFieldDocumentCounts.set( selectionData?.selected_custom_fields ?? [] @@ -479,7 +480,7 @@ export class BulkEditorComponent } this.documentService - .getSelectionData({ documents: Array.from(this.list.selected) }) + .getSelectionData(this.getSelectionQuery()) .pipe(first()) .subscribe((s) => { this.customFieldDocumentCounts.set(s.selected_custom_fields)