@sis-cc/dotstatsuite-components 14.2.0 → 14.2.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.
@@ -43,8 +43,10 @@ var getReportingYearStart = exports.getReportingYearStart = function getReportin
43
43
 
44
44
  var _R$match = R.match(/[\d]{2}/g, reportYearStart),
45
45
  _R$match2 = (0, _slicedToArray3.default)(_R$match, 2),
46
- month = _R$match2[0],
47
- day = _R$match2[1];
46
+ _R$match2$ = _R$match2[0],
47
+ month = _R$match2$ === undefined ? '01' : _R$match2$,
48
+ _R$match2$2 = _R$match2[1],
49
+ day = _R$match2$2 === undefined ? '01' : _R$match2$2;
48
50
 
49
51
  return { month: month, day: day };
50
52
  };
@@ -84,7 +84,7 @@ var dataTransformer = exports.dataTransformer = function dataTransformer(dataNew
84
84
  }
85
85
  var timeFormat = R.prop('timeFormat', options);
86
86
  return (0, _extends3.default)({}, value, {
87
- id: R.when(R.always(isTimeDimension), R.replace(/M/g, ''))(value.id),
87
+ id: R.pipe(R.when(R.isNil, R.always(parent + '-' + __index)), R.when(R.always(isTimeDimension), R.replace(/M/g, '')))(value.id),
88
88
  display: !isHidden,
89
89
  name: R.when(R.always(isTimeDimension), R.always((0, _date.getReportedTimePeriodLabel)(options.frequency, timeFormat, locale)(reportYearStart, { id: value.id, reportedStart: start, start: value.start })))(name),
90
90
  start: start ? start.toISOString() : null,
@@ -13,12 +13,15 @@ function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj;
13
13
 
14
14
  var hierarchiseDimensionWithNativeHierarchy = exports.hierarchiseDimensionWithNativeHierarchy = function hierarchiseDimensionWithNativeHierarchy(dimension) {
15
15
  var values = R.sortBy(R.prop('__indexPosition'), dimension.values || []);
16
- var grouped = R.groupBy(R.propOr('#ROOT', 'parent'), values);
16
+ var indexed = R.indexBy(R.prop('id'), values);
17
+ var grouped = R.groupBy(function (val) {
18
+ return val.parent && R.has(val.parent, indexed) ? val.parent : '#ROOT';
19
+ }, values);
17
20
 
18
21
  var getChildren = function getChildren(parents) {
19
22
  var childs = R.propOr([], R.last(parents) || '#ROOT', grouped);
20
23
  return R.reduce(function (acc, child) {
21
- var refined = R.assoc('parents', parents, child);
24
+ var refined = R.pipe(R.assoc('parents', parents), R.assoc('parent', R.last(parents)))(child);
22
25
  var children = getChildren(R.append(child.id, parents));
23
26
  return R.concat(acc, R.prepend(refined, children));
24
27
  }, [], childs);
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.2.0",
4
+ "version": "14.2.3",
5
5
  "main": "lib/index.js",
6
6
  "author": "OECD",
7
7
  "license": "MIT",
@@ -11,6 +11,6 @@ export const getReportingYearStart = (sdmxJson) => {
11
11
  return id === REPORTING_YEAR_START_DAY || id === REPYEARSTART;
12
12
  }, attributes) || {};
13
13
  const reportYearStart = R.pathOr('--01-01', ['values', 0, 'name'], reportYearStartAttr);
14
- const [month, day] = R.match(/[\d]{2}/g, reportYearStart);
14
+ const [month = '01', day = '01'] = R.match(/[\d]{2}/g, reportYearStart);
15
15
  return ({ month, day });
16
16
  };
@@ -62,9 +62,15 @@ export const dataTransformer = (dataNew, options = {}) => {
62
62
  const timeFormat = R.prop('timeFormat', options);
63
63
  return ({
64
64
  ...value,
65
- id: R.when(
66
- R.always(isTimeDimension),
67
- R.replace(/M/g, '')
65
+ id: R.pipe(
66
+ R.when(
67
+ R.isNil,
68
+ R.always(`${parent}-${__index}`)
69
+ ),
70
+ R.when(
71
+ R.always(isTimeDimension),
72
+ R.replace(/M/g, '')
73
+ )
68
74
  )(value.id),
69
75
  display: !isHidden,
70
76
  name: R.when(
@@ -2,13 +2,17 @@ import * as R from 'ramda';
2
2
 
3
3
  export const hierarchiseDimensionWithNativeHierarchy = (dimension) => {
4
4
  const values = R.sortBy(R.prop('__indexPosition'), dimension.values || []);
5
- const grouped = R.groupBy(R.propOr('#ROOT', 'parent'), values);
5
+ const indexed = R.indexBy(R.prop('id'), values);
6
+ const grouped = R.groupBy(val => val.parent && R.has(val.parent, indexed) ? val.parent : '#ROOT', values);
6
7
 
7
8
  const getChildren = (parents) => {
8
9
  const childs = R.propOr([], R.last(parents) || '#ROOT', grouped);
9
10
  return R.reduce(
10
11
  (acc, child) => {
11
- const refined = R.assoc('parents', parents, child);
12
+ const refined = R.pipe(
13
+ R.assoc('parents', parents),
14
+ R.assoc('parent', R.last(parents)),
15
+ )(child);
12
16
  const children = getChildren(R.append(child.id, parents));
13
17
  return R.concat(acc, R.prepend(refined, children));
14
18
  },
@@ -5,6 +5,22 @@ describe('getReportingYearStart tests', () => {
5
5
  it('no data', () => {
6
6
  expect(getReportingYearStart()).to.deep.equal({ month: '01', day: '01' });
7
7
  });
8
+ it('unexpected data in REPYEARSTART attr: "0"', () => {
9
+ const data = {
10
+ data: {
11
+ structure: {
12
+ attributes: {
13
+ observation: [
14
+ { "id": "REPYEARSTART",
15
+ "values": [{ "name": "0", "names": { "en": "0" } }]
16
+ }
17
+ ]
18
+ }
19
+ }
20
+ }
21
+ };
22
+ expect(getReportingYearStart(data)).to.deep.equal({ month: '01', day: '01' });
23
+ });
8
24
  it('REPORTING_YEAR_START_DAY', () => {
9
25
  const dataReportingYearStartDay = {
10
26
  data: {
@@ -27,6 +27,31 @@ describe('hierarchiseDimensionWithNativeHierarchy tests', () => {
27
27
  ]
28
28
  };
29
29
 
30
+ expect(hierarchiseDimensionWithNativeHierarchy(dimension)).to.deep.equal(expected);
31
+ });
32
+ it ('missing parent test', () => {
33
+ const dimension = {
34
+ id: 'test',
35
+ values: [
36
+ { id: 'FRA', parent: 'EA', __indexPosition: 101 },
37
+ { id: 'GER', parent: 'EA', __indexPosition: 100 },
38
+ { id: 'EA', parent: 'W', __indexPosition: 30 },
39
+ { id: 'A', parent: 'W', __indexPosition: 20 },
40
+ { id: 'CHI', parent: undefined, __indexPosition: 0 }
41
+ ]
42
+ };
43
+
44
+ const expected = {
45
+ id: 'test',
46
+ values: [
47
+ { id: 'CHI', parent: undefined, parents: [], __indexPosition: 0 },
48
+ { id: 'A', parent: undefined, parents: [], __indexPosition: 20 },
49
+ { id: 'EA', parent: undefined, parents: [], __indexPosition: 30 },
50
+ { id: 'GER', parent: 'EA', parents: ['EA'], __indexPosition: 100 },
51
+ { id: 'FRA', parent: 'EA', parents: ['EA'], __indexPosition: 101 }
52
+ ]
53
+ };
54
+
30
55
  expect(hierarchiseDimensionWithNativeHierarchy(dimension)).to.deep.equal(expected);
31
56
  });
32
57
  });