@sis-cc/dotstatsuite-components 15.0.19 → 15.0.21

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.
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright © OECD 2019-2022
3
+ Copyright © OECD 2019-2023
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -27,9 +27,10 @@ var getUnitsSeries = exports.getUnitsSeries = function getUnitsSeries(observatio
27
27
  R.map(function (obs) {
28
28
  series = R.over(R.lensProp(obs.units.serieKey), R.ifElse(R.isNil, R.always([obs.units]), R.append(obs.units)))(series);
29
29
  }, observations);
30
+ return R.reduce(function (_acc, key) {
31
+ var serie = series[key];
30
32
 
31
- return R.map(function (serie) {
32
- return R.reduce(function (acc, units) {
33
+ var _R$reduce = R.reduce(function (acc, units) {
33
34
  var unitsKeys = R.keys(units);
34
35
  if (R.isEmpty(acc.unitsKeys)) return { units: units, unitsKeys: unitsKeys };
35
36
  var communKeys = R.intersection(acc.unitsKeys, unitsKeys);
@@ -37,6 +38,12 @@ var getUnitsSeries = exports.getUnitsSeries = function getUnitsSeries(observatio
37
38
  units: getUnits(R.pick(communKeys, acc.units), R.pick(communKeys, units)),
38
39
  unitsKeys: communKeys
39
40
  };
40
- }, { unitsKeys: [], units: {} }, serie).units;
41
- })(series);
41
+ }, { unitsKeys: [], units: {} }, serie),
42
+ units = _R$reduce.units;
43
+
44
+ if (R.isEmpty(R.dissoc('serieKey', units))) {
45
+ return _acc;
46
+ }
47
+ return R.assoc(key, units, _acc);
48
+ }, {})(R.keys(series));
42
49
  };
@@ -35,7 +35,8 @@ var TIME_PERIOD_ID = 'TIME_PERIOD';
35
35
 
36
36
  var dataTransformer = exports.dataTransformer = function dataTransformer(dataNew) {
37
37
  var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
38
- var locale = options.locale;
38
+ var locale = options.locale,
39
+ _hiddenIds = options.hiddenIds;
39
40
 
40
41
  var reportYearStart = (0, _getReportingYearStart.getReportingYearStart)(dataNew);
41
42
 
@@ -65,7 +66,7 @@ var dataTransformer = exports.dataTransformer = function dataTransformer(dataNew
65
66
  var getValuesEnhanced = function getValuesEnhanced(locale, annotations, isTimeDimension, parent) {
66
67
  return R.pipe(R.addIndex(R.map)(function (value, __index) {
67
68
  var valueAnnotations = R.pipe(R.propOr([], 'annotations'), R.flip(R.props)(annotations))(value);
68
- var isHidden = R.has(parent + '.' + value.id, hiddenIds) || (0, _sdmxData.getIsHidden)(valueAnnotations);
69
+ var isHidden = _hiddenIds[parent] && R.includes(value.id, _hiddenIds[parent]) || R.has(parent + '.' + value.id, hiddenIds) || (0, _sdmxData.getIsHidden)(valueAnnotations);
69
70
  var name = (0, _dotstatsuiteSdmxjs.getRefinedName)(value);
70
71
  var __indexPosition = NaN;
71
72
  var notes = [];
@@ -151,16 +152,16 @@ var dataTransformer = exports.dataTransformer = function dataTransformer(dataNew
151
152
  return R.addIndex(R.reduce)(function (acc, observation, obsIndex) {
152
153
  var id = R.prop('id')(observation);
153
154
  var dimAnnotations = (0, _sdmxData.getRelationnalAnnotations)(R.propOr([], 'annotations')(observation))(annotations);
154
- var isHidden = R.has(id, hiddenIds) || (0, _sdmxData.getIsHidden)(dimAnnotations);
155
155
  var isTime = (0, _dotstatsuiteSdmxjs.isTimePeriodDimension)(observation);
156
156
  var values = getValuesEnhanced(locale, annotations, isTime, id)(R.propOr([], 'values', observation));
157
-
157
+ var _idHidden = _hiddenIds[id] && R.isEmpty(R.difference(_hiddenIds[id], R.pluck('id')(values)));
158
+ var isHidden = _idHidden || R.has(id, hiddenIds) || (0, _sdmxData.getIsHidden)(dimAnnotations);
158
159
  return {
159
160
  observation: R.append((0, _extends3.default)({}, observation, {
160
161
  display: !isHidden,
161
162
  __index: obsIndex,
162
163
  name: (0, _dotstatsuiteSdmxjs.getRefinedName)(observation),
163
- values: values,
164
+ values: _idHidden ? [] : values,
164
165
  role: isTime ? TIME_PERIOD_ID : R.head(R.propOr([], 'roles', observation))
165
166
  }))(acc.observation),
166
167
  dimensionsLayout: (0, _sdmxData.setAnnotationsLayout)(id, acc.dimensionsLayout)(dimAnnotations)
@@ -31,10 +31,14 @@ var getNotDisplayedIds = exports.getNotDisplayedIds = function getNotDisplayedId
31
31
  return R.assoc(dimensionId, dimensionId, acc);
32
32
  }
33
33
  return R.reduce(function (_acc, val) {
34
+ var _val = val;
34
35
  if (R.isEmpty(val)) {
35
36
  return _acc;
36
37
  }
37
- var key = dimensionId + '.' + val;
38
+ if (R.test('/[()]/')) {
39
+ _val = R.replace(/[()]/g, '')(val);
40
+ }
41
+ var key = R.isEmpty(_val) ? dimensionId : dimensionId + '.' + _val;
38
42
  return R.assoc(key, key, _acc);
39
43
  }, acc, values);
40
44
  }, {}, ids);
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": "15.0.19",
4
+ "version": "15.0.21",
5
5
  "main": "lib/index.js",
6
6
  "author": "OECD",
7
7
  "license": "MIT",
@@ -15,17 +15,27 @@ export const getUnitsSeries = (observations) => {
15
15
  R.ifElse(R.isNil, R.always([obs.units]), R.append(obs.units))
16
16
  )(series);
17
17
  }, observations);
18
-
19
- return R.map(
20
- serie => R.reduce(
21
- (acc, units) => {
22
- const unitsKeys = R.keys(units);
23
- if (R.isEmpty(acc.unitsKeys)) return { units, unitsKeys }
24
- const communKeys = R.intersection(acc.unitsKeys, unitsKeys);
25
- return {
26
- units: getUnits(R.pick(communKeys, acc.units), R.pick(communKeys, units)),
27
- unitsKeys: communKeys,
28
- };
29
- }, { unitsKeys: [], units: {} }, serie).units
30
- )(series);
18
+ return R.reduce(
19
+ (_acc, key) => {
20
+ const serie = series[key];
21
+ const { units } = R.reduce(
22
+ (acc, units) => {
23
+ const unitsKeys = R.keys(units);
24
+ if (R.isEmpty(acc.unitsKeys)) return { units, unitsKeys }
25
+ const communKeys = R.intersection(acc.unitsKeys, unitsKeys);
26
+ return {
27
+ units: getUnits(R.pick(communKeys, acc.units), R.pick(communKeys, units)),
28
+ unitsKeys: communKeys,
29
+ };
30
+ },
31
+ { unitsKeys: [], units: {} },
32
+ serie
33
+ );
34
+ if (R.isEmpty(R.dissoc('serieKey', units))) {
35
+ return _acc;
36
+ }
37
+ return R.assoc(key, units, _acc);
38
+ },
39
+ {}
40
+ )(R.keys(series));
31
41
  };
@@ -2,7 +2,8 @@ import * as R from 'ramda';
2
2
  import dateFns from 'date-fns';
3
3
  import { getCodeOrder, getRefinedName, isTimePeriodDimension } from '@sis-cc/dotstatsuite-sdmxjs';
4
4
  import {
5
- getRelationnalAnnotations, setAnnotationsLayout, getIsHidden } from './sdmx-data';
5
+ getRelationnalAnnotations, setAnnotationsLayout, getIsHidden
6
+ } from './sdmx-data';
6
7
  import { getReportedTimePeriodLabel, getReportedTimePeriodNote, getReportedTimePeriod } from './date';
7
8
  import { getReportingYearStart } from './preparators/getReportingYearStart';
8
9
  import { getNotDisplayedIds } from '../../rules2/src';
@@ -10,18 +11,18 @@ import { getNotDisplayedIds } from '../../rules2/src';
10
11
  const TIME_PERIOD_ID = 'TIME_PERIOD';
11
12
 
12
13
  export const dataTransformer = (dataNew, options = {}) => {
13
- const { locale } = options;
14
+ const { locale, hiddenIds: _hiddenIds } = options;
14
15
  const reportYearStart = getReportingYearStart(dataNew);
15
16
 
16
17
  //---------------------------------------------------------------------------------------Annotations
17
- const getStructure = R.pathOr({},['data', 'structure']);
18
+ const getStructure = R.pathOr({}, ['data', 'structure']);
18
19
  const structure = getStructure(dataNew);
19
20
  const getAnnotations = R.propOr([], 'annotations');
20
21
  const annotations = getAnnotations(structure);
21
- const getDataSets = R.pathOr({},['data', 'dataSets']);
22
+ const getDataSets = R.pathOr({}, ['data', 'dataSets']);
22
23
  const dataSets = getDataSets(dataNew);
23
24
 
24
- const dataSetsAnnotations = R.props(R.pathOr([],[0, 'annotations'], dataSets), annotations);
25
+ const dataSetsAnnotations = R.props(R.pathOr([], [0, 'annotations'], dataSets), annotations);
25
26
 
26
27
  const hiddenIds = getNotDisplayedIds(dataSetsAnnotations);
27
28
 
@@ -35,64 +36,64 @@ export const dataTransformer = (dataNew, options = {}) => {
35
36
  });
36
37
  }, values);
37
38
 
38
- const getValuesEnhanced = (locale, annotations, isTimeDimension, parent) =>
39
- R.pipe(
40
- R.addIndex(R.map)((value, __index) => {
41
- const valueAnnotations = R.pipe(
42
- R.propOr([], 'annotations'),
43
- R.flip(R.props)(annotations)
44
- )(value);
45
- const isHidden = R.has(`${parent}.${value.id}`, hiddenIds) || getIsHidden(valueAnnotations);
46
- const name = getRefinedName(value);
47
- let __indexPosition = NaN;
48
- let notes = [];
49
- let start = null;
50
- let end = null;
51
- if (isTimeDimension) {
52
- const reported = getReportedTimePeriod(reportYearStart, value, options.frequency);
53
- start = reported.start;
54
- end = reported.end;
55
- const reportTimeNote = getReportedTimePeriodNote(reportYearStart, start, end, options.frequency, options.isRtl);
56
- notes = R.isNil(reportTimeNote) ? notes : R.append(reportTimeNote, notes);
57
- __indexPosition = dateFns.getTime(new Date(R.prop('start', value)));
58
- }
59
- if (isNaN(__indexPosition)) {
60
- __indexPosition = getCodeOrder({ annotations: valueAnnotations });
61
- }
62
- const timeFormat = R.prop('timeFormat', options);
63
- return ({
64
- ...value,
65
- id: R.pipe(
66
- R.when(
67
- R.isNil,
68
- R.always(`${parent}-${__index}`)
69
- ),
70
- R.when(
39
+ const getValuesEnhanced = (locale, annotations, isTimeDimension, parent) =>
40
+ R.pipe(
41
+ R.addIndex(R.map)((value, __index) => {
42
+ const valueAnnotations = R.pipe(
43
+ R.propOr([], 'annotations'),
44
+ R.flip(R.props)(annotations)
45
+ )(value);
46
+ const isHidden = (_hiddenIds[parent] && R.includes(value.id, _hiddenIds[parent])) || R.has(`${parent}.${value.id}`, hiddenIds) || getIsHidden(valueAnnotations);
47
+ const name = getRefinedName(value);
48
+ let __indexPosition = NaN;
49
+ let notes = [];
50
+ let start = null;
51
+ let end = null;
52
+ if (isTimeDimension) {
53
+ const reported = getReportedTimePeriod(reportYearStart, value, options.frequency);
54
+ start = reported.start;
55
+ end = reported.end;
56
+ const reportTimeNote = getReportedTimePeriodNote(reportYearStart, start, end, options.frequency, options.isRtl);
57
+ notes = R.isNil(reportTimeNote) ? notes : R.append(reportTimeNote, notes);
58
+ __indexPosition = dateFns.getTime(new Date(R.prop('start', value)));
59
+ }
60
+ if (isNaN(__indexPosition)) {
61
+ __indexPosition = getCodeOrder({ annotations: valueAnnotations });
62
+ }
63
+ const timeFormat = R.prop('timeFormat', options);
64
+ return ({
65
+ ...value,
66
+ id: R.pipe(
67
+ R.when(
68
+ R.isNil,
69
+ R.always(`${parent}-${__index}`)
70
+ ),
71
+ R.when(
72
+ R.always(isTimeDimension),
73
+ R.replace(/M/g, '')
74
+ )
75
+ )(value.id),
76
+ display: !isHidden,
77
+ name: R.when(
71
78
  R.always(isTimeDimension),
72
- R.replace(/M/g, '')
73
- )
74
- )(value.id),
75
- display: !isHidden,
76
- name: R.when(
77
- R.always(isTimeDimension),
78
- R.always(getReportedTimePeriodLabel(options.frequency, timeFormat, locale)(reportYearStart, { id: value.id, reportedStart: start, start: new Date(value.start) }))
79
- )(name),
80
- start: start ? start.toISOString() : null,
81
- notes,
82
- __indexPosition,
83
- __index,
84
- });
85
- }),
86
- R.sortWith([
87
- R.ascend(R.prop('__indexPosition')),
88
- R.ascend(R.propOr(-1, 'order'))
89
- ]),
90
- R.addIndex(R.map)((val, index) => R.assoc('__indexPosition', index, val)),
91
- /* NEW */
92
- R.sortBy(R.prop('__index'))
93
- );
94
-
95
- //--------------------------------------------------------------------------------------------Header
79
+ R.always(getReportedTimePeriodLabel(options.frequency, timeFormat, locale)(reportYearStart, { id: value.id, reportedStart: start, start: new Date(value.start) }))
80
+ )(name),
81
+ start: start ? start.toISOString() : null,
82
+ notes,
83
+ __indexPosition,
84
+ __index,
85
+ });
86
+ }),
87
+ R.sortWith([
88
+ R.ascend(R.prop('__indexPosition')),
89
+ R.ascend(R.propOr(-1, 'order'))
90
+ ]),
91
+ R.addIndex(R.map)((val, index) => R.assoc('__indexPosition', index, val)),
92
+ /* NEW */
93
+ R.sortBy(R.prop('__index'))
94
+ );
95
+
96
+ //--------------------------------------------------------------------------------------------Header
96
97
  const getMeta = R.propOr({}, 'meta');
97
98
  const meta = getMeta(dataNew);
98
99
 
@@ -101,10 +102,10 @@ export const dataTransformer = (dataNew, options = {}) => {
101
102
 
102
103
  const resHeader = {
103
104
  ...meta,
104
- sender: {...sender, name: getRefinedName(sender)},
105
+ sender: { ...sender, name: getRefinedName(sender) },
105
106
  };
106
107
 
107
- //----------------------------------------------------------------------------------------Attributes
108
+ //----------------------------------------------------------------------------------------Attributes
108
109
  const getAttributes = R.propOr({}, 'attributes');
109
110
  const attributes = getAttributes(structure);
110
111
 
@@ -140,7 +141,7 @@ export const dataTransformer = (dataNew, options = {}) => {
140
141
  observation: R.concat(resAttrObservations, datasetAttributes)
141
142
  };
142
143
 
143
- //----------------------------------------------------------------------------------------Dimensions
144
+ //----------------------------------------------------------------------------------------Dimensions
144
145
  const getDimensions = R.propOr({}, 'dimensions');
145
146
  const dimensions = getDimensions(structure);
146
147
 
@@ -149,25 +150,25 @@ export const dataTransformer = (dataNew, options = {}) => {
149
150
 
150
151
  const getObservations = locale => R.addIndex(R.reduce)((acc, observation, obsIndex) => {
151
152
  const id = R.prop('id')(observation);
152
- const dimAnnotations = getRelationnalAnnotations(R.propOr([],'annotations')(observation))(annotations)
153
- const isHidden = R.has(id, hiddenIds) || getIsHidden(dimAnnotations);
153
+ const dimAnnotations = getRelationnalAnnotations(R.propOr([], 'annotations')(observation))(annotations)
154
154
  const isTime = isTimePeriodDimension(observation);
155
- const values = getValuesEnhanced(locale, annotations, isTime, id)(R.propOr([],'values', observation));
156
-
155
+ const values = getValuesEnhanced(locale, annotations, isTime, id)(R.propOr([], 'values', observation));
156
+ const _idHidden = _hiddenIds[id] && R.isEmpty(R.difference(_hiddenIds[id], R.pluck('id')(values)))
157
+ const isHidden = _idHidden || R.has(id, hiddenIds) || getIsHidden(dimAnnotations);
157
158
  return ({
158
159
  observation: R.append({
159
160
  ...observation,
160
161
  display: !isHidden,
161
162
  __index: obsIndex,
162
163
  name: getRefinedName(observation),
163
- values,
164
+ values: _idHidden ? [] : values,
164
165
  role: isTime ? TIME_PERIOD_ID : R.head(R.propOr([], 'roles', observation)),
165
166
  })(acc.observation),
166
167
  dimensionsLayout: setAnnotationsLayout(id, acc.dimensionsLayout)(dimAnnotations),
167
168
  });
168
- }, { observation: [], dimensionsLayout: {}});
169
+ }, { observation: [], dimensionsLayout: {} });
169
170
 
170
- //-----------------------------------------------------------------------------------------Structure
171
+ //-----------------------------------------------------------------------------------------Structure
171
172
  const { dimensionsLayout, observation } = getObservations(locale)(dimObservations);
172
173
  const resStructure = {
173
174
  ...structure,
@@ -177,12 +178,12 @@ export const dataTransformer = (dataNew, options = {}) => {
177
178
  dimensions: { observation },
178
179
  };
179
180
 
180
- //------------------------------------------------------------------------------------------------------Layout
181
+ //------------------------------------------------------------------------------------------------------Layout
181
182
  const dataSetsLayout = R.reduce((acc, dataSetsAnnotation) => {
182
183
  const title = R.propOr('', 'title')(dataSetsAnnotation);
183
184
  if (R.isEmpty(title)) return acc;
184
185
  return setAnnotationsLayout(title, acc)([dataSetsAnnotation])
185
186
  }, {})(dataSetsAnnotations);
186
187
 
187
- return ({ data: { header: resHeader, dataSets, structure: resStructure }, layout: R.mergeRight(dimensionsLayout, dataSetsLayout)});
188
+ return ({ data: { header: resHeader, dataSets, structure: resStructure }, layout: R.mergeRight(dimensionsLayout, dataSetsLayout) });
188
189
  };
@@ -23,10 +23,14 @@ export const getNotDisplayedIds = (annotations) => R.pipe(
23
23
  }
24
24
  return R.reduce(
25
25
  (_acc, val) => {
26
+ let _val = val
26
27
  if (R.isEmpty(val)) {
27
28
  return _acc;
28
29
  }
29
- const key = `${dimensionId}.${val}`;
30
+ if (R.test('/[()]/')) {
31
+ _val = R.replace(/[()]/g, '')(val)
32
+ }
33
+ const key = R.isEmpty(_val) ? dimensionId : `${dimensionId}.${_val}`;
30
34
  return R.assoc(key, key, _acc);
31
35
  },
32
36
  acc,
@@ -15,7 +15,7 @@ describe('getNotDisplayedIds tests', () => {
15
15
  const annotations = [
16
16
  { type: 'test0' },
17
17
  { type: 'test1' },
18
- { type: 'NOT_DISPLAYED', title: 'd0,d1=,d2=v0,d3=v0+,d4=v0+v1' },
18
+ { type: 'NOT_DISPLAYED', title: 'd0,d1=,d2=v0,d3=v0+,d4=v0+v1,d5=(v0+v1)+v2,d6=(v0+v1),d7=(v0+v1,d8=v0+v1),d9=()' },
19
19
  { type: 'test2' },
20
20
  ];
21
21
  const expected = {
@@ -24,7 +24,20 @@ describe('getNotDisplayedIds tests', () => {
24
24
  'd2.v0': 'd2.v0',
25
25
  'd3.v0': 'd3.v0',
26
26
  'd4.v0': 'd4.v0',
27
- 'd4.v1': 'd4.v1'
27
+ 'd4.v1': 'd4.v1',
28
+ 'd5.v0': 'd5.v0',
29
+ 'd5.v1': 'd5.v1',
30
+ 'd5.v2': 'd5.v2',
31
+ 'd6.v0': 'd6.v0',
32
+ 'd6.v1': 'd6.v1',
33
+ 'd7.v0': 'd7.v0',
34
+ 'd7.v1': 'd7.v1',
35
+ 'd8.v0': 'd8.v0',
36
+ 'd8.v1': 'd8.v1',
37
+ d9: 'd9',
38
+
39
+
40
+
28
41
  };
29
42
  expect(getNotDisplayedIds(annotations)).to.deep.equal(expected);
30
43
  });
@@ -61,6 +61,31 @@ describe('getUnitsSeries tests', () => {
61
61
  '2:0:x:x': { A: { value: { index: 2 } }, B: { value: { index: 0 } }, C: { value: { index: 0 } }, serieKey: '2:0:x:x' }
62
62
  });
63
63
  });
64
+ it('empty units test', () => {
65
+ const obs = {
66
+ 0: {
67
+ key: '0:0:0:0',
68
+ units: { serieKey: '0:0:x:x' }
69
+ },
70
+ 1: {
71
+ key: '0:0:1:0',
72
+ units: { serieKey: '0:0:x:x' }
73
+ },
74
+ 2: {
75
+ key: '1:0:0:0',
76
+ units: { serieKey: '1:0:x:x' }
77
+ },
78
+ 3: {
79
+ key: '1:0:1:0',
80
+ units: { serieKey: '1:0:x:x' }
81
+ },
82
+ 4: {
83
+ key: '2:0:0:0',
84
+ units: { serieKey: '2:0:x:x' }
85
+ }
86
+ };
87
+ expect(getUnitsSeries(obs)).to.deep.equal({});
88
+ });
64
89
  });
65
90
 
66
91
  describe('getUnitsSeries tests keys difference', () => {