Queue updates to handle workflow triggering

This commit is contained in:
shamoon
2026-02-17 10:48:34 -08:00
parent b49200e060
commit 600614cf5a
2 changed files with 48 additions and 6 deletions
@@ -1417,6 +1417,24 @@ describe('DocumentDetailComponent', () => {
expect(confirmDialog.messageBold).toContain('Document was updated at')
})
it('should queue incoming update while network is active and flush after', () => {
initNormally()
const loadSpy = jest.spyOn(component as any, 'loadDocument')
component.networkActive = true
;(component as any).handleIncomingDocumentUpdated({
document_id: component.documentId,
modified: '2026-02-17T00:00:00Z',
})
expect(loadSpy).not.toHaveBeenCalled()
component.networkActive = false
;(component as any).flushPendingIncomingUpdate()
expect(loadSpy).toHaveBeenCalledWith(component.documentId, true)
})
it('should change preview element by render type', () => {
initNormally()
component.document.archived_file_name = 'file.pdf'
@@ -145,6 +145,11 @@ enum ContentRenderType {
TIFF = 'tiff',
}
interface IncomingDocumentUpdate {
document_id: number
modified?: string
}
@Component({
selector: 'pngx-document-detail',
templateUrl: './document-detail.component.html',
@@ -271,6 +276,7 @@ export class DocumentDetailComponent
unsubscribeNotifier: Subject<any> = new Subject()
docChangeNotifier: Subject<any> = new Subject()
private incomingUpdateModal: NgbModalRef
private pendingIncomingUpdate: IncomingDocumentUpdate
requiresPassword: boolean = false
password: string
@@ -526,9 +532,17 @@ export class DocumentDetailComponent
this.incomingUpdateModal = null
}
private flushPendingIncomingUpdate() {
if (!this.pendingIncomingUpdate || this.networkActive) return
const pendingUpdate = this.pendingIncomingUpdate
this.pendingIncomingUpdate = null
this.handleIncomingDocumentUpdated(pendingUpdate)
}
private loadDocument(documentId: number, forceRemote: boolean = false): void {
let redirectedToRoot = false
this.closeIncomingUpdateModal()
this.pendingIncomingUpdate = null
this.selectedVersionId = documentId
this.previewUrl = this.documentsService.getPreviewUrl(
this.selectedVersionId
@@ -646,12 +660,17 @@ export class DocumentDetailComponent
})
}
private handleIncomingDocumentUpdated(data: {
document_id: number
modified?: string
}): void {
if (!this.documentId || data.document_id !== this.documentId) return
if (!this.document || this.networkActive) return
private handleIncomingDocumentUpdated(data: IncomingDocumentUpdate): void {
if (
!this.documentId ||
!this.document ||
data.document_id !== this.documentId
)
return
if (this.networkActive) {
this.pendingIncomingUpdate = data
return
}
if (this.openDocumentService.isDirty(this.document)) {
this.showIncomingUpdateModal(data.modified)
@@ -1183,11 +1202,13 @@ export class DocumentDetailComponent
this.networkActive = false
this.error = null
if (close) {
this.pendingIncomingUpdate = null
this.close(() =>
this.openDocumentService.refreshDocument(this.documentId)
)
} else {
this.openDocumentService.refreshDocument(this.documentId)
this.flushPendingIncomingUpdate()
}
this.savedViewService.maybeRefreshDocumentCounts()
},
@@ -1212,6 +1233,7 @@ export class DocumentDetailComponent
error
)
}
this.flushPendingIncomingUpdate()
},
})
}
@@ -1251,6 +1273,7 @@ export class DocumentDetailComponent
this.closeIncomingUpdateModal()
this.error = null
this.networkActive = false
this.pendingIncomingUpdate = null
if (closeResult && updateResult && nextDocId) {
this.router.navigate(['documents', nextDocId])
this.titleInput?.focus()
@@ -1260,6 +1283,7 @@ export class DocumentDetailComponent
this.networkActive = false
this.error = error.error
this.toastService.showError($localize`Error saving document`, error)
this.flushPendingIncomingUpdate()
},
})
}