RED-7115, edit radio button type description.

This commit is contained in:
George 2023-08-03 14:34:21 +03:00
parent b1b8ce2e49
commit 60b0d502ae

View File

@ -1,14 +1,21 @@
import { Component, EventEmitter, Input, Output } from '@angular/core';
import { Component, EventEmitter, inject, Input, OnChanges, Output, SimpleChanges } from '@angular/core';
import { DetailsRadioOption } from './details-radio-option';
import { FormsModule, NG_VALIDATORS, NG_VALUE_ACCESSOR, ReactiveFormsModule } from '@angular/forms';
import { FormFieldComponent } from '../form-field/form-field-component.directive';
import { NgClass, NgForOf, NgIf } from '@angular/common';
import { RoundCheckboxComponent } from '../round-checkbox/round-checkbox.component';
import { TranslateModule } from '@ngx-translate/core';
import { TranslateModule, TranslateService } from '@ngx-translate/core';
import { MatIconModule } from '@angular/material/icon';
import { MatCheckboxModule } from '@angular/material/checkbox';
import { MatTooltipModule } from '@angular/material/tooltip';
import { ReplaceNbspPipe } from '../../pipes/replace-nbsp.pipe';
import { removeActionDescriptorTranslations } from '../../../../../../apps/red-ui/src/app/translations/redact-text-translations';
import { List } from '../../utils';
export const removeActionDescriptorTranslationsPaths: List = [
removeActionDescriptorTranslations.redact,
removeActionDescriptorTranslations.recommend,
];
@Component({
selector: 'iqser-details-radio [options]',
@ -41,16 +48,32 @@ import { ReplaceNbspPipe } from '../../pipes/replace-nbsp.pipe';
ReplaceNbspPipe,
],
})
export class DetailsRadioComponent<I> extends FormFieldComponent<DetailsRadioOption<I>> {
export class DetailsRadioComponent<I> extends FormFieldComponent<DetailsRadioOption<I>> implements OnChanges {
@Input() options: DetailsRadioOption<I>[] = [];
@Input() displayInRow = false;
@Output() readonly extraOptionChanged: EventEmitter<DetailsRadioOption<I>> = new EventEmitter();
readonly #translateService = inject(TranslateService);
constructor() {
super();
}
ngOnChanges(changes: SimpleChanges) {
if (!changes['options']) return;
this.options = this.options.map(option => {
const type = option.descriptionParams?.['type'];
if (!type) return option;
return {
...option,
descriptionParams: {
...option.descriptionParams,
type: removeActionDescriptorTranslationsPaths.includes(type) ? this.#translateService.instant(type) : type,
},
};
});
}
toggleOption(option: DetailsRadioOption<I>): void {
if (option.value !== this._value?.value && !option.disabled) {
this.markAsTouched();