Skip to content

Commit e6e7a01

Browse files
MKirovaMKirova
authored andcommitted
chore(*): Additional fix + tests for related scenarios.
1 parent 46f0fad commit e6e7a01

File tree

2 files changed

+118
-3
lines changed

2 files changed

+118
-3
lines changed

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

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { IgxPivotDateDimension } from './pivot-grid-dimensions';
55
import { IgxPivotNumericAggregate } from './pivot-grid-aggregate';
66
import { IPivotConfiguration } from './pivot-grid.interface';
77
import { IgxPivotColumnPipe, IgxPivotRowExpansionPipe, IgxPivotRowPipe } from './pivot-grid.pipes';
8+
import { DATA } from 'src/app/shared/pivot-data';
89

910
describe('Pivot pipes #pivotGrid', () => {
1011
let rowPipe: IgxPivotRowPipe;
@@ -837,4 +838,118 @@ describe('Pivot pipes #pivotGrid', () => {
837838
expect(rowStatePipeResult[13]['Years']).not.toBeDefined();
838839
expect(rowStatePipeResult[13]['Date']).toEqual('01/01/2021');
839840
});
841+
842+
// automation for https://github.com/IgniteUI/igniteui-angular/issues/10545
843+
it('should generate last dimension values for all records.', () => {
844+
data = [
845+
{
846+
ProductCategory: 'Clothing', UnitPrice: 12.81, SellerName: 'Stanley',
847+
Country: 'Bulgaria', City: 'Sofia', Date: '01/01/2021', UnitsSold: 282
848+
},
849+
{
850+
ProductCategory: 'Clothing', UnitPrice: 49.57, SellerName: 'Elisa',
851+
Country: 'USA', City: 'New York', Date: '01/05/2019', UnitsSold: 296
852+
},
853+
{
854+
ProductCategory: 'Bikes', UnitPrice: 3.56, SellerName: 'Lydia',
855+
Country: 'Uruguay', City: 'Ciudad de la Costa', Date: '01/06/2020', UnitsSold: 68
856+
},
857+
{
858+
ProductCategory: 'Accessories', UnitPrice: 85.58, SellerName: 'David',
859+
Country: 'USA', City: 'New York', Date: '04/07/2021', UnitsSold: 293
860+
},
861+
{
862+
ProductCategory: 'Components', UnitPrice: 18.13, SellerName: 'John',
863+
Country: 'USA', City: 'New York', Date: '12/08/2021', UnitsSold: 240
864+
},
865+
{
866+
ProductCategory: 'Clothing', UnitPrice: 68.33, SellerName: 'Larry',
867+
Country: 'Uruguay', City: 'Ciudad de la Costa', Date: '05/12/2020', UnitsSold: 456
868+
},
869+
{
870+
ProductCategory: 'Clothing', UnitPrice: 16.05, SellerName: 'Walter',
871+
Country: 'Bulgaria', City: 'Plovdiv', Date: '02/19/2020', UnitsSold: 492
872+
}];
873+
pivotConfig.columns = [{
874+
memberName: 'Country',
875+
enabled: true
876+
}];
877+
pivotConfig.rows = [
878+
new IgxPivotDateDimension(
879+
{
880+
memberName: 'Date',
881+
enabled: true
882+
},
883+
{
884+
months: false
885+
}
886+
),
887+
{
888+
memberName: 'City',
889+
enabled: true
890+
},
891+
{
892+
memberFunction: () => 'All',
893+
memberName: 'AllProducts',
894+
enabled: true,
895+
childLevel: {
896+
memberFunction: (data) => data.ProductCategory,
897+
memberName: 'ProductCategory',
898+
enabled: true
899+
}
900+
},
901+
{
902+
memberName: 'SellerName',
903+
enabled: true
904+
}
905+
];
906+
const rowPipeResult = rowPipe.transform(data, pivotConfig, expansionStates);
907+
const columnPipeResult = columnPipe.transform(rowPipeResult, pivotConfig, new Map<any, boolean>());
908+
const rowStatePipeResult = rowStatePipe.transform(columnPipeResult, pivotConfig, expansionStates, true);
909+
const sellers = rowStatePipeResult.map(x => x.SellerName);
910+
// there should be no empty values.
911+
expect(sellers.filter(x => x === undefined).length).toBe(0);
912+
});
913+
914+
// automation for https://github.com/IgniteUI/igniteui-angular/issues/10662
915+
it('should retain processed values for last dimension when bound to complex object.', () => {
916+
data = DATA;
917+
pivotConfig.rows = [
918+
{
919+
memberName: 'Date',
920+
enabled: true,
921+
},
922+
{
923+
memberName: 'AllProduct',
924+
memberFunction: () => 'All Products',
925+
enabled: true,
926+
childLevel:
927+
{
928+
929+
memberName: 'Product',
930+
memberFunction: (data) => data.Product.Name,
931+
enabled: true
932+
}
933+
},
934+
{
935+
memberName: 'AllSeller',
936+
memberFunction: () => 'All Sellers',
937+
enabled: true,
938+
childLevel:
939+
{
940+
memberName: 'Seller',
941+
memberFunction: (data) => data.Seller.Name,
942+
enabled: true,
943+
},
944+
},
945+
];
946+
947+
const rowPipeResult = rowPipe.transform(data, pivotConfig, expansionStates);
948+
const columnPipeResult = columnPipe.transform(rowPipeResult, pivotConfig, new Map<any, boolean>());
949+
const rowStatePipeResult = rowStatePipe.transform(columnPipeResult, pivotConfig, expansionStates, true);
950+
951+
const res = rowStatePipeResult.filter(x => x.AllSeller === undefined).map(x => x.Seller);
952+
// all values should be strings as the result of the processed member function is string.
953+
expect(res.filter(x => typeof x !== 'string').length).toBe(0);
954+
});
840955
});

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export class PivotUtil {
1414
currDim = currDim.childLevel;
1515
lvl++;
1616
}
17-
17+
currDim.level = lvl;
1818
}
1919
}
2020
public static getFieldsHierarchy(data: any[], dimensions: IPivotDimension[],
@@ -303,6 +303,7 @@ export class PivotUtil {
303303
const flatData = [];
304304
hierarchies.forEach((h, key) => {
305305
const field = h.dimension.memberName;
306+
const keys = Object.assign({}, pivotKeys) as any;
306307
let obj = {};
307308
obj[field] = key;
308309
if (h[pivotKeys.records]) {
@@ -318,7 +319,6 @@ export class PivotUtil {
318319
for (const nested of nestedData) {
319320
if (nested[pivotKeys.records] && nested[pivotKeys.records].length === 1) {
320321
// only 1 child record, apply same props to parent.
321-
const keys = Object.assign({}, pivotKeys) as any;
322322
const memberName = h[pivotKeys.children].entries().next().value[1].dimension.memberName;
323323
keys[memberName] = memberName;
324324
PivotUtil.processSiblingProperties(nested[pivotKeys.records][0], [nested], keys);
@@ -327,7 +327,7 @@ export class PivotUtil {
327327
obj[pivotKeys.records] = this.getDirectLeafs(nestedData, pivotKeys);
328328
obj[field + pivotKeys.rowDimensionSeparator + pivotKeys.records] = nestedData;
329329
if (!rootData) {
330-
PivotUtil.processSiblingProperties(rec, obj[field + pivotKeys.rowDimensionSeparator + pivotKeys.records], pivotKeys);
330+
PivotUtil.processSiblingProperties(rec, obj[field + pivotKeys.rowDimensionSeparator + pivotKeys.records], keys);
331331
}
332332
}
333333
});

0 commit comments

Comments
 (0)