UI: rule chain selector search code cleanup

This commit is contained in:
rusikv 2024-01-04 20:24:14 +02:00
parent 98086153dd
commit 8976adad2c
4 changed files with 13 additions and 37 deletions

View File

@ -33,7 +33,7 @@
<mat-option *ngIf="!(filteredRuleChains | async)?.length" [value]="null" class="tb-not-found"> <mat-option *ngIf="!(filteredRuleChains | async)?.length" [value]="null" class="tb-not-found">
<div class="tb-not-found-content" (click)="$event.stopPropagation()"> <div class="tb-not-found-content" (click)="$event.stopPropagation()">
<span> <span>
{{ translate.get('rulechain.no-rulechains-matching', {entity: searchText}) | async }} {{ 'rulechain.no-rulechains-matching' | translate : {entity: searchText} }}
</span> </span>
</div> </div>
</mat-option> </mat-option>

View File

@ -14,18 +14,10 @@
/// limitations under the License. /// limitations under the License.
/// ///
import { import { AfterViewInit, Component, ElementRef, Inject, InjectionToken, ViewChild } from '@angular/core';
AfterViewInit,
Component,
ElementRef,
Inject,
InjectionToken,
OnDestroy,
ViewChild
} from '@angular/core';
import { FormBuilder, FormGroup } from '@angular/forms'; import { FormBuilder, FormGroup } from '@angular/forms';
import { Observable, of, Subject } from 'rxjs'; import { Observable, of } from 'rxjs';
import { catchError, debounceTime, distinctUntilChanged, map, switchMap, takeUntil, startWith, share } from 'rxjs/operators'; import { catchError, debounceTime, distinctUntilChanged, map, share, startWith, switchMap } from 'rxjs/operators';
import { PageLink } from '@shared/models/page/page-link'; import { PageLink } from '@shared/models/page/page-link';
import { Direction } from '@shared/models/page/sort-order'; import { Direction } from '@shared/models/page/sort-order';
import { emptyPageData, PageData } from '@shared/models/page/page-data'; import { emptyPageData, PageData } from '@shared/models/page/page-data';
@ -33,7 +25,6 @@ import { OverlayRef } from '@angular/cdk/overlay';
import { MatAutocompleteSelectedEvent } from '@angular/material/autocomplete'; import { MatAutocompleteSelectedEvent } from '@angular/material/autocomplete';
import { RuleChain, RuleChainType } from '@shared/models/rule-chain.models'; import { RuleChain, RuleChainType } from '@shared/models/rule-chain.models';
import { RuleChainService } from '@core/http/rule-chain.service'; import { RuleChainService } from '@core/http/rule-chain.service';
import { TranslateService } from '@ngx-translate/core';
export const RULE_CHAIN_SELECT_PANEL_DATA = new InjectionToken<any>('RuleChainSelectPanelData'); export const RULE_CHAIN_SELECT_PANEL_DATA = new InjectionToken<any>('RuleChainSelectPanelData');
@ -47,10 +38,10 @@ export interface RuleChainSelectPanelData {
templateUrl: './rule-chain-select-panel.component.html', templateUrl: './rule-chain-select-panel.component.html',
styleUrls: ['./rule-chain-select-panel.component.scss'] styleUrls: ['./rule-chain-select-panel.component.scss']
}) })
export class RuleChainSelectPanelComponent implements AfterViewInit, OnDestroy { export class RuleChainSelectPanelComponent implements AfterViewInit {
ruleChainId: string; ruleChainId: string;
ruleChainType: RuleChainType; private readonly ruleChainType: RuleChainType;
selectRuleChainGroup: FormGroup; selectRuleChainGroup: FormGroup;
@ -65,11 +56,9 @@ export class RuleChainSelectPanelComponent implements AfterViewInit, OnDestroy {
result?: RuleChain; result?: RuleChain;
private dirty = false; private dirty = false;
private destroy$ = new Subject<void>();
constructor(@Inject(RULE_CHAIN_SELECT_PANEL_DATA) public data: RuleChainSelectPanelData, constructor(@Inject(RULE_CHAIN_SELECT_PANEL_DATA) public data: RuleChainSelectPanelData,
public overlayRef: OverlayRef, private overlayRef: OverlayRef,
public translate: TranslateService,
private fb: FormBuilder, private fb: FormBuilder,
private ruleChainService: RuleChainService) { private ruleChainService: RuleChainService) {
this.ruleChainId = data.ruleChainId; this.ruleChainId = data.ruleChainId;
@ -83,8 +72,7 @@ export class RuleChainSelectPanelComponent implements AfterViewInit, OnDestroy {
startWith(''), startWith(''),
distinctUntilChanged((a: string, b: string) => a.trim() === b.trim()), distinctUntilChanged((a: string, b: string) => a.trim() === b.trim()),
switchMap(name => this.fetchRuleChains(name)), switchMap(name => this.fetchRuleChains(name)),
share(), share()
takeUntil(this.destroy$)
); );
} }
@ -94,11 +82,6 @@ export class RuleChainSelectPanelComponent implements AfterViewInit, OnDestroy {
}, 0); }, 0);
} }
ngOnDestroy() {
this.destroy$.next();
this.destroy$.complete();
}
selected(event: MatAutocompleteSelectedEvent): void { selected(event: MatAutocompleteSelectedEvent): void {
this.clear(); this.clear();
this.ruleChainSelected = true; this.ruleChainSelected = true;
@ -108,7 +91,7 @@ export class RuleChainSelectPanelComponent implements AfterViewInit, OnDestroy {
this.overlayRef.dispose(); this.overlayRef.dispose();
} }
fetchRuleChains(searchText?: string): Observable<Array<RuleChain>> { private fetchRuleChains(searchText?: string): Observable<Array<RuleChain>> {
this.searchText = searchText; this.searchText = searchText;
const pageLink = new PageLink(50, 0, searchText, { const pageLink = new PageLink(50, 0, searchText, {
property: 'name', property: 'name',

View File

@ -29,12 +29,7 @@
} }
} }
} }
} .disabled {
opacity: 0.5;
.cursor-pointer { }
cursor: pointer;
}
.disabled {
opacity: 0.5;
} }

View File

@ -18,7 +18,6 @@ import { Component, forwardRef, Injector, Input, StaticProvider, ViewContainerRe
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms'; import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';
import { TooltipPosition } from '@angular/material/tooltip'; import { TooltipPosition } from '@angular/material/tooltip';
import { RuleChain, RuleChainType } from '@shared/models/rule-chain.models'; import { RuleChain, RuleChainType } from '@shared/models/rule-chain.models';
import { RuleChainService } from '@core/http/rule-chain.service';
import { isDefinedAndNotNull } from '@core/utils'; import { isDefinedAndNotNull } from '@core/utils';
import { coerceBoolean } from '@shared/decorators/coercion'; import { coerceBoolean } from '@shared/decorators/coercion';
import { Overlay, OverlayConfig, OverlayRef } from '@angular/cdk/overlay'; import { Overlay, OverlayConfig, OverlayRef } from '@angular/cdk/overlay';
@ -61,8 +60,7 @@ export class RuleChainSelectComponent implements ControlValueAccessor {
private propagateChange = (v: any) => { }; private propagateChange = (v: any) => { };
constructor(private ruleChainService: RuleChainService, constructor(private overlay: Overlay,
private overlay: Overlay,
private viewContainerRef: ViewContainerRef) { private viewContainerRef: ViewContainerRef) {
} }