RED-8636: use the new recategorize endpoint & updated success message.

This commit is contained in:
Nicoleta Panaghiu 2024-04-10 16:12:54 +03:00
parent 313eeef0ae
commit ff129b64ca
9 changed files with 92 additions and 130 deletions

View File

@ -16,7 +16,7 @@ import {
import { CommentsApiService } from '@services/comments-api.service'; import { CommentsApiService } from '@services/comments-api.service';
import { DossierTemplatesService } from '@services/dossier-templates/dossier-templates.service'; import { DossierTemplatesService } from '@services/dossier-templates/dossier-templates.service';
import { PermissionsService } from '@services/permissions.service'; import { PermissionsService } from '@services/permissions.service';
import { firstValueFrom, Observable, zip } from 'rxjs'; import { firstValueFrom, Observable } from 'rxjs';
import { getFirstRelevantTextPart } from '../../../utils'; import { getFirstRelevantTextPart } from '../../../utils';
import { AnnotationDrawService } from '../../pdf-viewer/services/annotation-draw.service'; import { AnnotationDrawService } from '../../pdf-viewer/services/annotation-draw.service';
import { REDAnnotationManager } from '../../pdf-viewer/services/annotation-manager.service'; import { REDAnnotationManager } from '../../pdf-viewer/services/annotation-manager.service';
@ -32,6 +32,7 @@ import { ResizeRedactionDialogComponent } from '../dialogs/resize-redaction-dial
import { RemoveRedactionOptions } from '../utils/dialog-options'; import { RemoveRedactionOptions } from '../utils/dialog-options';
import { import {
EditRedactionData, EditRedactionData,
EditRedactResult,
RemoveRedactionData, RemoveRedactionData,
RemoveRedactionPermissions, RemoveRedactionPermissions,
RemoveRedactionResult, RemoveRedactionResult,
@ -101,47 +102,34 @@ export class AnnotationActionsService {
}; };
const result = await this.#getEditRedactionDialog(data).result(); const result = await this.#getEditRedactionDialog(data).result();
const requests: Observable<unknown>[] = [];
if (!result) { if (!result) {
return; return;
} }
if ( const recategorizeBody: List<IRecategorizationRequest> = annotations.map(annotation => {
!this.#isDocumine && const body = { annotationId: annotation.id, type: result.type ?? annotation.type };
(!annotations.every(annotation => annotation.legalBasis === result.legalBasis) || if (!this.#isDocumine) {
!annotations.every(annotation => annotation.section === result.section)) return {
) { ...body,
const changeLegalBasisBody = annotations.map(annotation => ({ legalBasis: result.legalBasis,
annotationId: annotation.id, section: result.section ?? annotation.section,
legalBasis: result.legalBasis, value: result.value ?? annotation.value,
section: result.section ?? annotation.section, };
value: result.value ?? annotation.value, }
})); return body;
requests.push( });
this._manualRedactionService.changeLegalBasis(
changeLegalBasisBody, await this.#processObsAndEmit(
dossierId, this._manualRedactionService
fileId, .recategorizeRedactions(
file().excludedFromAutomaticAnalysis && isUnprocessed,
),
);
}
if (result.type && !annotations.every(annotation => annotation.type === result.type)) {
const recategorizeBody: List<IRecategorizationRequest> = annotations.map(annotation => ({
annotationId: annotation.id,
type: result.type ?? annotation.type,
}));
requests.push(
this._manualRedactionService.recategorizeRedactions(
recategorizeBody, recategorizeBody,
dossierId, dossierId,
fileId, fileId,
this.#getChangedFields(annotations, result),
file().excludedFromAutomaticAnalysis && isUnprocessed, file().excludedFromAutomaticAnalysis && isUnprocessed,
), )
); .pipe(log()),
} );
if (result.comment) { if (result.comment) {
try { try {
@ -152,11 +140,6 @@ export class AnnotationActionsService {
this._toaster.rawError(error.error.message); this._toaster.rawError(error.error.message);
} }
} }
if (!requests.length) {
return;
}
await this.#processObsAndEmit(zip(requests).pipe(log()));
} }
async removeRedaction(redactions: AnnotationWrapper[], permissions: AnnotationPermissions) { async removeRedaction(redactions: AnnotationWrapper[], permissions: AnnotationPermissions) {
@ -498,4 +481,23 @@ export class AnnotationActionsService {
isApprover, isApprover,
}; };
} }
#getChangedFields(annotations: AnnotationWrapper[], result: EditRedactResult) {
const changedFields = [];
if (result.type && !annotations.every(annotation => annotation.type === result.type)) {
changedFields.push('type');
}
if (this.#isDocumine) {
return { changes: changedFields.join(', ') };
}
if (result.legalBasis && !annotations.every(annotation => annotation.legalBasis === result.legalBasis)) {
changedFields.push('reason');
}
if (typeof result.section === 'string' && !annotations.every(annotation => annotation.section === result.section)) {
changedFields.push('paragraph/location');
}
return { changes: changedFields.join(', ') };
}
} }

View File

@ -18,7 +18,7 @@ import type {
import { dictionaryActionsTranslations, manualRedactionActionsTranslations } from '@translations/annotation-actions-translations'; import { dictionaryActionsTranslations, manualRedactionActionsTranslations } from '@translations/annotation-actions-translations';
import { Roles } from '@users/roles'; import { Roles } from '@users/roles';
import { NGXLogger } from 'ngx-logger'; import { NGXLogger } from 'ngx-logger';
import { EMPTY, of, OperatorFunction, pipe } from 'rxjs'; import { EMPTY, of, pipe } from 'rxjs';
import { catchError, tap } from 'rxjs/operators'; import { catchError, tap } from 'rxjs/operators';
function getResponseType(error: boolean, isConflict: boolean) { function getResponseType(error: boolean, isConflict: boolean) {
@ -62,12 +62,18 @@ export class ManualRedactionService extends GenericService<IManualAddResponse> {
return this.addAnnotation(recommendations, dossierId, fileId); return this.addAnnotation(recommendations, dossierId, fileId);
} }
changeLegalBasis(body: List<ILegalBasisChangeRequest>, dossierId: string, fileId: string, includeUnprocessed = false) { recategorizeRedactions(
return this.legalBasisChange(body, dossierId, fileId, includeUnprocessed).pipe(this.#showToast('change-legal-basis')); body: List<IRecategorizationRequest>,
} dossierId: string,
fileId: string,
recategorizeRedactions(body: List<IRecategorizationRequest>, dossierId: string, fileId: string, includeUnprocessed = false) { successMessageParameters?: {
return this.recategorize(body, dossierId, fileId, includeUnprocessed).pipe(this.#showToast('change-type')); [key: string]: string;
},
includeUnprocessed = false,
) {
return this.recategorize(body, dossierId, fileId, includeUnprocessed).pipe(
this.#showToast('recategorize-annotation', false, successMessageParameters),
);
} }
addAnnotation( addAnnotation(
@ -131,13 +137,6 @@ export class ManualRedactionService extends GenericService<IManualAddResponse> {
); );
} }
legalBasisChange(body: List<ILegalBasisChangeRequest>, dossierId: string, fileId: string, includeUnprocessed = false) {
return this._post(
body,
`${this.#bulkRedaction}/legalBasisChange/${dossierId}/${fileId}?includeUnprocessed=${includeUnprocessed}`,
).pipe(this.#log('Legal basis change', body));
}
undo(annotationIds: List, dossierId: string, fileId: string) { undo(annotationIds: List, dossierId: string, fileId: string) {
const url = `${this._defaultModelPath}/bulk/undo/${dossierId}/${fileId}`; const url = `${this._defaultModelPath}/bulk/undo/${dossierId}/${fileId}`;
return super.delete(annotationIds, url).pipe(this.#log('Undo', annotationIds)); return super.delete(annotationIds, url).pipe(this.#log('Undo', annotationIds));
@ -165,7 +164,11 @@ export class ManualRedactionService extends GenericService<IManualAddResponse> {
}); });
} }
#showToast(action: ManualRedactionActions | DictionaryActions, isDictionary = false) { #showToast(
action: ManualRedactionActions | DictionaryActions,
isDictionary = false,
successMessageParameters?: { [key: string]: string },
) {
return pipe( return pipe(
catchError((error: unknown) => { catchError((error: unknown) => {
const isConflict = (error as HttpErrorResponse).status === HttpStatusCode.Conflict; const isConflict = (error as HttpErrorResponse).status === HttpStatusCode.Conflict;
@ -175,7 +178,12 @@ export class ManualRedactionService extends GenericService<IManualAddResponse> {
}); });
return EMPTY; return EMPTY;
}), }),
tap(() => this._toaster.success(getMessage(action, isDictionary), { positionClass: 'toast-file-preview' })), tap(() =>
this._toaster.success(getMessage(action, isDictionary), {
params: successMessageParameters,
positionClass: 'toast-file-preview',
}),
),
); );
} }

View File

@ -28,10 +28,6 @@ export const manualRedactionActionsTranslations: Record<ManualRedactionActions,
error: _('annotation-actions.message.manual-redaction.add.error'), error: _('annotation-actions.message.manual-redaction.add.error'),
success: _('annotation-actions.message.manual-redaction.add.success'), success: _('annotation-actions.message.manual-redaction.add.success'),
}, },
'change-legal-basis': {
error: _('annotation-actions.message.manual-redaction.change-legal-basis.error'),
success: _('annotation-actions.message.manual-redaction.change-legal-basis.success'),
},
'force-redaction': { 'force-redaction': {
error: _('annotation-actions.message.manual-redaction.force-redaction.error'), error: _('annotation-actions.message.manual-redaction.force-redaction.error'),
success: _('annotation-actions.message.manual-redaction.force-redaction.success'), success: _('annotation-actions.message.manual-redaction.force-redaction.success'),
@ -44,9 +40,9 @@ export const manualRedactionActionsTranslations: Record<ManualRedactionActions,
error: _('annotation-actions.message.manual-redaction.recategorize-image.error'), error: _('annotation-actions.message.manual-redaction.recategorize-image.error'),
success: _('annotation-actions.message.manual-redaction.recategorize-image.success'), success: _('annotation-actions.message.manual-redaction.recategorize-image.success'),
}, },
'change-type': { 'recategorize-annotation': {
error: _('annotation-actions.message.manual-redaction.change-type.error'), error: _('annotation-actions.message.manual-redaction.recategorize-annotation.error'),
success: _('annotation-actions.message.manual-redaction.change-type.success'), success: _('annotation-actions.message.manual-redaction.recategorize-annotation.success'),
}, },
undo: { undo: {
error: _('annotation-actions.message.manual-redaction.undo.error'), error: _('annotation-actions.message.manual-redaction.undo.error'),

View File

@ -288,14 +288,6 @@
"error": "Fehler beim Speichern der Schwärzung: {error}", "error": "Fehler beim Speichern der Schwärzung: {error}",
"success": "Schwärzung hinzugefügt!" "success": "Schwärzung hinzugefügt!"
}, },
"change-legal-basis": {
"error": "Fehler beim Bearbeiten der in der Anmerkung genannten Begründung: {error}",
"success": "In der Anmerkung genannte Begründung wurde bearbeitet."
},
"change-type": {
"error": "Failed to edit type: {error}",
"success": "Type was edited."
},
"force-hint": { "force-hint": {
"error": "Failed to save hint: {error}", "error": "Failed to save hint: {error}",
"success": "Hint added!" "success": "Hint added!"
@ -304,6 +296,10 @@
"error": "Die Schwärzung konnte nicht gespeichert werden!", "error": "Die Schwärzung konnte nicht gespeichert werden!",
"success": "Schwärzung eingefügt!" "success": "Schwärzung eingefügt!"
}, },
"recategorize-annotation": {
"error": "",
"success": ""
},
"recategorize-image": { "recategorize-image": {
"error": "Rekategorisierung des Bildes gescheitert: {error}", "error": "Rekategorisierung des Bildes gescheitert: {error}",
"success": "Bild wurde einer neuen Kategorie zugeordnet." "success": "Bild wurde einer neuen Kategorie zugeordnet."
@ -1266,15 +1262,6 @@
"heading": "Edit entity" "heading": "Edit entity"
} }
}, },
"entity": {
"info": {
"actions": {
"revert": "Revert",
"save": "Save changes"
},
"heading": "Edit entity"
}
},
"error": { "error": {
"deleted-entity": { "deleted-entity": {
"dossier": { "dossier": {
@ -1998,7 +1985,6 @@
"reason-placeholder": "Select a reason...", "reason-placeholder": "Select a reason...",
"revert-text": "Revert to selected text", "revert-text": "Revert to selected text",
"selected-text": "Selected text:", "selected-text": "Selected text:",
"text": "Text:",
"type": "Type", "type": "Type",
"type-placeholder": "Select type..." "type-placeholder": "Select type..."
}, },
@ -2079,9 +2065,7 @@
"description-bulk": "Do not redact the selected terms at this position in the current document.", "description-bulk": "Do not redact the selected terms at this position in the current document.",
"label": "Remove here" "label": "Remove here"
} }
}, }
"redacted-text": "Selected {type}",
"redacted-text-bulk": ""
}, },
"title": "Remove {type, select, redaction{redaction} recommendation{recommendation} other{hint}}", "title": "Remove {type, select, redaction{redaction} recommendation{recommendation} other{hint}}",
"title-bulk": "Remove {type, select, redaction{redactions} recommendation{recommendations} other{hints}}" "title-bulk": "Remove {type, select, redaction{redactions} recommendation{recommendations} other{hints}}"

View File

@ -288,14 +288,6 @@
"error": "Failed to save redaction: {error}", "error": "Failed to save redaction: {error}",
"success": "Redaction added!" "success": "Redaction added!"
}, },
"change-legal-basis": {
"error": "Failed to edit annotation reason: {error}",
"success": "Annotation reason was edited."
},
"change-type": {
"error": "Failed to edit type: {error}",
"success": "Type was edited."
},
"force-hint": { "force-hint": {
"error": "Failed to save hint: {error}", "error": "Failed to save hint: {error}",
"success": "Hint added!" "success": "Hint added!"
@ -304,6 +296,10 @@
"error": "Failed to save redaction: {error}", "error": "Failed to save redaction: {error}",
"success": "Redaction added!" "success": "Redaction added!"
}, },
"recategorize-annotation": {
"error": "Failed to edit type: {error}",
"success": "Annotation was edited: Changed {changes}."
},
"recategorize-image": { "recategorize-image": {
"error": "Failed to recategorize image: {error}", "error": "Failed to recategorize image: {error}",
"success": "Image recategorized." "success": "Image recategorized."
@ -1989,7 +1985,6 @@
"reason-placeholder": "Select a reason...", "reason-placeholder": "Select a reason...",
"revert-text": "Revert to selected text", "revert-text": "Revert to selected text",
"selected-text": "Selected text:", "selected-text": "Selected text:",
"text": "Text:",
"type": "Type", "type": "Type",
"type-placeholder": "Select type..." "type-placeholder": "Select type..."
}, },
@ -2070,9 +2065,7 @@
"description-bulk": "Do not redact the selected terms at this position in the current document.", "description-bulk": "Do not redact the selected terms at this position in the current document.",
"label": "Remove here" "label": "Remove here"
} }
}, }
"redacted-text": "Selected {type, select, redaction{redaction} recommendation{recommendation} other{hint}}",
"redacted-text-bulk": "Selected {type, select, redaction{redactions} recommendation{recommendations} other{hints}}"
}, },
"title": "Remove {type, select, redaction{redaction} recommendation{recommendation} other{hint}}", "title": "Remove {type, select, redaction{redaction} recommendation{recommendation} other{hint}}",
"title-bulk": "Remove {type, select, redaction{redactions} recommendation{recommendations} other{hints}}" "title-bulk": "Remove {type, select, redaction{redactions} recommendation{recommendations} other{hints}}"

View File

@ -288,14 +288,6 @@
"error": "Fehler beim Speichern der Schwärzung: {error}", "error": "Fehler beim Speichern der Schwärzung: {error}",
"success": "Schwärzung hinzugefügt!" "success": "Schwärzung hinzugefügt!"
}, },
"change-legal-basis": {
"error": "Fehler beim Bearbeiten der in der Anmerkung genannten Begründung: {error}",
"success": "In der Anmerkung genannte Begründung wurde bearbeitet."
},
"change-type": {
"error": "",
"success": ""
},
"force-hint": { "force-hint": {
"error": "Failed to save hint: {error}", "error": "Failed to save hint: {error}",
"success": "Hint added!" "success": "Hint added!"
@ -304,6 +296,10 @@
"error": "Die Schwärzung konnte nicht gespeichert werden!", "error": "Die Schwärzung konnte nicht gespeichert werden!",
"success": "Schwärzung eingefügt!" "success": "Schwärzung eingefügt!"
}, },
"recategorize-annotation": {
"error": "",
"success": ""
},
"recategorize-image": { "recategorize-image": {
"error": "Rekategorisierung des Bildes gescheitert: {error}", "error": "Rekategorisierung des Bildes gescheitert: {error}",
"success": "Bild wurde einer neuen Kategorie zugeordnet." "success": "Bild wurde einer neuen Kategorie zugeordnet."
@ -1266,15 +1262,6 @@
"heading": "Edit entity" "heading": "Edit entity"
} }
}, },
"entity": {
"info": {
"actions": {
"revert": "Revert",
"save": "Save changes"
},
"heading": "Edit entity"
}
},
"error": { "error": {
"deleted-entity": { "deleted-entity": {
"dossier": { "dossier": {
@ -1998,7 +1985,6 @@
"reason-placeholder": "Select a reasons...", "reason-placeholder": "Select a reasons...",
"revert-text": "", "revert-text": "",
"selected-text": "Selected text:", "selected-text": "Selected text:",
"text": "",
"type": "Type", "type": "Type",
"type-placeholder": "Select type..." "type-placeholder": "Select type..."
}, },
@ -2079,9 +2065,7 @@
"description-bulk": "", "description-bulk": "",
"label": "Remove here" "label": "Remove here"
} }
}, }
"redacted-text": "",
"redacted-text-bulk": ""
}, },
"title": "Remove {type}", "title": "Remove {type}",
"title-bulk": "" "title-bulk": ""

View File

@ -288,14 +288,6 @@
"error": "Failed to save annotation: {error}", "error": "Failed to save annotation: {error}",
"success": "Annotation added!" "success": "Annotation added!"
}, },
"change-legal-basis": {
"error": "Failed to edit annotation reason: {error}",
"success": "Annotation reason was edited."
},
"change-type": {
"error": "",
"success": ""
},
"force-hint": { "force-hint": {
"error": "Failed to save hint: {error}", "error": "Failed to save hint: {error}",
"success": "Hint added!" "success": "Hint added!"
@ -304,6 +296,10 @@
"error": "Failed to save annotation: {error}", "error": "Failed to save annotation: {error}",
"success": "Annotation added!" "success": "Annotation added!"
}, },
"recategorize-annotation": {
"error": "",
"success": ""
},
"recategorize-image": { "recategorize-image": {
"error": "Failed to recategorize image: {error}", "error": "Failed to recategorize image: {error}",
"success": "Image recategorized." "success": "Image recategorized."
@ -1989,7 +1985,6 @@
"reason-placeholder": "Select a reasons...", "reason-placeholder": "Select a reasons...",
"revert-text": "", "revert-text": "",
"selected-text": "Selected text:", "selected-text": "Selected text:",
"text": "",
"type": "Type", "type": "Type",
"type-placeholder": "Select type..." "type-placeholder": "Select type..."
}, },
@ -2070,9 +2065,7 @@
"description-bulk": "", "description-bulk": "",
"label": "Remove here" "label": "Remove here"
} }
}, }
"redacted-text": "",
"redacted-text-bulk": ""
}, },
"title": "Remove {type}", "title": "Remove {type}",
"title-bulk": "" "title-bulk": ""

View File

@ -6,12 +6,11 @@ export type ManualRedactionActions =
| 'add' | 'add'
| 'remove' | 'remove'
| 'remove-hint' | 'remove-hint'
| 'change-legal-basis'
| 'recategorize-image' | 'recategorize-image'
| 'undo' | 'undo'
| 'force-redaction' | 'force-redaction'
| 'force-hint' | 'force-hint'
| 'change-type'; | 'recategorize-annotation';
export const AnnotationIconTypes = { export const AnnotationIconTypes = {
square: 'square', square: 'square',

View File

@ -2,4 +2,7 @@ export interface IRecategorizationRequest {
readonly annotationId?: string; readonly annotationId?: string;
readonly comment?: string; readonly comment?: string;
readonly type?: string; readonly type?: string;
readonly legalBasis?: string;
readonly section?: string;
readonly value?: string;
} }