RED-5912 - Suggestions make redactions disappear in PREVIEW mode

This commit is contained in:
Valentin Mihai 2023-04-29 12:08:16 +03:00
parent 4e221d5e00
commit 39a0e8915b
5 changed files with 42 additions and 31 deletions

View File

@ -134,6 +134,10 @@ export class AnnotationWrapper implements IListable, Record<string, unknown> {
return this.type?.toLowerCase() === 'false_positive' && !!FalsePositiveSuperTypes[this.superType];
}
get isSuggestionAddToFalsePositive() {
return this.typeLabel === annotationTypesTranslations[SuggestionAddFalsePositive];
}
get isDeclinedSuggestion() {
return this.superType === SuperTypes.DeclinedSuggestion;
}

View File

@ -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);

View File

@ -215,7 +215,8 @@ export class FileDataService extends EntitiesService<AnnotationWrapper, Annotati
}
return filtered;
}, []);
this._suggestionsService.removedRedactions = await this.#buildAnnotations(redactionLogCopy, file);
const annotations = await this.#buildAnnotations(redactionLogCopy, file);
this._suggestionsService.removedRedactions = annotations.filter(a => !a.isSkipped);
}
}

View File

@ -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;
}
}

View File

@ -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));