diff --git a/apps/red-ui/src/app/modules/file-preview/components/file-workload/file-workload.component.ts b/apps/red-ui/src/app/modules/file-preview/components/file-workload/file-workload.component.ts index a8127f03a..e895f2bf1 100644 --- a/apps/red-ui/src/app/modules/file-preview/components/file-workload/file-workload.component.ts +++ b/apps/red-ui/src/app/modules/file-preview/components/file-workload/file-workload.component.ts @@ -363,7 +363,7 @@ export class FileWorkloadComponent extends AutoUnsubscribe implements OnInit, On if (this._viewModeService.isRedacted) { annotations = annotations.filter(a => !bool(a.isChangeLogRemoved)); - annotations = this._suggestionsService.convertWorkloadRemoveSuggestionsToRedactions(annotations); + annotations = this._suggestionsService.filterWorkloadSuggestionsInPreview(annotations); } this.displayedAnnotations = this._annotationProcessingService.filterAndGroupAnnotations(annotations, primary, secondary); diff --git a/apps/red-ui/src/app/modules/file-preview/services/file-data.service.ts b/apps/red-ui/src/app/modules/file-preview/services/file-data.service.ts index 6197b6cba..b4cf1e35b 100644 --- a/apps/red-ui/src/app/modules/file-preview/services/file-data.service.ts +++ b/apps/red-ui/src/app/modules/file-preview/services/file-data.service.ts @@ -210,7 +210,8 @@ export class FileDataService extends EntitiesService !a.isSkipped); } } diff --git a/apps/red-ui/src/app/modules/file-preview/services/suggestions.service.ts b/apps/red-ui/src/app/modules/file-preview/services/suggestions.service.ts index 9d81f0a65..0732dc7bb 100644 --- a/apps/red-ui/src/app/modules/file-preview/services/suggestions.service.ts +++ b/apps/red-ui/src/app/modules/file-preview/services/suggestions.service.ts @@ -24,39 +24,47 @@ export class SuggestionsService { } hideSuggestionsInPreview(annotations: Annotation[]): void { - if (!this._userPreferenceService.getDisplaySuggestionsInPreview()) { - const suggestions = annotations.filter(a => bool(a.getCustomData('suggestion'))); - this._annotationManager.hide(suggestions); - this.#convertSuggestionsToRedactions(suggestions); + if (this._readableRedactionsService.active) { + if (this._userPreferenceService.getDisplaySuggestionsInPreview()) { + const suggestionsRemove = annotations.filter( + a => bool(a.getCustomData('suggestionRemove')) || bool(a.getCustomData('suggestionRecategorizeImage')), + ); + this._annotationManager.hide(suggestionsRemove); + return; + } } + const suggestionsToHide = annotations.filter( + a => + (bool(a.getCustomData('suggestionAdd')) && !bool(a.getCustomData('suggestionAddToFalsePositive'))) || + bool(a.getCustomData('suggestionRecategorizeImage')), + ); + annotations.forEach(a => { + if (bool(a.getCustomData('suggestionRemove'))) { + const foundRedaction = this.#removedRedactions.find(r => r.id === a.Id); + if (!foundRedaction) { + suggestionsToHide.push(a); + } + } + }); + this._annotationManager.hide(suggestionsToHide); } - convertWorkloadRemoveSuggestionsToRedactions(annotations: AnnotationWrapper[]): AnnotationWrapper[] { - if (!this._userPreferenceService.getDisplaySuggestionsInPreview()) { - annotations = annotations.filter(a => !a.isSuggestion); - annotations = [...annotations, ...this.#removedRedactions]; + filterWorkloadSuggestionsInPreview(annotations: AnnotationWrapper[]): AnnotationWrapper[] { + if (this._readableRedactionsService.active) { + if (this._userPreferenceService.getDisplaySuggestionsInPreview()) { + return annotations.filter(a => !a.isSuggestionRemove && !a.isSuggestionRecategorizeImage); + } + } + + annotations = annotations.filter(a => !a.isSuggestionAdd || a.isSuggestionAddToFalsePositive); + for (let i = annotations.length - 1; i >= 0; i--) { + const foundRemovedRedaction = this.#removedRedactions.find(r => r.id === annotations[i].id); + if (foundRemovedRedaction) { + annotations[i] = foundRemovedRedaction; + } else if (annotations[i].isSuggestionRemove) { + annotations.splice(i, 1); + } } return annotations; } - - #convertSuggestionsToRedactions(suggestions: Annotation[]): void { - suggestions = this.#filterSuggestions(suggestions); - suggestions.forEach(s => s.setCustomData('suggestion', 'false')); - this._readableRedactionsService.setAnnotationsColor(suggestions, 'redactionColor'); - this._readableRedactionsService.setAnnotationsOpacity(suggestions); - this._annotationManager.show(suggestions); - } - - #filterSuggestions(suggestions: Annotation[]): Annotation[] { - const filteredSuggestions = []; - - this.#removedRedactions.forEach(r => { - const found = suggestions.find(s => s.Id === r.annotationId); - if (found) { - filteredSuggestions.push(found); - } - }); - - return filteredSuggestions; - } } diff --git a/apps/red-ui/src/app/modules/pdf-viewer/services/annotation-draw.service.ts b/apps/red-ui/src/app/modules/pdf-viewer/services/annotation-draw.service.ts index 1058d4930..e45fc2d71 100644 --- a/apps/red-ui/src/app/modules/pdf-viewer/services/annotation-draw.service.ts +++ b/apps/red-ui/src/app/modules/pdf-viewer/services/annotation-draw.service.ts @@ -156,7 +156,10 @@ export class AnnotationDrawService { annotation.setCustomData('redact-manager', 'true'); annotation.setCustomData('redaction', String(annotationWrapper.previewAnnotation)); annotation.setCustomData('suggestion', String(annotationWrapper.isSuggestion)); + annotation.setCustomData('suggestionAdd', String(annotationWrapper.isSuggestionAdd)); + annotation.setCustomData('suggestionAddToFalsePositive', String(annotationWrapper.isSuggestionAddToFalsePositive)); annotation.setCustomData('suggestionRemove', String(annotationWrapper.isSuggestionRemove)); + annotation.setCustomData('suggestionRecategorizeImage', String(annotationWrapper.isSuggestionRecategorizeImage)); annotation.setCustomData('skipped', String(annotationWrapper.isSkipped)); annotation.setCustomData('changeLog', String(annotationWrapper.isChangeLogEntry)); annotation.setCustomData('changeLogRemoved', String(annotationWrapper.isChangeLogRemoved)); diff --git a/apps/red-ui/src/app/modules/pdf-viewer/services/readable-redactions.service.ts b/apps/red-ui/src/app/modules/pdf-viewer/services/readable-redactions.service.ts index ee7eb278d..c9417bee2 100644 --- a/apps/red-ui/src/app/modules/pdf-viewer/services/readable-redactions.service.ts +++ b/apps/red-ui/src/app/modules/pdf-viewer/services/readable-redactions.service.ts @@ -1,5 +1,5 @@ -import { Inject, Injectable } from '@angular/core'; -import { BASE_HREF_FN, BaseHrefFn, bool } from '@iqser/common-ui'; +import { inject, Injectable } from '@angular/core'; +import { BASE_HREF_FN } from '@iqser/common-ui'; import { TranslateService } from '@ngx-translate/core'; import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker'; import { HeaderElements } from '../../file-preview/utils/constants'; @@ -13,12 +13,12 @@ import Annotation = Core.Annotations.Annotation; @Injectable() export class ReadableRedactionsService { readonly active$: Observable; + private readonly _convertPath = inject(BASE_HREF_FN); readonly #enableIcon = this._convertPath('/assets/icons/general/redaction-preview.svg'); readonly #disableIcon = this._convertPath('/assets/icons/general/redaction-final.svg'); readonly #active$ = new BehaviorSubject(true); constructor( - @Inject(BASE_HREF_FN) private readonly _convertPath: BaseHrefFn, private readonly _pdf: PdfViewer, private readonly _translateService: TranslateService, private readonly _annotationManager: REDAnnotationManager, @@ -79,7 +79,8 @@ export class ReadableRedactionsService { setAnnotationsOpacity(annotations: Annotation[], restoreToOriginal = false) { annotations.forEach(annotation => { - annotation['Opacity'] = restoreToOriginal ? parseFloat(annotation.getCustomData('opacity')) : 0.5; + const isSuggestion = annotation.getCustomData('suggestion'); + annotation['Opacity'] = restoreToOriginal || isSuggestion ? parseFloat(annotation.getCustomData('opacity')) : 0.5; }); }