@contrail/data-grouping 1.0.41 → 1.0.42
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
|
-
}): any[];
|
11
|
-
static buildChildDataGroups(data: any, parentGroup: DataGroup, groupingProperties: Array<DataGroupingProperty>, leafNodeDataCount: any, currentDepth: any, groupMultiSelectInSeparateFrame?: boolean): void;
|
12
|
-
static buildDataGroupStructure(data: Array<any>, groupingProperties: Array<DataGroupingProperty>, leafNodeDataCount: number, groupMultiSelectInSeparateFrame?: boolean): DataGroupStructure;
|
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;
|
13
13
|
static createPartitionedGroupsFromData(parentGroup: DataGroup, data: Array<any>, leafNodeDataCount: number): Array<DataGroup>;
|
14
14
|
}
|
@@ -4,11 +4,12 @@ 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 }) {
|
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) {
|
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();
|
11
11
|
const sortingArray = [];
|
12
|
+
let hasEmptyValues = false;
|
12
13
|
data.forEach((obj) => {
|
13
14
|
if (!obj) {
|
14
15
|
return;
|
@@ -22,7 +23,12 @@ class DataGroupGenerator {
|
|
22
23
|
}
|
23
24
|
}
|
24
25
|
let value = key;
|
25
|
-
if (!value) {
|
26
|
+
if ((!value || (typeof value === 'number' && isNaN(value))) && displayItemsWithEmptyGroupingValues) {
|
27
|
+
hasEmptyValues = true;
|
28
|
+
value = '(empty)';
|
29
|
+
key = '(empty)';
|
30
|
+
}
|
31
|
+
else if (!value || (typeof value === 'number' && isNaN(value))) {
|
26
32
|
return;
|
27
33
|
}
|
28
34
|
if (propertyTypeOptions.isDate && value) {
|
@@ -78,9 +84,16 @@ class DataGroupGenerator {
|
|
78
84
|
return sortingArray.indexOf(val1) - sortingArray.indexOf(val2);
|
79
85
|
}
|
80
86
|
});
|
87
|
+
if (hasEmptyValues && displayItemsWithEmptyGroupingValues) {
|
88
|
+
const emptyIndex = distinctValues.indexOf('(empty)');
|
89
|
+
if (emptyIndex !== -1) {
|
90
|
+
distinctValues.splice(emptyIndex, 1);
|
91
|
+
distinctValues.push('(empty)');
|
92
|
+
}
|
93
|
+
}
|
81
94
|
return distinctValues;
|
82
95
|
}
|
83
|
-
static buildChildDataGroups(data, parentGroup, groupingProperties, leafNodeDataCount, currentDepth, groupMultiSelectInSeparateFrame = false) {
|
96
|
+
static buildChildDataGroups(data, parentGroup, groupingProperties, leafNodeDataCount, currentDepth, groupMultiSelectInSeparateFrame = false, displayItemsWithEmptyGroupingValues = false) {
|
84
97
|
var _a, _b, _c, _d, _e;
|
85
98
|
const groupingProperty = groupingProperties[currentDepth];
|
86
99
|
const propertyTypeOptions = {
|
@@ -94,10 +107,13 @@ class DataGroupGenerator {
|
|
94
107
|
const slugAltIndex = groupingProperty.propertyDefinition.slug;
|
95
108
|
const sort = groupingProperty.sort || types_1.TypePropertySortOrder.ASCENDING;
|
96
109
|
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;
|
97
|
-
let distinctValues = this.getDistinctValues(data, rootIndex, slugIndex, rootAltIndex, slugAltIndex, groupMultiSelectInSeparateFrame, { sortOrder: sort, options }, propertyTypeOptions);
|
110
|
+
let distinctValues = this.getDistinctValues(data, rootIndex, slugIndex, rootAltIndex, slugAltIndex, groupMultiSelectInSeparateFrame, { sortOrder: sort, options }, propertyTypeOptions, displayItemsWithEmptyGroupingValues);
|
98
111
|
for (let val of distinctValues) {
|
99
112
|
const groupData = data.filter((obj) => {
|
100
113
|
const objVal = util_1.ObjectUtil.getBySlugs(obj, rootIndex, slugIndex) || util_1.ObjectUtil.getBySlugs(obj, rootAltIndex, slugAltIndex);
|
114
|
+
if (val === '(empty)') {
|
115
|
+
return !objVal;
|
116
|
+
}
|
101
117
|
if (propertyTypeOptions.isDate) {
|
102
118
|
const objDate = new Date(objVal).toISOString().split('T')[0];
|
103
119
|
const valDate = new Date(val).toISOString().split('T')[0];
|
@@ -130,18 +146,20 @@ class DataGroupGenerator {
|
|
130
146
|
group.propertyValues = Object.assign({}, details);
|
131
147
|
}
|
132
148
|
group.propertyValues[groupingProperty.propertyDefinition.slug] = val;
|
133
|
-
const label =
|
149
|
+
const label = val === '(empty)'
|
150
|
+
? '(empty)'
|
151
|
+
: new types_1.PropertyValueFormatter().formatValueForProperty(val, groupingProperty.propertyDefinition);
|
134
152
|
group.name = label;
|
135
153
|
if (currentDepth === groupingProperties.length - 1) {
|
136
154
|
group.subGroups = this.createPartitionedGroupsFromData(group, groupData, leafNodeDataCount);
|
137
155
|
}
|
138
156
|
else if (currentDepth < groupingProperties.length - 1) {
|
139
|
-
this.buildChildDataGroups(groupData, group, groupingProperties, leafNodeDataCount, currentDepth + 1, groupMultiSelectInSeparateFrame);
|
157
|
+
this.buildChildDataGroups(groupData, group, groupingProperties, leafNodeDataCount, currentDepth + 1, groupMultiSelectInSeparateFrame, displayItemsWithEmptyGroupingValues);
|
140
158
|
}
|
141
159
|
parentGroup.subGroups.push(group);
|
142
160
|
}
|
143
161
|
}
|
144
|
-
static buildDataGroupStructure(data, groupingProperties, leafNodeDataCount, groupMultiSelectInSeparateFrame = false) {
|
162
|
+
static buildDataGroupStructure(data, groupingProperties, leafNodeDataCount, groupMultiSelectInSeparateFrame = false, displayItemsWithEmptyGroupingValues = false) {
|
145
163
|
const structure = {
|
146
164
|
rootGroup: {
|
147
165
|
subGroups: [],
|
@@ -152,7 +170,7 @@ class DataGroupGenerator {
|
|
152
170
|
groupingProperties,
|
153
171
|
depth: groupingProperties ? groupingProperties.length : 0,
|
154
172
|
};
|
155
|
-
this.buildChildDataGroups(data, structure.rootGroup, groupingProperties, leafNodeDataCount, 0, groupMultiSelectInSeparateFrame);
|
173
|
+
this.buildChildDataGroups(data, structure.rootGroup, groupingProperties, leafNodeDataCount, 0, groupMultiSelectInSeparateFrame, displayItemsWithEmptyGroupingValues);
|
156
174
|
return structure;
|
157
175
|
}
|
158
176
|
static createPartitionedGroupsFromData(parentGroup, data, leafNodeDataCount) {
|
package/package.json
CHANGED