From d58bd6891887a566ec44e1a1b8573a1a003d0e95 Mon Sep 17 00:00:00 2001 From: Dan Percic Date: Mon, 6 Mar 2023 20:24:36 +0200 Subject: [PATCH] RED-6325: fix recommendation file actions on resize --- README.md | 1 + .../services/pdf-proxy.service.ts | 67 ++++++++++--------- 2 files changed, 38 insertions(+), 30 deletions(-) diff --git a/README.md b/README.md index d9ad3b041..cea49470f 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,7 @@ readonly trackBy = trackByFactory(); ``` * Don't use `setInterval` without calling `clearInterval` in `ngOnDestroy` +* Never call getters in HTML templates ## Keycloak Staging Config 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 de217e6a3..b283a4e07 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 @@ -49,8 +49,7 @@ export class PdfProxyService { ); canPerformActions = true; - instance = this._pdf.instance; - canPerformAnnotationActions$: Observable; + readonly canPerformAnnotationActions$: Observable; readonly #visibilityOffIcon = this._convertPath('/assets/icons/general/visibility-off.svg'); readonly #visibilityIcon = this._convertPath('/assets/icons/general/visibility.svg'); readonly #falsePositiveIcon = this._convertPath('/assets/icons/general/pdftron-action-false-positive.svg'); @@ -177,6 +176,14 @@ export class PdfProxyService { // When resizing a rectangle, the original annotation is removed and triggers a deselect event and a new one is created // So we want to skip the first deselect event. const wrapper = this._fileDataService.find(annotation.Id); + if (!wrapper) { + // It might be a recommendation, + // which is automatically converted to redaction when resized, + // so the original annotation(wrapper) is removed + this._annotationManager.resizingAnnotationId = undefined; + return; + } + if ( (wrapper.rectangle || wrapper.isImage || wrapper.imported) && annotation.ToolName !== AnnotationToolNames.AnnotationCreateRectangle @@ -204,42 +211,42 @@ export class PdfProxyService { if (allAnnotationsHaveImageAction) { const allAreVisible = viewerAnnotations.reduce((acc, next) => next.isVisible() && acc, true); - this.instance.UI.annotationPopup.add([ - { - type: 'actionButton', - img: allAreVisible ? this.#visibilityOffIcon : this.#visibilityIcon, - title: this._translateService.instant(`annotation-actions.${allAreVisible ? 'hide' : 'show'}`), - onClick: () => { - this._ngZone.run(() => { - if (allAreVisible) { - this._annotationManager.hide(viewerAnnotations); - this._annotationManager.addToHidden(viewerAnnotations[0].Id); - } else { - this._annotationManager.show(viewerAnnotations); - this._annotationManager.removeFromHidden(viewerAnnotations[0].Id); - } - this._annotationManager.deselect(); - }); - }, + const visibilityButton = { + type: 'actionButton', + img: allAreVisible ? this.#visibilityOffIcon : this.#visibilityIcon, + title: this._translateService.instant(`annotation-actions.${allAreVisible ? 'hide' : 'show'}`), + onClick: () => { + this._ngZone.run(() => { + if (allAreVisible) { + this._annotationManager.hide(viewerAnnotations); + this._annotationManager.addToHidden(viewerAnnotations[0].Id); + } else { + this._annotationManager.show(viewerAnnotations); + this._annotationManager.removeFromHidden(viewerAnnotations[0].Id); + } + this._annotationManager.deselect(); + }); }, - ]); + }; + + this._pdf.instance.UI.annotationPopup.add([visibilityButton]); } const actions = this._pdfAnnotationActionsService.get(annotationWrappers); - this.instance.UI.annotationPopup.add(actions); + this._pdf.instance.UI.annotationPopup.add(actions); } private _configureRectangleAnnotationPopup(annotation: Annotation) { if (!this._pdf.isCompare || annotation.getPageNumber() % 2 === 1) { - this.instance.UI.annotationPopup.add([ - { - type: 'actionButton', - dataElement: TextPopups.ADD_RECTANGLE, - img: this.#addRedactionIcon, - title: this.#getTitle(ManualRedactionEntryTypes.REDACTION), - onClick: () => this._addRectangleManualRedaction(), - }, - ]); + const addRectangleButton = { + type: 'actionButton', + dataElement: TextPopups.ADD_RECTANGLE, + img: this.#addRedactionIcon, + title: this.#getTitle(ManualRedactionEntryTypes.REDACTION), + onClick: () => this._addRectangleManualRedaction(), + }; + + this._pdf.instance.UI.annotationPopup.add([addRectangleButton]); } }