refactor state transitions for annotations
This commit is contained in:
parent
71aeb46a35
commit
f4dcabea29
@ -4,33 +4,16 @@ import { isArray } from 'rxjs/internal-compatibility';
|
||||
|
||||
export class AnnotationPermissions {
|
||||
canUndo = true;
|
||||
|
||||
canAcceptRecommendation = true;
|
||||
canMarkTextOnlyAsFalsePositive = true;
|
||||
canMarkAsFalsePositive = true;
|
||||
|
||||
canRemoveOrSuggestToRemoveOnlyHere = true;
|
||||
canRemoveOrSuggestToRemoveFromDictionary = true;
|
||||
|
||||
canAcceptSuggestion = true;
|
||||
canRejectSuggestion = true;
|
||||
|
||||
canForceRedaction = true;
|
||||
|
||||
canChangeLegalBasis = true;
|
||||
|
||||
canRecategorizeImage = true;
|
||||
|
||||
get canPerformMultipleRemoveActions() {
|
||||
return (
|
||||
<any>this.canMarkTextOnlyAsFalsePositive +
|
||||
<any>this.canMarkAsFalsePositive +
|
||||
<any>this.canRemoveOrSuggestToRemoveFromDictionary +
|
||||
<any>this.canRemoveOrSuggestToRemoveOnlyHere >=
|
||||
2
|
||||
);
|
||||
}
|
||||
|
||||
static forUser(isApprover: boolean, user: UserWrapper, annotations: AnnotationWrapper | AnnotationWrapper[]) {
|
||||
if (!isArray(annotations)) {
|
||||
annotations = [annotations];
|
||||
@ -45,18 +28,16 @@ export class AnnotationPermissions {
|
||||
permissions.canForceRedaction = annotation.isSkipped;
|
||||
permissions.canAcceptRecommendation = annotation.isRecommendation;
|
||||
|
||||
permissions.canMarkAsFalsePositive = annotation.canBeMarkedAsFalsePositive && !annotation.force;
|
||||
permissions.canMarkTextOnlyAsFalsePositive = annotation.canBeMarkedAsFalsePositiveWithTextOnly && !annotation.force;
|
||||
permissions.canMarkAsFalsePositive = annotation.canBeMarkedAsFalsePositive;
|
||||
|
||||
permissions.canRemoveOrSuggestToRemoveOnlyHere = annotation.isRedacted && !annotation.force;
|
||||
permissions.canRemoveOrSuggestToRemoveOnlyHere = annotation.isRedacted;
|
||||
permissions.canRemoveOrSuggestToRemoveFromDictionary =
|
||||
(annotation.isRedacted && !annotation.isManualRedaction && annotation.isModifyDictionary && !annotation.force) ||
|
||||
(annotation.isSkipped && annotation.isModifyDictionary);
|
||||
annotation.isModifyDictionary && (annotation.isRedacted || annotation.isSkipped);
|
||||
|
||||
permissions.canAcceptSuggestion = isApprover && (annotation.isSuggestion || annotation.isDeclinedSuggestion);
|
||||
permissions.canRejectSuggestion = isApprover && annotation.isSuggestion;
|
||||
|
||||
permissions.canChangeLegalBasis = !annotation.isManualRedaction && annotation.isRedacted;
|
||||
permissions.canChangeLegalBasis = annotation.isRedacted;
|
||||
|
||||
permissions.canRecategorizeImage = annotation.isImage;
|
||||
|
||||
|
||||
@ -60,10 +60,6 @@ export class AnnotationWrapper {
|
||||
|
||||
constructor() {}
|
||||
|
||||
get isUndoableActionForApprover() {
|
||||
return this.manual;
|
||||
}
|
||||
|
||||
get isChangeLogRemoved() {
|
||||
return this.changeLogType === 'REMOVED';
|
||||
}
|
||||
@ -81,11 +77,7 @@ export class AnnotationWrapper {
|
||||
}
|
||||
|
||||
get canBeMarkedAsFalsePositive() {
|
||||
return (this.isRecommendation || this.superType === 'redaction') && (this.hasTextAfter || this.hasTextBefore) && !this.isImage;
|
||||
}
|
||||
|
||||
get canBeMarkedAsFalsePositiveWithTextOnly() {
|
||||
return !this.canBeMarkedAsFalsePositive && (this.isRecommendation || this.superType === 'redaction') && !this.isImage;
|
||||
return (this.isRecommendation || this.superType === 'redaction') && !this.isImage;
|
||||
}
|
||||
|
||||
get isSuperTypeBasedColor() {
|
||||
@ -104,6 +96,10 @@ export class AnnotationWrapper {
|
||||
return this.dictionary?.toLowerCase() === 'ocr';
|
||||
}
|
||||
|
||||
get isManuallySkipped() {
|
||||
return this.isSkipped && this.manual;
|
||||
}
|
||||
|
||||
get isFalsePositive() {
|
||||
return (
|
||||
this.dictionary?.toLowerCase() === 'false_positive' &&
|
||||
@ -259,6 +255,32 @@ export class AnnotationWrapper {
|
||||
return;
|
||||
}
|
||||
|
||||
if (annotationWrapper.dictionary?.toLowerCase() === 'false_positive') {
|
||||
if (redactionLogEntryWrapper.status === 'REQUESTED') {
|
||||
annotationWrapper.superType = 'suggestion-add-dictionary';
|
||||
return;
|
||||
}
|
||||
if (redactionLogEntryWrapper.status === 'APPROVED') {
|
||||
annotationWrapper.superType = 'add-dictionary';
|
||||
return;
|
||||
}
|
||||
if (!redactionLogEntryWrapper.manual) {
|
||||
annotationWrapper.superType = 'skipped';
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (redactionLogEntryWrapper.type?.toLowerCase() === 'manual') {
|
||||
if (redactionLogEntryWrapper.status === 'REQUESTED') {
|
||||
annotationWrapper.superType = 'suggestion-add';
|
||||
return;
|
||||
}
|
||||
if (redactionLogEntryWrapper.status === 'APPROVED') {
|
||||
annotationWrapper.superType = 'manual-redaction';
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (redactionLogEntryWrapper.manualRedactionType === 'LEGAL_BASIS_CHANGE') {
|
||||
if (redactionLogEntryWrapper.status === 'REQUESTED') {
|
||||
annotationWrapper.superType = 'suggestion-change-legal-basis';
|
||||
@ -279,21 +301,6 @@ export class AnnotationWrapper {
|
||||
}
|
||||
}
|
||||
|
||||
if (annotationWrapper.dictionary?.toLowerCase() === 'false_positive') {
|
||||
if (redactionLogEntryWrapper.status === 'REQUESTED') {
|
||||
annotationWrapper.superType = 'suggestion-add-dictionary';
|
||||
return;
|
||||
}
|
||||
if (redactionLogEntryWrapper.status === 'APPROVED') {
|
||||
annotationWrapper.superType = 'add-dictionary';
|
||||
return;
|
||||
}
|
||||
if (!redactionLogEntryWrapper.manual) {
|
||||
annotationWrapper.superType = 'skipped';
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (redactionLogEntryWrapper.manualRedactionType === 'ADD') {
|
||||
if (redactionLogEntryWrapper.dictionaryEntry) {
|
||||
if (redactionLogEntryWrapper.status === 'REQUESTED') {
|
||||
|
||||
@ -53,15 +53,6 @@
|
||||
icon="red:thumb-down"
|
||||
></iqser-circle-button>
|
||||
|
||||
<iqser-circle-button
|
||||
(action)="annotationActionsService.markAsFalsePositive($event, annotations, annotationsChanged)"
|
||||
*ngIf="annotationPermissions.canMarkTextOnlyAsFalsePositive && !annotationPermissions.canPerformMultipleRemoveActions"
|
||||
[tooltipPosition]="tooltipPosition"
|
||||
[tooltip]="'annotation-actions.remove-annotation.false-positive' | translate"
|
||||
[type]="buttonType"
|
||||
icon="red:thumb-down"
|
||||
></iqser-circle-button>
|
||||
|
||||
<iqser-circle-button
|
||||
(action)="annotationActionsService.forceRedaction($event, annotations, annotationsChanged)"
|
||||
*ngIf="annotationPermissions.canForceRedaction"
|
||||
|
||||
@ -26,7 +26,6 @@ export class AnnotationActionsService {
|
||||
acceptSuggestion($event: MouseEvent, annotations: AnnotationWrapper[], annotationsChanged: EventEmitter<AnnotationWrapper>) {
|
||||
$event?.stopPropagation();
|
||||
annotations.forEach(annotation => {
|
||||
console.log('Accept ', annotation);
|
||||
this._processObsAndEmit(
|
||||
this._manualAnnotationService.approveRequest(annotation.id, annotation.isModifyDictionary),
|
||||
annotation,
|
||||
@ -89,14 +88,7 @@ export class AnnotationActionsService {
|
||||
|
||||
markAsFalsePositive($event: MouseEvent, annotations: AnnotationWrapper[], annotationsChanged: EventEmitter<AnnotationWrapper>) {
|
||||
annotations.forEach(annotation => {
|
||||
const permissions = AnnotationPermissions.forUser(
|
||||
this._permissionsService.isApprover(),
|
||||
this._userService.currentUser,
|
||||
annotation
|
||||
);
|
||||
const value = permissions.canMarkTextOnlyAsFalsePositive ? annotation.value : this._getFalsePositiveText(annotation);
|
||||
|
||||
this._markAsFalsePositive($event, annotation, value, annotationsChanged);
|
||||
this._markAsFalsePositive($event, annotation, this._getFalsePositiveText(annotation), annotationsChanged);
|
||||
});
|
||||
}
|
||||
|
||||
@ -212,10 +204,7 @@ export class AnnotationActionsService {
|
||||
});
|
||||
}
|
||||
|
||||
const canMarkAsFalsePositive = annotationPermissions.reduce(
|
||||
(acc, next) => acc && (next.permissions.canMarkAsFalsePositive || next.permissions.canMarkTextOnlyAsFalsePositive),
|
||||
true
|
||||
);
|
||||
const canMarkAsFalsePositive = annotationPermissions.reduce((acc, next) => acc && next.permissions.canMarkAsFalsePositive, true);
|
||||
if (canMarkAsFalsePositive) {
|
||||
availableActions.push({
|
||||
type: 'actionButton',
|
||||
@ -293,10 +282,13 @@ export class AnnotationActionsService {
|
||||
let text;
|
||||
if (annotation.hasTextAfter) {
|
||||
text = getFirstRelevantTextPart(annotation.textAfter, 'FORWARD');
|
||||
return (annotation.value + text).trim();
|
||||
} else {
|
||||
return text ? (annotation.value + text).trim() : annotation.value;
|
||||
}
|
||||
if (annotation.hasTextAfter) {
|
||||
text = getFirstRelevantTextPart(annotation.textBefore, 'BACKWARD');
|
||||
return (text + annotation.value).trim();
|
||||
return text ? (text + annotation.value).trim() : annotation.value;
|
||||
} else {
|
||||
return annotation.value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -169,7 +169,7 @@ export class ManualAnnotationService {
|
||||
if (this._permissionsService.isApprover()) {
|
||||
// if it was something manual simply decline the existing request
|
||||
if (annotationWrapper.dictionary === 'manual') {
|
||||
mode = 'decline';
|
||||
mode = 'undo';
|
||||
body = annotationWrapper.id;
|
||||
} else {
|
||||
mode = 'remove';
|
||||
@ -218,7 +218,6 @@ export class ManualAnnotationService {
|
||||
private _getMessage(mode: AnnotationActionMode, modifyDictionary?: boolean, error: boolean = false) {
|
||||
const type = modifyDictionary ? 'dictionary' : 'manual-redaction';
|
||||
const resultType = error ? 'error' : 'success';
|
||||
console.log(type, mode, resultType);
|
||||
return annotationActionsTranslations[type][mode][resultType];
|
||||
}
|
||||
}
|
||||
|
||||
@ -1 +1 @@
|
||||
Subproject commit 360ef9bd6c87ec2ebb22554253e9ce9390775f09
|
||||
Subproject commit 1d46b21c74c07d6811a99b9de6c940c740bc8ceb
|
||||
Loading…
x
Reference in New Issue
Block a user