@sis-cc/dotstatsuite-components 17.12.2 → 17.12.4
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.
- package/lib/rules/src/dimension-utils.js +4 -3
- package/lib/rules/src/get-values-enhanced.js +2 -1
- package/lib/rules/test/get-values-enhanced.test.js +4 -2
- package/lib/rules2/src/combinedValuesDisplay.js +4 -2
- package/package.json +1 -1
- package/src/rules/src/dimension-utils.js +36 -22
- package/src/rules/src/get-values-enhanced.js +2 -3
- package/src/rules/test/get-values-enhanced.test.js +3 -2
- package/src/rules2/src/combinedValuesDisplay.js +56 -45
|
@@ -32,15 +32,16 @@ var dimensionValueDisplay = exports.dimensionValueDisplay = function dimensionVa
|
|
|
32
32
|
return function (dimensionValue) {
|
|
33
33
|
var id = (0, _get3.default)(dimensionValue, accessors.id || 'id', '');
|
|
34
34
|
var name = (0, _get3.default)(dimensionValue, accessors.name || 'name', '');
|
|
35
|
+
// a non-coded component (dim | attr) has no name, names nor label
|
|
36
|
+
// the only valid thing to display is the id
|
|
37
|
+
if (dimensionValue.isNonCoded) return id;
|
|
35
38
|
switch (display) {
|
|
36
39
|
case 'label':
|
|
37
40
|
return (0, _isEmpty3.default)(name) ? '[' + id + ']' : name;
|
|
38
41
|
case 'code':
|
|
39
42
|
return id;
|
|
40
43
|
case 'both':
|
|
41
|
-
if ((0, _isNil3.default)(id) || (0, _isEmpty3.default)(id))
|
|
42
|
-
return name;
|
|
43
|
-
}
|
|
44
|
+
if ((0, _isNil3.default)(id) || (0, _isEmpty3.default)(id)) return name;
|
|
44
45
|
return '(' + id + ') ' + name;
|
|
45
46
|
default:
|
|
46
47
|
return null;
|
|
@@ -93,7 +93,8 @@ var getValuesEnhanced = exports.getValuesEnhanced = function getValuesEnhanced(_
|
|
|
93
93
|
start: start ? start.toISOString() : null,
|
|
94
94
|
notes: notes,
|
|
95
95
|
__indexPosition: __indexPosition,
|
|
96
|
-
__index: __index
|
|
96
|
+
__index: __index,
|
|
97
|
+
isNonCoded: isNonCoded(value)
|
|
97
98
|
});
|
|
98
99
|
if (!isNonCoded(value)) {
|
|
99
100
|
res = R.assoc('name', getName({ isTimeDimension: isTimeDimension, options: options, locale: locale, start: start, reportYearStart: reportYearStart })(value), res);
|
|
@@ -86,13 +86,15 @@ var nonCodedValues = [{ value: 'A' }, { value: 'B' }, { value: 'C' }];
|
|
|
86
86
|
|
|
87
87
|
var expectedValues = function expectedValues() {
|
|
88
88
|
var skippedValueEntries = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
89
|
+
var isNonCoded = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
89
90
|
return R.addIndex(R.map)(function (value, index) {
|
|
90
91
|
return (0, _extends3.default)({}, R.omit(R.prepend('names', skippedValueEntries), value), {
|
|
91
92
|
__index: index,
|
|
92
93
|
__indexPosition: index,
|
|
93
94
|
display: true,
|
|
94
95
|
notes: [],
|
|
95
|
-
start: R.propOr(null, 'start', value)
|
|
96
|
+
start: R.propOr(null, 'start', value),
|
|
97
|
+
isNonCoded: isNonCoded
|
|
96
98
|
});
|
|
97
99
|
});
|
|
98
100
|
};
|
|
@@ -111,7 +113,7 @@ describe('get values enhanced method', function () {
|
|
|
111
113
|
locale: 'en',
|
|
112
114
|
parent: 'ID'
|
|
113
115
|
})(nonCodedValues);
|
|
114
|
-
(0, _chai.expect)(enhancedValues).to.deep.equal(expectedValues(['name', 'order', 'value'])(values));
|
|
116
|
+
(0, _chai.expect)(enhancedValues).to.deep.equal(expectedValues(['name', 'order', 'value'], true)(values));
|
|
115
117
|
});
|
|
116
118
|
|
|
117
119
|
it('should pass with time values', function () {
|
|
@@ -60,8 +60,10 @@ var _combinedValuesDisplay = function _combinedValuesDisplay(_display) {
|
|
|
60
60
|
var combinedValuesDisplay = exports.combinedValuesDisplay = function combinedValuesDisplay(display, values) {
|
|
61
61
|
if (display === 'both') {
|
|
62
62
|
return R.converge(function (_ids, labels) {
|
|
63
|
-
|
|
64
|
-
|
|
63
|
+
return (0, _src.dimensionValueDisplay)('both')({
|
|
64
|
+
id: _ids,
|
|
65
|
+
name: labels
|
|
66
|
+
});
|
|
65
67
|
}, [_combinedValuesDisplay('code'), _combinedValuesDisplay('label')])(values);
|
|
66
68
|
}
|
|
67
69
|
return _combinedValuesDisplay(display)(values);
|
package/package.json
CHANGED
|
@@ -1,38 +1,52 @@
|
|
|
1
1
|
import { isEmpty, isNil, get, has, reduce } from 'lodash';
|
|
2
2
|
|
|
3
|
-
export const dimensionValueDisplay =
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
return name;
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
3
|
+
export const dimensionValueDisplay =
|
|
4
|
+
(display, accessors = {}) =>
|
|
5
|
+
(dimensionValue) => {
|
|
6
|
+
const id = get(dimensionValue, accessors.id || 'id', '');
|
|
7
|
+
const name = get(dimensionValue, accessors.name || 'name', '');
|
|
8
|
+
// a non-coded component (dim | attr) has no name, names nor label
|
|
9
|
+
// the only valid thing to display is the id
|
|
10
|
+
if (dimensionValue.isNonCoded) return id;
|
|
11
|
+
switch (display) {
|
|
12
|
+
case 'label':
|
|
13
|
+
return isEmpty(name) ? `[${id}]` : name;
|
|
14
|
+
case 'code':
|
|
15
|
+
return id;
|
|
16
|
+
case 'both':
|
|
17
|
+
if (isNil(id) || isEmpty(id)) return name;
|
|
18
|
+
return `(${id}) ${name}`;
|
|
19
|
+
default:
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
};
|
|
20
23
|
|
|
21
24
|
export const dimensionValueDisplayAt = (dimension, index, display) => {
|
|
22
25
|
const dimensionValue = get(dimension, `values[${Number(index)}]`, {});
|
|
23
26
|
return dimensionValueDisplay(display)(dimensionValue);
|
|
24
27
|
};
|
|
25
28
|
|
|
26
|
-
export const categoryDisplay = (
|
|
29
|
+
export const categoryDisplay = (
|
|
30
|
+
splitObservationKey,
|
|
31
|
+
dimensions,
|
|
32
|
+
dimensionsWithValuesIndexedById,
|
|
33
|
+
rejectedId,
|
|
34
|
+
display,
|
|
35
|
+
) => {
|
|
27
36
|
return reduce(
|
|
28
37
|
splitObservationKey,
|
|
29
38
|
(memo, dimensionValueIndex, dimensionIndex) => {
|
|
30
39
|
const dimension = get(dimensions, `[${dimensionIndex}]`, {});
|
|
31
|
-
if (
|
|
32
|
-
|
|
40
|
+
if (
|
|
41
|
+
has(dimensionsWithValuesIndexedById, dimension.id) &&
|
|
42
|
+
dimension.id !== rejectedId
|
|
43
|
+
) {
|
|
44
|
+
memo.push(
|
|
45
|
+
dimensionValueDisplayAt(dimension, dimensionValueIndex, display),
|
|
46
|
+
);
|
|
33
47
|
}
|
|
34
48
|
return memo;
|
|
35
49
|
},
|
|
36
|
-
[]
|
|
50
|
+
[],
|
|
37
51
|
).join(' - ');
|
|
38
|
-
};
|
|
52
|
+
};
|
|
@@ -77,6 +77,7 @@ export const getValuesEnhanced = ({
|
|
|
77
77
|
notes,
|
|
78
78
|
__indexPosition,
|
|
79
79
|
__index,
|
|
80
|
+
isNonCoded: isNonCoded(value),
|
|
80
81
|
};
|
|
81
82
|
if (!isNonCoded(value)) {
|
|
82
83
|
res = R.assoc(
|
|
@@ -104,9 +105,7 @@ export const getValuesEnhanced = ({
|
|
|
104
105
|
);
|
|
105
106
|
};
|
|
106
107
|
|
|
107
|
-
const getDateForSort = (key) => (val) =>
|
|
108
|
-
return dateFns.getTime(new Date(R.prop(key, val)));
|
|
109
|
-
};
|
|
108
|
+
const getDateForSort = (key) => (val) => dateFns.getTime(new Date(R.prop(key, val)));
|
|
110
109
|
const byStartDate = R.ascend(getDateForSort('start'));
|
|
111
110
|
const byEndDate = R.descend(getDateForSort('end'));
|
|
112
111
|
const timeDimensionSorts = [byStartDate, byEndDate];
|
|
@@ -82,7 +82,7 @@ const expectedTimeValues = [
|
|
|
82
82
|
|
|
83
83
|
const nonCodedValues = [{ value: 'A' }, { value: 'B' }, { value: 'C' }];
|
|
84
84
|
|
|
85
|
-
const expectedValues = (skippedValueEntries = []) => R.addIndex(R.map)((value, index) => {
|
|
85
|
+
const expectedValues = (skippedValueEntries = [], isNonCoded = false) => R.addIndex(R.map)((value, index) => {
|
|
86
86
|
return {
|
|
87
87
|
...R.omit(R.prepend('names', skippedValueEntries), value),
|
|
88
88
|
__index: index,
|
|
@@ -90,6 +90,7 @@ const expectedValues = (skippedValueEntries = []) => R.addIndex(R.map)((value, i
|
|
|
90
90
|
display: true,
|
|
91
91
|
notes: [],
|
|
92
92
|
start: R.propOr(null, 'start', value),
|
|
93
|
+
isNonCoded,
|
|
93
94
|
};
|
|
94
95
|
});
|
|
95
96
|
|
|
@@ -108,7 +109,7 @@ describe('get values enhanced method', () => {
|
|
|
108
109
|
parent: 'ID',
|
|
109
110
|
})(nonCodedValues);
|
|
110
111
|
expect(enhancedValues).to.deep.equal(
|
|
111
|
-
expectedValues(['name', 'order', 'value'])(values),
|
|
112
|
+
expectedValues(['name', 'order', 'value'], true)(values),
|
|
112
113
|
);
|
|
113
114
|
});
|
|
114
115
|
|
|
@@ -5,7 +5,10 @@ import { REJECTED_VALUE_IDS } from './constants';
|
|
|
5
5
|
const getRefinedMissinParentsLabels = R.pipe(
|
|
6
6
|
R.propOr([], 'missingParents'),
|
|
7
7
|
R.reduce((acc, par) => {
|
|
8
|
-
if (
|
|
8
|
+
if (
|
|
9
|
+
!R.propOr(true, 'display', par) ||
|
|
10
|
+
R.includes(par.id, REJECTED_VALUE_IDS)
|
|
11
|
+
) {
|
|
9
12
|
return acc;
|
|
10
13
|
}
|
|
11
14
|
return R.append(dimensionValueDisplay('label')(par), acc);
|
|
@@ -13,54 +16,62 @@ const getRefinedMissinParentsLabels = R.pipe(
|
|
|
13
16
|
);
|
|
14
17
|
|
|
15
18
|
export const singleValueDisplay = (display, value) => {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
19
|
+
if (display === 'label') {
|
|
20
|
+
return R.converge(
|
|
21
|
+
(missingParents, label) =>
|
|
22
|
+
R.isEmpty(missingParents)
|
|
23
|
+
? label
|
|
24
|
+
: R.join(' > ', R.append(label, missingParents)),
|
|
25
|
+
[getRefinedMissinParentsLabels, dimensionValueDisplay(display)],
|
|
26
|
+
)(value);
|
|
27
|
+
} else if (display === 'both') {
|
|
28
|
+
return `(${singleValueDisplay('code', value)}) ${singleValueDisplay(
|
|
29
|
+
'label',
|
|
30
|
+
value,
|
|
31
|
+
)}`;
|
|
32
|
+
}
|
|
33
|
+
return dimensionValueDisplay(display)(value);
|
|
34
|
+
};
|
|
30
35
|
|
|
31
|
-
const _combinedValuesDisplay = _display => values =>
|
|
32
|
-
R.
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
return R.
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
36
|
+
const _combinedValuesDisplay = (_display) => (values) =>
|
|
37
|
+
R.pipe(
|
|
38
|
+
R.reduce((acc, val) => {
|
|
39
|
+
if (
|
|
40
|
+
(!R.propOr(true, 'display', val) ||
|
|
41
|
+
R.includes(val.id, REJECTED_VALUE_IDS)) &&
|
|
42
|
+
_display === 'label'
|
|
43
|
+
) {
|
|
44
|
+
return acc;
|
|
45
|
+
}
|
|
46
|
+
return R.append(singleValueDisplay(_display, val), acc);
|
|
47
|
+
}, []),
|
|
48
|
+
(labels) => {
|
|
49
|
+
if (!R.isEmpty(labels) || _display !== 'label') {
|
|
50
|
+
return R.join(', ', labels);
|
|
51
|
+
}
|
|
52
|
+
const totalValue = R.find(R.propEq('id', '_T'), values);
|
|
53
|
+
if (!R.isNil(totalValue)) {
|
|
54
|
+
return dimensionValueDisplay('label')(totalValue);
|
|
55
|
+
}
|
|
56
|
+
if (R.isEmpty(values)) {
|
|
57
|
+
return '';
|
|
58
|
+
}
|
|
59
|
+
const firstValue = R.head(values);
|
|
60
|
+
return dimensionValueDisplay('label')(firstValue);
|
|
61
|
+
},
|
|
62
|
+
)(values);
|
|
54
63
|
|
|
55
64
|
export const combinedValuesDisplay = (display, values) => {
|
|
56
65
|
if (display === 'both') {
|
|
57
|
-
return R.converge(
|
|
58
|
-
|
|
59
|
-
return
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
66
|
+
return R.converge(
|
|
67
|
+
(_ids, labels) => {
|
|
68
|
+
return dimensionValueDisplay('both')({
|
|
69
|
+
id: _ids,
|
|
70
|
+
name: labels,
|
|
71
|
+
});
|
|
72
|
+
},
|
|
73
|
+
[_combinedValuesDisplay('code'), _combinedValuesDisplay('label')],
|
|
74
|
+
)(values);
|
|
64
75
|
}
|
|
65
76
|
return _combinedValuesDisplay(display)(values);
|
|
66
77
|
};
|