From bcab1cdfa2935c18eafd557f51d50cddf0329f7d Mon Sep 17 00:00:00 2001 From: Dan Percic Date: Thu, 23 Jun 2022 16:36:23 +0300 Subject: [PATCH] RED-3837: fix annotations pop-ups --- .../file-preview-screen.component.ts | 10 ++++----- .../services/pdf-proxy.service.ts | 22 +++++++++---------- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/apps/red-ui/src/app/modules/file-preview/file-preview-screen.component.ts b/apps/red-ui/src/app/modules/file-preview/file-preview-screen.component.ts index 5d9c1dee1..cf8b02fd6 100644 --- a/apps/red-ui/src/app/modules/file-preview/file-preview-screen.component.ts +++ b/apps/red-ui/src/app/modules/file-preview/file-preview-screen.component.ts @@ -417,7 +417,9 @@ export class FilePreviewScreenComponent extends AutoUnsubscribe implements OnIni #getAnnotationsToDraw(oldAnnotations: AnnotationWrapper[], newAnnotations: AnnotationWrapper[]) { const currentPage = this.pdf.currentPage; const currentPageAnnotations = this._annotationManager.get(a => a.getPageNumber() === currentPage); - const existingAnnotations = currentPageAnnotations.map(a => oldAnnotations.find(byId(a.Id))).filter(a => !!a); + const existingAnnotations = currentPageAnnotations + .map(a => oldAnnotations.find(byId(a.Id)) || newAnnotations.find(byId(a.Id))) + .filter(a => !!a); if (existingAnnotations.length > 0) { return this.#findAnnotationsToDraw(newAnnotations, oldAnnotations, existingAnnotations); @@ -470,11 +472,7 @@ export class FilePreviewScreenComponent extends AutoUnsubscribe implements OnIni return newAnnotations.filter(newAnnotation => { const oldAnnotation = oldAnnotations.find(byId(newAnnotation.id)); - if (!oldAnnotation) { - return true; - } - - if (!hasChanges(oldAnnotation, newAnnotation)) { + if (!oldAnnotation || !hasChanges(oldAnnotation, newAnnotation)) { return selectToDrawIfDoesNotExist(newAnnotation); } diff --git a/apps/red-ui/src/app/modules/file-preview/services/pdf-proxy.service.ts b/apps/red-ui/src/app/modules/file-preview/services/pdf-proxy.service.ts index 5b4926cfe..437200340 100644 --- a/apps/red-ui/src/app/modules/file-preview/services/pdf-proxy.service.ts +++ b/apps/red-ui/src/app/modules/file-preview/services/pdf-proxy.service.ts @@ -28,7 +28,6 @@ import { combineLatest, Observable, Subject } from 'rxjs'; import { ViewModeService } from './view-mode.service'; import { PermissionsService } from '../../../services/permissions.service'; import { AnnotationsListingService } from './annotations-listing.service'; -import { byPage } from '../../../utils'; import Annotation = Core.Annotations.Annotation; import Quad = Core.Math.Quad; @@ -118,9 +117,16 @@ export class PdfProxyService { // Remove deselected annotations from selected list nextAnnotations = this._annotationManager.selected.filter(ann => !annotations.some(a => a.Id === ann.Id)); this._pdf.disable(TextPopups.ADD_RECTANGLE); - this.#configureAnnotationSpecificActions(nextAnnotations); + const currentPage = this._pdf.currentPage; + if (nextAnnotations.some(a => a.getPageNumber() === currentPage)) { + this.#configureAnnotationSpecificActions(nextAnnotations); + } else { + this._pdf.resetAnnotationActions(); + } return nextAnnotations.map(ann => ann.Id); - } else if (!this._multiSelectService.isEnabled) { + } + + if (!this._multiSelectService.isEnabled) { // Only choose the last selected annotation, to bypass viewer multi select nextAnnotations = annotations; const notSelected = this._fileDataService.all.filter(wrapper => !nextAnnotations.some(ann => ann.Id === wrapper.id)); @@ -130,7 +136,7 @@ export class PdfProxyService { nextAnnotations = this._annotationManager.selected; } - this.#configureAnnotationSpecificActions(annotations); + this.#configureAnnotationSpecificActions(nextAnnotations); if (!(annotations.length === 1 && annotations[0].ReadOnly)) { this._pdf.enable(TextPopups.ADD_RECTANGLE); @@ -154,15 +160,9 @@ export class PdfProxyService { const annotationWrappers = viewerAnnotations.map(va => this._fileDataService.find(va.Id)).filter(va => !!va); this._pdf.resetAnnotationActions(); - const currentPageAnnotations = annotationWrappers.filter(byPage(this._pdf.currentPage)); - - if (currentPageAnnotations.length === 0) { - return this._pdf.resetAnnotationActions(); - } if (annotationWrappers.length === 0) { - this._configureRectangleAnnotationPopup(viewerAnnotations[0]); - return; + return this._configureRectangleAnnotationPopup(viewerAnnotations[0]); } // Add hide action as last item