@contrail/data-grouping 1.0.34 → 1.0.36

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.
@@ -3,7 +3,7 @@ export declare class DataGroupGenerator {
3
3
  static getDistinctValues(data: any, rootIndex: any, slugIndex?: any, rootAltIndex?: any, slugAltIndex?: any, groupMultiSelectInSeparateFrame?: boolean, sort?: {
4
4
  sortKey: string;
5
5
  options: any;
6
- }): any[];
6
+ }, isDateProperty?: boolean): any[];
7
7
  static buildChildDataGroups(data: any, parentGroup: DataGroup, groupingProperties: Array<DataGroupingProperty>, leafNodeDataCount: any, currentDepth: any, groupMultiSelectInSeparateFrame?: boolean): void;
8
8
  static buildDataGroupStructure(data: Array<any>, groupingProperties: Array<DataGroupingProperty>, leafNodeDataCount: number, groupMultiSelectInSeparateFrame?: boolean): DataGroupStructure;
9
9
  static createPartitionedGroupsFromData(parentGroup: DataGroup, data: Array<any>, leafNodeDataCount: number): Array<DataGroup>;
@@ -4,12 +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, sort = { sortKey: 'asc', options: null }) {
7
+ static getDistinctValues(data, rootIndex, slugIndex = null, rootAltIndex = null, slugAltIndex = null, groupMultiSelectInSeparateFrame = false, sort = { sortKey: 'asc', options: null }, isDateProperty = false) {
8
8
  const sortKey = (sort === null || sort === void 0 ? void 0 : sort.sortKey) || 'asc';
9
9
  const options = (sort === null || sort === void 0 ? void 0 : sort.options) || null;
10
10
  const map = new Map();
11
11
  const sortingArray = [];
12
- data.forEach(obj => {
12
+ data.forEach((obj) => {
13
13
  if (!obj) {
14
14
  return;
15
15
  }
@@ -25,11 +25,16 @@ class DataGroupGenerator {
25
25
  if (!value) {
26
26
  return;
27
27
  }
28
+ if (isDateProperty && value) {
29
+ const date = new Date(value);
30
+ value = date.toISOString().split('T')[0];
31
+ key = value;
32
+ }
28
33
  if (key && value && typeof key === 'object') {
29
34
  key = value.id || value.name || value;
30
35
  }
31
36
  if (Array.isArray(value) && !groupMultiSelectInSeparateFrame) {
32
- value.forEach(arrayValue => {
37
+ value.forEach((arrayValue) => {
33
38
  map[arrayValue] = arrayValue;
34
39
  if (!sortingArray.includes(arrayValue)) {
35
40
  sortingArray.push(arrayValue);
@@ -63,18 +68,24 @@ class DataGroupGenerator {
63
68
  return distinctValues;
64
69
  }
65
70
  static buildChildDataGroups(data, parentGroup, groupingProperties, leafNodeDataCount, currentDepth, groupMultiSelectInSeparateFrame = false) {
66
- var _a, _b;
71
+ var _a, _b, _c;
67
72
  const groupingProperty = groupingProperties[currentDepth];
73
+ const isDateProperty = ((_a = groupingProperty === null || groupingProperty === void 0 ? void 0 : groupingProperty.propertyDefinition) === null || _a === void 0 ? void 0 : _a.propertyType) === 'date';
68
74
  const rootIndex = groupingProperty.typeRootSlug;
69
75
  const slugIndex = groupingProperty.propertyDefinition.slug;
70
76
  const rootAltIndex = util_1.StringUtil.convertToCamelCase(groupingProperty.typeRootSlug);
71
77
  const slugAltIndex = groupingProperty.propertyDefinition.slug;
72
78
  const sort = groupingProperty.sort || 'asc';
73
- const options = ((_b = (_a = groupingProperty.propertyDefinition) === null || _a === void 0 ? void 0 : _a.options) === null || _b === void 0 ? void 0 : _b.map(x => x.value)) || null;
74
- let distinctValues = this.getDistinctValues(data, rootIndex, slugIndex, rootAltIndex, slugAltIndex, groupMultiSelectInSeparateFrame, { sortKey: sort, options });
79
+ 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;
80
+ let distinctValues = this.getDistinctValues(data, rootIndex, slugIndex, rootAltIndex, slugAltIndex, groupMultiSelectInSeparateFrame, { sortKey: sort, options }, isDateProperty);
75
81
  for (let val of distinctValues) {
76
- const groupData = data.filter(obj => {
82
+ const groupData = data.filter((obj) => {
77
83
  const objVal = util_1.ObjectUtil.getBySlugs(obj, rootIndex, slugIndex) || util_1.ObjectUtil.getBySlugs(obj, rootAltIndex, slugAltIndex);
84
+ if (isDateProperty) {
85
+ const objDate = new Date(objVal).toISOString().split('T')[0];
86
+ const valDate = new Date(val).toISOString().split('T')[0];
87
+ return objDate === valDate;
88
+ }
78
89
  if (Array.isArray(val) && Array.isArray(objVal)) {
79
90
  return val.sort().join() === objVal.sort().join();
80
91
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrail/data-grouping",
3
- "version": "1.0.34",
3
+ "version": "1.0.36",
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",