From 39a0e8915b80433a9859824f4eb372d05b14e5f9 Mon Sep 17 00:00:00 2001 From: Valentin Mihai Date: Sat, 29 Apr 2023 12:08:16 +0300 Subject: [PATCH] RED-5912 - Suggestions make redactions disappear in PREVIEW mode --- .../src/app/models/file/annotation.wrapper.ts | 4 ++ .../file-workload/file-workload.component.ts | 2 +- .../services/file-data.service.ts | 3 +- .../services/suggestions.service.ts | 62 ++++++++++--------- .../services/annotation-draw.service.ts | 2 + 5 files changed, 42 insertions(+), 31 deletions(-) diff --git a/apps/red-ui/src/app/models/file/annotation.wrapper.ts b/apps/red-ui/src/app/models/file/annotation.wrapper.ts index eb1104ca8..418cdc46f 100644 --- a/apps/red-ui/src/app/models/file/annotation.wrapper.ts +++ b/apps/red-ui/src/app/models/file/annotation.wrapper.ts @@ -134,6 +134,10 @@ export class AnnotationWrapper implements IListable, Record { return this.type?.toLowerCase() === 'false_positive' && !!FalsePositiveSuperTypes[this.superType]; } + get isSuggestionAddToFalsePositive() { + return this.typeLabel === annotationTypesTranslations[SuggestionAddFalsePositive]; + } + get isDeclinedSuggestion() { return this.superType === SuperTypes.DeclinedSuggestion; } 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 5b34c0aa6..522a373ce 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 @@ -375,7 +375,7 @@ export class FileWorkloadComponent extends AutoUnsubscribe implements OnDestroy 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 0374026eb..d9698192d 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 @@ -215,7 +215,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..0ac907e01 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,43 @@ 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'))); + this._annotationManager.hide(suggestionsRemove); + return; + } } + const suggestionsToHide = annotations.filter( + a => bool(a.getCustomData('suggestionAdd')) && !bool(a.getCustomData('suggestionAddToFalsePositive')), + ); + 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); + } + } + + 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 bd3baf584..2d642d896 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,6 +156,8 @@ 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('skipped', String(annotationWrapper.isSkipped)); annotation.setCustomData('changeLog', String(annotationWrapper.isChangeLogEntry));