@sis-cc/dotstatsuite-components 17.12.5 → 17.12.6
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.
|
@@ -29,11 +29,30 @@ var getDisplayableValues = function getDisplayableValues(values) {
|
|
|
29
29
|
}, values);
|
|
30
30
|
};
|
|
31
31
|
|
|
32
|
+
// invalid concepts:
|
|
33
|
+
// - empty/null/undefined/!array values (so far)
|
|
34
|
+
var hasInvalidValues = R.pipe(R.prop('values'), R.anyPass([R.isNil, R.complement(R.is(Array)), R.isEmpty]));
|
|
35
|
+
var isConceptInvalid = R.anyPass([hasInvalidValues /* add more... */]);
|
|
36
|
+
var filterInvalidConcepts = R.filter(isConceptInvalid);
|
|
37
|
+
// concepts is an array of ids... (misnamed!)
|
|
38
|
+
var conceptIdsLens = R.lensProp('concepts');
|
|
39
|
+
var rejectInvalidConceptIds = function rejectInvalidConceptIds() {
|
|
40
|
+
var concepts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
41
|
+
return function () {
|
|
42
|
+
var combinations = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
43
|
+
|
|
44
|
+
var invalidConceptIds = R.pluck('id', filterInvalidConcepts(concepts));
|
|
45
|
+
return R.map(R.over(conceptIdsLens, R.without(invalidConceptIds)), combinations);
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
|
|
32
49
|
var parseCombinations = exports.parseCombinations = function parseCombinations(combinations, parsedAttributes, dimensions) {
|
|
50
|
+
var concepts = R.concat(dimensions, parsedAttributes);
|
|
51
|
+
|
|
33
52
|
var indexedDimensions = R.indexBy(R.prop('id'), dimensions);
|
|
34
53
|
var indexedAttributes = R.indexBy(R.prop('id'), parsedAttributes);
|
|
35
54
|
|
|
36
|
-
return R.reduce(function (acc, comb) {
|
|
55
|
+
return R.pipe(rejectInvalidConceptIds(concepts), R.reduce(function (acc, comb) {
|
|
37
56
|
var relationship = [];
|
|
38
57
|
var ids = {};
|
|
39
58
|
var displayable_values_count = 0;
|
|
@@ -63,6 +82,10 @@ var parseCombinations = exports.parseCombinations = function parseCombinations(c
|
|
|
63
82
|
if (R.isEmpty(seriesConcepts)) {
|
|
64
83
|
return R.append((0, _extends4.default)({}, comb, { header: true, display: displayable_values_count > 0 }), acc);
|
|
65
84
|
}
|
|
66
|
-
return R.append((0, _extends4.default)({}, comb, {
|
|
67
|
-
|
|
85
|
+
return R.append((0, _extends4.default)({}, comb, {
|
|
86
|
+
series: true,
|
|
87
|
+
relationship: relationship,
|
|
88
|
+
display: displayable_values_count > 0
|
|
89
|
+
}), acc);
|
|
90
|
+
}, []))(combinations);
|
|
68
91
|
};
|
package/package.json
CHANGED
|
@@ -1,58 +1,100 @@
|
|
|
1
1
|
import * as R from 'ramda';
|
|
2
2
|
import { REJECTED_VALUE_IDS } from './constants';
|
|
3
3
|
|
|
4
|
-
const getDisplayableValues = values =>
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
const getDisplayableValues = (values) =>
|
|
5
|
+
R.filter(
|
|
6
|
+
(val) =>
|
|
7
|
+
!R.includes(R.prop('id', val), REJECTED_VALUE_IDS) &&
|
|
8
|
+
R.propOr(true, 'display', val),
|
|
9
|
+
values,
|
|
10
|
+
);
|
|
11
|
+
|
|
12
|
+
// invalid concepts:
|
|
13
|
+
// - empty/null/undefined/!array values (so far)
|
|
14
|
+
const hasInvalidValues = R.pipe(
|
|
15
|
+
R.prop('values'),
|
|
16
|
+
R.anyPass([R.isNil, R.complement(R.is(Array)), R.isEmpty]),
|
|
7
17
|
);
|
|
18
|
+
const isConceptInvalid = R.anyPass([hasInvalidValues /* add more... */]);
|
|
19
|
+
const filterInvalidConcepts = R.filter(isConceptInvalid);
|
|
20
|
+
// concepts is an array of ids... (misnamed!)
|
|
21
|
+
const conceptIdsLens = R.lensProp('concepts');
|
|
22
|
+
const rejectInvalidConceptIds =
|
|
23
|
+
(concepts = []) =>
|
|
24
|
+
(combinations = []) => {
|
|
25
|
+
const invalidConceptIds = R.pluck('id', filterInvalidConcepts(concepts));
|
|
26
|
+
return R.map(
|
|
27
|
+
R.over(conceptIdsLens, R.without(invalidConceptIds)),
|
|
28
|
+
combinations,
|
|
29
|
+
);
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export const parseCombinations = (
|
|
33
|
+
combinations,
|
|
34
|
+
parsedAttributes,
|
|
35
|
+
dimensions,
|
|
36
|
+
) => {
|
|
37
|
+
const concepts = R.concat(dimensions, parsedAttributes);
|
|
8
38
|
|
|
9
|
-
export const parseCombinations = (combinations, parsedAttributes, dimensions) => {
|
|
10
39
|
const indexedDimensions = R.indexBy(R.prop('id'), dimensions);
|
|
11
40
|
const indexedAttributes = R.indexBy(R.prop('id'), parsedAttributes);
|
|
12
41
|
|
|
13
|
-
return R.
|
|
14
|
-
(
|
|
42
|
+
return R.pipe(
|
|
43
|
+
rejectInvalidConceptIds(concepts),
|
|
44
|
+
R.reduce((acc, comb) => {
|
|
15
45
|
let relationship = [];
|
|
16
46
|
let ids = {};
|
|
17
47
|
let displayable_values_count = 0;
|
|
18
|
-
const seriesConcepts = R.filter(
|
|
19
|
-
concept
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
48
|
+
const seriesConcepts = R.filter((concept) => {
|
|
49
|
+
if (R.has(concept, ids)) {
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
if (R.has(concept, indexedDimensions)) {
|
|
53
|
+
const dimension = R.prop(concept, indexedDimensions);
|
|
54
|
+
relationship = !dimension.header
|
|
55
|
+
? R.append(concept, relationship)
|
|
56
|
+
: relationship;
|
|
57
|
+
ids = { ...ids, [concept]: concept };
|
|
58
|
+
displayable_values_count += R.length(dimension.values || []);
|
|
59
|
+
return !dimension.header;
|
|
60
|
+
} else if (!R.has(concept, indexedAttributes)) {
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
const attribute = R.prop(concept, indexedAttributes);
|
|
64
|
+
const displayableValues = getDisplayableValues(attribute.values || []);
|
|
65
|
+
const isDisplayable =
|
|
66
|
+
R.length(displayableValues) !== 0 &&
|
|
67
|
+
R.propOr(true, 'display', attribute);
|
|
68
|
+
relationship =
|
|
69
|
+
attribute.series && isDisplayable
|
|
70
|
+
? R.pipe(
|
|
71
|
+
R.reject((id) => R.has(id, ids)),
|
|
39
72
|
R.concat(relationship),
|
|
40
73
|
)(attribute.relationship)
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
);
|
|
74
|
+
: relationship;
|
|
75
|
+
ids = attribute.series
|
|
76
|
+
? { ...ids, ...R.indexBy(R.identity, attribute.relationship) }
|
|
77
|
+
: ids;
|
|
78
|
+
displayable_values_count = isDisplayable
|
|
79
|
+
? displayable_values_count + R.length(displayableValues)
|
|
80
|
+
: displayable_values_count;
|
|
81
|
+
return attribute.series && isDisplayable;
|
|
82
|
+
}, comb.concepts);
|
|
50
83
|
if (R.isEmpty(seriesConcepts)) {
|
|
51
|
-
return R.append(
|
|
84
|
+
return R.append(
|
|
85
|
+
{ ...comb, header: true, display: displayable_values_count > 0 },
|
|
86
|
+
acc,
|
|
87
|
+
);
|
|
52
88
|
}
|
|
53
|
-
return R.append(
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
89
|
+
return R.append(
|
|
90
|
+
{
|
|
91
|
+
...comb,
|
|
92
|
+
series: true,
|
|
93
|
+
relationship,
|
|
94
|
+
display: displayable_values_count > 0,
|
|
95
|
+
},
|
|
96
|
+
acc,
|
|
97
|
+
);
|
|
98
|
+
}, []),
|
|
99
|
+
)(combinations);
|
|
58
100
|
};
|
|
@@ -13,38 +13,152 @@ describe('parseCombinations tests', () => {
|
|
|
13
13
|
{ id: 'COMB7', concepts: ['ATTR5', 'ATTR6'] },
|
|
14
14
|
{ id: 'COMB8', concepts: ['DIM5', 'DIM6'] },
|
|
15
15
|
{ id: 'COMB9', concepts: ['DIM1', 'ATTR5'] },
|
|
16
|
-
{ id: 'COMB10', concepts: ['DIM4', 'ATTR5'] }
|
|
16
|
+
{ id: 'COMB10', concepts: ['DIM4', 'ATTR5'] },
|
|
17
|
+
{ id: 'COMB11', concepts: ['DIM4', 'DIM7'] },
|
|
18
|
+
{ id: 'COMB12', concepts: ['DIM4', 'ATTR7'] },
|
|
19
|
+
{ id: 'COMB13', concepts: ['DIM7', 'ATTR7'] },
|
|
17
20
|
];
|
|
18
21
|
|
|
19
22
|
const dimensions = [
|
|
20
|
-
{ id: 'DIM1',
|
|
21
|
-
{ id: 'DIM2',
|
|
22
|
-
{ id: 'DIM3',
|
|
23
|
-
{ id: 'DIM4',
|
|
24
|
-
{
|
|
25
|
-
|
|
23
|
+
{ id: 'DIM1', header: true, values: [{ id: 'v1' }] },
|
|
24
|
+
{ id: 'DIM2', header: true, values: [{ id: 'v1' }] },
|
|
25
|
+
{ id: 'DIM3', header: false, values: [{ id: 'v1' }, { id: 'v2' }] },
|
|
26
|
+
{ id: 'DIM4', header: false, values: [{ id: 'v1' }, { id: 'v2' }] },
|
|
27
|
+
{
|
|
28
|
+
id: 'DIM5',
|
|
29
|
+
header: false,
|
|
30
|
+
values: [{ id: '_Z' }, { id: 'v2', display: false }],
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
id: 'DIM6',
|
|
34
|
+
header: false,
|
|
35
|
+
values: [
|
|
36
|
+
{ id: 'v1', display: false },
|
|
37
|
+
{ id: 'v2', display: false },
|
|
38
|
+
],
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
id: 'DIM7',
|
|
42
|
+
header: false,
|
|
43
|
+
values: [],
|
|
44
|
+
},
|
|
26
45
|
];
|
|
27
46
|
|
|
28
47
|
const attributes = [
|
|
29
48
|
{ id: 'ATTR1', header: true, relationship: [], values: [{ id: 'v' }] },
|
|
30
|
-
{
|
|
49
|
+
{
|
|
50
|
+
id: 'ATTR2',
|
|
51
|
+
header: true,
|
|
52
|
+
relationship: ['DIM1'],
|
|
53
|
+
values: [{ id: 'v' }],
|
|
54
|
+
},
|
|
31
55
|
{ id: 'ATTR3', header: true, relationship: [], values: [{ id: 'v' }] },
|
|
32
|
-
{
|
|
33
|
-
|
|
34
|
-
|
|
56
|
+
{
|
|
57
|
+
id: 'ATTR4',
|
|
58
|
+
series: true,
|
|
59
|
+
relationship: ['DIM3', 'DIM4'],
|
|
60
|
+
values: [{ id: 'v' }],
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
id: 'ATTR5',
|
|
64
|
+
series: true,
|
|
65
|
+
display: false,
|
|
66
|
+
relationship: ['DIM5'],
|
|
67
|
+
values: [{ id: 'v' }],
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
id: 'ATTR6',
|
|
71
|
+
series: true,
|
|
72
|
+
relationship: [],
|
|
73
|
+
values: [{ id: '0', display: false }, { id: '_Z' }],
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
id: 'ATTR7',
|
|
77
|
+
series: true,
|
|
78
|
+
relationship: [],
|
|
79
|
+
values: [],
|
|
80
|
+
},
|
|
35
81
|
];
|
|
36
82
|
|
|
37
|
-
expect(
|
|
83
|
+
expect(
|
|
84
|
+
parseCombinations(combinations, attributes, dimensions),
|
|
85
|
+
).to.deep.equal([
|
|
38
86
|
{ id: 'COMB1', concepts: ['DIM1', 'DIM2'], header: true, display: true },
|
|
39
|
-
{
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
87
|
+
{
|
|
88
|
+
id: 'COMB2',
|
|
89
|
+
concepts: ['DIM3', 'DIM4'],
|
|
90
|
+
series: true,
|
|
91
|
+
relationship: ['DIM3', 'DIM4'],
|
|
92
|
+
display: true,
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
id: 'COMB3',
|
|
96
|
+
concepts: ['ATTR1', 'ATTR2'],
|
|
97
|
+
header: true,
|
|
98
|
+
display: true,
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
id: 'COMB4',
|
|
102
|
+
concepts: ['ATTR3', 'ATTR4'],
|
|
103
|
+
series: true,
|
|
104
|
+
relationship: ['DIM3', 'DIM4'],
|
|
105
|
+
display: true,
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
id: 'COMB5',
|
|
109
|
+
concepts: ['DIM1', 'ATTR4'],
|
|
110
|
+
series: true,
|
|
111
|
+
relationship: ['DIM3', 'DIM4'],
|
|
112
|
+
display: true,
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
id: 'COMB6',
|
|
116
|
+
concepts: ['DIM5', 'ATTR5'],
|
|
117
|
+
series: true,
|
|
118
|
+
relationship: ['DIM5'],
|
|
119
|
+
display: true,
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
id: 'COMB7',
|
|
123
|
+
concepts: ['ATTR5', 'ATTR6'],
|
|
124
|
+
header: true,
|
|
125
|
+
display: false,
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
id: 'COMB8',
|
|
129
|
+
concepts: ['DIM5', 'DIM6'],
|
|
130
|
+
series: true,
|
|
131
|
+
relationship: ['DIM5', 'DIM6'],
|
|
132
|
+
display: true,
|
|
133
|
+
},
|
|
46
134
|
{ id: 'COMB9', concepts: ['DIM1', 'ATTR5'], header: true, display: true },
|
|
47
|
-
{
|
|
135
|
+
{
|
|
136
|
+
id: 'COMB10',
|
|
137
|
+
concepts: ['DIM4', 'ATTR5'],
|
|
138
|
+
series: true,
|
|
139
|
+
relationship: ['DIM4'],
|
|
140
|
+
display: true,
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
id: 'COMB11',
|
|
144
|
+
concepts: ['DIM4'],
|
|
145
|
+
series: true,
|
|
146
|
+
relationship: ['DIM4'],
|
|
147
|
+
display: true,
|
|
148
|
+
},
|
|
149
|
+
{
|
|
150
|
+
id: 'COMB12',
|
|
151
|
+
concepts: ['DIM4'],
|
|
152
|
+
series: true,
|
|
153
|
+
relationship: ['DIM4'],
|
|
154
|
+
display: true,
|
|
155
|
+
},
|
|
156
|
+
{
|
|
157
|
+
id: 'COMB13',
|
|
158
|
+
concepts: [],
|
|
159
|
+
display: false,
|
|
160
|
+
header: true,
|
|
161
|
+
},
|
|
48
162
|
]);
|
|
49
163
|
});
|
|
50
164
|
});
|