- @for (field of selectedFields; track field.id) {
+ @for (field of fieldsToAdd; track field.id) {
@switch (field.data_type) {
@case (CustomFieldDataType.String) {
@@ -87,6 +87,9 @@
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 4ead91010..a5c76d5bc 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
@@ -40,7 +40,7 @@ describe('CustomFieldsBulkEditDialogComponent', () => {
{ id: 1, name: 'Field 1', data_type: CustomFieldDataType.String },
{ id: 2, name: 'Field 2', data_type: CustomFieldDataType.Integer },
]
- component.selectedFieldsIds = [1, 2]
+ component.fieldsToAddIds = [1, 2]
expect(component.form.contains('1')).toBeTruthy()
expect(component.form.contains('2')).toBeTruthy()
})
@@ -52,7 +52,7 @@ describe('CustomFieldsBulkEditDialogComponent', () => {
const successSpy = jest.spyOn(component.succeeded, 'emit')
component.documents = [1, 2]
- component.selectedFieldsIds = [1]
+ component.fieldsToAddIds = [1]
component.form.controls['1'].setValue('Value 1')
component.save()
@@ -67,7 +67,7 @@ describe('CustomFieldsBulkEditDialogComponent', () => {
const failSpy = jest.spyOn(component.failed, 'emit')
component.documents = [1, 2]
- component.selectedFieldsIds = [1]
+ component.fieldsToAddIds = [1]
component.form.controls['1'].setValue('Value 1')
component.save()
@@ -82,8 +82,8 @@ describe('CustomFieldsBulkEditDialogComponent', () => {
})
it('should remove field from selected fields', () => {
- component.selectedFieldsIds = [1, 2]
+ component.fieldsToAddIds = [1, 2]
component.removeField(1)
- expect(component.selectedFieldsIds).toEqual([2])
+ expect(component.fieldsToAddIds).toEqual([2])
})
})
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 bcdc6b919..02202df67 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
@@ -23,23 +23,25 @@ export class CustomFieldsBulkEditDialogComponent {
public customFields: CustomField[] = []
- private _selectedFields: CustomField[] = [] // static object for change detection
- public get selectedFields() {
- return this._selectedFields
+ private _fieldsToAdd: CustomField[] = [] // static object for change detection
+ public get fieldsToAdd() {
+ return this._fieldsToAdd
}
- private _selectedFieldsIds: number[] = []
- public get selectedFieldsIds() {
- return this._selectedFieldsIds
+ private _fieldsToAddIds: number[] = []
+ public get fieldsToAddIds() {
+ return this._fieldsToAddIds
}
- public set selectedFieldsIds(ids: number[]) {
- this._selectedFieldsIds = ids
- this._selectedFields = this.customFields.filter((field) =>
- this._selectedFieldsIds.includes(field.id)
+ public set fieldsToAddIds(ids: number[]) {
+ this._fieldsToAddIds = ids
+ this._fieldsToAdd = this.customFields.filter((field) =>
+ this._fieldsToAddIds.includes(field.id)
)
this.initForm()
}
+ public fieldsToRemoveIds: number[] = []
+
public form: FormGroup = new FormGroup({})
public documents: number[]
@@ -51,7 +53,7 @@ export class CustomFieldsBulkEditDialogComponent {
initForm() {
this.form = new FormGroup({})
- this._selectedFieldsIds.forEach((field_id) => {
+ this._fieldsToAddIds.forEach((field_id) => {
this.form.addControl(field_id.toString(), new FormControl(null))
})
}
@@ -60,7 +62,7 @@ export class CustomFieldsBulkEditDialogComponent {
this.documentService
.bulkEdit(this.documents, 'modify_custom_fields', {
add_custom_fields: this.form.value,
- remove_custom_fields: [],
+ remove_custom_fields: this.fieldsToRemoveIds,
})
.pipe(first())
.subscribe({
@@ -79,8 +81,6 @@ export class CustomFieldsBulkEditDialogComponent {
}
public removeField(fieldId: number) {
- this.selectedFieldsIds = this._selectedFieldsIds.filter(
- (id) => id !== fieldId
- )
+ this.fieldsToAddIds = this._fieldsToAddIds.filter((id) => id !== fieldId)
}
}