From 79001c280d7795c0f7b3a0fb03203b5d1372ca78 Mon Sep 17 00:00:00 2001 From: shamoon <4887959+shamoon@users.noreply.github.com> Date: Tue, 10 Feb 2026 11:07:39 -0800 Subject: [PATCH] Refresh versions after delete --- .../document-detail.component.ts | 32 ++++++++++++++++--- .../src/app/services/rest/document.service.ts | 13 ++++++-- 2 files changed, 37 insertions(+), 8 deletions(-) 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 f676ea84e..64c256a18 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 @@ -777,13 +777,35 @@ export class DocumentDetailComponent const wasSelected = this.selectedVersionId === versionId this.documentsService .deleteVersion(this.documentId, versionId) - .pipe(first(), takeUntil(this.unsubscribeNotifier)) + .pipe( + switchMap((result) => + this.documentsService + .getVersions(this.documentId) + .pipe(map((doc) => ({ doc, result }))) + ), + first(), + takeUntil(this.unsubscribeNotifier) + ) .subscribe({ - next: (result) => { - if (wasSelected && result?.current_version_id) { - this.selectVersion(result.current_version_id) + next: ({ doc, result }) => { + if (doc?.versions) { + this.document.versions = doc.versions + const openDoc = this.openDocumentService.getOpenDocument( + this.documentId + ) + if (openDoc) { + openDoc.versions = doc.versions + this.openDocumentService.save() + } + } + + if (wasSelected) { + const fallbackId = + result?.current_version_id ?? + doc?.versions?.[0]?.id ?? + this.documentId + this.selectVersion(fallbackId) } - this.openDocumentService.refreshDocument(this.documentId) }, error: (error) => { this.toastService.showError($localize`Error deleting version`, error) diff --git a/src-ui/src/app/services/rest/document.service.ts b/src-ui/src/app/services/rest/document.service.ts index c0c3c6cba..7ff001d6e 100644 --- a/src-ui/src/app/services/rest/document.service.ts +++ b/src-ui/src/app/services/rest/document.service.ts @@ -197,13 +197,20 @@ export class DocumentService extends AbstractPaperlessService { if (label) { formData.append('label', label) } - return this.http.post( + return this.http.post( this.getResourceUrl(documentId, 'update_version'), - formData, - { reportProgress: true, observe: 'events' } + formData ) } + getVersions(documentId: number): Observable { + return this.http.get(this.getResourceUrl(documentId), { + params: { + fields: 'id,versions', + }, + }) + } + deleteVersion(headDocumentId: number, versionId: number) { return this.http.delete<{ result: string; current_version_id: number }>( this.getResourceUrl(headDocumentId, `versions/${versionId}`)