@contrail/data-grouping 1.0.21 → 1.0.22
Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
|
|
1
1
|
import { DataGroup, DataGroupStructure, DataGroupingProperty } from "../interfaces";
|
2
2
|
export declare class DataGroupGenerator {
|
3
|
-
static getDistinctValues(data: any, index: any, altIndex?: any): any[];
|
4
|
-
static buildChildDataGroups(data: any, parentGroup: DataGroup, groupingProperties: Array<DataGroupingProperty>, leafNodeDataCount: any, currentDepth: any): void;
|
5
|
-
static buildDataGroupStructure(data: Array<any>, groupingProperties: Array<DataGroupingProperty>, leafNodeDataCount: number): DataGroupStructure;
|
3
|
+
static getDistinctValues(data: any, index: any, altIndex?: any, groupMultiSelectInSeparateFrame?: boolean): any[];
|
4
|
+
static buildChildDataGroups(data: any, parentGroup: DataGroup, groupingProperties: Array<DataGroupingProperty>, leafNodeDataCount: any, currentDepth: any, groupMultiSelectInSeparateFrame?: boolean): void;
|
5
|
+
static buildDataGroupStructure(data: Array<any>, groupingProperties: Array<DataGroupingProperty>, leafNodeDataCount: number, groupMultiSelectInSeparateFrame?: boolean): DataGroupStructure;
|
6
6
|
static createPartitionedGroupsFromData(parentGroup: DataGroup, data: Array<any>, leafNodeDataCount: number): Array<DataGroup>;
|
7
7
|
}
|
@@ -4,7 +4,7 @@ exports.DataGroupGenerator = void 0;
|
|
4
4
|
const util_1 = require("@contrail/util");
|
5
5
|
const types_1 = require("@contrail/types");
|
6
6
|
class DataGroupGenerator {
|
7
|
-
static getDistinctValues(data, index, altIndex = null) {
|
7
|
+
static getDistinctValues(data, index, altIndex = null, groupMultiSelectInSeparateFrame = false) {
|
8
8
|
const map = new Map();
|
9
9
|
data.forEach(obj => {
|
10
10
|
if (!obj) {
|
@@ -25,7 +25,14 @@ class DataGroupGenerator {
|
|
25
25
|
if (key && value && typeof key === 'object') {
|
26
26
|
key = value.id || value.name || value;
|
27
27
|
}
|
28
|
-
|
28
|
+
if (Array.isArray(value) && !groupMultiSelectInSeparateFrame) {
|
29
|
+
value.forEach(arrayValue => {
|
30
|
+
map[arrayValue] = arrayValue;
|
31
|
+
});
|
32
|
+
}
|
33
|
+
else {
|
34
|
+
map[key] = value;
|
35
|
+
}
|
29
36
|
});
|
30
37
|
const distinctValues = [...(Object.values(map))].sort((v1, v2) => {
|
31
38
|
let val1 = (v1 && typeof v1 === 'object') ? v1.name : v1;
|
@@ -34,17 +41,20 @@ class DataGroupGenerator {
|
|
34
41
|
});
|
35
42
|
return distinctValues;
|
36
43
|
}
|
37
|
-
static buildChildDataGroups(data, parentGroup, groupingProperties, leafNodeDataCount, currentDepth) {
|
44
|
+
static buildChildDataGroups(data, parentGroup, groupingProperties, leafNodeDataCount, currentDepth, groupMultiSelectInSeparateFrame = false) {
|
38
45
|
const groupingProperty = groupingProperties[currentDepth];
|
39
46
|
const index = groupingProperty.typeRootSlug + "." + groupingProperty.propertyDefinition.slug;
|
40
47
|
const altIndex = util_1.StringUtil.convertToCamelCase(groupingProperty.typeRootSlug) + "." + groupingProperty.propertyDefinition.slug;
|
41
|
-
let distinctValues = this.getDistinctValues(data, index, altIndex);
|
48
|
+
let distinctValues = this.getDistinctValues(data, index, altIndex, groupMultiSelectInSeparateFrame);
|
42
49
|
for (let val of distinctValues) {
|
43
50
|
const groupData = data.filter(obj => {
|
44
51
|
const objVal = util_1.ObjectUtil.getByPath(obj, index) || util_1.ObjectUtil.getByPath(obj, altIndex);
|
45
52
|
if (Array.isArray(val) && Array.isArray(objVal)) {
|
46
53
|
return val.sort().join() === objVal.sort().join();
|
47
54
|
}
|
55
|
+
else if (!Array.isArray(val) && Array.isArray(objVal)) {
|
56
|
+
return objVal.includes(val);
|
57
|
+
}
|
48
58
|
else if (val.id && (objVal === null || objVal === void 0 ? void 0 : objVal.id)) {
|
49
59
|
return val.id === objVal.id;
|
50
60
|
}
|
@@ -69,12 +79,12 @@ class DataGroupGenerator {
|
|
69
79
|
group.subGroups = this.createPartitionedGroupsFromData(group, groupData, leafNodeDataCount);
|
70
80
|
}
|
71
81
|
else if (currentDepth < groupingProperties.length - 1) {
|
72
|
-
this.buildChildDataGroups(groupData, group, groupingProperties, leafNodeDataCount, currentDepth + 1);
|
82
|
+
this.buildChildDataGroups(groupData, group, groupingProperties, leafNodeDataCount, currentDepth + 1, groupMultiSelectInSeparateFrame);
|
73
83
|
}
|
74
84
|
parentGroup.subGroups.push(group);
|
75
85
|
}
|
76
86
|
}
|
77
|
-
static buildDataGroupStructure(data, groupingProperties, leafNodeDataCount) {
|
87
|
+
static buildDataGroupStructure(data, groupingProperties, leafNodeDataCount, groupMultiSelectInSeparateFrame = false) {
|
78
88
|
const structure = {
|
79
89
|
rootGroup: {
|
80
90
|
subGroups: [],
|
@@ -85,7 +95,7 @@ class DataGroupGenerator {
|
|
85
95
|
groupingProperties,
|
86
96
|
depth: groupingProperties ? groupingProperties.length : 0,
|
87
97
|
};
|
88
|
-
this.buildChildDataGroups(data, structure.rootGroup, groupingProperties, leafNodeDataCount, 0);
|
98
|
+
this.buildChildDataGroups(data, structure.rootGroup, groupingProperties, leafNodeDataCount, 0, groupMultiSelectInSeparateFrame);
|
89
99
|
return structure;
|
90
100
|
}
|
91
101
|
static createPartitionedGroupsFromData(parentGroup, data, leafNodeDataCount) {
|
package/package.json
CHANGED