Commit 405000a7554c9d4d1930e20db7f5c1417c0817c1

Authored by Igor Kulikov
Committed by GitHub
2 parents fa98ac0f 0b3a2875

Merge pull request #5406 from ArtemDzhereleiko/bug-fix/aliases-autocomplete/double-request

[3.3.2] UI: Fixed double requests on aliases entity autocomplete
... ... @@ -17,7 +17,7 @@
17 17 import { AfterViewInit, Component, ElementRef, forwardRef, Input, OnInit, ViewChild } from '@angular/core';
18 18 import { ControlValueAccessor, FormBuilder, FormGroup, NG_VALUE_ACCESSOR } from '@angular/forms';
19 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 21 import { emptyPageData, PageData } from '@shared/models/page/page-data';
22 22 import { Store } from '@ngrx/store';
23 23 import { AppState } from '@app/core/core.state';
... ... @@ -26,6 +26,7 @@ import { coerceBooleanProperty } from '@angular/cdk/coercion';
26 26 import { EntityInfo } from '@shared/models/entity.models';
27 27 import { EntityFilter } from '@shared/models/query/query.models';
28 28 import { EntityService } from '@core/http/entity.service';
  29 +import { isDefinedAndNotNull } from '@core/utils';
29 30
30 31 @Component({
31 32 selector: 'tb-aliases-entity-autocomplete',
... ... @@ -98,10 +99,10 @@ export class AliasesEntityAutocompleteComponent implements ControlValueAccessor,
98 99 }
99 100 this.updateView(modelValue);
100 101 }),
101   - startWith<string | EntityInfo>(''),
102 102 map(value => value ? (typeof value === 'string' ? value : value.name) : ''),
103 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 115
115 116 writeValue(value: EntityInfo | null): void {
116 117 this.searchText = '';
117   - if (value != null) {
  118 + if (isDefinedAndNotNull(value)) {
118 119 this.modelValue = value;
119 120 this.selectEntityInfoFormGroup.get('entityInfo').patchValue(value, {emitEvent: true});
120 121 } else {
121 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
... ...