Commit 08b346da7fd19d0a9009f88dc234f12b0807523e

Authored by Vladyslav_Prykhodko
1 parent b7718b91

UI Refactoring rule-chain-autocomplete component

... ... @@ -17,11 +17,11 @@
17 17 -->
18 18 <mat-form-field [formGroup]="selectRuleChainFormGroup" class="mat-block">
19 19 <input matInput type="text" placeholder="{{ ruleChainLabel | translate }}"
20   - #entityInput
  20 + #ruleChainInput
21 21 formControlName="ruleChainId"
22 22 (focusin)="onFocus()"
23 23 [required]="required"
24   - [matAutocomplete]="entityAutocomplete">
  24 + [matAutocomplete]="ruleChainAutocomplete">
25 25 <button *ngIf="selectRuleChainFormGroup.get('ruleChainId').value && !disabled"
26 26 type="button"
27 27 matSuffix mat-button mat-icon-button aria-label="Clear"
... ... @@ -29,10 +29,10 @@
29 29 <mat-icon class="material-icons">close</mat-icon>
30 30 </button>
31 31 <mat-autocomplete class="tb-autocomplete"
32   - #entityAutocomplete="matAutocomplete"
33   - [displayWith]="displayEntityFn">
34   - <mat-option *ngFor="let entity of filteredRuleChains | async" [value]="entity">
35   - <span [innerHTML]="entity.name | highlight:searchText"></span>
  32 + #ruleChainAutocomplete="matAutocomplete"
  33 + [displayWith]="displayRuleChainFn">
  34 + <mat-option *ngFor="let ruleChain of filteredRuleChains | async" [value]="ruleChain">
  35 + <span [innerHTML]="ruleChain.name | highlight:searchText"></span>
36 36 </mat-option>
37 37 <mat-option *ngIf="!(filteredRuleChains | async)?.length" [value]="null" class="tb-not-found">
38 38 <div class="tb-not-found-content" (click)="$event.stopPropagation()">
... ...
... ... @@ -66,7 +66,8 @@ export class RuleChainAutocompleteComponent implements ControlValueAccessor, OnI
66 66 @Input()
67 67 disabled: boolean;
68 68
69   - @ViewChild('entityInput', {static: true}) entityInput: ElementRef;
  69 + @ViewChild('ruleChainInput', {static: true}) ruleChainInput: ElementRef;
  70 + @ViewChild('ruleChainInput', {read: MatAutocompleteTrigger}) ruleChainAutocomplete: MatAutocompleteTrigger;
70 71
71 72 filteredRuleChains: Observable<Array<BaseData<EntityId>>>;
72 73
... ... @@ -117,9 +118,9 @@ export class RuleChainAutocompleteComponent implements ControlValueAccessor, OnI
117 118 ngAfterViewInit(): void {}
118 119
119 120 getCurrentEntity(): BaseData<EntityId> | null {
120   - const currentEntity = this.selectRuleChainFormGroup.get('ruleChainId').value;
121   - if (currentEntity && typeof currentEntity !== 'string') {
122   - return currentEntity as BaseData<EntityId>;
  121 + const currentRuleChain = this.selectRuleChainFormGroup.get('ruleChainId').value;
  122 + if (currentRuleChain && typeof currentRuleChain !== 'string') {
  123 + return currentRuleChain as BaseData<EntityId>;
123 124 } else {
124 125 return null;
125 126 }
... ... @@ -180,8 +181,8 @@ export class RuleChainAutocompleteComponent implements ControlValueAccessor, OnI
180 181 }
181 182 }
182 183
183   - displayEntityFn(entity?: BaseData<EntityId>): string | undefined {
184   - return entity ? entity.name : undefined;
  184 + displayRuleChainFn(ruleChain?: BaseData<EntityId>): string | undefined {
  185 + return ruleChain ? ruleChain.name : undefined;
185 186 }
186 187
187 188 fetchRuleChain(searchText?: string): Observable<Array<BaseData<EntityId>>> {
... ... @@ -193,12 +194,14 @@ export class RuleChainAutocompleteComponent implements ControlValueAccessor, OnI
193 194 clear() {
194 195 this.selectRuleChainFormGroup.get('ruleChainId').patchValue('', {emitEvent: true});
195 196 setTimeout(() => {
196   - this.entityInput.nativeElement.blur();
197   - this.entityInput.nativeElement.focus();
  197 + this.ruleChainInput.nativeElement.blur();
  198 + this.ruleChainInput.nativeElement.focus();
198 199 }, 0);
199 200 }
200 201
201 202 createDefaultRuleChain($event: Event, ruleChainName: string) {
  203 + $event.preventDefault();
  204 + this.ruleChainAutocomplete.closePanel();
202 205 this.ruleChainService.createDefaultRuleChain(ruleChainName).subscribe((ruleChain) => {
203 206 this.updateView(ruleChain.id.id);
204 207 });
... ...