@contrail/data-grouping 1.0.22 → 1.0.24
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.
@@ -6,6 +6,7 @@ const types_1 = require("@contrail/types");
|
|
6
6
|
class DataGroupGenerator {
|
7
7
|
static getDistinctValues(data, index, altIndex = null, groupMultiSelectInSeparateFrame = false) {
|
8
8
|
const map = new Map();
|
9
|
+
const sortingArray = [];
|
9
10
|
data.forEach(obj => {
|
10
11
|
if (!obj) {
|
11
12
|
return;
|
@@ -28,16 +29,22 @@ class DataGroupGenerator {
|
|
28
29
|
if (Array.isArray(value) && !groupMultiSelectInSeparateFrame) {
|
29
30
|
value.forEach(arrayValue => {
|
30
31
|
map[arrayValue] = arrayValue;
|
32
|
+
if (!sortingArray.includes(arrayValue)) {
|
33
|
+
sortingArray.push(arrayValue);
|
34
|
+
}
|
31
35
|
});
|
32
36
|
}
|
33
37
|
else {
|
34
38
|
map[key] = value;
|
39
|
+
if (!sortingArray.includes(value)) {
|
40
|
+
sortingArray.push(value);
|
41
|
+
}
|
35
42
|
}
|
36
43
|
});
|
37
44
|
const distinctValues = [...(Object.values(map))].sort((v1, v2) => {
|
38
45
|
let val1 = (v1 && typeof v1 === 'object') ? v1.name : v1;
|
39
46
|
let val2 = (v2 && typeof v2 === 'object') ? v2.name : v2;
|
40
|
-
return val1
|
47
|
+
return sortingArray.indexOf(val1) - sortingArray.indexOf(val2);
|
41
48
|
});
|
42
49
|
return distinctValues;
|
43
50
|
}
|
@@ -68,6 +75,9 @@ class DataGroupGenerator {
|
|
68
75
|
propertyValues: {},
|
69
76
|
name: ''
|
70
77
|
};
|
78
|
+
if (groupingProperty.isSecondaryGroup) {
|
79
|
+
group.isSecondaryGroup = true;
|
80
|
+
}
|
71
81
|
if (groupData.length > 0) {
|
72
82
|
const details = groupData[0];
|
73
83
|
group.propertyValues = Object.assign({}, details);
|
package/lib/interfaces.d.ts
CHANGED
@@ -9,6 +9,7 @@ export interface DataGroup {
|
|
9
9
|
[key: string]: any;
|
10
10
|
};
|
11
11
|
data: Array<any>;
|
12
|
+
isSecondaryGroup?: boolean;
|
12
13
|
}
|
13
14
|
export interface DataGroupStructure {
|
14
15
|
rootGroup: DataGroup;
|
@@ -26,4 +27,5 @@ export interface DataGroupingProperty {
|
|
26
27
|
values?: Array<string>;
|
27
28
|
typeRootSlug: string;
|
28
29
|
sort: string;
|
30
|
+
isSecondaryGroup?: boolean;
|
29
31
|
}
|
package/package.json
CHANGED