@contrail/data-grouping 1.0.39 → 1.0.41

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.
@@ -4,7 +4,10 @@ export declare class DataGroupGenerator {
4
4
  static getDistinctValues(data: any, rootIndex: any, slugIndex?: any, rootAltIndex?: any, slugAltIndex?: any, groupMultiSelectInSeparateFrame?: boolean, sortOptions?: {
5
5
  sortOrder: TypePropertySortOrder;
6
6
  options: any;
7
- }, isDateProperty?: boolean): any[];
7
+ }, propertyTypeOptions?: {
8
+ isDate: boolean;
9
+ isNumber: boolean;
10
+ }): any[];
8
11
  static buildChildDataGroups(data: any, parentGroup: DataGroup, groupingProperties: Array<DataGroupingProperty>, leafNodeDataCount: any, currentDepth: any, groupMultiSelectInSeparateFrame?: boolean): void;
9
12
  static buildDataGroupStructure(data: Array<any>, groupingProperties: Array<DataGroupingProperty>, leafNodeDataCount: number, groupMultiSelectInSeparateFrame?: boolean): DataGroupStructure;
10
13
  static createPartitionedGroupsFromData(parentGroup: DataGroup, data: Array<any>, leafNodeDataCount: number): Array<DataGroup>;
@@ -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 }, isDateProperty = 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 }) {
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();
@@ -25,7 +25,7 @@ class DataGroupGenerator {
25
25
  if (!value) {
26
26
  return;
27
27
  }
28
- if (isDateProperty && value) {
28
+ if (propertyTypeOptions.isDate && value) {
29
29
  const date = new Date(value);
30
30
  value = date.toISOString().split('T')[0];
31
31
  key = value;
@@ -54,6 +54,13 @@ class DataGroupGenerator {
54
54
  : null;
55
55
  distinctValues.sort((v1, v2) => {
56
56
  var _a, _b, _c, _d, _e, _f, _g, _h;
57
+ if (propertyTypeOptions.isNumber) {
58
+ const num1 = parseFloat(String(v1));
59
+ const num2 = parseFloat(String(v2));
60
+ const val1 = isNaN(num1) ? 0 : num1;
61
+ const val2 = isNaN(num2) ? 0 : num2;
62
+ return sortOrder === types_1.TypePropertySortOrder.DESCENDING ? val2 - val1 : val1 - val2;
63
+ }
57
64
  const val1 = v1 && typeof v1 === 'object' ? (_a = v1 === null || v1 === void 0 ? void 0 : v1.name) === null || _a === void 0 ? void 0 : _a.toLowerCase() : (_b = String(v1)) === null || _b === void 0 ? void 0 : _b.toLowerCase();
58
65
  const val2 = v2 && typeof v2 === 'object' ? (_c = v2 === null || v2 === void 0 ? void 0 : v2.name) === null || _c === void 0 ? void 0 : _c.toLowerCase() : (_d = String(v2)) === null || _d === void 0 ? void 0 : _d.toLowerCase();
59
66
  const rawVal1 = v1 && typeof v1 === 'object' ? v1.name : String(v1);
@@ -74,20 +81,24 @@ class DataGroupGenerator {
74
81
  return distinctValues;
75
82
  }
76
83
  static buildChildDataGroups(data, parentGroup, groupingProperties, leafNodeDataCount, currentDepth, groupMultiSelectInSeparateFrame = false) {
77
- var _a, _b, _c;
84
+ var _a, _b, _c, _d, _e;
78
85
  const groupingProperty = groupingProperties[currentDepth];
79
- const isDateProperty = ((_a = groupingProperty === null || groupingProperty === void 0 ? void 0 : groupingProperty.propertyDefinition) === null || _a === void 0 ? void 0 : _a.propertyType) === 'date';
86
+ const propertyTypeOptions = {
87
+ 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) ||
89
+ ((_c = groupingProperty === null || groupingProperty === void 0 ? void 0 : groupingProperty.propertyDefinition) === null || _c === void 0 ? void 0 : _c.propertyType) === 'sequence',
90
+ };
80
91
  const rootIndex = groupingProperty.typeRootSlug;
81
92
  const slugIndex = groupingProperty.propertyDefinition.slug;
82
93
  const rootAltIndex = util_1.StringUtil.convertToCamelCase(groupingProperty.typeRootSlug);
83
94
  const slugAltIndex = groupingProperty.propertyDefinition.slug;
84
95
  const sort = groupingProperty.sort || types_1.TypePropertySortOrder.ASCENDING;
85
- const options = ((_c = (_b = groupingProperty.propertyDefinition) === null || _b === void 0 ? void 0 : _b.options) === null || _c === void 0 ? void 0 : _c.map((x) => x.value)) || null;
86
- let distinctValues = this.getDistinctValues(data, rootIndex, slugIndex, rootAltIndex, slugAltIndex, groupMultiSelectInSeparateFrame, { sortOrder: sort, options }, isDateProperty);
96
+ 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);
87
98
  for (let val of distinctValues) {
88
99
  const groupData = data.filter((obj) => {
89
100
  const objVal = util_1.ObjectUtil.getBySlugs(obj, rootIndex, slugIndex) || util_1.ObjectUtil.getBySlugs(obj, rootAltIndex, slugAltIndex);
90
- if (isDateProperty) {
101
+ if (propertyTypeOptions.isDate) {
91
102
  const objDate = new Date(objVal).toISOString().split('T')[0];
92
103
  const valDate = new Date(val).toISOString().split('T')[0];
93
104
  return objDate === valDate;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrail/data-grouping",
3
- "version": "1.0.39",
3
+ "version": "1.0.41",
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",