Commit 0b3a287530e8f4d7b41c82fe1c081a7aa2f71b16

Authored by ArtemDzhereleiko
1 parent e264f7b8

Fixed double requests on aliases entity autocomplete

@@ -17,7 +17,7 @@ @@ -17,7 +17,7 @@
17 import { AfterViewInit, Component, ElementRef, forwardRef, Input, OnInit, ViewChild } from '@angular/core'; 17 import { AfterViewInit, Component, ElementRef, forwardRef, Input, OnInit, ViewChild } from '@angular/core';
18 import { ControlValueAccessor, FormBuilder, FormGroup, NG_VALUE_ACCESSOR } from '@angular/forms'; 18 import { ControlValueAccessor, FormBuilder, FormGroup, NG_VALUE_ACCESSOR } from '@angular/forms';
19 import { Observable, of } from 'rxjs'; 19 import { Observable, of } from 'rxjs';
20 -import { catchError, debounceTime, distinctUntilChanged, map, startWith, switchMap, tap } from 'rxjs/operators'; 20 +import { catchError, debounceTime, distinctUntilChanged, map, share, switchMap, tap } from 'rxjs/operators';
21 import { emptyPageData, PageData } from '@shared/models/page/page-data'; 21 import { emptyPageData, PageData } from '@shared/models/page/page-data';
22 import { Store } from '@ngrx/store'; 22 import { Store } from '@ngrx/store';
23 import { AppState } from '@app/core/core.state'; 23 import { AppState } from '@app/core/core.state';
@@ -26,6 +26,7 @@ import { coerceBooleanProperty } from '@angular/cdk/coercion'; @@ -26,6 +26,7 @@ import { coerceBooleanProperty } from '@angular/cdk/coercion';
26 import { EntityInfo } from '@shared/models/entity.models'; 26 import { EntityInfo } from '@shared/models/entity.models';
27 import { EntityFilter } from '@shared/models/query/query.models'; 27 import { EntityFilter } from '@shared/models/query/query.models';
28 import { EntityService } from '@core/http/entity.service'; 28 import { EntityService } from '@core/http/entity.service';
  29 +import { isDefinedAndNotNull } from '@core/utils';
29 30
30 @Component({ 31 @Component({
31 selector: 'tb-aliases-entity-autocomplete', 32 selector: 'tb-aliases-entity-autocomplete',
@@ -98,10 +99,10 @@ export class AliasesEntityAutocompleteComponent implements ControlValueAccessor, @@ -98,10 +99,10 @@ export class AliasesEntityAutocompleteComponent implements ControlValueAccessor,
98 } 99 }
99 this.updateView(modelValue); 100 this.updateView(modelValue);
100 }), 101 }),
101 - startWith<string | EntityInfo>(''),  
102 map(value => value ? (typeof value === 'string' ? value : value.name) : ''), 102 map(value => value ? (typeof value === 'string' ? value : value.name) : ''),
103 distinctUntilChanged(), 103 distinctUntilChanged(),
104 - switchMap(name => this.fetchEntityInfos(name)) 104 + switchMap(name => this.fetchEntityInfos(name)),
  105 + share()
105 ); 106 );
106 } 107 }
107 108
@@ -114,12 +115,12 @@ export class AliasesEntityAutocompleteComponent implements ControlValueAccessor, @@ -114,12 +115,12 @@ export class AliasesEntityAutocompleteComponent implements ControlValueAccessor,
114 115
115 writeValue(value: EntityInfo | null): void { 116 writeValue(value: EntityInfo | null): void {
116 this.searchText = ''; 117 this.searchText = '';
117 - if (value != null) { 118 + if (isDefinedAndNotNull(value)) {
118 this.modelValue = value; 119 this.modelValue = value;
119 this.selectEntityInfoFormGroup.get('entityInfo').patchValue(value, {emitEvent: true}); 120 this.selectEntityInfoFormGroup.get('entityInfo').patchValue(value, {emitEvent: true});
120 } else { 121 } else {
121 this.modelValue = null; 122 this.modelValue = null;
122 - this.selectEntityInfoFormGroup.get('entityInfo').patchValue(null, {emitEvent: true}); 123 + this.selectEntityInfoFormGroup.get('entityInfo').patchValue(null, {emitEvent: false});
123 } 124 }
124 } 125 }
125 126