@contrail/data-grouping 1.0.18 → 1.0.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
|
|
1
1
|
import { DataGroup, DataGroupStructure, DataGroupingProperty } from "../interfaces";
|
2
2
|
export declare class DataGroupGenerator {
|
3
|
-
static getDistinctValues(data: any, index: any): any[];
|
3
|
+
static getDistinctValues(data: any, index: any, altIndex?: any): any[];
|
4
4
|
static buildChildDataGroups(data: any, parentGroup: DataGroup, groupingProperties: Array<DataGroupingProperty>, leafNodeDataCount: any, currentDepth: any): void;
|
5
5
|
static buildDataGroupStructure(data: Array<any>, groupingProperties: Array<DataGroupingProperty>, leafNodeDataCount: number): DataGroupStructure;
|
6
6
|
static createPartitionedGroupsFromData(parentGroup: DataGroup, data: Array<any>, leafNodeDataCount: number): Array<DataGroup>;
|
@@ -4,13 +4,20 @@ 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) {
|
7
|
+
static getDistinctValues(data, index, altIndex = null) {
|
8
8
|
const map = new Map();
|
9
9
|
data.forEach(obj => {
|
10
10
|
if (!obj) {
|
11
11
|
return;
|
12
12
|
}
|
13
13
|
let key = util_1.ObjectUtil.getByPath(obj, index);
|
14
|
+
let altKey = null;
|
15
|
+
if (altIndex) {
|
16
|
+
altKey = util_1.ObjectUtil.getByPath(obj, altIndex);
|
17
|
+
if (!key) {
|
18
|
+
key = altKey;
|
19
|
+
}
|
20
|
+
}
|
14
21
|
let value = key;
|
15
22
|
if (!value) {
|
16
23
|
return;
|
@@ -29,10 +36,13 @@ class DataGroupGenerator {
|
|
29
36
|
}
|
30
37
|
static buildChildDataGroups(data, parentGroup, groupingProperties, leafNodeDataCount, currentDepth) {
|
31
38
|
const groupingProperty = groupingProperties[currentDepth];
|
32
|
-
const index = groupingProperty.
|
33
|
-
const
|
39
|
+
const index = groupingProperty.typeRootSlug + "." + groupingProperty.propertyDefinition.slug;
|
40
|
+
const altIndex = util_1.StringUtil.convertToCamelCase(groupingProperty.typeRootSlug) + "." + groupingProperty.propertyDefinition.slug;
|
41
|
+
let distinctValues = this.getDistinctValues(data, index, altIndex);
|
34
42
|
for (let val of distinctValues) {
|
35
|
-
const groupData = data.filter(obj =>
|
43
|
+
const groupData = data.filter(obj => {
|
44
|
+
return (util_1.ObjectUtil.getByPath(obj, index) === val || util_1.ObjectUtil.getByPath(obj, altIndex) === val);
|
45
|
+
});
|
36
46
|
const group = {
|
37
47
|
data: [],
|
38
48
|
subGroups: [],
|
@@ -43,8 +53,8 @@ class DataGroupGenerator {
|
|
43
53
|
const details = groupData[0];
|
44
54
|
group.propertyValues = Object.assign({}, details);
|
45
55
|
}
|
46
|
-
group.propertyValues[groupingProperty.
|
47
|
-
const label = new types_1.PropertyValueFormatter().formatValueForProperty(val, groupingProperty.
|
56
|
+
group.propertyValues[groupingProperty.propertyDefinition.slug] = val;
|
57
|
+
const label = new types_1.PropertyValueFormatter().formatValueForProperty(val, groupingProperty.propertyDefinition);
|
48
58
|
group.name = label;
|
49
59
|
if (currentDepth === groupingProperties.length - 1) {
|
50
60
|
group.subGroups = this.createPartitionedGroupsFromData(group, groupData, leafNodeDataCount);
|
package/lib/interfaces.d.ts
CHANGED
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@contrail/data-grouping",
|
3
|
-
"version": "1.0.
|
3
|
+
"version": "1.0.20",
|
4
4
|
"description": "Utilities and interfaces for grouping data into hierarchial data structures based on properties.",
|
5
5
|
"main": "lib/index.js",
|
6
6
|
"types": "lib/index.d.ts",
|
@@ -14,7 +14,7 @@
|
|
14
14
|
"author": "",
|
15
15
|
"license": "ISC",
|
16
16
|
"devDependencies": {
|
17
|
-
"@contrail/util": "^1.0.
|
17
|
+
"@contrail/util": "^1.0.28",
|
18
18
|
"@types/jest": "^23.3.14",
|
19
19
|
"jest": "^23.6.0",
|
20
20
|
"prettier": "^1.19.1",
|