From e5d7abc8f9429ad8806f178249a0d45f7cd5bf3c Mon Sep 17 00:00:00 2001 From: shamoon <4887959+shamoon@users.noreply.github.com> Date: Thu, 12 Feb 2026 11:34:23 -0800 Subject: [PATCH] Only send version when needed for metadata too --- .../document-detail.component.spec.ts | 27 ++++++++++++++++++- .../document-detail.component.ts | 3 ++- 2 files changed, 28 insertions(+), 2 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 ae51a85ee..83490cb57 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 @@ -1216,7 +1216,32 @@ describe('DocumentDetailComponent', () => { const metadataSpy = jest.spyOn(documentService, 'getMetadata') metadataSpy.mockReturnValue(of({ has_archive_version: true })) initNormally() - expect(metadataSpy).toHaveBeenCalled() + expect(metadataSpy).toHaveBeenCalledWith(doc.id, null) + }) + + it('should pass metadata version only for non-latest selected versions', () => { + const metadataSpy = jest.spyOn(documentService, 'getMetadata') + metadataSpy.mockReturnValue(of({ has_archive_version: true })) + initNormally() + httpTestingController.expectOne(component.previewUrl).flush('preview') + + expect(metadataSpy).toHaveBeenCalledWith(doc.id, null) + + metadataSpy.mockClear() + component.document.versions = [ + { id: doc.id, is_root: true }, + { id: 10, is_root: false }, + ] as any + jest.spyOn(documentService, 'getPreviewUrl').mockReturnValue('preview-root') + jest.spyOn(documentService, 'getThumbUrl').mockReturnValue('thumb-root') + jest + .spyOn(documentService, 'get') + .mockReturnValue(of({ content: 'root' } as Document)) + + component.selectVersion(doc.id) + httpTestingController.expectOne('preview-root').flush('root') + + expect(metadataSpy).toHaveBeenCalledWith(doc.id, doc.id) }) it('should show an error if failed metadata retrieval', () => { 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 eff8103b0..522ef5474 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 @@ -379,8 +379,9 @@ export class DocumentDetailComponent } private loadMetadataForSelectedVersion() { + const selectedVersionId = this.getSelectedNonLatestVersionId() this.documentsService - .getMetadata(this.documentId, this.selectedVersionId) + .getMetadata(this.documentId, selectedVersionId) .pipe( first(), takeUntil(this.unsubscribeNotifier),