@contrail/data-grouping 1.0.16 → 1.0.17

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,6 +2,6 @@ import { DataGroup, DataGroupStructure, DataGroupingProperty } from "../interfac
2
2
  export declare class DataGroupGenerator {
3
3
  static getDistinctValues(data: any, index: any): any[];
4
4
  static buildChildDataGroups(data: any, parentGroup: DataGroup, groupingProperties: Array<DataGroupingProperty>, leafNodeDataCount: any, currentDepth: any): void;
5
- static buildDataGroupStructure(data: Array<any>, groupingProperties: Array<DataGroupingProperty>, leafNodeDataCount: number, currentDepth?: number): DataGroupStructure;
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>;
7
7
  }
@@ -31,6 +31,7 @@ class DataGroupGenerator {
31
31
  const groupingProperty = groupingProperties[currentDepth];
32
32
  const index = groupingProperty.scope + "." + groupingProperty.property.slug;
33
33
  const distinctValues = this.getDistinctValues(data, index);
34
+ console.log("distinctValues: ", distinctValues);
34
35
  for (let val of distinctValues) {
35
36
  const groupData = data.filter(obj => util_1.ObjectUtil.getByPath(obj, index) === val);
36
37
  const group = {
@@ -39,7 +40,13 @@ class DataGroupGenerator {
39
40
  propertyValues: {},
40
41
  name: ''
41
42
  };
42
- group.propertyValues[groupingProperty.property.slug] = val;
43
+ if (groupingProperty.scopeIdentityProperty === true && groupData.length) {
44
+ const details = groupData[0][groupingProperty.scope];
45
+ group.propertyValues = Object.assign({}, details);
46
+ }
47
+ else {
48
+ group.propertyValues[groupingProperty.property.slug] = val;
49
+ }
43
50
  const label = new types_1.PropertyValueFormatter().formatValueForProperty(val, groupingProperty.property);
44
51
  group.name = label;
45
52
  if (currentDepth === groupingProperties.length - 1) {
@@ -51,7 +58,7 @@ class DataGroupGenerator {
51
58
  parentGroup.subGroups.push(group);
52
59
  }
53
60
  }
54
- static buildDataGroupStructure(data, groupingProperties, leafNodeDataCount, currentDepth = 0) {
61
+ static buildDataGroupStructure(data, groupingProperties, leafNodeDataCount) {
55
62
  const structure = {
56
63
  rootGroup: {
57
64
  subGroups: [],
@@ -26,4 +26,5 @@ export interface DataGroupingProperty {
26
26
  values?: Array<string>;
27
27
  scope: string;
28
28
  sort: string;
29
+ scopeIdentityProperty?: boolean;
29
30
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrail/data-grouping",
3
- "version": "1.0.16",
3
+ "version": "1.0.17",
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",