From b076a89b5807532d25ef3839df49cbce79bb4592 Mon Sep 17 00:00:00 2001 From: Artem Dzhereleiko Date: Thu, 13 Jul 2023 11:46:04 +0300 Subject: [PATCH] UI: Improvement for entity autocomplete --- .../entity/entity-autocomplete.component.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/ui-ngx/src/app/shared/components/entity/entity-autocomplete.component.ts b/ui-ngx/src/app/shared/components/entity/entity-autocomplete.component.ts index af0373b7a9..ea89a064a3 100644 --- a/ui-ngx/src/app/shared/components/entity/entity-autocomplete.component.ts +++ b/ui-ngx/src/app/shared/components/entity/entity-autocomplete.component.ts @@ -26,7 +26,7 @@ import { ViewChild } from '@angular/core'; import { MatFormFieldAppearance } from '@angular/material/form-field'; -import { ControlValueAccessor, UntypedFormBuilder, UntypedFormGroup, NG_VALUE_ACCESSOR } from '@angular/forms'; +import { ControlValueAccessor, NG_VALUE_ACCESSOR, UntypedFormBuilder, UntypedFormGroup } from '@angular/forms'; import { merge, Observable, of, Subject } from 'rxjs'; import { catchError, debounceTime, map, share, switchMap, tap } from 'rxjs/operators'; import { Store } from '@ngrx/store'; @@ -55,7 +55,7 @@ export class EntityAutocompleteComponent implements ControlValueAccessor, OnInit selectEntityFormGroup: UntypedFormGroup; - modelValue: string | null; + modelValue: string | EntityId | null; entityTypeValue: EntityType | AliasEntityType; @@ -113,6 +113,10 @@ export class EntityAutocompleteComponent implements ControlValueAccessor, OnInit @Input() requiredText: string; + @Input() + @coerceBoolean() + useFullEntityId: boolean; + @Input() appearance: MatFormFieldAppearance = 'fill'; @@ -171,7 +175,7 @@ export class EntityAutocompleteComponent implements ControlValueAccessor, OnInit if (typeof value === 'string' || !value) { modelValue = null; } else { - modelValue = value.id.id; + modelValue = this.useFullEntityId ? value.id : value.id.id; } this.updateView(modelValue, value); if (value === null) { @@ -307,7 +311,7 @@ export class EntityAutocompleteComponent implements ControlValueAccessor, OnInit } catch (e) { this.propagateChange(null); } - this.modelValue = entity !== null ? entity.id.id : null; + this.modelValue = entity !== null ? (this.useFullEntityId ? entity.id : entity.id.id) : null; this.selectEntityFormGroup.get('entity').patchValue(entity !== null ? entity : '', {emitEvent: false}); this.entityChanged.emit(entity); } else {