@sis-cc/dotstatsuite-components 17.12.2 → 17.12.4

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.
@@ -32,15 +32,16 @@ var dimensionValueDisplay = exports.dimensionValueDisplay = function dimensionVa
32
32
  return function (dimensionValue) {
33
33
  var id = (0, _get3.default)(dimensionValue, accessors.id || 'id', '');
34
34
  var name = (0, _get3.default)(dimensionValue, accessors.name || 'name', '');
35
+ // a non-coded component (dim | attr) has no name, names nor label
36
+ // the only valid thing to display is the id
37
+ if (dimensionValue.isNonCoded) return id;
35
38
  switch (display) {
36
39
  case 'label':
37
40
  return (0, _isEmpty3.default)(name) ? '[' + id + ']' : name;
38
41
  case 'code':
39
42
  return id;
40
43
  case 'both':
41
- if ((0, _isNil3.default)(id) || (0, _isEmpty3.default)(id)) {
42
- return name;
43
- }
44
+ if ((0, _isNil3.default)(id) || (0, _isEmpty3.default)(id)) return name;
44
45
  return '(' + id + ') ' + name;
45
46
  default:
46
47
  return null;
@@ -93,7 +93,8 @@ var getValuesEnhanced = exports.getValuesEnhanced = function getValuesEnhanced(_
93
93
  start: start ? start.toISOString() : null,
94
94
  notes: notes,
95
95
  __indexPosition: __indexPosition,
96
- __index: __index
96
+ __index: __index,
97
+ isNonCoded: isNonCoded(value)
97
98
  });
98
99
  if (!isNonCoded(value)) {
99
100
  res = R.assoc('name', getName({ isTimeDimension: isTimeDimension, options: options, locale: locale, start: start, reportYearStart: reportYearStart })(value), res);
@@ -86,13 +86,15 @@ var nonCodedValues = [{ value: 'A' }, { value: 'B' }, { value: 'C' }];
86
86
 
87
87
  var expectedValues = function expectedValues() {
88
88
  var skippedValueEntries = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
89
+ var isNonCoded = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
89
90
  return R.addIndex(R.map)(function (value, index) {
90
91
  return (0, _extends3.default)({}, R.omit(R.prepend('names', skippedValueEntries), value), {
91
92
  __index: index,
92
93
  __indexPosition: index,
93
94
  display: true,
94
95
  notes: [],
95
- start: R.propOr(null, 'start', value)
96
+ start: R.propOr(null, 'start', value),
97
+ isNonCoded: isNonCoded
96
98
  });
97
99
  });
98
100
  };
@@ -111,7 +113,7 @@ describe('get values enhanced method', function () {
111
113
  locale: 'en',
112
114
  parent: 'ID'
113
115
  })(nonCodedValues);
114
- (0, _chai.expect)(enhancedValues).to.deep.equal(expectedValues(['name', 'order', 'value'])(values));
116
+ (0, _chai.expect)(enhancedValues).to.deep.equal(expectedValues(['name', 'order', 'value'], true)(values));
115
117
  });
116
118
 
117
119
  it('should pass with time values', function () {
@@ -60,8 +60,10 @@ var _combinedValuesDisplay = function _combinedValuesDisplay(_display) {
60
60
  var combinedValuesDisplay = exports.combinedValuesDisplay = function combinedValuesDisplay(display, values) {
61
61
  if (display === 'both') {
62
62
  return R.converge(function (_ids, labels) {
63
- var ids = R.isEmpty(_ids) ? _ids : '(' + _ids + ')';
64
- return R.isEmpty(ids) ? labels : ids + ' ' + labels;
63
+ return (0, _src.dimensionValueDisplay)('both')({
64
+ id: _ids,
65
+ name: labels
66
+ });
65
67
  }, [_combinedValuesDisplay('code'), _combinedValuesDisplay('label')])(values);
66
68
  }
67
69
  return _combinedValuesDisplay(display)(values);
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": "17.12.2",
4
+ "version": "17.12.4",
5
5
  "main": "lib/index.js",
6
6
  "author": "OECD",
7
7
  "license": "MIT",
@@ -1,38 +1,52 @@
1
1
  import { isEmpty, isNil, get, has, reduce } from 'lodash';
2
2
 
3
- export const dimensionValueDisplay = (display, accessors = {}) => (dimensionValue) => {
4
- const id = get(dimensionValue, accessors.id || 'id', '');
5
- const name = get(dimensionValue, accessors.name || 'name', '');
6
- switch(display) {
7
- case 'label':
8
- return isEmpty(name) ? `[${id}]` : name;
9
- case 'code':
10
- return id;
11
- case 'both':
12
- if (isNil(id) || isEmpty(id)) {
13
- return name;
14
- }
15
- return `(${id}) ${name}`
16
- default:
17
- return null;
18
- }
19
- };
3
+ export const dimensionValueDisplay =
4
+ (display, accessors = {}) =>
5
+ (dimensionValue) => {
6
+ const id = get(dimensionValue, accessors.id || 'id', '');
7
+ const name = get(dimensionValue, accessors.name || 'name', '');
8
+ // a non-coded component (dim | attr) has no name, names nor label
9
+ // the only valid thing to display is the id
10
+ if (dimensionValue.isNonCoded) return id;
11
+ switch (display) {
12
+ case 'label':
13
+ return isEmpty(name) ? `[${id}]` : name;
14
+ case 'code':
15
+ return id;
16
+ case 'both':
17
+ if (isNil(id) || isEmpty(id)) return name;
18
+ return `(${id}) ${name}`;
19
+ default:
20
+ return null;
21
+ }
22
+ };
20
23
 
21
24
  export const dimensionValueDisplayAt = (dimension, index, display) => {
22
25
  const dimensionValue = get(dimension, `values[${Number(index)}]`, {});
23
26
  return dimensionValueDisplay(display)(dimensionValue);
24
27
  };
25
28
 
26
- export const categoryDisplay = (splitObservationKey, dimensions, dimensionsWithValuesIndexedById, rejectedId, display) => {
29
+ export const categoryDisplay = (
30
+ splitObservationKey,
31
+ dimensions,
32
+ dimensionsWithValuesIndexedById,
33
+ rejectedId,
34
+ display,
35
+ ) => {
27
36
  return reduce(
28
37
  splitObservationKey,
29
38
  (memo, dimensionValueIndex, dimensionIndex) => {
30
39
  const dimension = get(dimensions, `[${dimensionIndex}]`, {});
31
- if (has(dimensionsWithValuesIndexedById, dimension.id) && dimension.id !== rejectedId) {
32
- memo.push(dimensionValueDisplayAt(dimension, dimensionValueIndex, display));
40
+ if (
41
+ has(dimensionsWithValuesIndexedById, dimension.id) &&
42
+ dimension.id !== rejectedId
43
+ ) {
44
+ memo.push(
45
+ dimensionValueDisplayAt(dimension, dimensionValueIndex, display),
46
+ );
33
47
  }
34
48
  return memo;
35
49
  },
36
- []
50
+ [],
37
51
  ).join(' - ');
38
- };
52
+ };
@@ -77,6 +77,7 @@ export const getValuesEnhanced = ({
77
77
  notes,
78
78
  __indexPosition,
79
79
  __index,
80
+ isNonCoded: isNonCoded(value),
80
81
  };
81
82
  if (!isNonCoded(value)) {
82
83
  res = R.assoc(
@@ -104,9 +105,7 @@ export const getValuesEnhanced = ({
104
105
  );
105
106
  };
106
107
 
107
- const getDateForSort = (key) => (val) => {
108
- return dateFns.getTime(new Date(R.prop(key, val)));
109
- };
108
+ const getDateForSort = (key) => (val) => dateFns.getTime(new Date(R.prop(key, val)));
110
109
  const byStartDate = R.ascend(getDateForSort('start'));
111
110
  const byEndDate = R.descend(getDateForSort('end'));
112
111
  const timeDimensionSorts = [byStartDate, byEndDate];
@@ -82,7 +82,7 @@ const expectedTimeValues = [
82
82
 
83
83
  const nonCodedValues = [{ value: 'A' }, { value: 'B' }, { value: 'C' }];
84
84
 
85
- const expectedValues = (skippedValueEntries = []) => R.addIndex(R.map)((value, index) => {
85
+ const expectedValues = (skippedValueEntries = [], isNonCoded = false) => R.addIndex(R.map)((value, index) => {
86
86
  return {
87
87
  ...R.omit(R.prepend('names', skippedValueEntries), value),
88
88
  __index: index,
@@ -90,6 +90,7 @@ const expectedValues = (skippedValueEntries = []) => R.addIndex(R.map)((value, i
90
90
  display: true,
91
91
  notes: [],
92
92
  start: R.propOr(null, 'start', value),
93
+ isNonCoded,
93
94
  };
94
95
  });
95
96
 
@@ -108,7 +109,7 @@ describe('get values enhanced method', () => {
108
109
  parent: 'ID',
109
110
  })(nonCodedValues);
110
111
  expect(enhancedValues).to.deep.equal(
111
- expectedValues(['name', 'order', 'value'])(values),
112
+ expectedValues(['name', 'order', 'value'], true)(values),
112
113
  );
113
114
  });
114
115
 
@@ -5,7 +5,10 @@ import { REJECTED_VALUE_IDS } from './constants';
5
5
  const getRefinedMissinParentsLabels = R.pipe(
6
6
  R.propOr([], 'missingParents'),
7
7
  R.reduce((acc, par) => {
8
- if (!R.propOr(true, 'display', par) || R.includes(par.id, REJECTED_VALUE_IDS)) {
8
+ if (
9
+ !R.propOr(true, 'display', par) ||
10
+ R.includes(par.id, REJECTED_VALUE_IDS)
11
+ ) {
9
12
  return acc;
10
13
  }
11
14
  return R.append(dimensionValueDisplay('label')(par), acc);
@@ -13,54 +16,62 @@ const getRefinedMissinParentsLabels = R.pipe(
13
16
  );
14
17
 
15
18
  export const singleValueDisplay = (display, value) => {
16
- if (display === 'label') {
17
- return R.converge(
18
- (missingParents, label) =>
19
- R.isEmpty(missingParents) ? label : R.join(' > ', R.append(label, missingParents)),
20
- [
21
- getRefinedMissinParentsLabels,
22
- dimensionValueDisplay(display),
23
- ],
24
- )(value);
25
- } else if (display === 'both') {
26
- return `(${singleValueDisplay('code', value)}) ${singleValueDisplay('label', value)}`;
27
- }
28
- return dimensionValueDisplay(display)(value);
29
- };
19
+ if (display === 'label') {
20
+ return R.converge(
21
+ (missingParents, label) =>
22
+ R.isEmpty(missingParents)
23
+ ? label
24
+ : R.join(' > ', R.append(label, missingParents)),
25
+ [getRefinedMissinParentsLabels, dimensionValueDisplay(display)],
26
+ )(value);
27
+ } else if (display === 'both') {
28
+ return `(${singleValueDisplay('code', value)}) ${singleValueDisplay(
29
+ 'label',
30
+ value,
31
+ )}`;
32
+ }
33
+ return dimensionValueDisplay(display)(value);
34
+ };
30
35
 
31
- const _combinedValuesDisplay = _display => values => R.pipe(
32
- R.reduce((acc, val) => {
33
- if ((!R.propOr(true, 'display', val) || R.includes(val.id, REJECTED_VALUE_IDS))
34
- && _display === 'label') {
35
- return acc;
36
- }
37
- return R.append(singleValueDisplay(_display, val), acc);
38
- }, []),
39
- labels => {
40
- if (!R.isEmpty(labels) || _display !== 'label') {
41
- return R.join(', ', labels);
42
- }
43
- const totalValue = R.find(R.propEq('id', '_T'), values);
44
- if (!R.isNil(totalValue)) {
45
- return dimensionValueDisplay('label')(totalValue);
46
- }
47
- if (R.isEmpty(values)) {
48
- return '';
49
- }
50
- const firstValue = R.head(values);
51
- return dimensionValueDisplay('label')(firstValue);
52
- },
53
- )(values);
36
+ const _combinedValuesDisplay = (_display) => (values) =>
37
+ R.pipe(
38
+ R.reduce((acc, val) => {
39
+ if (
40
+ (!R.propOr(true, 'display', val) ||
41
+ R.includes(val.id, REJECTED_VALUE_IDS)) &&
42
+ _display === 'label'
43
+ ) {
44
+ return acc;
45
+ }
46
+ return R.append(singleValueDisplay(_display, val), acc);
47
+ }, []),
48
+ (labels) => {
49
+ if (!R.isEmpty(labels) || _display !== 'label') {
50
+ return R.join(', ', labels);
51
+ }
52
+ const totalValue = R.find(R.propEq('id', '_T'), values);
53
+ if (!R.isNil(totalValue)) {
54
+ return dimensionValueDisplay('label')(totalValue);
55
+ }
56
+ if (R.isEmpty(values)) {
57
+ return '';
58
+ }
59
+ const firstValue = R.head(values);
60
+ return dimensionValueDisplay('label')(firstValue);
61
+ },
62
+ )(values);
54
63
 
55
64
  export const combinedValuesDisplay = (display, values) => {
56
65
  if (display === 'both') {
57
- return R.converge((_ids, labels) => {
58
- const ids = R.isEmpty(_ids) ? _ids : `(${_ids})`;
59
- return R.isEmpty(ids) ? labels : `${ids} ${labels}`;
60
- }, [
61
- _combinedValuesDisplay('code'),
62
- _combinedValuesDisplay('label'),
63
- ])(values);
66
+ return R.converge(
67
+ (_ids, labels) => {
68
+ return dimensionValueDisplay('both')({
69
+ id: _ids,
70
+ name: labels,
71
+ });
72
+ },
73
+ [_combinedValuesDisplay('code'), _combinedValuesDisplay('label')],
74
+ )(values);
64
75
  }
65
76
  return _combinedValuesDisplay(display)(values);
66
77
  };