• 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

57.52
/projects/igniteui-angular/src/lib/grids/common/pipes.ts
1
import { Pipe, PipeTransform, Inject } from '@angular/core';
2
import { DataUtil } from '../../data-operations/data-util';
3
import { cloneArray, resolveNestedPath } from '../../core/utils';
4
import { GridType, IGX_GRID_BASE, RowType } from './grid.interface';
5
import { IgxAddRow } from './crud.service';
6
import { IgxSummaryOperand, IgxSummaryResult } from '../summaries/grid-summary';
7
import { IgxGridRow } from '../grid-public-row';
8

9
interface GridStyleCSSProperty {
10
    [prop: string]: any;
11
}
12

13
/**
14
 * @hidden
15
 * @internal
16
 */
17
@Pipe({
18
    name: 'igxCellStyleClasses',
19
    standalone: true
20
})
21
export class IgxGridCellStyleClassesPipe implements PipeTransform {
2✔
22

23
    public transform(cssClasses: GridStyleCSSProperty, _: any, data: any, field: string, index: number, __: number): string {
24
        if (!cssClasses) {
2,063✔
25
            return '';
2,063✔
26
        }
27

UNCOV
28
        const result = [];
×
29

UNCOV
30
        for (const cssClass of Object.keys(cssClasses)) {
×
UNCOV
31
            const callbackOrValue = cssClasses[cssClass];
×
UNCOV
32
            const apply = typeof callbackOrValue === 'function' ?
×
33
                callbackOrValue(data, field, resolveNestedPath(data, field), index) : callbackOrValue;
UNCOV
34
            if (apply) {
×
UNCOV
35
                result.push(cssClass);
×
36
            }
37
        }
38

UNCOV
39
        return result.join(' ');
×
40
    }
41
}
42

43
/**
44
 * @hidden
45
 * @internal
46
 */
47
@Pipe({
48
    name: 'igxCellStyles',
49
    standalone: true
50
})
51
export class IgxGridCellStylesPipe implements PipeTransform {
2✔
52

53
    public transform(styles: GridStyleCSSProperty, _: any, data: any, field: string, index: number, __: number):
54
        GridStyleCSSProperty {
55
        const css = {};
2,063✔
56
        if (!styles) {
2,063✔
57
            return css;
2,063✔
58
        }
59

UNCOV
60
        for (const prop of Object.keys(styles)) {
×
UNCOV
61
            const res = styles[prop];
×
UNCOV
62
            css[prop] = typeof res === 'function' ? res(data, field, resolveNestedPath(data, field), index) : res;
×
63
        }
64

UNCOV
65
        return css;
×
66
    }
67
}
68

69
/**
70
 * @hidden
71
 * @internal
72
 */
73
 @Pipe({
74
    name: 'igxCellImageAlt',
75
    standalone: true
76
})
77
export class IgxGridCellImageAltPipe implements PipeTransform {
2✔
78

79
    public transform(value: string): string {
UNCOV
80
        if (value) {
×
UNCOV
81
            const val = value.split('/');
×
UNCOV
82
            const imagename = val[val.length - 1].split('.');
×
UNCOV
83
            return imagename.length ? imagename[0] : '';
×
84
        }
85
        return value;
×
86
    }
87
}
88

89

90
/**
91
 * @hidden
92
 * @internal
93
 */
94
@Pipe({
95
    name: 'igxGridRowClasses',
96
    standalone: true
97
})
98
export class IgxGridRowClassesPipe implements PipeTransform {
2✔
99
    public row: RowType;
100

101
    constructor(@Inject(IGX_GRID_BASE) private grid: GridType) {
265✔
102
        this.row = new IgxGridRow(this.grid as any, -1, {});
265✔
103
    }
104

105
    public transform(
106
        cssClasses: GridStyleCSSProperty,
107
        row: RowType,
108
        editMode: boolean,
109
        selected: boolean,
110
        dirty: boolean,
111
        deleted: boolean,
112
        dragging: boolean,
113
        index: number,
114
        mrl: boolean,
115
        filteredOut: boolean,
116
        _rowData: any,
117
        _: number
118
    ) {
119
        const result = new Set(['igx-grid__tr', index % 2 ? 'igx-grid__tr--even': 'igx-grid__tr--odd']);
308✔
120
        const mapping = [
308✔
121
            [selected, 'igx-grid__tr--selected'],
122
            [editMode, 'igx-grid__tr--edit'],
123
            [dirty, 'igx-grid__tr--edited'],
124
            [deleted, 'igx-grid__tr--deleted'],
125
            [dragging, 'igx-grid__tr--drag'],
126
            [mrl, 'igx-grid__tr--mrl'],
127
            // Tree grid only
128
            [filteredOut, 'igx-grid__tr--filtered']
129
        ];
130

131
        for (const [state, _class] of mapping) {
308✔
132
            if (state) {
2,156!
UNCOV
133
                result.add(_class as string);
×
134
            }
135
        }
136

137
        for (const cssClass of Object.keys(cssClasses ?? {})) {
308✔
UNCOV
138
            const callbackOrValue = cssClasses[cssClass];
×
UNCOV
139
            this.row.index = index;
×
UNCOV
140
            (this.row as any)._data = row.data;
×
UNCOV
141
            const apply = typeof callbackOrValue === 'function' ? callbackOrValue(this.row) : callbackOrValue;
×
UNCOV
142
            if (apply) {
×
UNCOV
143
                result.add(cssClass);
×
144
            }
145
        }
146
        return result;
308✔
147
    }
148
}
149

150
/**
151
 * @hidden
152
 * @internal
153
 */
154
@Pipe({
155
    name: 'igxGridRowStyles',
156
    standalone: true
157
})
158
export class IgxGridRowStylesPipe implements PipeTransform {
2✔
159

160
    constructor(@Inject(IGX_GRID_BASE) private grid: GridType) { }
265✔
161

162
    public transform(styles: GridStyleCSSProperty, rowData: any, index: number, __: number): GridStyleCSSProperty {
163
        const css = {};
308✔
164
        if (!styles) {
308✔
165
            return css;
308✔
166
        }
UNCOV
167
        for (const prop of Object.keys(styles)) {
×
UNCOV
168
            const cb = styles[prop];
×
UNCOV
169
            const data = this.grid.isTreeRow && this.grid.isTreeRow(rowData) ? rowData.data : rowData;
×
UNCOV
170
            const row = new IgxGridRow((this.grid as any), index, data);
×
UNCOV
171
            css[prop] = typeof cb === 'function' ? cb(row) : cb;
×
172
        }
UNCOV
173
        return css;
×
174
    }
175
}
176

177
/**
178
 * @hidden
179
 * @internal
180
 */
181
@Pipe({
182
    name: 'igxNotGrouped',
183
    standalone: true
184
})
185
export class IgxGridNotGroupedPipe implements PipeTransform {
2✔
186

187
    public transform(value: any[]): any[] {
188
        return value.filter(item => !item.columnGroup);
6,268✔
189
    }
190
}
191

192
/**
193
 * @hidden
194
 * @internal
195
 */
196
@Pipe({
197
    name: 'igxTopLevel',
198
    standalone: true
199
})
200
export class IgxGridTopLevelColumns implements PipeTransform {
2✔
201

202
    public transform(value: any[]): any[] {
203
        return value.filter(item => item.level === 0);
1,398✔
204
    }
205
}
206

207
/**
208
 * @hidden
209
 * @internal
210
 */
211
@Pipe({
212
    name: 'filterCondition',
213
    pure: true,
214
    standalone: true
215
})
216
export class IgxGridFilterConditionPipe implements PipeTransform {
2✔
217

218
    public transform(value: string): string {
219
        return value.split(/(?=[A-Z])/).join(' ');
×
220
    }
221
}
222

223
/**
224
 * @hidden
225
 * @internal
226
 */
227
@Pipe({
228
    name: 'gridTransaction',
229
    standalone: true
230
})
231
export class IgxGridTransactionPipe implements PipeTransform {
2✔
232

233
    constructor(@Inject(IGX_GRID_BASE) private grid: GridType) { }
37✔
234

235
    public transform(collection: any[], _id: string, _pipeTrigger: number) {
236

237
        if (this.grid.transactions.enabled) {
40!
UNCOV
238
            const result = DataUtil.mergeTransactions(
×
239
                cloneArray(collection),
240
                this.grid.transactions.getAggregatedChanges(true),
241
                this.grid.primaryKey,
242
                this.grid.dataCloneStrategy);
UNCOV
243
            return result;
×
244
        }
245
        return collection;
40✔
246
    }
247
}
248

249
/**
250
 * @hidden
251
 * @internal
252
 */
253
@Pipe({
254
    name: 'paginatorOptions',
255
    standalone: true
256
})
257
export class IgxGridPaginatorOptionsPipe implements PipeTransform {
2✔
258
    public transform(values: Array<number>) {
259
        return Array.from(new Set([...values])).sort((a, b) => a - b);
×
260
    }
261
}
262

263
/**
264
 * @hidden
265
 * @internal
266
 */
267
@Pipe({
268
    name: 'visibleColumns',
269
    standalone: true
270
})
271
export class IgxHasVisibleColumnsPipe implements PipeTransform {
2✔
272
    public transform(values: any[], hasVisibleColumns) {
273
        if (!(values && values.length)) {
38!
UNCOV
274
            return values;
×
275
        }
276
        return hasVisibleColumns ? values : [];
38!
277
    }
278

279
}
280

281
/** @hidden @internal */
282
function buildDataView(): MethodDecorator {
283
    return function (_target: unknown, _propertyKey: string, descriptor: PropertyDescriptor) {
2✔
284
        const original = descriptor.value;
2✔
285
        descriptor.value = function (...args: unknown[]) {
2✔
286
            const result = original.apply(this, args);
67✔
287
            this.grid.buildDataView();
67✔
288
            return result;
67✔
289
        }
290
        return descriptor;
2✔
291
    }
292
}
293

294
/**
295
 * @hidden
296
 */
297
@Pipe({
298
    name: 'gridRowPinning',
299
    standalone: true
300
})
301
export class IgxGridRowPinningPipe implements PipeTransform {
2✔
302

303
    constructor(@Inject(IGX_GRID_BASE) private grid: GridType) { }
37✔
304

305
    @buildDataView()
306
    public transform(collection: any[], id: string, isPinned = false, _pipeTrigger: number) {
2!
307

308
        if (this.grid.hasPinnedRecords && isPinned) {
67!
UNCOV
309
            const result = collection.filter(rec => !this.grid.isSummaryRow(rec) && this.grid.isRecordPinned(rec));
×
UNCOV
310
            result.sort((rec1, rec2) => this.grid.getInitialPinnedIndex(rec1) - this.grid.getInitialPinnedIndex(rec2));
×
UNCOV
311
            return result;
×
312
        }
313

314
        this.grid.unpinnedRecords = collection;
67✔
315
        if (!this.grid.hasPinnedRecords) {
67✔
316
            this.grid.pinnedRecords = [];
67✔
317
            return isPinned ? [] : collection;
67!
318
        }
319

UNCOV
320
        return collection.map((rec) => !this.grid.isSummaryRow(rec) &&
×
321
            this.grid.isRecordPinned(rec) ? { recordRef: rec, ghostRecord: true } : rec);
322
    }
323
}
324

325
@Pipe({
326
    name: 'dataMapper',
327
    standalone: true
328
})
329
export class IgxGridDataMapperPipe implements PipeTransform {
2✔
330

331
    public transform(data: any[], field: string, _: number, val: any, isNestedPath: boolean) {
332
        return isNestedPath ? resolveNestedPath(data, field) : val;
2,063!
333
    }
334
}
335

336
@Pipe({
337
    name: 'igxStringReplace',
338
    standalone: true
339
})
340
export class IgxStringReplacePipe implements PipeTransform {
2✔
341

342
    public transform(value: string, search: string | RegExp, replacement: string): string {
UNCOV
343
        return value.replace(search, replacement);
×
344
    }
345
}
346

347
@Pipe({
348
    name: 'transactionState',
349
    standalone: true
350
})
351
export class IgxGridTransactionStatePipe implements PipeTransform {
2✔
352

353
    public transform(row_id: any, field: string, rowEditable: boolean, transactions: any, _: any, __: any, ___: any) {
354
        if (rowEditable) {
2,063!
UNCOV
355
            const rowCurrentState = transactions.getAggregatedValue(row_id, false);
×
UNCOV
356
            if (rowCurrentState) {
×
UNCOV
357
                const value = resolveNestedPath(rowCurrentState, field);
×
UNCOV
358
                return value !== undefined && value !== null;
×
359
            }
360
        } else {
361
            const transaction = transactions.getState(row_id);
2,063✔
362
            const value = resolveNestedPath(transaction?.value ?? {}, field);
2,063✔
363
            return transaction && transaction.value && (value || value === 0 || value === false);
2,063!
364
        }
365
    }
366
}
367

368
@Pipe({
369
    name: 'columnFormatter',
370
    standalone: true
371
})
372
export class IgxColumnFormatterPipe implements PipeTransform {
2✔
373

374
    public transform(value: any, formatter: (v: any, data: any, columnData? :any) => any, rowData: any, columnData? : any) {
375
        return formatter(value, rowData, columnData);
30✔
376
    }
377
}
378

379
@Pipe({
380
    name: 'summaryFormatter',
381
    standalone: true
382
})
383
export class IgxSummaryFormatterPipe implements PipeTransform {
2✔
384

385
    public transform(summaryResult: IgxSummaryResult, summaryOperand: IgxSummaryOperand,
386
        summaryFormatter: (s: IgxSummaryResult, o: IgxSummaryOperand) => any) {
387
        return summaryFormatter(summaryResult, summaryOperand);
×
388
    }
389
}
390

391
@Pipe({
392
    name: 'gridAddRow',
393
    standalone: true
394
})
395
export class IgxGridAddRowPipe implements PipeTransform {
2✔
396

397
    constructor(@Inject(IGX_GRID_BASE) private grid: GridType) { }
37✔
398

399
    public transform(collection: any, isPinned = false, _pipeTrigger: number) {
×
400
        if (!this.grid.rowEditable || !this.grid.crudService.row || this.grid.crudService.row.getClassName() !== IgxAddRow.name ||
67!
401
            !this.grid.crudService.addRowParent || isPinned !== this.grid.crudService.addRowParent.isPinned) {
402
            return collection;
67✔
403
        }
UNCOV
404
        const copy = collection.slice(0);
×
UNCOV
405
        const rec = (this.grid.crudService.row as IgxAddRow).recordRef;
×
UNCOV
406
        copy.splice(this.grid.crudService.row.index, 0, rec);
×
UNCOV
407
        return copy;
×
408
    }
409
}
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