Skip to content

A community-supported supercharged document management system: scan, index and archive all your documents

Fix (beta): fix custom field bulk editing for 'all' (#13191)

shamoonc063b3799f45
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 e17a0f799..60f478670 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
@@ -1020,6 +1020,7 @@ export class BulkEditorComponent
)
dialog.selection = this.getSelectionQuery()
+ dialog.selectionCount = this.getSelectionSize()
dialog.succeeded.subscribe((result) => {
this.toastService.showInfo($localize`Custom fields updated.`)
this.list.reload()
diff --git a/src-ui/src/app/components/document-list/bulk-editor/custom-fields-bulk-edit-dialog/custom-fields-bulk-edit-dialog.component.html b/src-ui/src/app/components/document-list/bulk-editor/custom-fields-bulk-edit-dialog/custom-fields-bulk-edit-dialog.component.html
index 78bce22a2..da4f47999 100644
--- a/src-ui/src/app/components/document-list/bulk-editor/custom-fields-bulk-edit-dialog/custom-fields-bulk-edit-dialog.component.html
+++ b/src-ui/src/app/components/document-list/bulk-editor/custom-fields-bulk-edit-dialog/custom-fields-bulk-edit-dialog.component.html
@@ -1,9 +1,9 @@
<form [formGroup]="form" (ngSubmit)="save()" autocomplete="off">
<div class="modal-header">
<h4 class="modal-title" id="modal-basic-title" i8n>{
- documents.length,
+ documentCount,
plural,
- =1 {Set custom fields for 1 document} other {Set custom fields for {{documents.length}} documents}
+ =1 {Set custom fields for 1 document} other {Set custom fields for {{documentCount}} documents}
}</h4>
<button type="button" class="btn-close" aria-label="Close" (click)="cancel()">
</button>
diff --git a/src-ui/src/app/components/document-list/bulk-editor/custom-fields-bulk-edit-dialog/custom-fields-bulk-edit-dialog.component.spec.ts b/src-ui/src/app/components/document-list/bulk-editor/custom-fields-bulk-edit-dialog/custom-fields-bulk-edit-dialog.component.spec.ts
index 1e31c0e05..01865e531 100644
--- a/src-ui/src/app/components/document-list/bulk-editor/custom-fields-bulk-edit-dialog/custom-fields-bulk-edit-dialog.component.spec.ts
+++ b/src-ui/src/app/components/document-list/bulk-editor/custom-fields-bulk-edit-dialog/custom-fields-bulk-edit-dialog.component.spec.ts
@@ -42,6 +42,20 @@ describe('CustomFieldsBulkEditDialogComponent', () => {
expect(component.form.contains('2')).toBeTruthy()
})
+ it('should render the document count for a filtered selection', () => {
+ component.selection = {
+ all: true,
+ filters: { title__icontains: 'invoice' },
+ }
+ component.selectionCount = 42
+ fixture.detectChanges()
+
+ expect(component.documents).toEqual([])
+ expect(
+ fixture.nativeElement.querySelector('.modal-title').textContent
+ ).toContain('Set custom fields for 42 documents')
+ })
+
it('should emit succeeded event and close modal on successful save', () => {
const editSpy = jest
.spyOn(documentService, 'bulkEdit')
diff --git a/src-ui/src/app/components/document-list/bulk-editor/custom-fields-bulk-edit-dialog/custom-fields-bulk-edit-dialog.component.ts b/src-ui/src/app/components/document-list/bulk-editor/custom-fields-bulk-edit-dialog/custom-fields-bulk-edit-dialog.component.ts
index 7d3878c59..ae521ac40 100644
--- a/src-ui/src/app/components/document-list/bulk-editor/custom-fields-bulk-edit-dialog/custom-fields-bulk-edit-dialog.component.ts
+++ b/src-ui/src/app/components/document-list/bulk-editor/custom-fields-bulk-edit-dialog/custom-fields-bulk-edit-dialog.component.ts
@@ -81,8 +81,14 @@ export class CustomFieldsBulkEditDialogComponent {
public selection: DocumentSelectionQuery = { documents: [] }
+ public selectionCount: number
+
public get documents(): number[] {
- return this.selection.documents
+ return this.selection.documents ?? []
+ }
+
+ public get documentCount(): number {
+ return this.selectionCount ?? this.documents.length
}
initForm() {