@sis-cc/dotstatsuite-components 14.3.1 → 14.3.2

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.
@@ -22,21 +22,24 @@ var getHCodelistsRefs = exports.getHCodelistsRefs = function getHCodelistsRefs(a
22
22
  if (annotation.type !== 'HIER_CONTEXT') {
23
23
  return acc;
24
24
  }
25
- var reference = annotation.text || annotation.title || '';
26
- var match = reference.match(/([\w@_.]+):([\w@_.]+):([\w@_.]+)\(([\d.]+)\).([\w@_.]+)$/);
27
- if (R.isNil(match)) {
28
- return acc;
29
- }
30
-
31
- var _R$tail = R.tail(match),
32
- _R$tail2 = (0, _slicedToArray3.default)(_R$tail, 5),
33
- codelistId = _R$tail2[0],
34
- agencyId = _R$tail2[1],
35
- code = _R$tail2[2],
36
- version = _R$tail2[3],
37
- hierarchy = _R$tail2[4];
38
-
39
- return R.assoc(codelistId, { agencyId: agencyId, code: code, version: version, hierarchy: hierarchy, codelistId: codelistId }, acc);
25
+ var references = annotation.text || annotation.title || '';
26
+ var refs = R.pipe(R.split(','), R.reduce(function (acc2, ref) {
27
+ var match = ref.match(/([\w@_.]+):([\w@_.]+):([\w@_.]+)\(([\d.]+)\).([\w@_.]+)$/);
28
+ if (R.isNil(match)) {
29
+ return acc2;
30
+ }
31
+
32
+ var _R$tail = R.tail(match),
33
+ _R$tail2 = (0, _slicedToArray3.default)(_R$tail, 5),
34
+ codelistId = _R$tail2[0],
35
+ agencyId = _R$tail2[1],
36
+ code = _R$tail2[2],
37
+ version = _R$tail2[3],
38
+ hierarchy = _R$tail2[4];
39
+
40
+ return R.assoc(codelistId, { agencyId: agencyId, code: code, version: version, hierarchy: hierarchy, codelistId: codelistId }, acc2);
41
+ }, {}))(references);
42
+ return R.mergeRight(acc, refs);
40
43
  }, {}, annotations);
41
44
  };
42
45
 
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.hierarchiseDimensionWithAdvancedHierarchy = undefined;
6
+ exports.hierarchiseDimensionWithAdvancedHierarchy = exports.refinePartialHierarchy = undefined;
7
7
 
8
8
  var _extends2 = require('babel-runtime/helpers/extends');
9
9
 
@@ -17,11 +17,40 @@ function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj;
17
17
 
18
18
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
19
 
20
- var hierarchiseDimensionWithAdvancedHierarchy = exports.hierarchiseDimensionWithAdvancedHierarchy = function hierarchiseDimensionWithAdvancedHierarchy(dimension, hierarchy) {
20
+ var refinePartialHierarchy = exports.refinePartialHierarchy = function refinePartialHierarchy(hier, indexed) {
21
+ return R.pipe(R.keys, R.reduce(function (acc, key) {
22
+ var ids = R.prop(key, hier);
23
+ if (key === '#ROOT') {
24
+ return R.assoc(key, ids, acc);
25
+ }
26
+ var refinedKey = R.pipe(R.split('.'), R.takeLastWhile(function (id) {
27
+ return R.has(id, indexed);
28
+ }), R.join('.'))(key);
29
+ if (R.isEmpty(refinedKey)) {
30
+ return R.over(R.lensProp('#ROOT0'), R.ifElse(R.isNil, R.always([ids]), R.append(ids)))(acc);
31
+ }
32
+ return R.over(R.lensProp(refinedKey), R.ifElse(R.isNil, R.always([ids]), R.append(ids)))(acc);
33
+ }, {}), function (res) {
34
+ var roots = R.pipe(R.propOr([], '#ROOT0'), R.unnest, R.sortBy(function (id) {
35
+ return R.path([id, '__indexPosition'], indexed);
36
+ }))(res);
37
+ return R.pipe(R.over(R.lensProp('#ROOT'), function (ids) {
38
+ return [R.concat(roots, ids)];
39
+ }), R.dissoc('#ROOT0'))(res);
40
+ }, R.mapObjIndexed(function (ids) {
41
+ if (R.length(ids) > 1) {
42
+ return null;
43
+ }
44
+ return R.head(ids);
45
+ }))(hier);
46
+ };
47
+
48
+ var hierarchiseDimensionWithAdvancedHierarchy = exports.hierarchiseDimensionWithAdvancedHierarchy = function hierarchiseDimensionWithAdvancedHierarchy(dimension, _hierarchy) {
21
49
  var indexed = R.indexBy(R.prop('id'), dimension.values);
50
+ var hierarchy = refinePartialHierarchy(_hierarchy, indexed);
22
51
 
23
52
  var rest = indexed;
24
- var getChildren = function getChildren(parents) {
53
+ var getChildren = function getChildren(parents, hier) {
25
54
  return R.pipe(function (ids) {
26
55
  rest = R.omit(ids, rest);
27
56
  return R.props(ids, indexed);
@@ -30,9 +59,9 @@ var hierarchiseDimensionWithAdvancedHierarchy = exports.hierarchiseDimensionWith
30
59
  parent: R.last(parents),
31
60
  parents: parents
32
61
  });
33
- var children = getChildren(R.append(val.id, parents));
62
+ var children = getChildren(R.append(val.id, parents), hier);
34
63
  return R.prepend(_val, children);
35
- }))(R.propOr([], R.isEmpty(parents) ? '#ROOT' : R.join('.', parents), hierarchy));
64
+ }))(R.propOr([], R.isEmpty(parents) ? '#ROOT' : R.join('.', parents), hier));
36
65
  };
37
66
 
38
67
  return R.set(R.lensProp('values'), R.pipe(getChildren, R.flatten, function (values) {
@@ -43,5 +72,5 @@ var hierarchiseDimensionWithAdvancedHierarchy = exports.hierarchiseDimensionWith
43
72
  return (0, _extends3.default)({}, val, { parent: undefined, parents: [] });
44
73
  }), R.sortBy(R.prop('__indexPosition')))(rest);
45
74
  return R.concat(sortedRest, values);
46
- })([]))(dimension);
75
+ })([], hierarchy))(dimension);
47
76
  };
@@ -95,4 +95,13 @@ Object.defineProperty(exports, 'parseHierarchicalCodelist', {
95
95
  get: function get() {
96
96
  return _parseHierarchicalCodelist.parseHierarchicalCodelist;
97
97
  }
98
+ });
99
+
100
+ var _hierarchiseDimensionWithAdvancedHierarchy = require('./hierarchiseDimensionWithAdvancedHierarchy');
101
+
102
+ Object.defineProperty(exports, 'refinePartialHierarchy', {
103
+ enumerable: true,
104
+ get: function get() {
105
+ return _hierarchiseDimensionWithAdvancedHierarchy.refinePartialHierarchy;
106
+ }
98
107
  });
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": "14.3.1",
4
+ "version": "14.3.2",
5
5
  "main": "lib/index.js",
6
6
  "author": "OECD",
7
7
  "license": "MIT",
@@ -5,13 +5,22 @@ export const getHCodelistsRefs = annotations => R.reduce(
5
5
  if (annotation.type !== 'HIER_CONTEXT') {
6
6
  return acc;
7
7
  }
8
- const reference = annotation.text || annotation.title || '';
9
- const match = reference.match(/([\w@_.]+):([\w@_.]+):([\w@_.]+)\(([\d.]+)\).([\w@_.]+)$/);
10
- if (R.isNil(match)) {
11
- return acc;
12
- }
13
- const [codelistId, agencyId, code, version, hierarchy] = R.tail(match);
14
- return R.assoc(codelistId, { agencyId, code, version, hierarchy, codelistId }, acc);
8
+ const references = annotation.text || annotation.title || '';
9
+ const refs = R.pipe(
10
+ R.split(','),
11
+ R.reduce(
12
+ (acc2, ref) => {
13
+ const match = ref.match(/([\w@_.]+):([\w@_.]+):([\w@_.]+)\(([\d.]+)\).([\w@_.]+)$/);
14
+ if (R.isNil(match)) {
15
+ return acc2;
16
+ }
17
+ const [codelistId, agencyId, code, version, hierarchy] = R.tail(match);
18
+ return R.assoc(codelistId, { agencyId, code, version, hierarchy, codelistId }, acc2);
19
+ },
20
+ {}
21
+ )
22
+ )(references);
23
+ return R.mergeRight(acc, refs);
15
24
  },
16
25
  {},
17
26
  annotations,
@@ -1,10 +1,53 @@
1
1
  import * as R from 'ramda';
2
2
 
3
- export const hierarchiseDimensionWithAdvancedHierarchy = (dimension, hierarchy) => {
3
+ export const refinePartialHierarchy = (hier, indexed) => R.pipe(
4
+ R.keys,
5
+ R.reduce(
6
+ (acc, key) => {
7
+ const ids = R.prop(key, hier);
8
+ if (key === '#ROOT') {
9
+ return R.assoc(key, ids, acc);
10
+ }
11
+ const refinedKey = R.pipe(
12
+ R.split('.'),
13
+ R.takeLastWhile(id => R.has(id, indexed)),
14
+ R.join('.')
15
+ )(key);
16
+ if (R.isEmpty(refinedKey)) {
17
+ return R.over(R.lensProp('#ROOT0'), R.ifElse(R.isNil, R.always([ids]), R.append(ids)))(acc)
18
+ }
19
+ return R.over(R.lensProp(refinedKey), R.ifElse(R.isNil, R.always([ids]), R.append(ids)))(acc);
20
+ },
21
+ {}
22
+ ),
23
+ (res) => {
24
+ const roots = R.pipe(
25
+ R.propOr([], '#ROOT0'),
26
+ R.unnest,
27
+ R.sortBy(id => R.path([id, '__indexPosition'], indexed))
28
+ )(res);
29
+ return R.pipe(
30
+ R.over(R.lensProp('#ROOT'), ids => [R.concat(roots, ids)]),
31
+ R.dissoc('#ROOT0')
32
+ )(res);
33
+ },
34
+ R.mapObjIndexed(
35
+ (ids) => {
36
+ if (R.length(ids) > 1) {
37
+ return null;
38
+ }
39
+ return R.head(ids);
40
+ }
41
+ )
42
+ )(hier);
43
+
44
+ export const hierarchiseDimensionWithAdvancedHierarchy = (dimension, _hierarchy) => {
4
45
  const indexed = R.indexBy(R.prop('id'), dimension.values);
46
+ const hierarchy = refinePartialHierarchy(_hierarchy, indexed);
47
+
5
48
 
6
49
  let rest = indexed;
7
- const getChildren = (parents) => R.pipe(
50
+ const getChildren = (parents, hier) => R.pipe(
8
51
  ids => {
9
52
  rest = R.omit(ids, rest);
10
53
  return R.props(ids, indexed)
@@ -17,11 +60,11 @@ export const hierarchiseDimensionWithAdvancedHierarchy = (dimension, hierarchy)
17
60
  parent: R.last(parents),
18
61
  parents
19
62
  };
20
- const children = getChildren(R.append(val.id, parents));
63
+ const children = getChildren(R.append(val.id, parents), hier);
21
64
  return R.prepend(_val, children);
22
65
  },
23
66
  )
24
- )(R.propOr([], R.isEmpty(parents) ? '#ROOT' : R.join('.', parents), hierarchy));
67
+ )(R.propOr([], R.isEmpty(parents) ? '#ROOT' : R.join('.', parents), hier));
25
68
 
26
69
  return R.set(
27
70
  R.lensProp('values'),
@@ -39,6 +82,6 @@ export const hierarchiseDimensionWithAdvancedHierarchy = (dimension, hierarchy)
39
82
  )(rest);
40
83
  return R.concat(sortedRest, values);
41
84
  }
42
- )([])
85
+ )([], hierarchy)
43
86
  )(dimension);
44
87
  };
@@ -11,3 +11,4 @@ export { getMSDInformations } from './getMSDInformations';
11
11
  export { getNotDisplayedIds } from './getNotDisplayedIds';
12
12
  export { getHCodelistsRefs, getHCodelistsRefsInData } from './getHCodelistsRefsInData';
13
13
  export { parseHierarchicalCodelist } from './parseHierarchicalCodelist';
14
+ export { refinePartialHierarchy } from './hierarchiseDimensionWithAdvancedHierarchy';
@@ -8,11 +8,14 @@ describe('getHCodelistsRefs tests', () => {
8
8
  { type: 'HIER_CONTEXT', text: 'C1:A:HCL1(1.0).HIER1' },
9
9
  { type: 'HIER_CONTEXT', title: 'C2:A:HCL2(1.0).HIER1' },
10
10
  { type: 'HIER_CONTEXT', text: 'C1:A:HCL1(1.0).HIER2' },
11
+ { type: 'HIER_CONTEXT', text: 'C3:A:HCL3(1.0).HIER,C4:A:HCL4(1.0).HIER' }
11
12
  ];
12
13
 
13
14
  const expected = {
14
15
  C1: { agencyId: 'A', codelistId: 'C1', code: 'HCL1', hierarchy: 'HIER2', version: '1.0' },
15
16
  C2: { agencyId: 'A', codelistId: 'C2', code: 'HCL2', hierarchy: 'HIER1', version: '1.0' },
17
+ C3: { agencyId: 'A', codelistId: 'C3', code: 'HCL3', hierarchy: 'HIER', version: '1.0' },
18
+ C4: { agencyId: 'A', codelistId: 'C4', code: 'HCL4', hierarchy: 'HIER', version: '1.0' },
16
19
  }
17
20
 
18
21
  expect(getHCodelistsRefs(annotations)).to.deep.equal(expected);
@@ -55,33 +55,80 @@ describe('hierarchiseDimensionWithAdvancedHierarchy tests', () => {
55
55
  const dimension = {
56
56
  id: 'test',
57
57
  values: [
58
- { id: 'IDF' },
59
- { id: 'CAN' },
60
- { id: 'USA' },
61
- { id: 'AFK' },
62
- { id: 'GER' },
63
- { id: 'FRA' },
64
- { id: 'EA' },
65
- { id: 'A' },
66
- { id: 'W' },
58
+ { id: 'IDF', __indexPosition: 0 },
59
+ { id: 'CAN', __indexPosition: 1 },
60
+ { id: 'USA', __indexPosition: 2 },
61
+ { id: 'AFK', __indexPosition: 3 },
62
+ { id: 'GER', __indexPosition: 4 },
63
+ { id: 'FRA', __indexPosition: 5 },
64
+ { id: 'EA', __indexPosition: 6 },
65
+ { id: 'A', __indexPosition: 7 },
66
+ { id: 'W', __indexPosition: 8 },
67
67
  ]
68
68
  };
69
69
 
70
70
  const hierarchised = {
71
71
  id: 'test',
72
72
  values: [
73
- { id: 'CAN', parent: undefined, parents: [] },
74
- { id: 'USA', parent: undefined, parents: [] },
75
- { id: 'AFK', parent: undefined, parents: [] },
76
- { id: 'W', parent: undefined, parents: [] },
77
- { id: 'EA', parent: 'W', parents: ['W'] },
78
- { id: 'FRA', parent: 'EA', parents: ['W', 'EA'] },
79
- { id: 'IDF', parent: 'FRA', parents: ['W', 'EA', 'FRA'] },
80
- { id: 'GER', parent: 'EA', parents: ['W', 'EA'] },
81
- { id: 'A', parent: 'W', parents: ['W'] },
73
+ { id: 'AFK', parent: undefined, parents: [], __indexPosition: 3 },
74
+ { id: 'CAN', parent: undefined, parents: [], __indexPosition: 1 },
75
+ { id: 'USA', parent: undefined, parents: [], __indexPosition: 2 },
76
+ { id: 'W', parent: undefined, parents: [], __indexPosition: 8 },
77
+ { id: 'EA', parent: 'W', parents: ['W'], __indexPosition: 6 },
78
+ { id: 'FRA', parent: 'EA', parents: ['W', 'EA'], __indexPosition: 5 },
79
+ { id: 'IDF', parent: 'FRA', parents: ['W', 'EA', 'FRA'], __indexPosition: 0 },
80
+ { id: 'GER', parent: 'EA', parents: ['W', 'EA'], __indexPosition: 4 },
81
+ { id: 'A', parent: 'W', parents: ['W'], __indexPosition: 7 },
82
82
  ]
83
83
  };
84
84
 
85
85
  expect(hierarchiseDimensionWithAdvancedHierarchy(dimension, hierarchy)).to.deep.equal(hierarchised);
86
86
  });
87
+ it('partial deep hierarchy', () => {
88
+ const hierarchy = {
89
+ '#ROOT': ['W'],
90
+ 'W': ['OECD', 'UE'],
91
+ 'W.OECD': ['USA', 'FRA'],
92
+ 'W.OECD.USA': ['NY', 'SF', 'LA'],
93
+ 'W.OECD.FRA': ['IDF'],
94
+ 'W.UE': ['FRA', 'GER'],
95
+ 'W.UE.FRA': ['IDF'],
96
+ 'W.UE.GER': ['BER'],
97
+ };
98
+ const dimension = {
99
+ id: 'test',
100
+ values: [
101
+ { id: 'OECD' },
102
+ { id: 'UE' },
103
+ { id: 'USA' },
104
+ { id: 'FRA' },
105
+ { id: 'GER' },
106
+ { id: 'NY' },
107
+ { id: 'SF' },
108
+ { id: 'LA' },
109
+ { id: 'IDF' },
110
+ { id: 'BER' },
111
+ ]
112
+ };
113
+
114
+ const expected = {
115
+ id: 'test',
116
+ values: [
117
+ { id: 'OECD', parents: [], parent: undefined },
118
+ { id: 'USA', parents: ['OECD'], parent: 'OECD' },
119
+ { id: 'NY', parents: ['OECD', 'USA'], parent: 'USA' },
120
+ { id: 'SF', parents: ['OECD', 'USA'], parent: 'USA' },
121
+ { id: 'LA', parents: ['OECD', 'USA'], parent: 'USA' },
122
+ { id: 'FRA', parents: ['OECD'], parent: 'OECD' },
123
+ { id: 'IDF', parents: ['OECD', 'FRA'], parent: 'FRA' },
124
+ { id: 'UE', parents: [], parent: undefined },
125
+ { id: 'FRA', parents: ['UE'], parent: 'UE' },
126
+ { id: 'IDF', parents: ['UE', 'FRA'], parent: 'FRA' },
127
+ { id: 'GER', parents: ['UE'], parent: 'UE' },
128
+ { id: 'BER', parents: ['UE', 'GER'], parent: 'GER' },
129
+ ]
130
+ };
131
+
132
+ expect(hierarchiseDimensionWithAdvancedHierarchy(dimension, hierarchy)).to.deep.equal(expected);
133
+ });
87
134
  });