All files / src/app/shared/components/filter/filter-dropdown filter-dropdown.component.ts

70.58% Statements 12/17
0% Branches 0/2
71.42% Functions 5/7
73.33% Lines 11/15

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 462x     2x                 2x   2x 2x   2x             4x       2x       2x   4x   2x                  
import { ChangeDetectionStrategy, Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
 
import { Facet } from 'ish-core/models/facet/facet.model';
import { Filter } from 'ish-core/models/filter/filter.model';
import { URLFormParams } from 'ish-core/utils/url-form-params';
 
@Component({
  selector: 'ish-filter-dropdown',
  templateUrl: './filter-dropdown.component.html',
  changeDetection: ChangeDetectionStrategy.OnPush,
  styleUrls: ['./filter-dropdown.component.scss'],
})
export class FilterDropdownComponent implements OnInit {
  @Input({ required: true }) filterElement: Filter;
  @Input() placeholderType: 'groupName' | 'selectedFacets' = 'groupName';
  @Output() applyFilter: EventEmitter<{ searchParameter: URLFormParams }> = new EventEmitter();
 
  placeholder = '';
 
  apply(facet: Facet) {
    this.applyFilter.emit({ searchParameter: facet.searchParameter });
  }
 
  trackByFn(_: number, item: Facet) {
    return item.name;
  }
 
  ngOnInit() {
    this.initPlaceHolder();
  }
 
  private initPlaceHolder() {
    this.placeholder = this.filterElement.name;
 
    const selectedFacets = this.filterElement.facets.filter(x => x.selected);
 
    Iif (this.placeholderType === 'selectedFacets') {
      const placeholder = selectedFacets.map(x => x.displayName).join(', ');
 
      Iif (placeholder) {
        this.placeholder = placeholder;
      }
    }
  }
}