diff --git a/src-ui/src/app/components/common/custom-fields-dropdown/custom-fields-dropdown.component.spec.ts b/src-ui/src/app/components/common/custom-fields-dropdown/custom-fields-dropdown.component.spec.ts index a95697b1e..e1892acc6 100644 --- a/src-ui/src/app/components/common/custom-fields-dropdown/custom-fields-dropdown.component.spec.ts +++ b/src-ui/src/app/components/common/custom-fields-dropdown/custom-fields-dropdown.component.spec.ts @@ -92,7 +92,7 @@ describe('CustomFieldsDropdownComponent', () => { CustomFieldsDropdownComponent.prototype as any, 'updateUnusedFields' ) - component.existingFields = [{ field: fields[1] } as any] + component.existingFields = [{ field: fields[1].id } as any] component.onOpenClose() expect(updateSpy).toHaveBeenCalled() expect(component.unusedFields).toEqual([fields[0]]) diff --git a/src-ui/src/app/components/common/custom-fields-dropdown/custom-fields-dropdown.component.ts b/src-ui/src/app/components/common/custom-fields-dropdown/custom-fields-dropdown.component.ts index deab5d6f3..8a237286a 100644 --- a/src-ui/src/app/components/common/custom-fields-dropdown/custom-fields-dropdown.component.ts +++ b/src-ui/src/app/components/common/custom-fields-dropdown/custom-fields-dropdown.component.ts @@ -34,7 +34,10 @@ export class CustomFieldsDropdownComponent implements OnDestroy { existingFields: PaperlessCustomFieldInstance[] = [] @Output() - added = new EventEmitter() + added: EventEmitter = new EventEmitter() + + @Output() + created: EventEmitter = new EventEmitter() private customFields: PaperlessCustomField[] = [] public unusedFields: PaperlessCustomField[] @@ -84,9 +87,18 @@ export class CustomFieldsDropdownComponent implements OnDestroy { }) } + public getCustomFieldFromInstance( + instance: PaperlessCustomFieldInstance + ): PaperlessCustomField { + return this.customFields.find((f) => f.id === instance.field) + } + private updateUnusedFields() { this.unusedFields = this.customFields.filter( - (f) => !this.existingFields?.find((e) => e.field.id === f.id) + (f) => + !this.existingFields?.find( + (e) => this.getCustomFieldFromInstance(e)?.id === f.id + ) ) } @@ -108,6 +120,7 @@ export class CustomFieldsDropdownComponent implements OnDestroy { this.toastService.showInfo($localize`Saved field "${newField.name}".`) this.customFieldsService.clearCache() this.getFields() + this.created.emit(newField) }) modal.componentInstance.failed .pipe(takeUntil(this.unsubscribeNotifier)) diff --git a/src-ui/src/app/components/document-detail/document-detail.component.html b/src-ui/src/app/components/document-detail/document-detail.component.html index a6632e853..adfa90887 100644 --- a/src-ui/src/app/components/document-detail/document-detail.component.html +++ b/src-ui/src/app/components/document-detail/document-detail.component.html @@ -54,6 +54,7 @@ [documentId]="documentId" [disabled]="!userIsOwner" [existingFields]="document?.custom_fields" + (created)="refreshCustomFields()" (added)="addField($event)"> @@ -94,7 +95,7 @@ -