@contrail/data-grouping 1.0.42 → 1.0.44

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.
@@ -10,7 +10,7 @@ class DataGroupGenerator {
10
10
  const map = new Map();
11
11
  const sortingArray = [];
12
12
  let hasEmptyValues = false;
13
- data.forEach((obj) => {
13
+ data.forEach(obj => {
14
14
  if (!obj) {
15
15
  return;
16
16
  }
@@ -23,15 +23,24 @@ class DataGroupGenerator {
23
23
  }
24
24
  }
25
25
  let value = key;
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))) {
32
- return;
26
+ const isEmptyValue = (value === undefined ||
27
+ value === null ||
28
+ value === '' ||
29
+ (Array.isArray(value) && value.length === 0) ||
30
+ (typeof value === 'string' && value.trim() === '') ||
31
+ (typeof value === 'number' && isNaN(value))) &&
32
+ value !== false;
33
+ if (isEmptyValue) {
34
+ if (displayItemsWithEmptyGroupingValues) {
35
+ hasEmptyValues = true;
36
+ value = '(empty)';
37
+ key = '(empty)';
38
+ }
39
+ else {
40
+ return;
41
+ }
33
42
  }
34
- if (propertyTypeOptions.isDate && value) {
43
+ if (propertyTypeOptions.isDate && value && value !== '(empty)') {
35
44
  const date = new Date(value);
36
45
  value = date.toISOString().split('T')[0];
37
46
  key = value;
@@ -40,7 +49,7 @@ class DataGroupGenerator {
40
49
  key = value.id || value.name || value;
41
50
  }
42
51
  if (Array.isArray(value) && !groupMultiSelectInSeparateFrame) {
43
- value.forEach((arrayValue) => {
52
+ value.forEach(arrayValue => {
44
53
  map[arrayValue] = arrayValue;
45
54
  if (!sortingArray.includes(arrayValue)) {
46
55
  sortingArray.push(arrayValue);
@@ -106,10 +115,10 @@ class DataGroupGenerator {
106
115
  const rootAltIndex = util_1.StringUtil.convertToCamelCase(groupingProperty.typeRootSlug);
107
116
  const slugAltIndex = groupingProperty.propertyDefinition.slug;
108
117
  const sort = groupingProperty.sort || types_1.TypePropertySortOrder.ASCENDING;
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;
118
+ 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
119
  let distinctValues = this.getDistinctValues(data, rootIndex, slugIndex, rootAltIndex, slugAltIndex, groupMultiSelectInSeparateFrame, { sortOrder: sort, options }, propertyTypeOptions, displayItemsWithEmptyGroupingValues);
111
120
  for (let val of distinctValues) {
112
- const groupData = data.filter((obj) => {
121
+ const groupData = data.filter(obj => {
113
122
  const objVal = util_1.ObjectUtil.getBySlugs(obj, rootIndex, slugIndex) || util_1.ObjectUtil.getBySlugs(obj, rootAltIndex, slugAltIndex);
114
123
  if (val === '(empty)') {
115
124
  return !objVal;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrail/data-grouping",
3
- "version": "1.0.42",
3
+ "version": "1.0.44",
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",