From bc43a39643448132ec65f0a35a875a269ea85900 Mon Sep 17 00:00:00 2001 From: Artem Dzhereleiko Date: Mon, 31 Jul 2023 16:05:27 +0300 Subject: [PATCH] UI: Refactoring --- .../entity/entity-select.component.ts | 20 ++++++++----------- 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/ui-ngx/src/app/shared/components/entity/entity-select.component.ts b/ui-ngx/src/app/shared/components/entity/entity-select.component.ts index 93452e4620..6e235a2dad 100644 --- a/ui-ngx/src/app/shared/components/entity/entity-select.component.ts +++ b/ui-ngx/src/app/shared/components/entity/entity-select.component.ts @@ -121,18 +121,12 @@ export class EntitySelectComponent implements ControlValueAccessor, OnInit, Afte } writeValue(value: EntityId | null): void { - if (value != null) { - this.modelValue = value; - this.entitySelectFormGroup.get('entityType').patchValue(value.entityType, {emitEvent: false}); - this.entitySelectFormGroup.get('entityId').patchValue(value, {emitEvent: false}); - } else { - this.modelValue = { - entityType: this.defaultEntityType, - id: null - }; - this.entitySelectFormGroup.get('entityType').patchValue(this.defaultEntityType, {emitEvent: false}); - this.entitySelectFormGroup.get('entityId').patchValue(null, {emitEvent: false}); - } + this.modelValue = { + entityType: value?.entityType ? value.entityType : this.defaultEntityType, + id: value?.id ? value.id : null + }; + this.entitySelectFormGroup.get('entityType').patchValue(this.modelValue.entityType, {emitEvent: false}); + this.entitySelectFormGroup.get('entityId').patchValue(this.modelValue.id, {emitEvent: false}); } updateView(entityType: EntityType | AliasEntityType | null, entityId: string | null) { @@ -146,6 +140,8 @@ export class EntitySelectComponent implements ControlValueAccessor, OnInit, Afte || this.modelValue.entityType === AliasEntityType.CURRENT_USER || this.modelValue.entityType === AliasEntityType.CURRENT_USER_OWNER) { this.modelValue.id = NULL_UUID; + } else if (this.modelValue.entityType === AliasEntityType.CURRENT_CUSTOMER && !this.modelValue.id) { + this.modelValue.id = NULL_UUID; } if (this.modelValue.entityType && this.modelValue.id) {