@contrail/data-grouping 1.0.36 → 1.0.37
Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,8 @@
|
|
1
1
|
import { DataGroup, DataGroupStructure, DataGroupingProperty } from '../interfaces';
|
2
|
+
import { TypePropertySortOrder } from '@contrail/types';
|
2
3
|
export declare class DataGroupGenerator {
|
3
|
-
static getDistinctValues(data: any, rootIndex: any, slugIndex?: any, rootAltIndex?: any, slugAltIndex?: any, groupMultiSelectInSeparateFrame?: boolean,
|
4
|
-
|
4
|
+
static getDistinctValues(data: any, rootIndex: any, slugIndex?: any, rootAltIndex?: any, slugAltIndex?: any, groupMultiSelectInSeparateFrame?: boolean, sortOptions?: {
|
5
|
+
sortOrder: TypePropertySortOrder;
|
5
6
|
options: any;
|
6
7
|
}, isDateProperty?: boolean): any[];
|
7
8
|
static buildChildDataGroups(data: any, parentGroup: DataGroup, groupingProperties: Array<DataGroupingProperty>, leafNodeDataCount: any, currentDepth: any, groupMultiSelectInSeparateFrame?: boolean): void;
|
@@ -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,
|
8
|
-
const
|
9
|
-
const options = (
|
7
|
+
static getDistinctValues(data, rootIndex, slugIndex = null, rootAltIndex = null, slugAltIndex = null, groupMultiSelectInSeparateFrame = false, sortOptions = { sortOrder: types_1.TypePropertySortOrder.ASCENDING, options: null }, isDateProperty = false) {
|
8
|
+
const sortOrder = (sortOptions === null || sortOptions === void 0 ? void 0 : sortOptions.sortOrder) || types_1.TypePropertySortOrder.ASCENDING;
|
9
|
+
const options = (sortOptions === null || sortOptions === void 0 ? void 0 : sortOptions.options) || null;
|
10
10
|
const map = new Map();
|
11
11
|
const sortingArray = [];
|
12
|
-
data.forEach(
|
12
|
+
data.forEach(obj => {
|
13
13
|
if (!obj) {
|
14
14
|
return;
|
15
15
|
}
|
@@ -34,7 +34,7 @@ class DataGroupGenerator {
|
|
34
34
|
key = value.id || value.name || value;
|
35
35
|
}
|
36
36
|
if (Array.isArray(value) && !groupMultiSelectInSeparateFrame) {
|
37
|
-
value.forEach(
|
37
|
+
value.forEach(arrayValue => {
|
38
38
|
map[arrayValue] = arrayValue;
|
39
39
|
if (!sortingArray.includes(arrayValue)) {
|
40
40
|
sortingArray.push(arrayValue);
|
@@ -49,18 +49,22 @@ class DataGroupGenerator {
|
|
49
49
|
}
|
50
50
|
});
|
51
51
|
const distinctValues = [...Object.values(map)];
|
52
|
+
const optionsMap = options
|
53
|
+
? new Map(options.map((val, index) => [val, index]))
|
54
|
+
: null;
|
52
55
|
distinctValues.sort((v1, v2) => {
|
53
|
-
|
54
|
-
const
|
55
|
-
|
56
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
57
|
+
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
|
+
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
|
+
switch (sortOrder) {
|
56
60
|
case 'asc':
|
57
61
|
return val1 > val2 ? 1 : val1 < val2 ? -1 : 0;
|
58
62
|
case 'desc':
|
59
63
|
return val1 < val2 ? 1 : val1 > val2 ? -1 : 0;
|
60
64
|
case 'list_order_asc':
|
61
|
-
return
|
65
|
+
return ((_e = optionsMap.get(val1)) !== null && _e !== void 0 ? _e : 0) - ((_f = optionsMap.get(val2)) !== null && _f !== void 0 ? _f : 0);
|
62
66
|
case 'list_order_desc':
|
63
|
-
return
|
67
|
+
return ((_g = optionsMap.get(val2)) !== null && _g !== void 0 ? _g : 0) - ((_h = optionsMap.get(val1)) !== null && _h !== void 0 ? _h : 0);
|
64
68
|
default:
|
65
69
|
return sortingArray.indexOf(val1) - sortingArray.indexOf(val2);
|
66
70
|
}
|
@@ -75,11 +79,11 @@ class DataGroupGenerator {
|
|
75
79
|
const slugIndex = groupingProperty.propertyDefinition.slug;
|
76
80
|
const rootAltIndex = util_1.StringUtil.convertToCamelCase(groupingProperty.typeRootSlug);
|
77
81
|
const slugAltIndex = groupingProperty.propertyDefinition.slug;
|
78
|
-
const sort = groupingProperty.sort ||
|
79
|
-
const options = ((_c = (_b = groupingProperty.propertyDefinition) === null || _b === void 0 ? void 0 : _b.options) === null || _c === void 0 ? void 0 : _c.map(
|
80
|
-
let distinctValues = this.getDistinctValues(data, rootIndex, slugIndex, rootAltIndex, slugAltIndex, groupMultiSelectInSeparateFrame, {
|
82
|
+
const sort = groupingProperty.sort || types_1.TypePropertySortOrder.ASCENDING;
|
83
|
+
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;
|
84
|
+
let distinctValues = this.getDistinctValues(data, rootIndex, slugIndex, rootAltIndex, slugAltIndex, groupMultiSelectInSeparateFrame, { sortOrder: sort, options }, isDateProperty);
|
81
85
|
for (let val of distinctValues) {
|
82
|
-
const groupData = data.filter(
|
86
|
+
const groupData = data.filter(obj => {
|
83
87
|
const objVal = util_1.ObjectUtil.getBySlugs(obj, rootIndex, slugIndex) || util_1.ObjectUtil.getBySlugs(obj, rootAltIndex, slugAltIndex);
|
84
88
|
if (isDateProperty) {
|
85
89
|
const objDate = new Date(objVal).toISOString().split('T')[0];
|
package/lib/interfaces.d.ts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import { TypeProperty } from '@contrail/types';
|
1
|
+
import { TypeProperty, TypePropertySortOrder } from '@contrail/types';
|
2
2
|
export interface DataGroup {
|
3
3
|
subGroups: Array<DataGroup>;
|
4
4
|
name: string;
|
@@ -26,6 +26,6 @@ export interface DataGroupingProperty {
|
|
26
26
|
propertyDefinition: TypeProperty;
|
27
27
|
values?: Array<string>;
|
28
28
|
typeRootSlug: string;
|
29
|
-
sort:
|
29
|
+
sort: TypePropertySortOrder;
|
30
30
|
isSecondaryGroup?: boolean;
|
31
31
|
}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@contrail/data-grouping",
|
3
|
-
"version": "1.0.
|
3
|
+
"version": "1.0.37",
|
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",
|
@@ -39,6 +39,6 @@
|
|
39
39
|
},
|
40
40
|
"dependencies": {
|
41
41
|
"@contrail/documents": "^1.0.38",
|
42
|
-
"@contrail/types": "^3.0.
|
42
|
+
"@contrail/types": "^3.0.83"
|
43
43
|
}
|
44
44
|
}
|