From ff129b64ca664394e5f896daf533a5d899ccee21 Mon Sep 17 00:00:00 2001 From: Nicoleta Panaghiu Date: Wed, 10 Apr 2024 16:12:54 +0300 Subject: [PATCH] RED-8636: use the new recategorize endpoint & updated success message. --- .../services/annotation-actions.service.ts | 80 ++++++++++--------- .../services/manual-redaction.service.ts | 40 ++++++---- .../annotation-actions-translations.ts | 10 +-- apps/red-ui/src/assets/i18n/redact/de.json | 26 ++---- apps/red-ui/src/assets/i18n/redact/en.json | 17 ++-- apps/red-ui/src/assets/i18n/scm/de.json | 26 ++---- apps/red-ui/src/assets/i18n/scm/en.json | 17 ++-- libs/red-domain/src/lib/annotations/types.ts | 3 +- .../redaction-log/recategorization.request.ts | 3 + 9 files changed, 92 insertions(+), 130 deletions(-) diff --git a/apps/red-ui/src/app/modules/file-preview/services/annotation-actions.service.ts b/apps/red-ui/src/app/modules/file-preview/services/annotation-actions.service.ts index 23a115d14..a5e7058b4 100644 --- a/apps/red-ui/src/app/modules/file-preview/services/annotation-actions.service.ts +++ b/apps/red-ui/src/app/modules/file-preview/services/annotation-actions.service.ts @@ -16,7 +16,7 @@ import { import { CommentsApiService } from '@services/comments-api.service'; import { DossierTemplatesService } from '@services/dossier-templates/dossier-templates.service'; import { PermissionsService } from '@services/permissions.service'; -import { firstValueFrom, Observable, zip } from 'rxjs'; +import { firstValueFrom, Observable } from 'rxjs'; import { getFirstRelevantTextPart } from '../../../utils'; import { AnnotationDrawService } from '../../pdf-viewer/services/annotation-draw.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 { EditRedactionData, + EditRedactResult, RemoveRedactionData, RemoveRedactionPermissions, RemoveRedactionResult, @@ -101,47 +102,34 @@ export class AnnotationActionsService { }; const result = await this.#getEditRedactionDialog(data).result(); - - const requests: Observable[] = []; - if (!result) { return; } - if ( - !this.#isDocumine && - (!annotations.every(annotation => annotation.legalBasis === result.legalBasis) || - !annotations.every(annotation => annotation.section === result.section)) - ) { - const changeLegalBasisBody = annotations.map(annotation => ({ - annotationId: annotation.id, - legalBasis: result.legalBasis, - section: result.section ?? annotation.section, - value: result.value ?? annotation.value, - })); - requests.push( - this._manualRedactionService.changeLegalBasis( - changeLegalBasisBody, - dossierId, - fileId, - file().excludedFromAutomaticAnalysis && isUnprocessed, - ), - ); - } - if (result.type && !annotations.every(annotation => annotation.type === result.type)) { - const recategorizeBody: List = annotations.map(annotation => ({ - annotationId: annotation.id, - type: result.type ?? annotation.type, - })); - requests.push( - this._manualRedactionService.recategorizeRedactions( + const recategorizeBody: List = annotations.map(annotation => { + const body = { annotationId: annotation.id, type: result.type ?? annotation.type }; + if (!this.#isDocumine) { + return { + ...body, + legalBasis: result.legalBasis, + section: result.section ?? annotation.section, + value: result.value ?? annotation.value, + }; + } + return body; + }); + + await this.#processObsAndEmit( + this._manualRedactionService + .recategorizeRedactions( recategorizeBody, dossierId, fileId, + this.#getChangedFields(annotations, result), file().excludedFromAutomaticAnalysis && isUnprocessed, - ), - ); - } + ) + .pipe(log()), + ); if (result.comment) { try { @@ -152,11 +140,6 @@ export class AnnotationActionsService { this._toaster.rawError(error.error.message); } } - - if (!requests.length) { - return; - } - await this.#processObsAndEmit(zip(requests).pipe(log())); } async removeRedaction(redactions: AnnotationWrapper[], permissions: AnnotationPermissions) { @@ -498,4 +481,23 @@ export class AnnotationActionsService { 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(', ') }; + } } diff --git a/apps/red-ui/src/app/modules/file-preview/services/manual-redaction.service.ts b/apps/red-ui/src/app/modules/file-preview/services/manual-redaction.service.ts index e8c7799b1..a86a57ef7 100644 --- a/apps/red-ui/src/app/modules/file-preview/services/manual-redaction.service.ts +++ b/apps/red-ui/src/app/modules/file-preview/services/manual-redaction.service.ts @@ -18,7 +18,7 @@ import type { import { dictionaryActionsTranslations, manualRedactionActionsTranslations } from '@translations/annotation-actions-translations'; import { Roles } from '@users/roles'; import { NGXLogger } from 'ngx-logger'; -import { EMPTY, of, OperatorFunction, pipe } from 'rxjs'; +import { EMPTY, of, pipe } from 'rxjs'; import { catchError, tap } from 'rxjs/operators'; function getResponseType(error: boolean, isConflict: boolean) { @@ -62,12 +62,18 @@ export class ManualRedactionService extends GenericService { return this.addAnnotation(recommendations, dossierId, fileId); } - changeLegalBasis(body: List, dossierId: string, fileId: string, includeUnprocessed = false) { - return this.legalBasisChange(body, dossierId, fileId, includeUnprocessed).pipe(this.#showToast('change-legal-basis')); - } - - recategorizeRedactions(body: List, dossierId: string, fileId: string, includeUnprocessed = false) { - return this.recategorize(body, dossierId, fileId, includeUnprocessed).pipe(this.#showToast('change-type')); + recategorizeRedactions( + body: List, + dossierId: string, + fileId: string, + successMessageParameters?: { + [key: string]: string; + }, + includeUnprocessed = false, + ) { + return this.recategorize(body, dossierId, fileId, includeUnprocessed).pipe( + this.#showToast('recategorize-annotation', false, successMessageParameters), + ); } addAnnotation( @@ -131,13 +137,6 @@ export class ManualRedactionService extends GenericService { ); } - legalBasisChange(body: List, 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) { const url = `${this._defaultModelPath}/bulk/undo/${dossierId}/${fileId}`; return super.delete(annotationIds, url).pipe(this.#log('Undo', annotationIds)); @@ -165,7 +164,11 @@ export class ManualRedactionService extends GenericService { }); } - #showToast(action: ManualRedactionActions | DictionaryActions, isDictionary = false) { + #showToast( + action: ManualRedactionActions | DictionaryActions, + isDictionary = false, + successMessageParameters?: { [key: string]: string }, + ) { return pipe( catchError((error: unknown) => { const isConflict = (error as HttpErrorResponse).status === HttpStatusCode.Conflict; @@ -175,7 +178,12 @@ export class ManualRedactionService extends GenericService { }); 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', + }), + ), ); } diff --git a/apps/red-ui/src/app/translations/annotation-actions-translations.ts b/apps/red-ui/src/app/translations/annotation-actions-translations.ts index fe1b0f8b6..b08871dea 100644 --- a/apps/red-ui/src/app/translations/annotation-actions-translations.ts +++ b/apps/red-ui/src/app/translations/annotation-actions-translations.ts @@ -28,10 +28,6 @@ export const manualRedactionActionsTranslations: Record