@sis-cc/dotstatsuite-components 19.0.0 → 19.1.0
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.
|
@@ -5,10 +5,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.applyHierarchicalCodesToDim = undefined;
|
|
7
7
|
|
|
8
|
-
var _objectWithoutProperties2 = require('babel-runtime/helpers/objectWithoutProperties');
|
|
9
|
-
|
|
10
|
-
var _objectWithoutProperties3 = _interopRequireDefault(_objectWithoutProperties2);
|
|
11
|
-
|
|
12
8
|
var _extends2 = require('babel-runtime/helpers/extends');
|
|
13
9
|
|
|
14
10
|
var _extends3 = _interopRequireDefault(_extends2);
|
|
@@ -30,8 +26,57 @@ var addParentId = function addParentId(id, ids) {
|
|
|
30
26
|
return R.append(R.isNil(last) ? id : last + '.' + id, ids);
|
|
31
27
|
};
|
|
32
28
|
|
|
33
|
-
var
|
|
29
|
+
var refineUnconfirmedPaths = function refineUnconfirmedPaths(paths) {
|
|
30
|
+
var confirmedPaths = R.filter(function (p) {
|
|
31
|
+
return p.length === 1;
|
|
32
|
+
}, paths);
|
|
33
|
+
if (!R.isEmpty(confirmedPaths)) {
|
|
34
|
+
confirmedPaths = R.reduce(function (acc, k) {
|
|
35
|
+
if (R.has(k, acc)) {
|
|
36
|
+
return acc;
|
|
37
|
+
}
|
|
38
|
+
var ps = R.prop(k, paths);
|
|
39
|
+
var flatConfirmed = R.unnest(R.values(acc));
|
|
40
|
+
var filtered = R.filter(function (p) {
|
|
41
|
+
return !!R.find(function (cP) {
|
|
42
|
+
return R.includes(p, cP) || R.includes(cP, p);
|
|
43
|
+
}, flatConfirmed);
|
|
44
|
+
}, ps);
|
|
45
|
+
if (!R.isEmpty(filtered)) {
|
|
46
|
+
return R.assoc(k, [R.head(filtered)], acc);
|
|
47
|
+
}
|
|
48
|
+
return acc;
|
|
49
|
+
}, confirmedPaths, R.keys(paths));
|
|
50
|
+
}
|
|
51
|
+
var remainingIds = R.reject(function (id) {
|
|
52
|
+
return R.has(id, confirmedPaths);
|
|
53
|
+
}, R.keys(paths));
|
|
54
|
+
var getCommonPaths = function getCommonPaths(ids) {
|
|
55
|
+
var _R$reduce = R.reduce(function (acc, id) {
|
|
56
|
+
var ps = R.prop(id, paths);
|
|
57
|
+
if (R.isEmpty(acc.commonPaths)) {
|
|
58
|
+
return R.assoc('commonPaths', ps, acc);
|
|
59
|
+
}
|
|
60
|
+
var common = R.intersection(acc.commonPaths, ps);
|
|
61
|
+
return R.isEmpty(common) ? R.assoc('rejectedChildrenIds', id, acc) : R.assoc('commonPaths', common, acc);
|
|
62
|
+
}, { commonPaths: [], rejectedIds: [] })(ids),
|
|
63
|
+
commonPaths = _R$reduce.commonPaths,
|
|
64
|
+
rejectedIds = _R$reduce.rejectedIds;
|
|
65
|
+
|
|
66
|
+
if (!R.isEmpty(rejectedIds)) {
|
|
67
|
+
return R.append(R.head(commonPaths), getCommonPaths(rejectedIds));
|
|
68
|
+
}
|
|
69
|
+
return [R.head(commonPaths)];
|
|
70
|
+
};
|
|
71
|
+
var commons = getCommonPaths(remainingIds);
|
|
72
|
+
return R.reduce(function (acc, id) {
|
|
73
|
+
return R.assoc(id, R.intersection(commons, R.prop(id, paths)), acc);
|
|
74
|
+
}, confirmedPaths, remainingIds);
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
var applyHierarchicalCodesToDim = exports.applyHierarchicalCodesToDim = function applyHierarchicalCodesToDim(hCodes, dim) {
|
|
34
78
|
var confirmedHierarchisedChilds = new _set2.default([]);
|
|
79
|
+
var unconfirmedPaths = {};
|
|
35
80
|
|
|
36
81
|
var indexedValues = R.reduce(function (acc, val) {
|
|
37
82
|
if (!val.isSelected) {
|
|
@@ -52,13 +97,18 @@ var applyHierarchicalCodesToDim = function applyHierarchicalCodesToDim(hCodes, d
|
|
|
52
97
|
if (!hasInDim) {
|
|
53
98
|
return R.concat(acc, children);
|
|
54
99
|
}
|
|
100
|
+
var path = R.join('.', parentsDef);
|
|
55
101
|
var val = (0, _extends3.default)({}, R.prop(codeID, indexedValues), {
|
|
102
|
+
path: path,
|
|
56
103
|
parents: parentsInDim,
|
|
57
104
|
parent: R.last(parentsInDim),
|
|
58
105
|
children: children
|
|
59
106
|
});
|
|
60
107
|
|
|
61
108
|
if (isUnconfirmed) {
|
|
109
|
+
unconfirmedPaths = R.over(R.lensProp(val.id), function (paths) {
|
|
110
|
+
return R.append(path, paths || []);
|
|
111
|
+
}, unconfirmedPaths);
|
|
62
112
|
val = R.assoc('unconfirmed', true, val);
|
|
63
113
|
return R.append(val, acc);
|
|
64
114
|
}
|
|
@@ -69,34 +119,33 @@ var applyHierarchicalCodesToDim = function applyHierarchicalCodesToDim(hCodes, d
|
|
|
69
119
|
|
|
70
120
|
var parsed = parseHCodes([], [])(hCodes);
|
|
71
121
|
|
|
122
|
+
var _unconfirmedPaths = R.pipe(R.reject(function (id) {
|
|
123
|
+
return confirmedHierarchisedChilds.has(id);
|
|
124
|
+
}), function (ids) {
|
|
125
|
+
return R.pick(ids, unconfirmedPaths);
|
|
126
|
+
})(R.keys(unconfirmedPaths));
|
|
127
|
+
|
|
128
|
+
var refinedUnconfirmedPaths = refineUnconfirmedPaths(_unconfirmedPaths);
|
|
129
|
+
|
|
72
130
|
var flattenDescendants = R.reduce(function (acc, val) {
|
|
73
131
|
var children = flattenDescendants(val.children || []);
|
|
74
132
|
return R.concat(acc, R.prepend(val, children));
|
|
75
133
|
}, []);
|
|
76
134
|
|
|
77
135
|
var isValid = function isValid(val) {
|
|
78
|
-
return !val.unconfirmed ||
|
|
136
|
+
return !val.unconfirmed || R.includes(val.path, R.propOr([], val.id, refinedUnconfirmedPaths));
|
|
79
137
|
};
|
|
80
138
|
|
|
81
139
|
var refineCodes = R.reduce(function (acc, hC) {
|
|
82
|
-
var
|
|
83
|
-
|
|
84
|
-
unconfirmed = _hC$unconfirmed === undefined ? false : _hC$unconfirmed,
|
|
85
|
-
val = (0, _objectWithoutProperties3.default)(hC, ['children', 'unconfirmed']);
|
|
86
|
-
|
|
87
|
-
if (isValid(hC)) {
|
|
88
|
-
var _children = refineCodes(children || []);
|
|
89
|
-
confirmedHierarchisedChilds.add(val.id);
|
|
90
|
-
return R.concat(acc, R.prepend(val, _children));
|
|
91
|
-
}
|
|
92
|
-
var flatDescendants = flattenDescendants(children);
|
|
140
|
+
var _flatDescendants = flattenDescendants(hC.children);
|
|
141
|
+
var flatDescendants = R.prepend(hC, _flatDescendants);
|
|
93
142
|
var validDescendant = R.find(isValid, flatDescendants);
|
|
94
143
|
if (!validDescendant) {
|
|
95
144
|
return acc;
|
|
96
145
|
}
|
|
97
|
-
var refined = R.pipe(R.
|
|
146
|
+
var refined = R.pipe(R.map(function (v) {
|
|
98
147
|
confirmedHierarchisedChilds.add(v.id);
|
|
99
|
-
return R.omit(['unconfirmed', 'children'], v);
|
|
148
|
+
return R.omit(['unconfirmed', 'children', 'path'], v);
|
|
100
149
|
}))(flatDescendants);
|
|
101
150
|
return R.concat(acc, refined);
|
|
102
151
|
}, []);
|
|
@@ -112,7 +161,6 @@ var applyHierarchicalCodesToDim = function applyHierarchicalCodesToDim(hCodes, d
|
|
|
112
161
|
}), R.sortBy(R.propOr(-1, '__indexPosition')))(indexedValues);
|
|
113
162
|
|
|
114
163
|
var hierarchicalIndexes = {};
|
|
115
|
-
|
|
116
164
|
return R.pipe(R.concat, R.addIndex(R.map)(function (v, ind) {
|
|
117
165
|
var parents = R.props(v.parents, hierarchicalIndexes);
|
|
118
166
|
var hierId = R.last(v.parents) ? R.last(v.parents) + '.' + v.id : v.id;
|
|
@@ -124,5 +172,4 @@ var applyHierarchicalCodesToDim = function applyHierarchicalCodesToDim(hCodes, d
|
|
|
124
172
|
}), function (values) {
|
|
125
173
|
return (0, _extends3.default)({}, dim, { values: values });
|
|
126
174
|
})(missingValues, refined);
|
|
127
|
-
};
|
|
128
|
-
exports.applyHierarchicalCodesToDim = applyHierarchicalCodesToDim;
|
|
175
|
+
};
|
package/package.json
CHANGED
|
@@ -5,8 +5,53 @@ const addParentId = (id, ids) => {
|
|
|
5
5
|
return R.append(R.isNil(last) ? id : `${last}.${id}`, ids);
|
|
6
6
|
}
|
|
7
7
|
|
|
8
|
+
const refineUnconfirmedPaths = (paths) => {
|
|
9
|
+
let confirmedPaths = R.filter(p => p.length === 1, paths);
|
|
10
|
+
if (!R.isEmpty(confirmedPaths)) {
|
|
11
|
+
confirmedPaths = R.reduce((acc, k) => {
|
|
12
|
+
if (R.has(k, acc)) {
|
|
13
|
+
return acc;
|
|
14
|
+
}
|
|
15
|
+
const ps = R.prop(k, paths);
|
|
16
|
+
const flatConfirmed = R.unnest(R.values(acc));
|
|
17
|
+
const filtered = R.filter(p => !!R.find(cP => R.includes(p, cP) || R.includes(cP, p), flatConfirmed), ps);
|
|
18
|
+
if (!R.isEmpty(filtered)) {
|
|
19
|
+
return R.assoc(k, [R.head(filtered)], acc);
|
|
20
|
+
}
|
|
21
|
+
return acc;
|
|
22
|
+
}, confirmedPaths, R.keys(paths));
|
|
23
|
+
}
|
|
24
|
+
const remainingIds = R.reject(id => R.has(id, confirmedPaths), R.keys(paths));
|
|
25
|
+
const getCommonPaths = ids => {
|
|
26
|
+
const { commonPaths, rejectedIds } = R.reduce(
|
|
27
|
+
(acc, id) => {
|
|
28
|
+
const ps = R.prop(id, paths);
|
|
29
|
+
if (R.isEmpty(acc.commonPaths)) {
|
|
30
|
+
return R.assoc('commonPaths', ps, acc);
|
|
31
|
+
}
|
|
32
|
+
const common = R.intersection(acc.commonPaths, ps);
|
|
33
|
+
return R.isEmpty(common)
|
|
34
|
+
? R.assoc('rejectedChildrenIds', id, acc)
|
|
35
|
+
: R.assoc('commonPaths', common, acc);
|
|
36
|
+
},
|
|
37
|
+
{ commonPaths: [], rejectedIds: [] }
|
|
38
|
+
)(ids);
|
|
39
|
+
if (!R.isEmpty(rejectedIds)) {
|
|
40
|
+
return R.append(R.head(commonPaths), getCommonPaths(rejectedIds));
|
|
41
|
+
}
|
|
42
|
+
return [R.head(commonPaths)];
|
|
43
|
+
};
|
|
44
|
+
const commons = getCommonPaths(remainingIds);
|
|
45
|
+
return R.reduce(
|
|
46
|
+
(acc, id) => R.assoc(id, R.intersection(commons, R.prop(id, paths)), acc),
|
|
47
|
+
confirmedPaths,
|
|
48
|
+
remainingIds
|
|
49
|
+
);
|
|
50
|
+
};
|
|
51
|
+
|
|
8
52
|
export const applyHierarchicalCodesToDim = (hCodes, dim) => {
|
|
9
|
-
|
|
53
|
+
const confirmedHierarchisedChilds = new Set([]);
|
|
54
|
+
let unconfirmedPaths = {};
|
|
10
55
|
|
|
11
56
|
const indexedValues = R.reduce((acc, val) => {
|
|
12
57
|
if (!val.isSelected) {
|
|
@@ -26,14 +71,17 @@ export const applyHierarchicalCodesToDim = (hCodes, dim) => {
|
|
|
26
71
|
if (!hasInDim) {
|
|
27
72
|
return R.concat(acc, children);
|
|
28
73
|
}
|
|
74
|
+
const path = R.join('.', parentsDef);
|
|
29
75
|
let val = {
|
|
30
76
|
...R.prop(codeID, indexedValues),
|
|
77
|
+
path,
|
|
31
78
|
parents: parentsInDim,
|
|
32
79
|
parent: R.last(parentsInDim),
|
|
33
80
|
children
|
|
34
81
|
};
|
|
35
82
|
|
|
36
83
|
if (isUnconfirmed) {
|
|
84
|
+
unconfirmedPaths = R.over(R.lensProp(val.id), paths => R.append(path, paths || []), unconfirmedPaths);
|
|
37
85
|
val = R.assoc('unconfirmed', true, val);
|
|
38
86
|
return R.append(val, acc);
|
|
39
87
|
}
|
|
@@ -43,30 +91,31 @@ export const applyHierarchicalCodesToDim = (hCodes, dim) => {
|
|
|
43
91
|
|
|
44
92
|
const parsed = parseHCodes([], [])(hCodes);
|
|
45
93
|
|
|
94
|
+
const _unconfirmedPaths = R.pipe(
|
|
95
|
+
R.reject(id => confirmedHierarchisedChilds.has(id)),
|
|
96
|
+
ids => R.pick(ids, unconfirmedPaths)
|
|
97
|
+
)(R.keys(unconfirmedPaths));
|
|
98
|
+
|
|
99
|
+
const refinedUnconfirmedPaths = refineUnconfirmedPaths(_unconfirmedPaths);
|
|
100
|
+
|
|
46
101
|
const flattenDescendants = R.reduce((acc, val ) => {
|
|
47
102
|
const children = flattenDescendants(val.children || []);
|
|
48
103
|
return R.concat(acc, R.prepend(val, children));
|
|
49
104
|
}, []);
|
|
50
105
|
|
|
51
|
-
const isValid = val => !val.unconfirmed ||
|
|
106
|
+
const isValid = val => !val.unconfirmed || R.includes(val.path, R.propOr([], val.id, refinedUnconfirmedPaths));
|
|
52
107
|
|
|
53
108
|
const refineCodes = R.reduce((acc, hC) => {
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
-
const _children = refineCodes(children || []);
|
|
57
|
-
confirmedHierarchisedChilds.add(val.id);
|
|
58
|
-
return R.concat(acc, R.prepend(val, _children));
|
|
59
|
-
}
|
|
60
|
-
const flatDescendants = flattenDescendants(children);
|
|
109
|
+
const _flatDescendants = flattenDescendants(hC.children);
|
|
110
|
+
const flatDescendants = R.prepend(hC, _flatDescendants);
|
|
61
111
|
const validDescendant = R.find(isValid, flatDescendants);
|
|
62
112
|
if (!validDescendant) {
|
|
63
113
|
return acc;
|
|
64
114
|
}
|
|
65
115
|
const refined = R.pipe(
|
|
66
|
-
R.prepend(hC),
|
|
67
116
|
R.map(v => {
|
|
68
117
|
confirmedHierarchisedChilds.add(v.id);
|
|
69
|
-
return R.omit(['unconfirmed', 'children'], v);
|
|
118
|
+
return R.omit(['unconfirmed', 'children', 'path'], v);
|
|
70
119
|
})
|
|
71
120
|
)(flatDescendants);
|
|
72
121
|
return R.concat(acc, refined);
|
|
@@ -83,7 +132,6 @@ export const applyHierarchicalCodesToDim = (hCodes, dim) => {
|
|
|
83
132
|
)(indexedValues);
|
|
84
133
|
|
|
85
134
|
let hierarchicalIndexes = {};
|
|
86
|
-
|
|
87
135
|
return R.pipe(
|
|
88
136
|
R.concat,
|
|
89
137
|
R.addIndex(R.map)((v, ind) => {
|
|
@@ -144,4 +144,17 @@ describe('refineHierarchicalCodelist tests', () => {
|
|
|
144
144
|
};
|
|
145
145
|
expect(applyHierarchicalCodesToDim(hCodes, partialDim)).to.deep.equal(expected);
|
|
146
146
|
});
|
|
147
|
+
it('partial test 6', () => {
|
|
148
|
+
const partialDim = deselectedDim([0, 1, 3, 4, 6]);
|
|
149
|
+
|
|
150
|
+
const expected = {
|
|
151
|
+
id: 'DIM',
|
|
152
|
+
values: [
|
|
153
|
+
{ id: 'ITEM', parents: [], parent: undefined, isSelected: true, __indexPosition: 0 },
|
|
154
|
+
{ id: 'CHILD_A', parents: [0], parent: 'ITEM', isSelected: true, __indexPosition: 1 },
|
|
155
|
+
{ id: 'CHILD_C', parents: [0], parent: 'ITEM', isSelected: true, __indexPosition: 2 },
|
|
156
|
+
]
|
|
157
|
+
};
|
|
158
|
+
expect(applyHierarchicalCodesToDim(hCodes, partialDim)).to.deep.equal(expected);
|
|
159
|
+
});
|
|
147
160
|
});
|