1- import { Component , EventEmitter , Input , Output } from '@angular/core' ;
1+ import { Component , EventEmitter , Input , OnChanges , Output , SimpleChanges } from '@angular/core' ;
22import { SecurityGroupViewMode } from '../sg-view-mode' ;
3+ import { Account } from '../../shared/models' ;
34
45export interface SecurityGroupFilter {
56 viewMode : SecurityGroupViewMode ;
@@ -13,7 +14,7 @@ export interface SecurityGroupFilter {
1314 templateUrl : 'sg-filter.component.html' ,
1415 styleUrls : [ 'sg-filter.component.scss' ] ,
1516} )
16- export class SgFilterComponent {
17+ export class SgFilterComponent implements OnChanges {
1718 @Input ( )
1819 public accounts : Account [ ] ;
1920 @Input ( )
@@ -32,6 +33,8 @@ export class SgFilterComponent {
3233 public viewMode : SecurityGroupViewMode ;
3334 public query : string ;
3435 public selectedAccountIds : string [ ] ;
36+ public accountsFiltered : Account [ ] = [ ] ;
37+ public accountQuery = '' ;
3538
3639 @Input ( )
3740 public set filters ( filter : SecurityGroupFilter ) {
@@ -44,4 +47,18 @@ export class SgFilterComponent {
4447 public get SecurityGroupViewMode ( ) {
4548 return SecurityGroupViewMode ;
4649 }
50+
51+ public ngOnChanges ( changes : SimpleChanges ) {
52+ const accounts = changes [ 'accounts' ] ;
53+ if ( accounts ) {
54+ this . onAccountQueryChanged ( this . accountQuery ) ;
55+ }
56+ }
57+
58+ public onAccountQueryChanged ( accountQuery : string ) {
59+ const queryLower = accountQuery && accountQuery . toLowerCase ( ) ;
60+ this . accountsFiltered = this . accounts . filter (
61+ account => ! accountQuery || account . name . toLowerCase ( ) . includes ( queryLower ) ,
62+ ) ;
63+ }
4764}
0 commit comments