@sis-cc/dotstatsuite-components 14.2.2 → 14.2.3
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.
|
@@ -13,12 +13,15 @@ function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj;
|
|
|
13
13
|
|
|
14
14
|
var hierarchiseDimensionWithNativeHierarchy = exports.hierarchiseDimensionWithNativeHierarchy = function hierarchiseDimensionWithNativeHierarchy(dimension) {
|
|
15
15
|
var values = R.sortBy(R.prop('__indexPosition'), dimension.values || []);
|
|
16
|
-
var
|
|
16
|
+
var indexed = R.indexBy(R.prop('id'), values);
|
|
17
|
+
var grouped = R.groupBy(function (val) {
|
|
18
|
+
return val.parent && R.has(val.parent, indexed) ? val.parent : '#ROOT';
|
|
19
|
+
}, values);
|
|
17
20
|
|
|
18
21
|
var getChildren = function getChildren(parents) {
|
|
19
22
|
var childs = R.propOr([], R.last(parents) || '#ROOT', grouped);
|
|
20
23
|
return R.reduce(function (acc, child) {
|
|
21
|
-
var refined = R.assoc('parents', parents, child);
|
|
24
|
+
var refined = R.pipe(R.assoc('parents', parents), R.assoc('parent', R.last(parents)))(child);
|
|
22
25
|
var children = getChildren(R.append(child.id, parents));
|
|
23
26
|
return R.concat(acc, R.prepend(refined, children));
|
|
24
27
|
}, [], childs);
|
package/package.json
CHANGED
|
@@ -2,13 +2,17 @@ import * as R from 'ramda';
|
|
|
2
2
|
|
|
3
3
|
export const hierarchiseDimensionWithNativeHierarchy = (dimension) => {
|
|
4
4
|
const values = R.sortBy(R.prop('__indexPosition'), dimension.values || []);
|
|
5
|
-
const
|
|
5
|
+
const indexed = R.indexBy(R.prop('id'), values);
|
|
6
|
+
const grouped = R.groupBy(val => val.parent && R.has(val.parent, indexed) ? val.parent : '#ROOT', values);
|
|
6
7
|
|
|
7
8
|
const getChildren = (parents) => {
|
|
8
9
|
const childs = R.propOr([], R.last(parents) || '#ROOT', grouped);
|
|
9
10
|
return R.reduce(
|
|
10
11
|
(acc, child) => {
|
|
11
|
-
const refined = R.
|
|
12
|
+
const refined = R.pipe(
|
|
13
|
+
R.assoc('parents', parents),
|
|
14
|
+
R.assoc('parent', R.last(parents)),
|
|
15
|
+
)(child);
|
|
12
16
|
const children = getChildren(R.append(child.id, parents));
|
|
13
17
|
return R.concat(acc, R.prepend(refined, children));
|
|
14
18
|
},
|
|
@@ -27,6 +27,31 @@ describe('hierarchiseDimensionWithNativeHierarchy tests', () => {
|
|
|
27
27
|
]
|
|
28
28
|
};
|
|
29
29
|
|
|
30
|
+
expect(hierarchiseDimensionWithNativeHierarchy(dimension)).to.deep.equal(expected);
|
|
31
|
+
});
|
|
32
|
+
it ('missing parent test', () => {
|
|
33
|
+
const dimension = {
|
|
34
|
+
id: 'test',
|
|
35
|
+
values: [
|
|
36
|
+
{ id: 'FRA', parent: 'EA', __indexPosition: 101 },
|
|
37
|
+
{ id: 'GER', parent: 'EA', __indexPosition: 100 },
|
|
38
|
+
{ id: 'EA', parent: 'W', __indexPosition: 30 },
|
|
39
|
+
{ id: 'A', parent: 'W', __indexPosition: 20 },
|
|
40
|
+
{ id: 'CHI', parent: undefined, __indexPosition: 0 }
|
|
41
|
+
]
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const expected = {
|
|
45
|
+
id: 'test',
|
|
46
|
+
values: [
|
|
47
|
+
{ id: 'CHI', parent: undefined, parents: [], __indexPosition: 0 },
|
|
48
|
+
{ id: 'A', parent: undefined, parents: [], __indexPosition: 20 },
|
|
49
|
+
{ id: 'EA', parent: undefined, parents: [], __indexPosition: 30 },
|
|
50
|
+
{ id: 'GER', parent: 'EA', parents: ['EA'], __indexPosition: 100 },
|
|
51
|
+
{ id: 'FRA', parent: 'EA', parents: ['EA'], __indexPosition: 101 }
|
|
52
|
+
]
|
|
53
|
+
};
|
|
54
|
+
|
|
30
55
|
expect(hierarchiseDimensionWithNativeHierarchy(dimension)).to.deep.equal(expected);
|
|
31
56
|
});
|
|
32
57
|
});
|