From f8cc82975da7628d971364ae59637578fa5363d4 Mon Sep 17 00:00:00 2001 From: Nicoleta Panaghiu Date: Wed, 20 Mar 2024 15:47:38 +0200 Subject: [PATCH] RED-8795: changed default options for add and remove dialogs. --- .../redact-text-dialog.component.ts | 15 ++++++- .../remove-redaction-dialog.component.ts | 39 ++++++++----------- .../file-preview/utils/dialog-options.ts | 8 ++-- 3 files changed, 33 insertions(+), 29 deletions(-) diff --git a/apps/red-ui/src/app/modules/file-preview/dialogs/redact-text-dialog/redact-text-dialog.component.ts b/apps/red-ui/src/app/modules/file-preview/dialogs/redact-text-dialog/redact-text-dialog.component.ts index 1404a02fe..5399600be 100644 --- a/apps/red-ui/src/app/modules/file-preview/dialogs/redact-text-dialog/redact-text-dialog.component.ts +++ b/apps/red-ui/src/app/modules/file-preview/dialogs/redact-text-dialog/redact-text-dialog.component.ts @@ -40,6 +40,16 @@ export class RedactTextDialogComponent readonly #manualRedactionTypeExists = inject(DictionaryService).hasManualType(this.#dossier.dossierTemplateId); #applyToAllDossiers = this.data.applyToAllDossiers ?? true; + get defaultOption() { + const inDossierOption = this.options.find(option => option.value === RedactOrHintOptions.IN_DOSSIER); + this.dictionaryRequest = !!inDossierOption && !inDossierOption.disabled; + if (this.dictionaryRequest) { + this.#setDictionaries(); + return inDossierOption; + } + return this.options[0]; + } + constructor( private readonly _justificationsService: JustificationsService, private readonly _dictionaryService: DictionaryService, @@ -49,6 +59,7 @@ export class RedactTextDialogComponent this.options = getRedactOrHintOptions(this.#dossier, this.#applyToAllDossiers, this.data.isApprover, this.data.isPageExcluded); this.form = this.#getForm(); + this.#setupValidators(this.dictionaryRequest ? RedactOrHintOptions.IN_DOSSIER : RedactOrHintOptions.ONLY_HERE); this.form.controls.option.valueChanges .pipe( @@ -152,10 +163,10 @@ export class RedactTextDialogComponent #getForm(): FormGroup { return this._formBuilder.group({ selectedText: this.data?.manualRedactionEntryWrapper?.manualRedactionEntry?.value, - reason: [null as LegalBasisOption, Validators.required], + reason: [null as LegalBasisOption], comment: [null], dictionary: [this.#manualRedactionTypeExists ? SuperTypes.ManualRedaction : null], - option: this.options[0], + option: this.defaultOption, }); } 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 d34385035..bf4619847 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 @@ -1,9 +1,12 @@ import { Component } from '@angular/core'; -import { takeUntilDestroyed } from '@angular/core/rxjs-interop'; import { FormBuilder, UntypedFormGroup } from '@angular/forms'; import { DetailsRadioOption, IconButtonTypes, IqserDialogComponent } from '@iqser/common-ui'; -import { tap } from 'rxjs/operators'; -import { getRemoveRedactionOptions, RemoveAnnotationOptions, RemoveRedactionOption } from '../../utils/dialog-options'; +import { + getRemoveRedactionOptions, + RemoveAnnotationOptions, + RemoveRedactionOption, + RemoveRedactionOptions, +} from '../../utils/dialog-options'; import { RemoveRedactionData, RemoveRedactionResult } from '../../utils/dialog-types'; import { Roles } from '@users/roles'; import { DialogHelpModeKeys } from '../../utils/constants'; @@ -17,7 +20,6 @@ export class RemoveRedactionDialogComponent extends IqserDialogComponent< RemoveRedactionData, RemoveRedactionResult > { - #applyToAllDossiers: boolean; readonly iconButtonTypes = IconButtonTypes; readonly options: DetailsRadioOption[]; readonly recommendation: boolean; @@ -35,21 +37,6 @@ export class RemoveRedactionDialogComponent extends IqserDialogComponent< this.options = getRemoveRedactionOptions(this.data); this.redactedTexts = this.data.redactions.map(annotation => annotation.value); this.form = this.#getForm(); - this.#applyToAllDossiers = this.data.applyToAllDossiers ?? true; - - this.form - .get('option') - .valueChanges.pipe( - tap(() => { - for (const option of this.options) { - if (option.extraOption) { - option.extraOption.checked = this.#applyToAllDossiers; - } - } - }), - takeUntilDestroyed(), - ) - .subscribe(); } get isFalsePositive(): boolean { @@ -58,17 +45,23 @@ export class RemoveRedactionDialogComponent extends IqserDialogComponent< get helpButtonKey() { if (this.hint) { - return DialogHelpModeKeys.HINT_REMOVE + return DialogHelpModeKeys.HINT_REMOVE; } if (this.recommendation) { - return DialogHelpModeKeys.RECOMMENDATION_REMOVE + return DialogHelpModeKeys.RECOMMENDATION_REMOVE; } if (this.skipped) { - return DialogHelpModeKeys.SKIPPED_REMOVE + return DialogHelpModeKeys.SKIPPED_REMOVE; } return DialogHelpModeKeys.REDACTION_REMOVE; } + get defaultOption() { + const removeHereOption = this.options.find(option => option.value === RemoveRedactionOptions.ONLY_HERE); + if (!!removeHereOption && !removeHereOption.disabled) return removeHereOption; + return this.options[0]; + } + save(): void { this.close(this.form.getRawValue()); } @@ -76,7 +69,7 @@ export class RemoveRedactionDialogComponent extends IqserDialogComponent< #getForm() { return this._formBuilder.group({ comment: [null], - option: [this.options[0]], + option: [this.defaultOption], }); } } 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 cee558c76..9ff5d572f 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 @@ -177,14 +177,14 @@ export const getRemoveRedactionOptions = ( extraOption: !isDocumine ? { label: translations.IN_DOSSIER.extraOptionLabel, - checked: applyToAllDossiers ?? true, + checked: redactions[0].isRecommendation && applyToAllDossiers, hidden: !isApprover, } : null, }); } if (permissions.canMarkAsFalsePositive) { - if (data.redactions[0].isRecommendation) { + if (redactions[0].isRecommendation) { options.push({ label: translations.DO_NOT_RECOMMEND.label, description: isBulk ? translations.DO_NOT_RECOMMEND.descriptionBulk : translations.DO_NOT_RECOMMEND.description, @@ -198,7 +198,7 @@ export const getRemoveRedactionOptions = ( extraOption: !isDocumine ? { label: translations.DO_NOT_RECOMMEND.extraOptionLabel, - checked: applyToAllDossiers ?? true, + checked: applyToAllDossiers, hidden: !isApprover, } : null, @@ -217,7 +217,7 @@ export const getRemoveRedactionOptions = ( extraOption: !isDocumine ? { label: translations.FALSE_POSITIVE.extraOptionLabel, - checked: applyToAllDossiers ?? true, + checked: false, hidden: !isApprover, } : null,