@sis-cc/dotstatsuite-components 14.3.2 → 14.3.3

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.
@@ -17,32 +17,51 @@ 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 uniq = R.pipe(R.reduce(function (_ref, id) {
21
+ var ids = _ref.ids,
22
+ list = _ref.list;
23
+
24
+ if (R.has(id, list)) {
25
+ return { ids: ids, list: list };
26
+ }
27
+ return { ids: R.append(id, ids), list: R.assoc(id, id, list) };
28
+ }, { ids: [], list: {} }), R.prop('ids'));
29
+
20
30
  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);
31
+ var _R$pipe = R.pipe(R.keys, R.reduce(function (_ref2, key) {
32
+ var intact = _ref2.intact,
33
+ broken = _ref2.broken;
34
+
35
+ var ids = R.filter(function (id) {
36
+ return R.has(id, indexed);
37
+ }, hier[key]);
23
38
  if (key === '#ROOT') {
24
- return R.assoc(key, ids, acc);
39
+ return { broken: broken, intact: R.assoc(key, ids, intact) };
25
40
  }
26
- var refinedKey = R.pipe(R.split('.'), R.takeLastWhile(function (id) {
41
+ var splitKey = R.split('.', key);
42
+ var filtered = R.takeLastWhile(function (id) {
27
43
  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);
44
+ }, splitKey);
45
+ if (R.length(filtered) === R.length(splitKey)) {
46
+ return { broken: broken, intact: R.assoc(key, ids, intact) };
31
47
  }
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);
48
+ var refinedKey = R.isEmpty(filtered) ? '#ROOT' : R.join('.', filtered);
49
+ return {
50
+ intact: intact,
51
+ broken: R.over(R.lensProp(refinedKey), R.ifElse(R.isNil, R.always([ids]), R.append(ids)))(broken)
52
+ };
53
+ }, { intact: {}, broken: {} }))(hier),
54
+ intact = _R$pipe.intact,
55
+ broken = _R$pipe.broken;
56
+
57
+ var intactIds = R.pipe(R.values, R.unnest)(intact);
58
+ var refinedBroken = R.pipe(R.omit(intactIds), R.over(R.lensProp('#ROOT'), R.pipe(function (i) {
59
+ return R.isNil(i) ? [] : i;
60
+ }, R.unnest, R.reject(R.flip(R.includes)(intactIds)))), R.map(R.pipe(R.unnest, uniq)))(broken);
61
+
62
+ return (0, _extends3.default)({}, refinedBroken, intact, {
63
+ '#ROOT': R.concat(refinedBroken['#ROOT'], intact['#ROOT'])
64
+ });
46
65
  };
47
66
 
48
67
  var hierarchiseDimensionWithAdvancedHierarchy = exports.hierarchiseDimensionWithAdvancedHierarchy = function hierarchiseDimensionWithAdvancedHierarchy(dimension, _hierarchy) {
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.2",
4
+ "version": "14.3.3",
5
5
  "main": "lib/index.js",
6
6
  "author": "OECD",
7
7
  "license": "MIT",
@@ -1,50 +1,64 @@
1
1
  import * as R from 'ramda';
2
2
 
3
- export const refinePartialHierarchy = (hier, indexed) => R.pipe(
4
- R.keys,
3
+ const uniq = R.pipe(
5
4
  R.reduce(
6
- (acc, key) => {
7
- const ids = R.prop(key, hier);
8
- if (key === '#ROOT') {
9
- return R.assoc(key, ids, acc);
5
+ ({ ids, list }, id) => {
6
+ if (R.has(id, list)) {
7
+ return ({ ids, list });
10
8
  }
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);
9
+ return ({ ids: R.append(id, ids), list: R.assoc(id, id, list) });
20
10
  },
21
- {}
11
+ { ids: [], list: {} }
22
12
  ),
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);
13
+ R.prop('ids')
14
+ );
15
+
16
+ export const refinePartialHierarchy = (hier, indexed) => {
17
+ const { intact, broken } = R.pipe(
18
+ R.keys,
19
+ R.reduce(
20
+ ({ intact, broken }, key) => {
21
+ const ids = R.filter(id => R.has(id, indexed), hier[key]);
22
+ if (key === '#ROOT') {
23
+ return ({ broken, intact: R.assoc(key, ids, intact) });
24
+ }
25
+ const splitKey = R.split('.', key);
26
+ const filtered = R.takeLastWhile(id => R.has(id, indexed), splitKey);
27
+ if (R.length(filtered) === R.length(splitKey)) {
28
+ return ({ broken, intact: R.assoc(key, ids, intact) });
29
+ }
30
+ const refinedKey = R.isEmpty(filtered) ? '#ROOT' : R.join('.', filtered);
31
+ return ({
32
+ intact,
33
+ broken: R.over(R.lensProp(refinedKey), R.ifElse(R.isNil, R.always([ids]), R.append(ids)))(broken)
34
+ });
35
+ },
36
+ { intact: {}, broken: {} }
37
+ )
38
+ )(hier);
39
+ const intactIds = R.pipe(R.values, R.unnest)(intact);
40
+ const refinedBroken = R.pipe(
41
+ R.omit(intactIds),
42
+ R.over(
43
+ R.lensProp('#ROOT'),
44
+ R.pipe(
45
+ i => R.isNil(i) ? [] : i,
46
+ R.unnest,
47
+ R.reject(R.flip(R.includes)(intactIds)))
48
+ ),
49
+ R.map(R.pipe(R.unnest, uniq))
50
+ )(broken);
51
+
52
+ return ({
53
+ ...refinedBroken,
54
+ ...intact,
55
+ '#ROOT': R.concat(refinedBroken['#ROOT'], intact['#ROOT'])
56
+ })
57
+ };
43
58
 
44
59
  export const hierarchiseDimensionWithAdvancedHierarchy = (dimension, _hierarchy) => {
45
60
  const indexed = R.indexBy(R.prop('id'), dimension.values);
46
61
  const hierarchy = refinePartialHierarchy(_hierarchy, indexed);
47
-
48
62
 
49
63
  let rest = indexed;
50
64
  const getChildren = (parents, hier) => R.pipe(
@@ -71,8 +71,8 @@ describe('hierarchiseDimensionWithAdvancedHierarchy tests', () => {
71
71
  id: 'test',
72
72
  values: [
73
73
  { id: 'AFK', parent: undefined, parents: [], __indexPosition: 3 },
74
- { id: 'CAN', parent: undefined, parents: [], __indexPosition: 1 },
75
74
  { id: 'USA', parent: undefined, parents: [], __indexPosition: 2 },
75
+ { id: 'CAN', parent: undefined, parents: [], __indexPosition: 1 },
76
76
  { id: 'W', parent: undefined, parents: [], __indexPosition: 8 },
77
77
  { id: 'EA', parent: 'W', parents: ['W'], __indexPosition: 6 },
78
78
  { id: 'FRA', parent: 'EA', parents: ['W', 'EA'], __indexPosition: 5 },
@@ -131,4 +131,64 @@ describe('hierarchiseDimensionWithAdvancedHierarchy tests', () => {
131
131
 
132
132
  expect(hierarchiseDimensionWithAdvancedHierarchy(dimension, hierarchy)).to.deep.equal(expected);
133
133
  });
134
+ it('non duplicates case 1', () => {
135
+ const hierarchy = {
136
+ '#ROOT': ['ONU', 'OECD'],
137
+ 'OECD': ['FRA', 'USA'],
138
+ 'ONU': ['USA', 'FRA'],
139
+ };
140
+
141
+ const dimension = {
142
+ id: 'REF_AREA',
143
+ values: [
144
+ { id: 'FRA' },
145
+ { id: 'USA' }
146
+ ]
147
+ };
148
+
149
+ const expected = {
150
+ id: 'REF_AREA',
151
+ values: [
152
+ { id: 'FRA', parents: [], parent: undefined },
153
+ { id: 'USA', parents: [], parent: undefined }
154
+ ]
155
+ };
156
+
157
+ expect(hierarchiseDimensionWithAdvancedHierarchy(dimension, hierarchy)).to.deep.equal(expected);
158
+ });
159
+ it('non duplicates case 2', () => {
160
+ const hierarchy = {
161
+ '#ROOT': ['ONU', 'OECD'],
162
+ 'ONU': ['USA', 'FRA'],
163
+ 'OECD': ['FRA', 'USA'],
164
+ 'ONU.USA': ['NY', 'LA'],
165
+ 'ONU.FRA': ['PA', 'LY']
166
+ };
167
+
168
+ const dimension = {
169
+ id: 'REF_AREA',
170
+ values: [
171
+ { id: 'OECD' },
172
+ { id: 'FRA' },
173
+ { id: 'PA' },
174
+ { id: 'LY' },
175
+ { id: 'USA' },
176
+ { id: 'NY' },
177
+ { id: 'LA' },
178
+ ]
179
+ };
180
+
181
+ const expected = {
182
+ id: 'REF_AREA',
183
+ values: [
184
+ { id: 'OECD', parents: [], parent: undefined },
185
+ { id: 'FRA', parents: ['OECD'], parent: 'OECD' },
186
+ { id: 'PA', parents: ['OECD.FRA'], parent: 'FRA' },
187
+ { id: 'LY', parents: ['OECD.FRA'], parent: 'FRA' },
188
+ { id: 'USA', parents: ['OECD'], parent: 'OECD' },
189
+ { id: 'NY', parents: ['OECD.USA'], parent: 'USA' },
190
+ { id: 'LA', parents: ['OECD.USA'], parent: 'USA' },
191
+ ]
192
+ };
193
+ });
134
194
  });