From d673348defe237f2f7e65b20b2e3dd6ad6bfab04 Mon Sep 17 00:00:00 2001 From: Valentin Mihai Date: Tue, 12 Nov 2024 18:45:44 +0200 Subject: [PATCH] RED-10373 - remove redaction dialog updates to be able to create multiple bulk requests for rectangle annotations --- .../edit-redaction-dialog.component.ts | 6 +--- .../remove-redaction-dialog.component.ts | 11 +++--- .../services/annotation-actions.service.ts | 36 +++++++++++-------- .../file-preview/utils/dialog-options.ts | 8 ++++- .../file-preview/utils/dialog-types.ts | 2 +- .../enhance-manual-redaction-request.utils.ts | 2 +- apps/red-ui/src/assets/i18n/redact/en.json | 4 +-- 7 files changed, 41 insertions(+), 28 deletions(-) diff --git a/apps/red-ui/src/app/modules/file-preview/dialogs/edit-redaction-dialog/edit-redaction-dialog.component.ts b/apps/red-ui/src/app/modules/file-preview/dialogs/edit-redaction-dialog/edit-redaction-dialog.component.ts index 645fa6850..b90c2de37 100644 --- a/apps/red-ui/src/app/modules/file-preview/dialogs/edit-redaction-dialog/edit-redaction-dialog.component.ts +++ b/apps/red-ui/src/app/modules/file-preview/dialogs/edit-redaction-dialog/edit-redaction-dialog.component.ts @@ -214,11 +214,7 @@ export class EditRedactionDialogComponent const value = this.form.value; const initialReason: LegalBasisOption = this.initialFormValue.reason; const initialLegalBasis = initialReason?.legalBasis ?? ''; - const pageNumbers = parseSelectedPageNumbers( - this.form.get('option').value?.additionalInput?.value, - this.data.file, - this.data.annotations[0], - ); + const pageNumbers = parseSelectedPageNumbers(this.form.get('option').value?.additionalInput?.value, this.data.file); const position = parseRectanglePosition(this.annotations[0]); this.close({ diff --git a/apps/red-ui/src/app/modules/file-preview/dialogs/remove-redaction-dialog/remove-redaction-dialog.component.ts b/apps/red-ui/src/app/modules/file-preview/dialogs/remove-redaction-dialog/remove-redaction-dialog.component.ts index 0ffa843bb..a5b198b4b 100644 --- a/apps/red-ui/src/app/modules/file-preview/dialogs/remove-redaction-dialog/remove-redaction-dialog.component.ts +++ b/apps/red-ui/src/app/modules/file-preview/dialogs/remove-redaction-dialog/remove-redaction-dialog.component.ts @@ -103,7 +103,7 @@ export class RemoveRedactionDialogComponent extends IqserDialogComponent< : this.optionByType[this.annotationsType].main; readonly extraOptionPreference = stringToBoolean(this.optionByType[this.annotationsType].extra); readonly options: DetailsRadioOption[] = this.#allRectangles - ? getRectangleRedactOptions('remove') + ? getRectangleRedactOptions('remove', this.data) : getRemoveRedactionOptions( this.data, this.isSystemDefault || this.isExtraOptionSystemDefault ? this.#applyToAllDossiers : this.extraOptionPreference, @@ -187,14 +187,17 @@ export class RemoveRedactionDialogComponent extends IqserDialogComponent< save(): void { const optionValue = this.form.controls.option?.value?.value; const optionInputValue = this.form.controls.option?.value?.additionalInput?.value; - const pageNumbers = parseSelectedPageNumbers(optionInputValue, this.data.file, this.data.redactions[0]); - const position = parseRectanglePosition(this.data.redactions[0]); + const pageNumbers = parseSelectedPageNumbers(optionInputValue, this.data.file); + const positions = []; + for (const redaction of this.data.redactions) { + positions.push(parseRectanglePosition(redaction)); + } this.close({ ...this.form.getRawValue(), bulkLocal: optionValue === ResizeOptions.IN_DOCUMENT || optionValue === RectangleRedactOptions.MULTIPLE_PAGES, pageNumbers, - position, + positions, }); } 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 fdddc5c1c..8df5c15c7 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 @@ -479,6 +479,7 @@ export class AnnotationActionsService { const isHint = redactions.every(r => r.isHint); const { dossierId, fileId } = this._state; const maximumNumberEntries = 100; + const bulkLocal = dialogResult.bulkLocal || !!dialogResult.pageNumbers.length; if (removeFromDictionary && (body as List).length > maximumNumberEntries) { const requests = body as List; const splitNumber = Math.floor(requests.length / maximumNumberEntries); @@ -493,15 +494,28 @@ export class AnnotationActionsService { const promises = []; for (const split of splitRequests) { + promises.push( + firstValueFrom( + this._manualRedactionService.removeRedaction(split, dossierId, fileId, removeFromDictionary, isHint, bulkLocal), + ), + ); + } + Promise.all(promises).finally(() => this._fileDataService.annotationsChanged()); + return; + } + + if (redactions[0].AREA && bulkLocal) { + const promises = []; + for (const request of body) { promises.push( firstValueFrom( this._manualRedactionService.removeRedaction( - split, + request as IBulkLocalRemoveRequest, dossierId, fileId, removeFromDictionary, isHint, - dialogResult.bulkLocal, + bulkLocal, ), ), ); @@ -509,15 +523,9 @@ export class AnnotationActionsService { Promise.all(promises).finally(() => this._fileDataService.annotationsChanged()); return; } + this.#processObsAndEmit( - this._manualRedactionService.removeRedaction( - body, - dossierId, - fileId, - removeFromDictionary, - isHint, - dialogResult.bulkLocal || !!dialogResult.pageNumbers.length, - ), + this._manualRedactionService.removeRedaction(body, dossierId, fileId, removeFromDictionary, isHint, bulkLocal), ).then(); } @@ -577,16 +585,16 @@ export class AnnotationActionsService { #getRemoveRedactionBody( redactions: AnnotationWrapper[], dialogResult: RemoveRedactionResult, - ): List | IBulkLocalRemoveRequest { + ): List { if (dialogResult.bulkLocal || !!dialogResult.pageNumbers.length) { const redaction = redactions[0]; - return { + return dialogResult.positions.map(position => ({ value: redaction.value, rectangle: redaction.AREA, pageNumbers: dialogResult.pageNumbers, - position: dialogResult.position, + position: position, comment: dialogResult.comment, - }; + })); } return redactions.map(redaction => ({ diff --git a/apps/red-ui/src/app/modules/file-preview/utils/dialog-options.ts b/apps/red-ui/src/app/modules/file-preview/utils/dialog-options.ts index a512cf90a..bd35ccf4c 100644 --- a/apps/red-ui/src/app/modules/file-preview/utils/dialog-options.ts +++ b/apps/red-ui/src/app/modules/file-preview/utils/dialog-options.ts @@ -102,19 +102,25 @@ export const getRedactOrHintOptions = ( return options; }; -export const getRectangleRedactOptions = (action: 'add' | 'edit' | 'remove' = 'add'): DetailsRadioOption[] => { +export const getRectangleRedactOptions = ( + action: 'add' | 'edit' | 'remove' = 'add', + data?: RemoveRedactionData, +): DetailsRadioOption[] => { const translations = action === 'add' ? rectangleRedactTranslations : action === 'edit' ? editRectangleTranslations : removeRectangleTranslations; + const redactions = data?.redactions ?? []; return [ { label: translations.onlyThisPage.label, description: translations.onlyThisPage.description, + descriptionParams: { length: redactions.length }, icon: PIN_ICON, value: RectangleRedactOptions.ONLY_THIS_PAGE, }, { label: translations.multiplePages.label, description: translations.multiplePages.description, + descriptionParams: { length: redactions.length }, icon: DOCUMENT_ICON, value: RectangleRedactOptions.MULTIPLE_PAGES, additionalInput: { diff --git a/apps/red-ui/src/app/modules/file-preview/utils/dialog-types.ts b/apps/red-ui/src/app/modules/file-preview/utils/dialog-types.ts index c1c5ac931..229b0639f 100644 --- a/apps/red-ui/src/app/modules/file-preview/utils/dialog-types.ts +++ b/apps/red-ui/src/app/modules/file-preview/utils/dialog-types.ts @@ -168,7 +168,7 @@ export interface RemoveRedactionResult { applyToAllDossiers?: boolean; bulkLocal?: boolean; pageNumbers?: number[]; - position: IEntityLogEntryPosition; + positions: IEntityLogEntryPosition[]; } export type RemoveAnnotationResult = RemoveRedactionResult; diff --git a/apps/red-ui/src/app/modules/file-preview/utils/enhance-manual-redaction-request.utils.ts b/apps/red-ui/src/app/modules/file-preview/utils/enhance-manual-redaction-request.utils.ts index 17e16a046..4930abc31 100644 --- a/apps/red-ui/src/app/modules/file-preview/utils/enhance-manual-redaction-request.utils.ts +++ b/apps/red-ui/src/app/modules/file-preview/utils/enhance-manual-redaction-request.utils.ts @@ -49,7 +49,7 @@ export const enhanceManualRedactionRequest = (addRedactionRequest: IAddRedaction addRedactionRequest.addToAllDossiers = data.isApprover && data.dictionaryRequest && data.applyToAllDossiers; }; -export const parseSelectedPageNumbers = (inputValue: string, file: File, annotation: AnnotationWrapper) => { +export const parseSelectedPageNumbers = (inputValue: string, file: File) => { if (!inputValue) { return []; } diff --git a/apps/red-ui/src/assets/i18n/redact/en.json b/apps/red-ui/src/assets/i18n/redact/en.json index ac9e4bdbb..c52ba5f5f 100644 --- a/apps/red-ui/src/assets/i18n/redact/en.json +++ b/apps/red-ui/src/assets/i18n/redact/en.json @@ -2188,14 +2188,14 @@ "content": { "options": { "multiple-pages": { - "description": "Remove redaction on a range of pages", + "description": "Remove {length, plural, one{redaction} other {redactions}} on a range of pages", "extraOptionDescription": "Minus(-) for range and comma(,) for enumeration", "extraOptionLabel": "Pages", "extraOptionPlaceholder": "e.g. 1-20,22,32", "label": "Remove on multiple pages" }, "only-this-page": { - "description": "Remove redaction only at this position in this document", + "description": "Remove {length, plural, one{redaction} other {redactions}} only at this position in this document", "label": "Remove only on this page" } }