Skip to content

Commit a3fc966

Browse files
MKirovaMKirova
authored andcommitted
Address review comments - extract default pivot keys in global var and replace hardcoded values.
1 parent 0b87d47 commit a3fc966

File tree

4 files changed

+18
-33
lines changed

4 files changed

+18
-33
lines changed

projects/igniteui-angular/src/lib/data-operations/pivot-strategy.ts

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
import { GridType, PivotGridType } from '../grids/common/grid.interface';
3-
import { IPivotDimension, IPivotDimensionStrategy, IPivotKeys, IPivotValue, PivotDimensionType } from '../grids/pivot-grid/pivot-grid.interface';
3+
import { DEFAULT_PIVOT_KEYS, IPivotDimension, IPivotDimensionStrategy, IPivotKeys, IPivotValue, PivotDimensionType } from '../grids/pivot-grid/pivot-grid.interface';
44
import { PivotUtil } from '../grids/pivot-grid/pivot-util';
55
import { FilteringStrategy } from './filtering-strategy';
66
import { GridColumnDataType } from './data-util';
@@ -31,11 +31,7 @@ export class PivotRowDimensionsStrategy implements IPivotDimensionStrategy {
3131
collection: any,
3232
rows: IPivotDimension[],
3333
values?: IPivotValue[],
34-
pivotKeys: IPivotKeys =
35-
{
36-
aggregations: 'aggregations', records: 'records', children: 'children', level: 'level',
37-
rowDimensionSeparator: '_', columnDimensionSeparator: '-'
38-
}
34+
pivotKeys: IPivotKeys = DEFAULT_PIVOT_KEYS
3935
): any[] {
4036
let hierarchies;
4137
let data;
@@ -90,10 +86,7 @@ export class PivotColumnDimensionsStrategy implements IPivotDimensionStrategy {
9086
collection: any[],
9187
columns: IPivotDimension[],
9288
values: IPivotValue[],
93-
pivotKeys: IPivotKeys = {
94-
aggregations: 'aggregations', records: 'records', children: 'children', level: 'level',
95-
rowDimensionSeparator: '_', columnDimensionSeparator: '-'
96-
}
89+
pivotKeys: IPivotKeys = DEFAULT_PIVOT_KEYS
9790
): any[] {
9891
const res = this.processHierarchy(collection, columns, values, pivotKeys);
9992
return res;

projects/igniteui-angular/src/lib/grids/pivot-grid/pivot-grid.component.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import { IgxForOfSyncService, IgxForOfScrollSyncService } from '../../directives
3333
import { GridServiceType, GridType, IGX_GRID_BASE, IGX_GRID_SERVICE_BASE, RowType } from '../common/grid.interface';
3434
import { IgxGridCRUDService } from '../common/crud.service';
3535
import { IgxGridSummaryService } from '../summaries/grid-summary.service';
36-
import { IDimensionsChange, IPivotConfiguration, IPivotDimension, IPivotKeys, IValuesChange, PivotDimensionType } from './pivot-grid.interface';
36+
import { DEFAULT_PIVOT_KEYS, IDimensionsChange, IPivotConfiguration, IPivotDimension, IPivotKeys, IValuesChange, PivotDimensionType } from './pivot-grid.interface';
3737
import { IgxPivotHeaderRowComponent } from './pivot-header-row.component';
3838
import { IgxColumnGroupComponent } from '../columns/column-group.component';
3939
import { IgxColumnComponent } from '../columns/column.component';
@@ -294,10 +294,7 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
294294
public columnGroupStates = new Map<string, boolean>();
295295
public dimensionDataColumns;
296296
public get pivotKeys() {
297-
return this.pivotConfiguration.pivotKeys || {
298-
aggregations: 'aggregations', records: 'records', children: 'children', level: 'level',
299-
rowDimensionSeparator: '_', columnDimensionSeparator: '-'
300-
};
297+
return this.pivotConfiguration.pivotKeys || DEFAULT_PIVOT_KEYS;
301298
}
302299
public isPivot = true;
303300

@@ -1019,7 +1016,8 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
10191016
const rowFields = PivotUtil.flatten(this.pivotConfiguration.rows).map(x => x.memberName);
10201017
const keyFields = Object.values(this.pivotKeys);
10211018
const filteredFields = fields.filter(x => rowFields.indexOf(x) === -1 && keyFields.indexOf(x) === -1 &&
1022-
x.indexOf(this.pivotKeys.rowDimensionSeparator + 'level') === -1 && x.indexOf(this.pivotKeys.rowDimensionSeparator + 'records') === -1);
1019+
x.indexOf(this.pivotKeys.rowDimensionSeparator + this.pivotKeys.level) === -1 &&
1020+
x.indexOf(this.pivotKeys.rowDimensionSeparator + this.pivotKeys.records) === -1);
10231021
fieldsMap = this.generateFromData(filteredFields);
10241022
} else {
10251023
fieldsMap = PivotUtil.getFieldsHierarchy(

projects/igniteui-angular/src/lib/grids/pivot-grid/pivot-grid.interface.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ import { FilteringExpressionsTree } from '../../data-operations/filtering-expres
33
import { SortingDirection } from '../../data-operations/sorting-strategy';
44
import { ColumnType } from '../common/grid.interface';
55

6+
export const DEFAULT_PIVOT_KEYS = {
7+
aggregations: 'aggregations', records: 'records', children: 'children', level: 'level',
8+
rowDimensionSeparator: '_', columnDimensionSeparator: '-'
9+
};
10+
611
export interface IDimensionsChange {
712
dimensions: IPivotDimension[],
813
dimensionCollectionType: PivotDimensionType

projects/igniteui-angular/src/lib/grids/pivot-grid/pivot-grid.pipes.ts

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { cloneArray } from '../../core/utils';
33
import { DataUtil } from '../../data-operations/data-util';
44
import { FilteringExpressionsTree, IFilteringExpressionsTree } from '../../data-operations/filtering-expressions-tree';
55
import { IFilteringStrategy } from '../../data-operations/filtering-strategy';
6-
import { IPivotConfiguration, IPivotKeys } from './pivot-grid.interface';
6+
import { DEFAULT_PIVOT_KEYS, IPivotConfiguration, IPivotKeys } from './pivot-grid.interface';
77
import {
88
DefaultPivotSortingStrategy, DimensionValuesFilteringStrategy, PivotColumnDimensionsStrategy,
99
PivotRowDimensionsStrategy
@@ -15,6 +15,7 @@ import { GridType } from '../common/grid.interface';
1515
import { GridBaseAPIService } from '../api.service';
1616
import { IgxGridBaseDirective } from '../grid-base.directive';
1717
import { IGridSortingStrategy } from '../common/strategy';
18+
1819
/**
1920
* @hidden
2021
*/
@@ -33,10 +34,7 @@ export class IgxPivotRowPipe implements PipeTransform {
3334
_pipeTrigger?: number,
3435
__?
3536
): any[] {
36-
const pivotKeys = config.pivotKeys || {
37-
aggregations: 'aggregations', records: 'records', children: 'children', level: 'level',
38-
rowDimensionSeparator: '_', columnDimensionSeparator: '-'
39-
};
37+
const pivotKeys = config.pivotKeys || DEFAULT_PIVOT_KEYS;
4038
const enabledRows = config.rows.filter(x => x.enabled);
4139
const rowStrategy = config.rowStrategy || PivotRowDimensionsStrategy.instance();
4240
const data = cloneArray(collection, true);
@@ -63,10 +61,7 @@ export class IgxPivotRowExpansionPipe implements PipeTransform {
6361
_pipeTrigger?: number,
6462
__?,
6563
): any[] {
66-
const pivotKeys = config.pivotKeys || {
67-
aggregations: 'aggregations', records: 'records', children: 'children', level: 'level',
68-
rowDimensionSeparator: '_', columnDimensionSeparator: '-'
69-
};
64+
const pivotKeys = config.pivotKeys || DEFAULT_PIVOT_KEYS;
7065
const enabledRows = config.rows.filter(x => x.enabled);
7166
const data = collection ? cloneArray(collection, true) : [];
7267
let totalLlv = 0;
@@ -113,10 +108,7 @@ export class IgxPivotColumnPipe implements PipeTransform {
113108
_pipeTrigger?: number,
114109
__?
115110
): any[] {
116-
const pivotKeys = config.pivotKeys || {
117-
aggregations: 'aggregations', records: 'records', children: 'children', level: 'level',
118-
rowDimensionSeparator: '_', columnDimensionSeparator: '-'
119-
};
111+
const pivotKeys = config.pivotKeys || DEFAULT_PIVOT_KEYS;
120112
const enabledColumns = config.columns.filter(x => x.enabled);
121113
const enabledValues = config.values.filter(x => x.enabled);
122114

@@ -182,10 +174,7 @@ export class IgxPivotGridColumnSortingPipe implements PipeTransform {
182174
expressions: ISortingExpression[],
183175
sorting: IGridSortingStrategy,
184176
pipeTrigger: number,
185-
pivotKeys: IPivotKeys = {
186-
aggregations: 'aggregations', records: 'records', children: 'children', level: 'level',
187-
rowDimensionSeparator: '_', columnDimensionSeparator: '-'
188-
}
177+
pivotKeys: IPivotKeys = DEFAULT_PIVOT_KEYS
189178
): any[] {
190179
let result: any[];
191180

0 commit comments

Comments
 (0)