fix the filter pipe

This commit is contained in:
jonaswinkler 2020-12-28 12:31:30 +01:00
parent 9e311241b3
commit bd02c78966

View File

@ -1,17 +1,18 @@
import { Pipe, PipeTransform } from '@angular/core';
import { ToggleableItem } from 'src/app/components/common/filterable-dropdown/toggleable-dropdown-button/toggleable-dropdown-button.component';
import { MatchingModel } from '../data/matching-model';
@Pipe({
name: 'filter'
})
export class FilterPipe implements PipeTransform {
transform(toggleableItems: ToggleableItem[], searchText: string): any[] {
if (!toggleableItems) return [];
if (!searchText) return toggleableItems;
transform(items: MatchingModel[], searchText: string): any[] {
if (!items) return [];
if (!searchText) return items;
return toggleableItems.filter(toggleableItem => {
return Object.keys(toggleableItem.item).some(key => {
return String(toggleableItem.item[key]).toLowerCase().includes(searchText.toLowerCase());
return items.filter(item => {
return Object.keys(item).some(key => {
return String(item[key]).toLowerCase().includes(searchText.toLowerCase());
});
});
}