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

IgniteUI / igniteui-angular / 13331632524

14 Feb 2025 02:51PM CUT 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

6.0
/projects/igniteui-angular/src/lib/grids/tree-grid/tree-grid.grouping.pipe.ts
1
import { Pipe, PipeTransform } from '@angular/core';
2
import { formatDate } from '../../core/utils';
3
import { GridColumnDataType } from '../../data-operations/data-util';
4
import { IGroupingExpression } from '../../data-operations/grouping-expression.interface';
5
import { GridType } from '../common/grid.interface';
6
import { IgxSorting } from '../common/strategy';
7

8
const HIDDEN_FIELD_NAME = '_Igx_Hidden_Data_';
2✔
9

10
/**
11
 * @hidden
12
 * @internal
13
 */
14
class GroupByRecord {
15
    public key: string;
16
    public value: any;
17
    public groups: GroupByRecord[];
18
    public records: any[];
19
}
20

21
export class ITreeGridAggregation {
22
    public field: string;
23
    public aggregate: (parent: any, children: any[]) => any;
24
}
25

26
export class IgxGroupedTreeGridSorting extends IgxSorting {
27
    private static _instance: IgxGroupedTreeGridSorting = null;
2✔
28

29
    public static instance() {
30
        return this._instance || (this._instance = new IgxGroupedTreeGridSorting());
×
31
    }
32

33
    protected override getFieldValue(obj: any, key: string, isDate = false, isTime = false): any {
×
34
        const data = obj.data[HIDDEN_FIELD_NAME] ?
×
35
            obj.data.hasOwnProperty(key) ?
×
36
                obj.data :
37
                obj.data[HIDDEN_FIELD_NAME] :
38
            obj.data;
39

40
        return super.getFieldValue(data, key, isDate, isTime);
×
41
    }
42
}
43

44
/** @hidden */
45
@Pipe({
46
    name: 'treeGridGrouping',
47
    standalone: true
48
})
49
export class IgxTreeGridGroupingPipe implements PipeTransform {
2✔
50
    private grid: GridType;
51

52
    public transform(collection: any[],
53
                     groupingExpressions: IGroupingExpression[],
54
                     groupKey: string,
55
                     childDataKey: string,
56
                     grid: GridType,
57
                     aggregations?: ITreeGridAggregation[]
58
                    ): any[] {
UNCOV
59
        if (groupingExpressions.length === 0) {
×
UNCOV
60
            return collection;
×
61
        }
62

UNCOV
63
        if (groupKey?.toLowerCase() === childDataKey?.toLowerCase()) {
×
64
            throw new Error('Group key and child data key cannot be the same.');
×
65
        }
66

UNCOV
67
        this.grid = grid;
×
68

UNCOV
69
        const result = [];
×
UNCOV
70
        const groupedRecords = this.groupByMultiple(collection, groupingExpressions);
×
UNCOV
71
        this.flattenGrouping(groupedRecords, groupKey,
×
72
            childDataKey, result, aggregations);
73

UNCOV
74
        return result;
×
75
    }
76

77
    private flattenGrouping(groupRecords: GroupByRecord[],
78
                            groupKey: string,
79
                            childDataKey: string,
80
                            data: any[],
81
                            aggregations: ITreeGridAggregation[] = []) {
×
UNCOV
82
        for (const groupRecord of groupRecords) {
×
UNCOV
83
            const parent = {};
×
UNCOV
84
            const children = groupRecord.records;
×
85

UNCOV
86
            parent[childDataKey] = [];
×
87

UNCOV
88
            for (const aggregation of aggregations) {
×
UNCOV
89
                parent[aggregation.field] = aggregation.aggregate(parent, children);
×
90
            }
91

UNCOV
92
            parent[groupKey] = groupRecord.value + ` (${groupRecord.records.length})`;
×
UNCOV
93
            parent[HIDDEN_FIELD_NAME] = { [groupRecord.key]: groupRecord.value };
×
UNCOV
94
            data.push(parent);
×
95

UNCOV
96
            if (groupRecord.groups) {
×
UNCOV
97
                this.flattenGrouping(groupRecord.groups, groupKey, childDataKey,
×
98
                    parent[childDataKey], aggregations);
99
            } else {
UNCOV
100
                parent[childDataKey] = children;
×
101
            }
102
        }
103
    }
104

105
    private groupByMultiple(array: any[], groupingExpressions: IGroupingExpression[], index = 0): GroupByRecord[] {
×
UNCOV
106
        const res = this.groupBy(array, groupingExpressions[index]);
×
107

UNCOV
108
        if (index + 1 < groupingExpressions.length) {
×
UNCOV
109
           for (const groupByRecord of res) {
×
UNCOV
110
                groupByRecord.groups = this.groupByMultiple(groupByRecord.records, groupingExpressions, index + 1);
×
111
            }
112
        }
113

UNCOV
114
        return res;
×
115
    }
116

117
    private groupBy(array: any[], groupingExpression: IGroupingExpression): GroupByRecord[] {
UNCOV
118
        const key = groupingExpression.fieldName;
×
UNCOV
119
        const column = this.grid?.getColumnByName(key);
×
UNCOV
120
        const isDateTime = column?.dataType === GridColumnDataType.Date ||
×
121
            column?.dataType === GridColumnDataType.DateTime ||
122
            column?.dataType === GridColumnDataType.Time;
UNCOV
123
        const map: Map<any, GroupByRecord> = new Map<any, GroupByRecord>();
×
UNCOV
124
        for (const record of array) {
×
UNCOV
125
            const value = isDateTime
×
126
                ? formatDate(record[key], column.pipeArgs.format, this.grid.locale)
127
                : record[key];
128

UNCOV
129
            let valueCase = value;
×
130
            let groupByRecord: GroupByRecord;
131

UNCOV
132
            if (groupingExpression.ignoreCase) {
×
UNCOV
133
                valueCase = value?.toString().toLowerCase();
×
134
            }
UNCOV
135
            if (map.has(valueCase)) {
×
UNCOV
136
                groupByRecord = map.get(valueCase);
×
137
            } else {
UNCOV
138
                groupByRecord = new GroupByRecord();
×
UNCOV
139
                groupByRecord.key = key;
×
UNCOV
140
                groupByRecord.value = value;
×
UNCOV
141
                groupByRecord.records = [];
×
UNCOV
142
                map.set(valueCase, groupByRecord);
×
143
            }
144

UNCOV
145
            groupByRecord.records.push(record);
×
146
        }
147

UNCOV
148
        return Array.from(map.values());
×
149
    }
150
}
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