@contrail/data-grouping 1.0.48 → 1.0.50-alpha.0
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.
@@ -7,8 +7,8 @@ export declare class DataGroupGenerator {
|
|
7
7
|
}, propertyTypeOptions?: {
|
8
8
|
isDate: boolean;
|
9
9
|
isNumber: boolean;
|
10
|
-
}, displayItemsWithEmptyGroupingValues?: boolean): any[];
|
11
|
-
static buildChildDataGroups(data: any, parentGroup: DataGroup, groupingProperties: Array<DataGroupingProperty>, leafNodeDataCount: any, currentDepth: any, groupMultiSelectInSeparateFrame?: boolean, displayItemsWithEmptyGroupingValues?: boolean): void;
|
12
|
-
static buildDataGroupStructure(data: Array<any>, groupingProperties: Array<DataGroupingProperty>, leafNodeDataCount: number, groupMultiSelectInSeparateFrame?: boolean, displayItemsWithEmptyGroupingValues?: boolean): DataGroupStructure;
|
10
|
+
}, displayItemsWithEmptyGroupingValues?: boolean, displayOptionFrameWithNoData?: boolean): any[];
|
11
|
+
static buildChildDataGroups(data: any, parentGroup: DataGroup, groupingProperties: Array<DataGroupingProperty>, leafNodeDataCount: any, currentDepth: any, groupMultiSelectInSeparateFrame?: boolean, displayItemsWithEmptyGroupingValues?: boolean, displayOptionFrameWithNoData?: boolean): void;
|
12
|
+
static buildDataGroupStructure(data: Array<any>, groupingProperties: Array<DataGroupingProperty>, leafNodeDataCount: number, groupMultiSelectInSeparateFrame?: boolean, displayItemsWithEmptyGroupingValues?: boolean, displayOptionFrameWithNoData?: boolean): DataGroupStructure;
|
13
13
|
static createPartitionedGroupsFromData(parentGroup: DataGroup, data: Array<any>, leafNodeDataCount: number): Array<DataGroup>;
|
14
14
|
}
|
@@ -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, rootIndex, slugIndex = null, rootAltIndex = null, slugAltIndex = null, groupMultiSelectInSeparateFrame = false, sortOptions = { sortOrder: types_1.TypePropertySortOrder.ASCENDING, options: null }, propertyTypeOptions = { isDate: false, isNumber: false }, displayItemsWithEmptyGroupingValues = false) {
|
7
|
+
static getDistinctValues(data, rootIndex, slugIndex = null, rootAltIndex = null, slugAltIndex = null, groupMultiSelectInSeparateFrame = false, sortOptions = { sortOrder: types_1.TypePropertySortOrder.ASCENDING, options: null }, propertyTypeOptions = { isDate: false, isNumber: false }, displayItemsWithEmptyGroupingValues = false, displayOptionFrameWithNoData = false) {
|
8
8
|
const sortOrder = (sortOptions === null || sortOptions === void 0 ? void 0 : sortOptions.sortOrder) || types_1.TypePropertySortOrder.ASCENDING;
|
9
9
|
const options = (sortOptions === null || sortOptions === void 0 ? void 0 : sortOptions.options) || null;
|
10
10
|
const map = new Map();
|
@@ -64,6 +64,14 @@ class DataGroupGenerator {
|
|
64
64
|
}
|
65
65
|
});
|
66
66
|
const distinctValues = [...Object.values(map)];
|
67
|
+
if (options && Array.isArray(options) && displayOptionFrameWithNoData) {
|
68
|
+
const distinctValuesSet = new Set(distinctValues);
|
69
|
+
options.forEach((option) => {
|
70
|
+
if (!distinctValuesSet.has(option)) {
|
71
|
+
distinctValues.push(option);
|
72
|
+
}
|
73
|
+
});
|
74
|
+
}
|
67
75
|
const sortingArrayMap = new Map(sortingArray.map((value, index) => [value, index]));
|
68
76
|
const optionsMap = options
|
69
77
|
? new Map(options.map((val, index) => [val, index]))
|
@@ -103,7 +111,7 @@ class DataGroupGenerator {
|
|
103
111
|
}
|
104
112
|
return distinctValues;
|
105
113
|
}
|
106
|
-
static buildChildDataGroups(data, parentGroup, groupingProperties, leafNodeDataCount, currentDepth, groupMultiSelectInSeparateFrame = false, displayItemsWithEmptyGroupingValues = false) {
|
114
|
+
static buildChildDataGroups(data, parentGroup, groupingProperties, leafNodeDataCount, currentDepth, groupMultiSelectInSeparateFrame = false, displayItemsWithEmptyGroupingValues = false, displayOptionFrameWithNoData = false) {
|
107
115
|
var _a, _b, _c, _d, _e;
|
108
116
|
const groupingProperty = groupingProperties[currentDepth];
|
109
117
|
const propertyTypeOptions = {
|
@@ -117,7 +125,7 @@ class DataGroupGenerator {
|
|
117
125
|
const slugAltIndex = groupingProperty.propertyDefinition.slug;
|
118
126
|
const sort = groupingProperty.sort || types_1.TypePropertySortOrder.ASCENDING;
|
119
127
|
const options = ((_e = (_d = groupingProperty.propertyDefinition) === null || _d === void 0 ? void 0 : _d.options) === null || _e === void 0 ? void 0 : _e.map((x) => x.value)) || null;
|
120
|
-
let distinctValues = this.getDistinctValues(data, rootIndex, slugIndex, rootAltIndex, slugAltIndex, groupMultiSelectInSeparateFrame, { sortOrder: sort, options }, propertyTypeOptions, displayItemsWithEmptyGroupingValues);
|
128
|
+
let distinctValues = this.getDistinctValues(data, rootIndex, slugIndex, rootAltIndex, slugAltIndex, groupMultiSelectInSeparateFrame, { sortOrder: sort, options }, propertyTypeOptions, displayItemsWithEmptyGroupingValues, displayOptionFrameWithNoData);
|
121
129
|
for (let val of distinctValues) {
|
122
130
|
const groupData = data.filter((obj) => {
|
123
131
|
const objVal = util_1.ObjectUtil.getBySlugs(obj, rootIndex, slugIndex) || util_1.ObjectUtil.getBySlugs(obj, rootAltIndex, slugAltIndex);
|
@@ -164,12 +172,12 @@ class DataGroupGenerator {
|
|
164
172
|
group.subGroups = this.createPartitionedGroupsFromData(group, groupData, leafNodeDataCount);
|
165
173
|
}
|
166
174
|
else if (currentDepth < groupingProperties.length - 1) {
|
167
|
-
this.buildChildDataGroups(groupData, group, groupingProperties, leafNodeDataCount, currentDepth + 1, groupMultiSelectInSeparateFrame, displayItemsWithEmptyGroupingValues);
|
175
|
+
this.buildChildDataGroups(groupData, group, groupingProperties, leafNodeDataCount, currentDepth + 1, groupMultiSelectInSeparateFrame, displayItemsWithEmptyGroupingValues, displayOptionFrameWithNoData);
|
168
176
|
}
|
169
177
|
parentGroup.subGroups.push(group);
|
170
178
|
}
|
171
179
|
}
|
172
|
-
static buildDataGroupStructure(data, groupingProperties, leafNodeDataCount, groupMultiSelectInSeparateFrame = false, displayItemsWithEmptyGroupingValues = false) {
|
180
|
+
static buildDataGroupStructure(data, groupingProperties, leafNodeDataCount, groupMultiSelectInSeparateFrame = false, displayItemsWithEmptyGroupingValues = false, displayOptionFrameWithNoData = false) {
|
173
181
|
const structure = {
|
174
182
|
rootGroup: {
|
175
183
|
subGroups: [],
|
@@ -180,25 +188,36 @@ class DataGroupGenerator {
|
|
180
188
|
groupingProperties,
|
181
189
|
depth: groupingProperties ? groupingProperties.length : 0,
|
182
190
|
};
|
183
|
-
this.buildChildDataGroups(data, structure.rootGroup, groupingProperties, leafNodeDataCount, 0, groupMultiSelectInSeparateFrame, displayItemsWithEmptyGroupingValues);
|
191
|
+
this.buildChildDataGroups(data, structure.rootGroup, groupingProperties, leafNodeDataCount, 0, groupMultiSelectInSeparateFrame, displayItemsWithEmptyGroupingValues, displayOptionFrameWithNoData);
|
184
192
|
return structure;
|
185
193
|
}
|
186
194
|
static createPartitionedGroupsFromData(parentGroup, data, leafNodeDataCount) {
|
187
195
|
const dataLength = data.length;
|
188
196
|
const frameCount = Math.ceil(dataLength / leafNodeDataCount);
|
189
197
|
const groups = [];
|
190
|
-
|
191
|
-
const startIndex = (i - 1) * leafNodeDataCount;
|
192
|
-
const endIndex = startIndex + leafNodeDataCount;
|
193
|
-
let groupData = data.slice(startIndex, endIndex);
|
198
|
+
if (data.length === 0) {
|
194
199
|
const group = {
|
195
|
-
data:
|
200
|
+
data: [],
|
196
201
|
subGroups: [],
|
197
202
|
name: parentGroup.name,
|
198
203
|
propertyValues: parentGroup.propertyValues,
|
199
204
|
};
|
200
205
|
groups.push(group);
|
201
206
|
}
|
207
|
+
else {
|
208
|
+
for (let i = 1; i <= frameCount; i++) {
|
209
|
+
const startIndex = (i - 1) * leafNodeDataCount;
|
210
|
+
const endIndex = startIndex + leafNodeDataCount;
|
211
|
+
let groupData = data.slice(startIndex, endIndex);
|
212
|
+
const group = {
|
213
|
+
data: groupData,
|
214
|
+
subGroups: [],
|
215
|
+
name: parentGroup.name,
|
216
|
+
propertyValues: parentGroup.propertyValues,
|
217
|
+
};
|
218
|
+
groups.push(group);
|
219
|
+
}
|
220
|
+
}
|
202
221
|
return groups;
|
203
222
|
}
|
204
223
|
}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@contrail/data-grouping",
|
3
|
-
"version": "1.0.
|
3
|
+
"version": "1.0.50-alpha.0",
|
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.1.17-alpha.0",
|
18
18
|
"@types/jest": "^29.5.2",
|
19
19
|
"jest": "^29.5.0",
|
20
20
|
"prettier": "^1.19.1",
|
@@ -38,7 +38,7 @@
|
|
38
38
|
"testEnvironment": "node"
|
39
39
|
},
|
40
40
|
"dependencies": {
|
41
|
-
"@contrail/documents": "^1.0
|
42
|
-
"@contrail/types": "^3.0
|
41
|
+
"@contrail/documents": "^1.2.9-alpha.0",
|
42
|
+
"@contrail/types": "^3.1.2-alpha.0"
|
43
43
|
}
|
44
44
|
}
|