@contrail/data-grouping 1.0.45 → 1.0.47

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
  }
@@ -49,7 +49,7 @@ class DataGroupGenerator {
49
49
  key = value.id || value.name || value;
50
50
  }
51
51
  if (Array.isArray(value) && !groupMultiSelectInSeparateFrame) {
52
- value.forEach(arrayValue => {
52
+ value.forEach((arrayValue) => {
53
53
  map[arrayValue] = arrayValue;
54
54
  if (!sortingArray.includes(arrayValue)) {
55
55
  sortingArray.push(arrayValue);
@@ -64,11 +64,12 @@ class DataGroupGenerator {
64
64
  }
65
65
  });
66
66
  const distinctValues = [...Object.values(map)];
67
+ const sortingArrayMap = new Map(sortingArray.map((value, index) => [value, index]));
67
68
  const optionsMap = options
68
69
  ? new Map(options.map((val, index) => [val, index]))
69
70
  : null;
70
71
  distinctValues.sort((v1, v2) => {
71
- var _a, _b, _c, _d, _e, _f, _g, _h;
72
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
72
73
  if (propertyTypeOptions.isNumber) {
73
74
  const num1 = parseFloat(String(v1));
74
75
  const num2 = parseFloat(String(v2));
@@ -90,7 +91,7 @@ class DataGroupGenerator {
90
91
  case types_1.TypePropertySortOrder.LIST_ORDER_DESCENDING:
91
92
  return ((_g = optionsMap.get(rawVal2)) !== null && _g !== void 0 ? _g : 0) - ((_h = optionsMap.get(rawVal1)) !== null && _h !== void 0 ? _h : 0);
92
93
  default:
93
- return sortingArray.indexOf(val1) - sortingArray.indexOf(val2);
94
+ return ((_j = sortingArrayMap.get(val1)) !== null && _j !== void 0 ? _j : -1) - ((_k = sortingArrayMap.get(val2)) !== null && _k !== void 0 ? _k : -1);
94
95
  }
95
96
  });
96
97
  if (hasEmptyValues && displayItemsWithEmptyGroupingValues) {
@@ -103,23 +104,22 @@ class DataGroupGenerator {
103
104
  return distinctValues;
104
105
  }
105
106
  static buildChildDataGroups(data, parentGroup, groupingProperties, leafNodeDataCount, currentDepth, groupMultiSelectInSeparateFrame = false, displayItemsWithEmptyGroupingValues = false) {
106
- var _a, _b, _c, _d, _e, _f, _g;
107
+ var _a, _b, _c, _d, _e;
107
108
  const groupingProperty = groupingProperties[currentDepth];
108
109
  const propertyTypeOptions = {
109
110
  isDate: ((_a = groupingProperty === null || groupingProperty === void 0 ? void 0 : groupingProperty.propertyDefinition) === null || _a === void 0 ? void 0 : _a.propertyType) === 'date',
110
- isNumber: !!((_c = (_b = groupingProperty === null || groupingProperty === void 0 ? void 0 : groupingProperty.propertyDefinition) === null || _b === void 0 ? void 0 : _b.numberFormat) === null || _c === void 0 ? void 0 : _c.format) ||
111
- ((_d = groupingProperty === null || groupingProperty === void 0 ? void 0 : groupingProperty.propertyDefinition) === null || _d === void 0 ? void 0 : _d.propertyType) === 'sequence',
111
+ isNumber: !!((_b = groupingProperty === null || groupingProperty === void 0 ? void 0 : groupingProperty.propertyDefinition) === null || _b === void 0 ? void 0 : _b.numberFormat) ||
112
+ ((_c = groupingProperty === null || groupingProperty === void 0 ? void 0 : groupingProperty.propertyDefinition) === null || _c === void 0 ? void 0 : _c.propertyType) === 'sequence',
112
113
  };
113
114
  const rootIndex = groupingProperty.typeRootSlug;
114
115
  const slugIndex = groupingProperty.propertyDefinition.slug;
115
116
  const rootAltIndex = util_1.StringUtil.convertToCamelCase(groupingProperty.typeRootSlug);
116
117
  const slugAltIndex = groupingProperty.propertyDefinition.slug;
117
118
  const sort = groupingProperty.sort || types_1.TypePropertySortOrder.ASCENDING;
118
- console.log('OPTS PROP', (_e = groupingProperty.propertyDefinition) === null || _e === void 0 ? void 0 : _e.options);
119
- const options = ((_g = (_f = groupingProperty.propertyDefinition) === null || _f === void 0 ? void 0 : _f.options) === null || _g === void 0 ? void 0 : _g.map(x => x.value)) || null;
119
+ 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
120
  let distinctValues = this.getDistinctValues(data, rootIndex, slugIndex, rootAltIndex, slugAltIndex, groupMultiSelectInSeparateFrame, { sortOrder: sort, options }, propertyTypeOptions, displayItemsWithEmptyGroupingValues);
121
121
  for (let val of distinctValues) {
122
- const groupData = data.filter(obj => {
122
+ const groupData = data.filter((obj) => {
123
123
  const objVal = util_1.ObjectUtil.getBySlugs(obj, rootIndex, slugIndex) || util_1.ObjectUtil.getBySlugs(obj, rootAltIndex, slugAltIndex);
124
124
  if (val === '(empty)') {
125
125
  return !objVal;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrail/data-grouping",
3
- "version": "1.0.45",
3
+ "version": "1.0.47",
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",