@contrail/data-grouping 1.0.40 → 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,25 +84,36 @@ 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) {
|
84
|
-
var _a, _b, _c, _d;
|
96
|
+
static buildChildDataGroups(data, parentGroup, groupingProperties, leafNodeDataCount, currentDepth, groupMultiSelectInSeparateFrame = false, displayItemsWithEmptyGroupingValues = false) {
|
97
|
+
var _a, _b, _c, _d, _e;
|
85
98
|
const groupingProperty = groupingProperties[currentDepth];
|
86
99
|
const propertyTypeOptions = {
|
87
100
|
isDate: ((_a = groupingProperty === null || groupingProperty === void 0 ? void 0 : groupingProperty.propertyDefinition) === null || _a === void 0 ? void 0 : _a.propertyType) === 'date',
|
88
|
-
isNumber: !!((_b = groupingProperty === null || groupingProperty === void 0 ? void 0 : groupingProperty.propertyDefinition) === null || _b === void 0 ? void 0 : _b.numberFormat)
|
101
|
+
isNumber: !!((_b = groupingProperty === null || groupingProperty === void 0 ? void 0 : groupingProperty.propertyDefinition) === null || _b === void 0 ? void 0 : _b.numberFormat) ||
|
102
|
+
((_c = groupingProperty === null || groupingProperty === void 0 ? void 0 : groupingProperty.propertyDefinition) === null || _c === void 0 ? void 0 : _c.propertyType) === 'sequence',
|
89
103
|
};
|
90
104
|
const rootIndex = groupingProperty.typeRootSlug;
|
91
105
|
const slugIndex = groupingProperty.propertyDefinition.slug;
|
92
106
|
const rootAltIndex = util_1.StringUtil.convertToCamelCase(groupingProperty.typeRootSlug);
|
93
107
|
const slugAltIndex = groupingProperty.propertyDefinition.slug;
|
94
108
|
const sort = groupingProperty.sort || types_1.TypePropertySortOrder.ASCENDING;
|
95
|
-
const options = ((
|
96
|
-
let distinctValues = this.getDistinctValues(data, rootIndex, slugIndex, rootAltIndex, slugAltIndex, groupMultiSelectInSeparateFrame, { sortOrder: sort, options }, propertyTypeOptions);
|
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;
|
110
|
+
let distinctValues = this.getDistinctValues(data, rootIndex, slugIndex, rootAltIndex, slugAltIndex, groupMultiSelectInSeparateFrame, { sortOrder: sort, options }, propertyTypeOptions, displayItemsWithEmptyGroupingValues);
|
97
111
|
for (let val of distinctValues) {
|
98
112
|
const groupData = data.filter((obj) => {
|
99
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
|
+
}
|
100
117
|
if (propertyTypeOptions.isDate) {
|
101
118
|
const objDate = new Date(objVal).toISOString().split('T')[0];
|
102
119
|
const valDate = new Date(val).toISOString().split('T')[0];
|
@@ -129,18 +146,20 @@ class DataGroupGenerator {
|
|
129
146
|
group.propertyValues = Object.assign({}, details);
|
130
147
|
}
|
131
148
|
group.propertyValues[groupingProperty.propertyDefinition.slug] = val;
|
132
|
-
const label =
|
149
|
+
const label = val === '(empty)'
|
150
|
+
? '(empty)'
|
151
|
+
: new types_1.PropertyValueFormatter().formatValueForProperty(val, groupingProperty.propertyDefinition);
|
133
152
|
group.name = label;
|
134
153
|
if (currentDepth === groupingProperties.length - 1) {
|
135
154
|
group.subGroups = this.createPartitionedGroupsFromData(group, groupData, leafNodeDataCount);
|
136
155
|
}
|
137
156
|
else if (currentDepth < groupingProperties.length - 1) {
|
138
|
-
this.buildChildDataGroups(groupData, group, groupingProperties, leafNodeDataCount, currentDepth + 1, groupMultiSelectInSeparateFrame);
|
157
|
+
this.buildChildDataGroups(groupData, group, groupingProperties, leafNodeDataCount, currentDepth + 1, groupMultiSelectInSeparateFrame, displayItemsWithEmptyGroupingValues);
|
139
158
|
}
|
140
159
|
parentGroup.subGroups.push(group);
|
141
160
|
}
|
142
161
|
}
|
143
|
-
static buildDataGroupStructure(data, groupingProperties, leafNodeDataCount, groupMultiSelectInSeparateFrame = false) {
|
162
|
+
static buildDataGroupStructure(data, groupingProperties, leafNodeDataCount, groupMultiSelectInSeparateFrame = false, displayItemsWithEmptyGroupingValues = false) {
|
144
163
|
const structure = {
|
145
164
|
rootGroup: {
|
146
165
|
subGroups: [],
|
@@ -151,7 +170,7 @@ class DataGroupGenerator {
|
|
151
170
|
groupingProperties,
|
152
171
|
depth: groupingProperties ? groupingProperties.length : 0,
|
153
172
|
};
|
154
|
-
this.buildChildDataGroups(data, structure.rootGroup, groupingProperties, leafNodeDataCount, 0, groupMultiSelectInSeparateFrame);
|
173
|
+
this.buildChildDataGroups(data, structure.rootGroup, groupingProperties, leafNodeDataCount, 0, groupMultiSelectInSeparateFrame, displayItemsWithEmptyGroupingValues);
|
155
174
|
return structure;
|
156
175
|
}
|
157
176
|
static createPartitionedGroupsFromData(parentGroup, data, leafNodeDataCount) {
|
package/package.json
CHANGED