Merge pull request #11337 from ArtemDzhereleiko/AD/bug-fix/delete-recipient

Fixed updating target after deleted recipient
This commit is contained in:
Igor Kulikov 2024-08-19 18:37:57 +03:00 committed by GitHub
commit bdca04c2bd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 0 deletions

View File

@ -104,6 +104,7 @@
</ng-template> </ng-template>
<ng-template #recipientsList> <ng-template #recipientsList>
<tb-entity-list <tb-entity-list
syncIdsWithDB
required required
formControlName="targets" formControlName="targets"
labelText="{{ 'notification.recipients' | translate }}" labelText="{{ 'notification.recipients' | translate }}"

View File

@ -45,6 +45,7 @@ import { MatAutocomplete } from '@angular/material/autocomplete';
import { MatChipGrid } from '@angular/material/chips'; import { MatChipGrid } from '@angular/material/chips';
import { coerceBooleanProperty } from '@angular/cdk/coercion'; import { coerceBooleanProperty } from '@angular/cdk/coercion';
import { SubscriptSizing } from '@angular/material/form-field'; import { SubscriptSizing } from '@angular/material/form-field';
import { coerceBoolean } from '@shared/decorators/coercion';
@Component({ @Component({
selector: 'tb-entity-list', selector: 'tb-entity-list',
@ -106,6 +107,10 @@ export class EntityListComponent implements ControlValueAccessor, OnInit, AfterV
@Input() @Input()
hint: string; hint: string;
@Input()
@coerceBoolean()
syncIdsWithDB = false;
@ViewChild('entityInput') entityInput: ElementRef<HTMLInputElement>; @ViewChild('entityInput') entityInput: ElementRef<HTMLInputElement>;
@ViewChild('entityAutocomplete') matAutocomplete: MatAutocomplete; @ViewChild('entityAutocomplete') matAutocomplete: MatAutocomplete;
@ViewChild('chipList', {static: true}) chipList: MatChipGrid; @ViewChild('chipList', {static: true}) chipList: MatChipGrid;
@ -189,6 +194,10 @@ export class EntityListComponent implements ControlValueAccessor, OnInit, AfterV
(entities) => { (entities) => {
this.entities = entities; this.entities = entities;
this.entityListFormGroup.get('entities').setValue(this.entities); this.entityListFormGroup.get('entities').setValue(this.entities);
if (this.syncIdsWithDB && this.modelValue.length !== entities.length) {
this.modelValue = entities.map(entity => entity.id.id);
this.propagateChange(this.modelValue);
}
} }
); );
} else { } else {