From 73b2321e871a7311733857170c96fb0296cac290 Mon Sep 17 00:00:00 2001 From: shamoon <4887959+shamoon@users.noreply.github.com> Date: Mon, 5 Oct 2026 20:04:35 -0700 Subject: [PATCH] Fix create after ML-only --- .../document-detail.component.spec.ts | 39 +++++++++++++++++++ .../document-detail.component.ts | 22 ++++++----- 2 files changed, 52 insertions(+), 9 deletions(-) diff --git a/src-ui/src/app/components/document-detail/document-detail.component.spec.ts b/src-ui/src/app/components/document-detail/document-detail.component.spec.ts index 1412ced27..13bba3f7b 100644 --- a/src-ui/src/app/components/document-detail/document-detail.component.spec.ts +++ b/src-ui/src/app/components/document-detail/document-detail.component.spec.ts @@ -662,6 +662,45 @@ describe('DocumentDetailComponent', () => { ) }) + it.each([ + ['tag', 'createTag', 'tags', 'suggested_tags'], + [ + 'document type', + 'createDocumentType', + 'document_type', + 'suggested_document_types', + ], + [ + 'correspondent', + 'createCorrespondent', + 'correspondent', + 'suggested_correspondents', + ], + ])( + 'should create a %s after ML-only suggestions', + (_, method, field, suggestedField) => { + initNormally() + component.suggestions.set({ tags: [1] }) + let openModal: NgbModalRef + modalService.activeInstances.subscribe((modal) => (openModal = modal[0])) + component[method]('New value') + openModal.componentInstance.succeeded.next({ + id: 12, + name: 'New value', + is_inbox_tag: false, + color: '#ff0000', + text_color: '#000000', + }) + + if (field === 'tags') { + expect(component.tagsInput.value).toContain(12) + } else { + expect(component.documentForm.get(field).value).toBe(12) + } + expect(component.suggestions()[suggestedField]).toEqual([]) + } + ) + it('should support creating storage path', () => { initNormally() let openModal: NgbModalRef diff --git a/src-ui/src/app/components/document-detail/document-detail.component.ts b/src-ui/src/app/components/document-detail/document-detail.component.ts index 24680d35b..02d461ed6 100644 --- a/src-ui/src/app/components/document-detail/document-detail.component.ts +++ b/src-ui/src/app/components/document-detail/document-detail.component.ts @@ -1154,7 +1154,7 @@ export class DocumentDetailComponent if (this.suggestions()) { this.suggestions.set({ ...this.suggestions(), - suggested_tags: this.suggestions().suggested_tags.filter( + suggested_tags: (this.suggestions().suggested_tags ?? []).filter( (tag) => tag !== newTag.name ), }) @@ -1193,10 +1193,12 @@ export class DocumentDetailComponent this.documentForm.get('document_type').setValue(newDocumentType.id) this.documentForm.get('document_type').markAsDirty() if (this.suggestions()) { - this.suggestions().suggested_document_types = - this.suggestions().suggested_document_types.filter( - (dt) => dt !== newName - ) + this.suggestions.set({ + ...this.suggestions(), + suggested_document_types: ( + this.suggestions().suggested_document_types ?? [] + ).filter((dt) => dt !== newName), + }) } }) } @@ -1223,10 +1225,12 @@ export class DocumentDetailComponent this.documentForm.get('correspondent').setValue(newCorrespondent.id) this.documentForm.get('correspondent').markAsDirty() if (this.suggestions()) { - this.suggestions().suggested_correspondents = - this.suggestions().suggested_correspondents.filter( - (c) => c !== newName - ) + this.suggestions.set({ + ...this.suggestions(), + suggested_correspondents: ( + this.suggestions().suggested_correspondents ?? [] + ).filter((c) => c !== newName), + }) } }) }