@sis-cc/dotstatsuite-components 15.0.16 → 15.0.17

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.
@@ -18,20 +18,24 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
18
18
  function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
19
19
 
20
20
  var isValidNumber = R.both(R.is(Number), R.complement(R.equals(NaN)));
21
+ var parseValidNumber = R.pipe(function (v) {
22
+ return R.isNil(v) ? null : Number(v);
23
+ }, function (v) {
24
+ return isNaN(v) ? null : v;
25
+ });
21
26
 
22
27
  var getFormatAttributesValues = function getFormatAttributesValues(observation, formatAttributesIndexes, attributes) {
23
28
  return R.mapObjIndexed(function (attributeIndex) {
24
- var valueIndex = R.pipe(R.propOr([], 'attrValuesIndexes'), R.nth(attributeIndex), function (v) {
25
- return R.isNil(v) ? null : Number(v);
26
- }, function (v) {
27
- return isNaN(v) ? null : v;
28
- })(observation);
29
+ var valueIndex = void 0;
30
+ var relationship = R.pipe(R.nth(attributeIndex), R.propOr({}, 'relationship'))(attributes);
31
+ //if (!R.isNil(attributeIndex) && attributeIndex >= R.length(R.propOr([], 'attrValuesIndexes', observation))) {
32
+ if (R.has('none', relationship) || R.has('dataflow', relationship)) {
33
+ valueIndex = 0;
34
+ } else {
35
+ valueIndex = R.pipe(R.propOr([], 'attrValuesIndexes'), R.nth(attributeIndex), parseValidNumber)(observation);
36
+ }
29
37
 
30
- return R.pipe(R.path([attributeIndex, 'values', valueIndex, 'id']), function (v) {
31
- return R.isNil(v) ? null : Number(v);
32
- }, function (v) {
33
- return isNaN(v) ? null : v;
34
- })(attributes);
38
+ return R.pipe(R.path([attributeIndex, 'values', valueIndex, 'id']), parseValidNumber)(attributes);
35
39
  }, formatAttributesIndexes);
36
40
  };
37
41
 
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.16",
4
+ "version": "15.0.17",
5
5
  "main": "lib/index.js",
6
6
  "author": "OECD",
7
7
  "license": "MIT",
@@ -2,20 +2,30 @@ import * as R from 'ramda';
2
2
  import numeral from 'numeral';
3
3
 
4
4
  const isValidNumber = R.both(R.is(Number), R.complement(R.equals(NaN)));
5
+ const parseValidNumber = R.pipe(
6
+ v => R.isNil(v) ? null : Number(v),
7
+ v => isNaN(v) ? null : v
8
+ );
5
9
 
6
10
  const getFormatAttributesValues = (observation, formatAttributesIndexes, attributes) => R.mapObjIndexed(
7
11
  attributeIndex => {
8
- const valueIndex = R.pipe(
9
- R.propOr([], 'attrValuesIndexes'),
10
- R.nth(attributeIndex),
11
- v => R.isNil(v) ? null : Number(v),
12
- v => isNaN(v) ? null : v
13
- )(observation);
12
+ let valueIndex;
13
+ const relationship = R.pipe(R.nth(attributeIndex), R.propOr({}, 'relationship'))(attributes);
14
+ //if (!R.isNil(attributeIndex) && attributeIndex >= R.length(R.propOr([], 'attrValuesIndexes', observation))) {
15
+ if (R.has('none', relationship) || R.has('dataflow', relationship)) {
16
+ valueIndex = 0;
17
+ }
18
+ else {
19
+ valueIndex = R.pipe(
20
+ R.propOr([], 'attrValuesIndexes'),
21
+ R.nth(attributeIndex),
22
+ parseValidNumber
23
+ )(observation);
24
+ }
14
25
 
15
26
  return R.pipe(
16
27
  R.path([attributeIndex, 'values', valueIndex, 'id']),
17
- v => R.isNil(v) ? null : Number(v),
18
- v => isNaN(v) ? null : v
28
+ parseValidNumber
19
29
  )(attributes);
20
30
  },
21
31
  formatAttributesIndexes
@@ -312,5 +312,29 @@ describe('enhanceObservations tests', () => {
312
312
  },
313
313
  })
314
314
  })
315
+ it('apply format attrs from dataflow level', () => {
316
+ const observations = {
317
+ a: { value: 2.358, attrValuesIndexes: [], dimValuesIndexes: [] },
318
+ b: { value: 10.578, attrValuesIndexes: [], dimValuesIndexes: [] },
319
+ };
320
+
321
+ const attributes = [
322
+ { id: 'PREF', relationship: { none: {} }, values: [{ id: '-1' }] },
323
+ { id: 'DEC', relationship: { dataflow: {} }, values: [{ id: '1' }] }
324
+ ];
325
+
326
+ const options = {
327
+ noDisplayIndexes: [],
328
+ notDisplayedCodes: {},
329
+ attributesIds: [],
330
+ unitsIds: [],
331
+ rejectedValueIds: [],
332
+ customAttributes: { prefscale: 'PREF', decimals: 'DEC' }
333
+ };
334
+ expect(enhanceObservations([], observations, attributes, options)).to.deep.equal({
335
+ a: { attributes: {}, units: { serieKey: '' }, value: 2.358, formattedValue: '23.6', attrValuesIndexes: [], dimValuesIndexes: [], indexedDimValIds: {} },
336
+ b: { attributes: {}, units: { serieKey: '' }, value: 10.578, formattedValue: '105.8', attrValuesIndexes: [], dimValuesIndexes: [], indexedDimValIds: {} },
337
+ });
338
+ });
315
339
  });
316
340