@sis-cc/dotstatsuite-components 17.12.2 → 17.12.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.
@@ -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 () {
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.3",
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