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 618b9b02a..f23eab407 100644 --- a/apps/red-ui/src/app/models/file/annotation.wrapper.ts +++ b/apps/red-ui/src/app/models/file/annotation.wrapper.ts @@ -2,28 +2,17 @@ import { annotationTypesTranslations } from '../../translations/annotation-types import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker'; import { IComment, IManualChange, ImportedRedaction, IPoint, IRectangle, LogEntryStatus, ManualRedactionType } from '@red/domain'; import { RedactionLogEntry } from '@models/file/redaction-log.entry'; - -export type AnnotationSuperType = - | 'text-highlight' - | 'suggestion-change-legal-basis' - | 'suggestion-recategorize-image' - | 'suggestion-add-dictionary' - | 'suggestion-force-redaction' - | 'suggestion-force-hint' - | 'suggestion-resize' - | 'suggestion-remove-dictionary' - | 'suggestion-add' - | 'suggestion-remove' - | 'ignored-hint' - | 'skipped' - | 'redaction' - | 'manual-redaction' - | 'recommendation' - | 'hint' - | 'declined-suggestion'; +import { + FalsePositiveSuperTypes, + LowLevelFilterTypes, + SuggestionAddSuperTypes, + SuggestionsSuperTypes, + SuperType, + SuperTypes, +} from '@models/file/super-types'; export class AnnotationWrapper { - superType: AnnotationSuperType; + superType: SuperType; typeValue: string; recategorizationType: string; @@ -88,7 +77,7 @@ export class AnnotationWrapper { } get canBeMarkedAsFalsePositive() { - return (this.isRecommendation || this.superType === 'redaction') && !this.isImage; + return (this.isRecommendation || this.superType === SuperTypes.Redaction) && !this.isImage; } get isSuperTypeBasedColor() { @@ -96,7 +85,7 @@ export class AnnotationWrapper { } get isSkipped() { - return this.superType === 'skipped'; + return this.superType === SuperTypes.Skipped; } get isImage() { @@ -112,13 +101,7 @@ export class AnnotationWrapper { } get topLevelFilter() { - return ( - this.superType !== 'hint' && - this.superType !== 'redaction' && - this.superType !== 'recommendation' && - this.superType !== 'ignored-hint' && - this.superType !== 'skipped' - ); + return !LowLevelFilterTypes[this.superType]; } get filterKey() { @@ -129,26 +112,12 @@ export class AnnotationWrapper { return this.topLevelFilter ? this.superType : this.superType + this.type; } - get isManuallySkipped() { - return this.isSkipped && this.manual; - } - get isFalsePositive() { - return ( - this.type?.toLowerCase() === 'false_positive' && - (this.superType === 'skipped' || - this.superType === 'hint' || - this.superType === 'ignored-hint' || - this.superType === 'redaction') - ); - } - - get isManualRedaction() { - return this.superType === 'manual-redaction'; + return this.type?.toLowerCase() === 'false_positive' && !!FalsePositiveSuperTypes[this.superType]; } get isDeclinedSuggestion() { - return this.superType === 'declined-suggestion'; + return this.superType === SuperTypes.DeclinedSuggestion; } get isApproved() { @@ -156,53 +125,39 @@ export class AnnotationWrapper { } get isHint() { - return this.superType === 'hint'; + return this.superType === SuperTypes.Hint; } get isHighlight() { - return this.superType === 'text-highlight'; + return this.superType === SuperTypes.TextHighlight; } get isIgnoredHint() { - return this.superType === 'ignored-hint'; + return this.superType === SuperTypes.IgnoredHint; } get isRedacted() { - return this.superType === 'redaction' || this.superType === 'manual-redaction'; + return this.superType === SuperTypes.Redaction || this.superType === SuperTypes.ManualRedaction; } get isSuggestion() { - return ( - this.isSuggestionAdd || - this.isSuggestionRemove || - this.isSuggestionChangeLegalBasis || - this.isSuggestionRecategorizeImage || - this.isSuggestionResize - ); + return !!SuggestionsSuperTypes[this.superType]; } get isSuggestionResize() { - return this.superType === 'suggestion-resize'; + return this.superType === SuperTypes.SuggestionResize; } get isSuggestionRecategorizeImage() { - return this.superType === 'suggestion-recategorize-image'; - } - - get isSuggestionChangeLegalBasis() { - return this.superType === 'suggestion-change-legal-basis'; + return this.superType === SuperTypes.SuggestionRecategorizeImage; } get isSuggestionAdd() { - return ( - this.superType === 'suggestion-add' || - this.superType === 'suggestion-add-dictionary' || - this.superType === 'suggestion-force-redaction' - ); + return !!SuggestionAddSuperTypes[this.superType]; } get isSuggestionRemove() { - return this.superType === 'suggestion-remove' || this.superType === 'suggestion-remove-dictionary'; + return this.superType === SuperTypes.SuggestionRemove || this.superType === SuperTypes.SuggestionRemoveDictionary; } get isModifyDictionary() { @@ -221,11 +176,11 @@ export class AnnotationWrapper { } get isConvertedRecommendation() { - return this.isRecommendation && this.superType === 'suggestion-add-dictionary'; + return this.isRecommendation && this.superType === SuperTypes.SuggestionAddDictionary; } get isRecommendation() { - return this.superType === 'recommendation'; + return this.superType === SuperTypes.Recommendation; } get id() { @@ -402,7 +357,7 @@ export class AnnotationWrapper { redactionLogEntry: RedactionLogEntry, lastManualChange: IManualChange, isHintDictionary: boolean, - ): AnnotationSuperType { + ): SuperType { switch (lastManualChange.manualRedactionType) { case ManualRedactionType.ADD_LOCALLY: switch (lastManualChange.annotationStatus) { diff --git a/apps/red-ui/src/app/models/file/super-types.ts b/apps/red-ui/src/app/models/file/super-types.ts new file mode 100644 index 000000000..b27c5bd6b --- /dev/null +++ b/apps/red-ui/src/app/models/file/super-types.ts @@ -0,0 +1,57 @@ +import { ValuesOf } from '@iqser/common-ui'; + +export const SuperTypes = { + TextHighlight: 'text-highlight', + SuggestionChangeLegalBasis: 'suggestion-change-legal-basis', + SuggestionRecategorizeImage: 'suggestion-recategorize-image', + SuggestionAddDictionary: 'suggestion-add-dictionary', + SuggestionForceRedaction: 'suggestion-force-redaction', + SuggestionForceHint: 'suggestion-force-hint', + SuggestionResize: 'suggestion-resize', + SuggestionRemoveDictionary: 'suggestion-remove-dictionary', + SuggestionAdd: 'suggestion-add', + SuggestionRemove: 'suggestion-remove', + IgnoredHint: 'ignored-hint', + Skipped: 'skipped', + Redaction: 'redaction', + ManualRedaction: 'manual-redaction', + Recommendation: 'recommendation', + Hint: 'hint', + DeclinedSuggestion: 'declined-suggestion', +} as const; + +export type SuperType = ValuesOf; + +export const LowLevelFilterTypes = { + [SuperTypes.Hint]: true, + [SuperTypes.Redaction]: true, + [SuperTypes.Recommendation]: true, + [SuperTypes.IgnoredHint]: true, + [SuperTypes.Skipped]: true, +} as const; + +export const FalsePositiveSuperTypes = { + [SuperTypes.Hint]: true, + [SuperTypes.Redaction]: true, + [SuperTypes.IgnoredHint]: true, + [SuperTypes.Skipped]: true, +} as const; + +export const SuggestionAddSuperTypes = { + [SuperTypes.SuggestionAdd]: true, + [SuperTypes.SuggestionAddDictionary]: true, + [SuperTypes.SuggestionForceRedaction]: true, + [SuperTypes.SuggestionForceHint]: true, +} as const; + +export const SuggestionsSuperTypes = { + [SuperTypes.SuggestionAdd]: true, + [SuperTypes.SuggestionAddDictionary]: true, + [SuperTypes.SuggestionForceRedaction]: true, + [SuperTypes.SuggestionForceHint]: true, + [SuperTypes.SuggestionChangeLegalBasis]: true, + [SuperTypes.SuggestionRecategorizeImage]: true, + [SuperTypes.SuggestionRemove]: true, + [SuperTypes.SuggestionRemoveDictionary]: true, + [SuperTypes.SuggestionResize]: true, +} as const; diff --git a/apps/red-ui/src/app/translations/annotation-types-translations.ts b/apps/red-ui/src/app/translations/annotation-types-translations.ts index 0ea4d69c1..e09d3cd18 100644 --- a/apps/red-ui/src/app/translations/annotation-types-translations.ts +++ b/apps/red-ui/src/app/translations/annotation-types-translations.ts @@ -1,7 +1,7 @@ import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker'; -import { AnnotationSuperType } from '@models/file/annotation.wrapper'; +import { SuperType } from '@models/file/super-types'; -export const annotationTypesTranslations: { [key in AnnotationSuperType]: string } = { +export const annotationTypesTranslations: { [key in SuperType]: string } = { 'text-highlight': _('annotation-type.text-highlight'), 'declined-suggestion': _('annotation-type.declined-suggestion'), hint: _('annotation-type.hint'), diff --git a/apps/red-ui/src/app/utils/sorters/super-type-sorter.ts b/apps/red-ui/src/app/utils/sorters/super-type-sorter.ts index c7d976872..246efd1a9 100644 --- a/apps/red-ui/src/app/utils/sorters/super-type-sorter.ts +++ b/apps/red-ui/src/app/utils/sorters/super-type-sorter.ts @@ -1,6 +1,6 @@ -import { AnnotationSuperType } from '../../models/file/annotation.wrapper'; +import { SuperType } from '../../models/file/super-types'; -export const SuperTypeSorter: { [key in AnnotationSuperType]: number } = { +export const SuperTypeSorter: { [key in SuperType]: number } = { 'text-highlight': 100, 'suggestion-change-legal-basis': 14, 'suggestion-force-redaction': 15,