diff --git a/apps/red-ui/src/app/modules/dossier/screens/file-preview-screen/file-preview-screen.component.ts b/apps/red-ui/src/app/modules/dossier/screens/file-preview-screen/file-preview-screen.component.ts index 60812e67a..45c33001a 100644 --- a/apps/red-ui/src/app/modules/dossier/screens/file-preview-screen/file-preview-screen.component.ts +++ b/apps/red-ui/src/app/modules/dossier/screens/file-preview-screen/file-preview-screen.component.ts @@ -538,8 +538,9 @@ export class FilePreviewScreenComponent extends AutoUnsubscribe implements OnIni .pipe(filter(file => file.fileId === this.fileId)) .subscribe(async file => { if (file.lastProcessed !== this.fileData?.file.lastProcessed) { + const previousAnnotations = this.visibleAnnotations; await this._loadFileData(file); - await this._reloadAnnotations(); + await this._reloadAnnotations(previousAnnotations); } this._loadingService.stop(); }); @@ -591,13 +592,9 @@ export class FilePreviewScreenComponent extends AutoUnsubscribe implements OnIni this._workloadComponent?.scrollAnnotations(); } - private async _reloadAnnotations() { - this.fileData.redactionLog = await this._fileDownloadService.loadRedactionLogFor(this.dossierId, this.fileId).toPromise(); - this._instance.Core.annotationManager.deleteAnnotations(this._instance.Core.annotationManager.getAnnotationsList(), { - imported: true, - force: true, - }); - await this._cleanupAndRedrawAnnotations(); + private async _reloadAnnotations(previousAnnotations?: AnnotationWrapper[]) { + this._deleteAnnotations(); + await this._cleanupAndRedrawAnnotations(previousAnnotations); } private async _reloadAnnotationsForPage(page: number) { @@ -612,22 +609,32 @@ export class FilePreviewScreenComponent extends AutoUnsubscribe implements OnIni const currentPageAnnotations = this.visibleAnnotations.filter(a => a.pageNumber === page); this.fileData.redactionLog = await this._fileDownloadService.loadRedactionLogFor(this.dossierId, this.fileId).toPromise(); + this._deleteAnnotations(currentPageAnnotations); await this._cleanupAndRedrawAnnotations(currentPageAnnotations, annotation => annotation.pageNumber === page); } + private _deleteAnnotations(annotationsToDelete?: AnnotationWrapper[]) { + if (!annotationsToDelete) { + this._instance.Core.annotationManager.deleteAnnotations(this._instance.Core.annotationManager.getAnnotationsList(), { + imported: true, + force: true, + }); + } + annotationsToDelete?.forEach(annotation => { + this._findAndDeleteAnnotation(annotation.id); + }); + } + private async _cleanupAndRedrawAnnotations( - annotationsToDelete?: AnnotationWrapper[], + currentAnnotations?: AnnotationWrapper[], newAnnotationsFilter?: (annotation: AnnotationWrapper) => boolean, ) { this.rebuildFilters(); if (this.viewModeService.viewMode === 'STANDARD') { const startTime = new Date().getTime(); - annotationsToDelete?.forEach(annotation => { - this._findAndDeleteAnnotation(annotation.id); - }); - const newAnnotations = newAnnotationsFilter ? this.allAnnotations.filter(newAnnotationsFilter) : this.allAnnotations; - this._handleDeltaAnnotationFilters(annotationsToDelete ?? [], newAnnotations); + const newAnnotations = newAnnotationsFilter ? this.visibleAnnotations.filter(newAnnotationsFilter) : this.visibleAnnotations; + this._handleDeltaAnnotationFilters(currentAnnotations ?? [], newAnnotations); await this._redrawAnnotations(newAnnotations); console.log( `[REDACTION] Annotations redraw time: ${new Date().getTime() - startTime} ms for ${newAnnotations.length} annotations`, @@ -658,7 +665,6 @@ export class FilePreviewScreenComponent extends AutoUnsubscribe implements OnIni const oldPageSpecificFilters = this._annotationProcessingService.getAnnotationFilter(currentPageAnnotations); const newPageSpecificFilters = this._annotationProcessingService.getAnnotationFilter(newPageAnnotations); - console.log(currentPageAnnotations, newPageAnnotations); handleFilterDelta(oldPageSpecificFilters, newPageSpecificFilters, primaryFilters); this._filterService.addFilterGroup({ ...primaryFilterGroup,