@contrail/data-grouping 1.0.21 → 1.0.23
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,8 +4,9 @@ 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
|
+
const sortingArray = [];
|
9
10
|
data.forEach(obj => {
|
10
11
|
if (!obj) {
|
11
12
|
return;
|
@@ -25,26 +26,42 @@ class DataGroupGenerator {
|
|
25
26
|
if (key && value && typeof key === 'object') {
|
26
27
|
key = value.id || value.name || value;
|
27
28
|
}
|
28
|
-
|
29
|
+
if (Array.isArray(value) && !groupMultiSelectInSeparateFrame) {
|
30
|
+
value.forEach(arrayValue => {
|
31
|
+
map[arrayValue] = arrayValue;
|
32
|
+
if (!sortingArray.includes(arrayValue)) {
|
33
|
+
sortingArray.push(arrayValue);
|
34
|
+
}
|
35
|
+
});
|
36
|
+
}
|
37
|
+
else {
|
38
|
+
map[key] = value;
|
39
|
+
if (!sortingArray.includes(value)) {
|
40
|
+
sortingArray.push(value);
|
41
|
+
}
|
42
|
+
}
|
29
43
|
});
|
30
44
|
const distinctValues = [...(Object.values(map))].sort((v1, v2) => {
|
31
45
|
let val1 = (v1 && typeof v1 === 'object') ? v1.name : v1;
|
32
46
|
let val2 = (v2 && typeof v2 === 'object') ? v2.name : v2;
|
33
|
-
return val1
|
47
|
+
return sortingArray.indexOf(val1) - sortingArray.indexOf(val2);
|
34
48
|
});
|
35
49
|
return distinctValues;
|
36
50
|
}
|
37
|
-
static buildChildDataGroups(data, parentGroup, groupingProperties, leafNodeDataCount, currentDepth) {
|
51
|
+
static buildChildDataGroups(data, parentGroup, groupingProperties, leafNodeDataCount, currentDepth, groupMultiSelectInSeparateFrame = false) {
|
38
52
|
const groupingProperty = groupingProperties[currentDepth];
|
39
53
|
const index = groupingProperty.typeRootSlug + "." + groupingProperty.propertyDefinition.slug;
|
40
54
|
const altIndex = util_1.StringUtil.convertToCamelCase(groupingProperty.typeRootSlug) + "." + groupingProperty.propertyDefinition.slug;
|
41
|
-
let distinctValues = this.getDistinctValues(data, index, altIndex);
|
55
|
+
let distinctValues = this.getDistinctValues(data, index, altIndex, groupMultiSelectInSeparateFrame);
|
42
56
|
for (let val of distinctValues) {
|
43
57
|
const groupData = data.filter(obj => {
|
44
58
|
const objVal = util_1.ObjectUtil.getByPath(obj, index) || util_1.ObjectUtil.getByPath(obj, altIndex);
|
45
59
|
if (Array.isArray(val) && Array.isArray(objVal)) {
|
46
60
|
return val.sort().join() === objVal.sort().join();
|
47
61
|
}
|
62
|
+
else if (!Array.isArray(val) && Array.isArray(objVal)) {
|
63
|
+
return objVal.includes(val);
|
64
|
+
}
|
48
65
|
else if (val.id && (objVal === null || objVal === void 0 ? void 0 : objVal.id)) {
|
49
66
|
return val.id === objVal.id;
|
50
67
|
}
|
@@ -69,12 +86,12 @@ class DataGroupGenerator {
|
|
69
86
|
group.subGroups = this.createPartitionedGroupsFromData(group, groupData, leafNodeDataCount);
|
70
87
|
}
|
71
88
|
else if (currentDepth < groupingProperties.length - 1) {
|
72
|
-
this.buildChildDataGroups(groupData, group, groupingProperties, leafNodeDataCount, currentDepth + 1);
|
89
|
+
this.buildChildDataGroups(groupData, group, groupingProperties, leafNodeDataCount, currentDepth + 1, groupMultiSelectInSeparateFrame);
|
73
90
|
}
|
74
91
|
parentGroup.subGroups.push(group);
|
75
92
|
}
|
76
93
|
}
|
77
|
-
static buildDataGroupStructure(data, groupingProperties, leafNodeDataCount) {
|
94
|
+
static buildDataGroupStructure(data, groupingProperties, leafNodeDataCount, groupMultiSelectInSeparateFrame = false) {
|
78
95
|
const structure = {
|
79
96
|
rootGroup: {
|
80
97
|
subGroups: [],
|
@@ -85,7 +102,7 @@ class DataGroupGenerator {
|
|
85
102
|
groupingProperties,
|
86
103
|
depth: groupingProperties ? groupingProperties.length : 0,
|
87
104
|
};
|
88
|
-
this.buildChildDataGroups(data, structure.rootGroup, groupingProperties, leafNodeDataCount, 0);
|
105
|
+
this.buildChildDataGroups(data, structure.rootGroup, groupingProperties, leafNodeDataCount, 0, groupMultiSelectInSeparateFrame);
|
89
106
|
return structure;
|
90
107
|
}
|
91
108
|
static createPartitionedGroupsFromData(parentGroup, data, leafNodeDataCount) {
|
package/package.json
CHANGED