From b22e47cec381e424d9ff776b45d39825ebb6c608 Mon Sep 17 00:00:00 2001 From: Dan Percic Date: Fri, 7 Jul 2023 19:56:12 +0300 Subject: [PATCH] RED-6680 fix annotation deselecting while selected --- .../services/pdf-proxy.service.ts | 145 +++++++++--------- .../services/annotation-manager.service.ts | 2 + 2 files changed, 78 insertions(+), 69 deletions(-) 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 b2058dd3e..a6a71e2a1 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 @@ -37,6 +37,7 @@ import { Roles } from '@users/roles'; import { AnnotationActionsService } from './annotation-actions.service'; import { getCurrentUser } from '@iqser/common-ui/lib/users'; import { BASE_HREF_FN, isJustOne, shareDistinctLast } from '@iqser/common-ui/lib/utils'; +import { NGXLogger } from 'ngx-logger'; import Annotation = Core.Annotations.Annotation; import Quad = Core.Math.Quad; @@ -55,7 +56,7 @@ export class PdfProxyService { readonly redactTextRequested$ = new Subject(); readonly currentUser = getCurrentUser(); readonly pageChanged$ = this._pdf.pageChanged$.pipe( - tap(() => this.#handleCustomActions()), + tap(() => this.#handleExcludedPageActions()), tap(() => this._pdf.resetAnnotationActions()), shareDistinctLast(), ); @@ -80,6 +81,7 @@ export class PdfProxyService { private readonly _documentViewer: REDDocumentViewer, private readonly _annotationManager: REDAnnotationManager, private readonly _pdf: PdfViewer, + private readonly _logger: NGXLogger, private readonly _state: FilePreviewStateService, private readonly _multiSelectService: MultiSelectService, private readonly _listingService: AnnotationsListingService, @@ -88,15 +90,29 @@ export class PdfProxyService { ) { effect( () => { - this.canPerformActions(); + const canPerformActions = this.canPerformActions(); this._pdf.isCompareMode(); - this.#handleCustomActions(); this.#configureTextPopup(); - this.#deactivateMultiSelect(); + this.#handleExcludedPageActions(); + + if (canPerformActions) { + this.#enableActions(); + } else { + this.#disableActions(); + this.#deactivateMultiSelect(); + } }, { allowSignalWrites: true }, ); + + effect(() => { + if (this._viewModeService.isRedacted()) { + this._viewerHeaderService.enable([HeaderElements.TOGGLE_READABLE_REDACTIONS]); + } else { + this._viewerHeaderService.disable([HeaderElements.TOGGLE_READABLE_REDACTIONS]); + } + }); } get #annotationSelected$() { @@ -146,42 +162,41 @@ export class PdfProxyService { } #configureTextPopup() { + if (this._state.file().isApproved) { + this._pdf.configureTextPopups([]); + } + const popups: IHeaderElement[] = []; + // Adding directly to the false-positive dict is only available in dev-mode + if (this._userPreferenceService.areDevFeaturesEnabled) { + popups.push({ + type: 'actionButton', + dataElement: TextPopups.ADD_FALSE_POSITIVE, + img: this.#falsePositiveIcon, + title: this.#getTitle(ManualRedactionEntryTypes.FALSE_POSITIVE), + onClick: () => this._ngZone.run(() => this.#addManualRedactionOfType(ManualRedactionEntryTypes.FALSE_POSITIVE)), + }); + } - if (!this._state.file().isApproved) { - // Adding directly to the false-positive dict is only available in dev-mode - if (this._userPreferenceService.areDevFeaturesEnabled) { - popups.push({ - type: 'actionButton', - dataElement: TextPopups.ADD_FALSE_POSITIVE, - img: this.#falsePositiveIcon, - title: this.#getTitle(ManualRedactionEntryTypes.FALSE_POSITIVE), - onClick: () => this._ngZone.run(() => this.#addManualRedactionOfType(ManualRedactionEntryTypes.FALSE_POSITIVE)), - }); - } - - const isApprover = this._permissionsService.isApprover(this._state.dossier()); - if (this._iqserPermissionsService.has(Roles.redactions.write) && isApprover) { - popups.push({ - type: 'actionButton', - dataElement: TextPopups.REDACT_TEXT, - img: this.#addRedactionIcon, - title: this.#getTitle(ManualRedactionEntryTypes.REDACT), - onClick: () => this._ngZone.run(() => this.#redactText(ManualRedactionEntryTypes.REDACT)), - }); - popups.push({ - type: 'actionButton', - dataElement: TextPopups.ADD_HINT, - img: this.#addHintIcon, - title: this.#getTitle(ManualRedactionEntryTypes.HINT), - onClick: () => this._ngZone.run(() => this.#redactText(ManualRedactionEntryTypes.HINT)), - }); - } + const isApprover = this._permissionsService.isApprover(this._state.dossier()); + if (this._iqserPermissionsService.has(Roles.redactions.write) && isApprover) { + popups.push({ + type: 'actionButton', + dataElement: TextPopups.REDACT_TEXT, + img: this.#addRedactionIcon, + title: this.#getTitle(ManualRedactionEntryTypes.REDACT), + onClick: () => this._ngZone.run(() => this.#redactText(ManualRedactionEntryTypes.REDACT)), + }); + popups.push({ + type: 'actionButton', + dataElement: TextPopups.ADD_HINT, + img: this.#addHintIcon, + title: this.#getTitle(ManualRedactionEntryTypes.HINT), + onClick: () => this._ngZone.run(() => this.#redactText(ManualRedactionEntryTypes.HINT)), + }); } this._pdf.configureTextPopups(popups); - - return this.#handleCustomActions(); } #addManualRedactionOfType(type: ManualRedactionEntryType) { @@ -198,46 +213,37 @@ export class PdfProxyService { this.redactTextRequested$.next({ manualRedactionEntry, type }); } - #handleCustomActions() { + #handleExcludedPageActions() { const isCurrentPageExcluded = this._state.file().isPageExcluded(this._pdf.currentPage()); - - if (this._viewModeService.isRedacted()) { - this._viewerHeaderService.enable([HeaderElements.TOGGLE_READABLE_REDACTIONS]); - } else { - this._viewerHeaderService.disable([HeaderElements.TOGGLE_READABLE_REDACTIONS]); - } - - if (isCurrentPageExcluded) { - let textPopupElementsToDisable = [...TEXT_POPUPS_TO_TOGGLE]; - let headerElementsToDisable = [...HEADER_ITEMS_TO_TOGGLE]; - - if (this.canPerformActions()) { - this._pdf.enable(ALLOWED_ACTIONS_WHEN_PAGE_EXCLUDED); - this._viewerHeaderService.enable(ALLOWED_ACTIONS_WHEN_PAGE_EXCLUDED as HeaderElementType[]); - - textPopupElementsToDisable = textPopupElementsToDisable.filter( - element => !ALLOWED_ACTIONS_WHEN_PAGE_EXCLUDED.includes(element), - ); - headerElementsToDisable = headerElementsToDisable.filter(element => !ALLOWED_ACTIONS_WHEN_PAGE_EXCLUDED.includes(element)); - } - - this._pdf.disable(textPopupElementsToDisable); - this._viewerHeaderService.disable(headerElementsToDisable); + if (!isCurrentPageExcluded) { return; } - if (!this.canPerformActions()) { - this._pdf.instance.UI.disableTools([AnnotationToolNames.AnnotationCreateRectangle]); - this._pdf.disable(TEXT_POPUPS_TO_TOGGLE); - this._viewerHeaderService.disable(HEADER_ITEMS_TO_TOGGLE); - return; + let textPopupElementsToDisable = [...TEXT_POPUPS_TO_TOGGLE]; + let headerElementsToDisable = [...HEADER_ITEMS_TO_TOGGLE]; + + if (this.canPerformActions()) { + this._pdf.enable(ALLOWED_ACTIONS_WHEN_PAGE_EXCLUDED); + this._viewerHeaderService.enable(ALLOWED_ACTIONS_WHEN_PAGE_EXCLUDED as HeaderElementType[]); + + textPopupElementsToDisable = textPopupElementsToDisable.filter( + element => !ALLOWED_ACTIONS_WHEN_PAGE_EXCLUDED.includes(element), + ); + headerElementsToDisable = headerElementsToDisable.filter(element => !ALLOWED_ACTIONS_WHEN_PAGE_EXCLUDED.includes(element)); } - try { - this._pdf.instance.UI.enableTools([AnnotationToolNames.AnnotationCreateRectangle]); - } catch (e) { - // happens - } + this._pdf.disable(textPopupElementsToDisable); + this._viewerHeaderService.disable(headerElementsToDisable); + } + + #disableActions() { + this._pdf.instance.UI.disableTools([AnnotationToolNames.AnnotationCreateRectangle]); + this._pdf.disable(TEXT_POPUPS_TO_TOGGLE); + this._viewerHeaderService.disable(HEADER_ITEMS_TO_TOGGLE); + } + + #enableActions() { + this._pdf.instance.UI.enableTools([AnnotationToolNames.AnnotationCreateRectangle]); this._pdf.enable(TEXT_POPUPS_TO_TOGGLE); this._viewerHeaderService.enable(HEADER_ITEMS_TO_TOGGLE); @@ -263,6 +269,7 @@ export class PdfProxyService { } #deactivateMultiSelect() { + this._logger.info('[PDF] Deactivating multi-select'); this._multiSelectService.deactivate(); this._annotationManager.deselect(); this.handleAnnotationSelected([]); diff --git a/apps/red-ui/src/app/modules/pdf-viewer/services/annotation-manager.service.ts b/apps/red-ui/src/app/modules/pdf-viewer/services/annotation-manager.service.ts index ad79534b7..e0f0def1e 100644 --- a/apps/red-ui/src/app/modules/pdf-viewer/services/annotation-manager.service.ts +++ b/apps/red-ui/src/app/modules/pdf-viewer/services/annotation-manager.service.ts @@ -75,9 +75,11 @@ export class REDAnnotationManager { deselect(annotations?: List | List): void; deselect(argument?: string | AnnotationWrapper | List | List) { if (!argument) { + this.#logger.info('[ANNOTATIONS] Deselect all'); return this.#manager.deselectAllAnnotations(); } + this.#logger.info('[ANNOTATIONS] Deselecting: ', argument); const ann = isStringOrWrapper(argument) ? [this.#getById(argument)] : this.#getByIds(argument); this.#manager.deselectAnnotations(ann); }