From 59a08ff2a209981643279bb792b6fbe337c28d14 Mon Sep 17 00:00:00 2001 From: shamoon <4887959+shamoon@users.noreply.github.com> Date: Fri, 3 Nov 2023 02:19:25 -0700 Subject: [PATCH] Update frontend for new custom_fields API spec --- .../custom-fields-dropdown.component.spec.ts | 2 +- .../custom-fields-dropdown.component.ts | 17 +++++- .../document-detail.component.html | 13 +++-- .../document-detail.component.spec.ts | 55 ++++++++++++++----- .../document-detail.component.ts | 40 +++++++++++--- .../data/paperless-custom-field-instance.ts | 2 +- 6 files changed, 95 insertions(+), 34 deletions(-) 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 @@ -