• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

IgniteUI / igniteui-angular / 13331632524

14 Feb 2025 02:51PM UTC coverage: 22.015% (-69.6%) from 91.622%
13331632524

Pull #15372

github

web-flow
Merge d52d57714 into bcb78ae0a
Pull Request #15372: chore(*): test ci passing

1990 of 15592 branches covered (12.76%)

431 of 964 new or added lines in 18 files covered. (44.71%)

19956 existing lines in 307 files now uncovered.

6452 of 29307 relevant lines covered (22.02%)

249.17 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

27.91
/projects/igniteui-angular/src/lib/combo/combo.pipes.ts
1
import { Inject, Pipe, PipeTransform } from '@angular/core';
2
import { SortingDirection } from '../data-operations/sorting-strategy';
3
import { IComboFilteringOptions, IgxComboBase, IGX_COMBO_COMPONENT } from './combo.common';
4

5
/** @hidden */
6
@Pipe({
7
    name: 'comboFiltering',
8
    standalone: true
9
})
10
export class IgxComboFilteringPipe implements PipeTransform {
2✔
11
    public transform(
12
        collection: any[],
13
        searchValue: any,
14
        displayKey: any,
15
        filteringOptions: IComboFilteringOptions,
16
        filterFunction: (collection: any[], searchValue: any, filteringOptions: IComboFilteringOptions) => any[] = defaultFilterFunction,
66✔
17
        disableFiltering: boolean = false) {
×
18
        if (!collection) {
66!
19
            return [];
×
20
        }
21
        if (disableFiltering) {
66!
UNCOV
22
            return collection;
×
23
        }
24
        filteringOptions.filteringKey = filteringOptions.filteringKey ?? displayKey;
66✔
25
        return filterFunction(collection, searchValue, filteringOptions);
66✔
26
    }
27
}
28

29
/** @hidden */
30
@Pipe({
31
    name: 'comboGrouping',
32
    standalone: true
33
})
34
export class IgxComboGroupingPipe implements PipeTransform {
2✔
35

36
    constructor(@Inject(IGX_COMBO_COMPONENT) public combo: IgxComboBase) { }
40✔
37

38
    public transform(collection: any[], groupKey: any, valueKey: any, sortingDirection: SortingDirection, compareCollator: Intl.Collator) {
39
        // TODO: should filteredData be changed here?
40
        this.combo.filteredData = collection;
66✔
41
        if ((!groupKey && groupKey !== 0) || !collection.length) {
66!
42
            return collection;
66✔
43
        }
UNCOV
44
        const groups = Object.entries(groupBy(collection, (item) => item[groupKey] ?? 'Other'));
×
UNCOV
45
        if (sortingDirection !== SortingDirection.None) {
×
UNCOV
46
            const reverse = sortingDirection === SortingDirection.Desc ? -1 : 1;
×
UNCOV
47
            groups.sort((a,b) => {
×
UNCOV
48
                return compareCollator.compare(a[0], b[0]) * reverse;
×
49
            });
50
        }
UNCOV
51
        const result = groups.flatMap(([_, items]) => {
×
UNCOV
52
            items.unshift({
×
53
                isHeader: true,
54
                [valueKey]: items[0][groupKey],
55
                [groupKey]: items[0][groupKey]
56
            })
UNCOV
57
            return items;
×
58
        });
UNCOV
59
        return result;
×
60
    }
61
}
62

63
function defaultFilterFunction<T>(collection: T[], searchValue: string, filteringOptions: IComboFilteringOptions): T[] {
64
    if (!searchValue) {
66✔
65
        return collection;
66✔
66
    }
67

UNCOV
68
    const { caseSensitive, filteringKey } = filteringOptions;
×
UNCOV
69
    const term = caseSensitive ? searchValue : searchValue.toLowerCase();
×
70

UNCOV
71
    return collection.filter(item => {
×
UNCOV
72
        const str = filteringKey ? `${item[filteringKey]}` : `${item}`;
×
UNCOV
73
        return (caseSensitive ? str : str.toLowerCase()).includes(term);
×
74
    });
75
}
76

77
function normalizeString(str: string, caseSensitive = false): string {
×
UNCOV
78
    return (caseSensitive ? str : str.toLocaleLowerCase())
×
79
        .normalize('NFKD')
80
        .replace(/\p{M}/gu, '');
81
}
82

83
function groupBy<T>(data: T[], key: keyof T | ((item: T) => any)) {
UNCOV
84
    const result: Record<string, T[]> = {};
×
UNCOV
85
    const _get = typeof key === 'function' ? key : (item: T) => item[key];
×
86

UNCOV
87
    for (const item of data) {
×
UNCOV
88
      const category = _get(item);
×
UNCOV
89
      const group = result[category];
×
90

UNCOV
91
      Array.isArray(group) ? group.push(item) : (result[category] = [item]);
×
92
    }
93

UNCOV
94
    return result;
×
95
}
96

97
/**
98
 * Combo filter function which does not distinguish between accented letters and their base letters.
99
 * For example, when filtering for "resume", this function will match both "resume" and "résumé".
100
 *
101
 * @example
102
 * ```html
103
 * <igx-combo [filterFunction]="comboIgnoreDiacriticFilterFunction"></igx-combo>
104
 * ```
105
 */
106
export function comboIgnoreDiacriticsFilter<T>(collection: T[], searchValue: string, filteringOptions: IComboFilteringOptions): T[] {
UNCOV
107
    if (!searchValue) {
×
UNCOV
108
        return collection;
×
109
    }
110

UNCOV
111
    const { caseSensitive, filteringKey } = filteringOptions;
×
UNCOV
112
    const term = normalizeString(searchValue, caseSensitive);
×
113

UNCOV
114
    return collection.filter(item => {
×
UNCOV
115
        const str = filteringKey ? `${item[filteringKey]}` : `${item}`;
×
UNCOV
116
        return normalizeString(str, caseSensitive).includes(term);
×
117
    });
118
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc