@sis-cc/dotstatsuite-components 19.0.0 → 19.2.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 applyHierarchicalCodesToDim = function applyHierarchicalCodesToDim(hCodes, dim) {
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 || !confirmedHierarchisedChilds.has(val.id);
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 children = hC.children,
83
- _hC$unconfirmed = hC.unconfirmed,
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.prepend(hC), R.map(function (v) {
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
+ };
@@ -35,7 +35,6 @@ var hasInvalidValues = R.pipe(R.prop('values'), R.anyPass([R.isNil, R.complement
35
35
  var isConceptInvalid = R.anyPass([hasInvalidValues /* add more... */]);
36
36
  var filterValidConcepts = R.reject(isConceptInvalid);
37
37
  // concepts is an array of ids... (misnamed!)
38
- var conceptIdsLens = R.lensProp('concepts');
39
38
  var rejectInvalidConceptIds = function rejectInvalidConceptIds() {
40
39
  var concepts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
41
40
  return function () {
@@ -44,7 +43,7 @@ var rejectInvalidConceptIds = function rejectInvalidConceptIds() {
44
43
  var validConceptIds = R.pluck('id', filterValidConcepts(concepts));
45
44
  return R.reduce(function (acc, comb) {
46
45
  var refinedConcepts = R.intersection(validConceptIds, comb.concepts);
47
- if (R.length(refinedConcepts) < 2) {
46
+ if (R.length(refinedConcepts) < 1) {
48
47
  return acc;
49
48
  }
50
49
  return R.append((0, _extends4.default)({}, comb, { concepts: refinedConcepts }), acc);
@@ -90,7 +90,7 @@ var getCoordinates = function getCoordinates(indexes, topCoordinates, definition
90
90
 
91
91
  var getAttributesSeries = function getAttributesSeries(validator, attributesSeries) {
92
92
  return R.reduce(function (acc, attrs) {
93
- var attr = R.head(R.values(attrs));
93
+ var attr = R.head(R.values(attrs)) || {};
94
94
  if (R.length(attr.relationship || []) === 1 && !attr.combined) {
95
95
  return acc;
96
96
  }
@@ -130,7 +130,7 @@ var getSerieFlagsAndSideProps = function getSerieFlagsAndSideProps(coordinates,
130
130
  var flags = (0, _getFlagsAndNotes.getFlagsAndNotes)(layoutAttrValues, customAttributes);
131
131
  var hasMetadata = !R.isNil(R.find(validator, metadataCoordinates));
132
132
  var hasDataAdvancedAttributes = R.any(function (d) {
133
- return R.has('value', d) ? d.hasAdvancedAttributes : R.any(R.prop('hasAdvancedAttributes'), d.values);
133
+ return R.has('value', d) ? R.prop('hasAdvancedAttributes', d.value) : R.any(R.prop('hasAdvancedAttributes'), d.values);
134
134
  }, data);
135
135
  var hasAdvancedAttributes = hasDataAdvancedAttributes || getHasAdvancedAttributes(layoutAttrValues, customAttributes);
136
136
  var sideProps = hasMetadata || hasAdvancedAttributes ? { hasMetadata: hasMetadata, hasAdvancedAttributes: hasAdvancedAttributes, coordinates: coordinates } : null;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sis-cc/dotstatsuite-components",
3
3
  "description": "Set components based on React.",
4
- "version": "19.0.0",
4
+ "version": "19.2.0",
5
5
  "main": "lib/index.js",
6
6
  "type": "module",
7
7
  "author": "OECD",
@@ -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
- let confirmedHierarchisedChilds = new Set([]);
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 || !confirmedHierarchisedChilds.has(val.id);
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 { children, unconfirmed = false, ...val } = hC;
55
- if (isValid(hC)) {
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) => {
@@ -18,14 +18,13 @@ const hasInvalidValues = R.pipe(
18
18
  const isConceptInvalid = R.anyPass([hasInvalidValues /* add more... */]);
19
19
  const filterValidConcepts = R.reject(isConceptInvalid);
20
20
  // concepts is an array of ids... (misnamed!)
21
- const conceptIdsLens = R.lensProp('concepts');
22
21
  const rejectInvalidConceptIds =
23
22
  (concepts = []) =>
24
23
  (combinations = []) => {
25
24
  const validConceptIds = R.pluck('id', filterValidConcepts(concepts));
26
25
  return R.reduce((acc, comb) => {
27
26
  const refinedConcepts = R.intersection(validConceptIds, comb.concepts);
28
- if (R.length(refinedConcepts) < 2) {
27
+ if (R.length(refinedConcepts) < 1) {
29
28
  return acc;
30
29
  }
31
30
  return R.append({ ...comb, concepts: refinedConcepts }, acc);
@@ -51,7 +51,7 @@ const getCoordinates = (indexes, topCoordinates, definition) => R.addIndex(R.red
51
51
  }, topCoordinates, definition);
52
52
 
53
53
  const getAttributesSeries = (validator, attributesSeries) => R.reduce((acc, attrs) => {
54
- const attr = R.head(R.values(attrs));
54
+ const attr = R.head(R.values(attrs)) || {};
55
55
  if (R.length(attr.relationship || []) === 1 && !attr.combined) {
56
56
  return acc;
57
57
  }
@@ -87,7 +87,7 @@ const getSerieFlagsAndSideProps = (coordinates, validator, attributesValues, cus
87
87
  const flags = getFlagsAndNotes(layoutAttrValues, customAttributes);
88
88
  const hasMetadata = !R.isNil(R.find(validator, metadataCoordinates));
89
89
  const hasDataAdvancedAttributes = R.any(
90
- d => R.has('value', d) ? d.hasAdvancedAttributes : R.any(R.prop('hasAdvancedAttributes'), d.values)
90
+ d => R.has('value', d) ? R.prop('hasAdvancedAttributes', d.value) : R.any(R.prop('hasAdvancedAttributes'), d.values)
91
91
  , data);
92
92
  const hasAdvancedAttributes = hasDataAdvancedAttributes || getHasAdvancedAttributes(layoutAttrValues, customAttributes);
93
93
  const sideProps = hasMetadata || hasAdvancedAttributes
@@ -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
  });
@@ -439,4 +439,52 @@ describe('getLayoutData 2 tests', () => {
439
439
  }
440
440
  });
441
441
  });
442
+ it('getSerieDataWithMissingLines, advanced attributes as dim level plus enpty series', () => {
443
+ const dimensions = [
444
+ {
445
+ id: 'D0',
446
+ values: [
447
+ { id: 'D0V0', flags: [], hasAdvancedAttributes: true },
448
+ { id: 'D0V1' }
449
+ ]
450
+ }
451
+ ];
452
+
453
+ const attributesSeries = {
454
+ 'D1=D1V0': {},
455
+ 'D0=D0V0:D1=D1V0': {},
456
+ };
457
+
458
+ const topCoordinates = {};
459
+
460
+ const serie = {
461
+ indexes: [0],
462
+ parentsIndexes: [[]],
463
+ missingIndexes: [[]],
464
+ };
465
+
466
+ const customAttributes = {
467
+ flags: [],
468
+ notes: ['A0', 'A2']
469
+ }
470
+
471
+ expect(getSerieDataWithMissingLines(serie, dimensions, topCoordinates, attributesSeries, customAttributes, {})).to.deep.equal([{
472
+ data: [
473
+ {
474
+ dimension: { id: 'D0' },
475
+ value: { id: 'D0V0', missingParents: [], parents: [], flags: [], hasAdvancedAttributes: true }
476
+ },
477
+ ],
478
+ coordinates: { D0: 'D0V0' },
479
+ key: 'D0=D0V0',
480
+ flags: [],
481
+ sideProps: {
482
+ coordinates: {
483
+ D0: 'D0V0',
484
+ },
485
+ hasAdvancedAttributes: true,
486
+ hasMetadata: false
487
+ }
488
+ }]);
489
+ });
442
490
  });
@@ -146,6 +146,20 @@ describe('parseCombinations tests', () => {
146
146
  relationship: ['DIM4'],
147
147
  display: true,
148
148
  },
149
+ {
150
+ id: 'COMB11',
151
+ concepts: ['DIM4'],
152
+ relationship: ['DIM4'],
153
+ series: true,
154
+ display: true
155
+ },
156
+ {
157
+ id: 'COMB12',
158
+ concepts: ['DIM4'],
159
+ relationship: ['DIM4'],
160
+ series: true,
161
+ display: true
162
+ },
149
163
  {
150
164
  id: 'COMB14',
151
165
  concepts: ['DIM3', 'ATTR5', 'ATTR8'],