@contrail/data-grouping 1.0.19 → 1.0.21

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,6 @@
1
1
  import { DataGroup, DataGroupStructure, DataGroupingProperty } from "../interfaces";
2
2
  export declare class DataGroupGenerator {
3
- static getDistinctValues(data: any, index: any): any[];
3
+ static getDistinctValues(data: any, index: any, altIndex?: any): any[];
4
4
  static buildChildDataGroups(data: any, parentGroup: DataGroup, groupingProperties: Array<DataGroupingProperty>, leafNodeDataCount: any, currentDepth: any): void;
5
5
  static buildDataGroupStructure(data: Array<any>, groupingProperties: Array<DataGroupingProperty>, leafNodeDataCount: number): DataGroupStructure;
6
6
  static createPartitionedGroupsFromData(parentGroup: DataGroup, data: Array<any>, leafNodeDataCount: number): Array<DataGroup>;
@@ -4,13 +4,20 @@ 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, index) {
7
+ static getDistinctValues(data, index, altIndex = null) {
8
8
  const map = new Map();
9
9
  data.forEach(obj => {
10
10
  if (!obj) {
11
11
  return;
12
12
  }
13
13
  let key = util_1.ObjectUtil.getByPath(obj, index);
14
+ let altKey = null;
15
+ if (altIndex) {
16
+ altKey = util_1.ObjectUtil.getByPath(obj, altIndex);
17
+ if (!key) {
18
+ key = altKey;
19
+ }
20
+ }
14
21
  let value = key;
15
22
  if (!value) {
16
23
  return;
@@ -30,9 +37,21 @@ class DataGroupGenerator {
30
37
  static buildChildDataGroups(data, parentGroup, groupingProperties, leafNodeDataCount, currentDepth) {
31
38
  const groupingProperty = groupingProperties[currentDepth];
32
39
  const index = groupingProperty.typeRootSlug + "." + groupingProperty.propertyDefinition.slug;
33
- const distinctValues = this.getDistinctValues(data, index);
40
+ const altIndex = util_1.StringUtil.convertToCamelCase(groupingProperty.typeRootSlug) + "." + groupingProperty.propertyDefinition.slug;
41
+ let distinctValues = this.getDistinctValues(data, index, altIndex);
34
42
  for (let val of distinctValues) {
35
- const groupData = data.filter(obj => util_1.ObjectUtil.getByPath(obj, index) === val);
43
+ const groupData = data.filter(obj => {
44
+ const objVal = util_1.ObjectUtil.getByPath(obj, index) || util_1.ObjectUtil.getByPath(obj, altIndex);
45
+ if (Array.isArray(val) && Array.isArray(objVal)) {
46
+ return val.sort().join() === objVal.sort().join();
47
+ }
48
+ else if (val.id && (objVal === null || objVal === void 0 ? void 0 : objVal.id)) {
49
+ return val.id === objVal.id;
50
+ }
51
+ else {
52
+ return (objVal === val);
53
+ }
54
+ });
36
55
  const group = {
37
56
  data: [],
38
57
  subGroups: [],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrail/data-grouping",
3
- "version": "1.0.19",
3
+ "version": "1.0.21",
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",
@@ -14,11 +14,11 @@
14
14
  "author": "",
15
15
  "license": "ISC",
16
16
  "devDependencies": {
17
- "@contrail/util": "^1.0.26",
18
- "@types/jest": "^23.3.14",
19
- "jest": "^23.6.0",
17
+ "@contrail/util": "^1.0.34",
18
+ "@types/jest": "^29.5.2",
19
+ "jest": "^29.5.0",
20
20
  "prettier": "^1.19.1",
21
- "ts-jest": "^23.10.5",
21
+ "ts-jest": "^29.1.1",
22
22
  "tslint": "^5.11.0",
23
23
  "tslint-config-prettier": "^1.18.0",
24
24
  "typescript": "^4.0.0"