@sis-cc/dotstatsuite-components 17.4.0 → 17.6.0

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.
@@ -80,7 +80,6 @@ var dataTransformer = exports.dataTransformer = function dataTransformer(dataNew
80
80
  end = reported.end;
81
81
  var reportTimeNote = (0, _date.getReportedTimePeriodNote)(reportYearStart, start, end, options.frequency, options.isRtl);
82
82
  notes = R.isNil(reportTimeNote) ? notes : R.append(reportTimeNote, notes);
83
- //__indexPosition = dateFns.getTime(new Date(R.prop('start', value)));
84
83
  }
85
84
  if (isNaN(__indexPosition)) {
86
85
  __indexPosition = (0, _dotstatsuiteSdmxjs.getCodeOrder)({ annotations: valueAnnotations });
@@ -95,7 +94,7 @@ var dataTransformer = exports.dataTransformer = function dataTransformer(dataNew
95
94
  __indexPosition: __indexPosition,
96
95
  __index: __index
97
96
  });
98
- return isTimeDimension ? (0, _refineTimePeriod.refineTimePeriod)(res, { locale: locale }) : res;
97
+ return isTimeDimension ? (0, _refineTimePeriod.refineTimePeriod)(res, { locale: locale, monthlyFormat: timeFormat }) : res;
99
98
  }), R.ifElse(R.always(isTimeDimension), R.pipe(R.sortWith([R.ascend(function (val) {
100
99
  return _dateFns2.default.getTime(new Date(R.prop('start', val)));
101
100
  }), R.descend(function (val) {
@@ -0,0 +1,68 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.combinedValuesDisplay = exports.singleValueDisplay = undefined;
7
+
8
+ var _ramda = require('ramda');
9
+
10
+ var R = _interopRequireWildcard(_ramda);
11
+
12
+ var _src = require('../../rules/src');
13
+
14
+ var _constants = require('./constants');
15
+
16
+ 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; } }
17
+
18
+ var getRefinedMissinParentsLabels = R.pipe(R.propOr([], 'missingParents'), R.reduce(function (acc, par) {
19
+ if (!R.propOr(true, 'display', par) || R.includes(par.id, _constants.REJECTED_VALUE_IDS)) {
20
+ return acc;
21
+ }
22
+ return R.append((0, _src.dimensionValueDisplay)('label')(par), acc);
23
+ }, []));
24
+
25
+ var singleValueDisplay = exports.singleValueDisplay = function singleValueDisplay(display, value) {
26
+ if (display === 'label') {
27
+ return R.converge(function (missingParents, label) {
28
+ return R.isEmpty(missingParents) ? label : R.join(' > ', R.append(label, missingParents));
29
+ }, [getRefinedMissinParentsLabels, (0, _src.dimensionValueDisplay)(display)])(value);
30
+ } else if (display === 'both') {
31
+ return '(' + singleValueDisplay('code', value) + ') ' + singleValueDisplay('label', value);
32
+ }
33
+ return (0, _src.dimensionValueDisplay)(display)(value);
34
+ };
35
+
36
+ var _combinedValuesDisplay = function _combinedValuesDisplay(_display) {
37
+ return function (values) {
38
+ return R.pipe(R.reduce(function (acc, val) {
39
+ if ((!R.propOr(true, 'display', val) || R.includes(val.id, _constants.REJECTED_VALUE_IDS)) && _display === 'label') {
40
+ return acc;
41
+ }
42
+ return R.append(singleValueDisplay(_display, val), acc);
43
+ }, []), function (labels) {
44
+ if (!R.isEmpty(labels) || _display !== 'label') {
45
+ return R.join(', ', labels);
46
+ }
47
+ var totalValue = R.find(R.propEq('id', '_T'), values);
48
+ if (!R.isNil(totalValue)) {
49
+ return (0, _src.dimensionValueDisplay)('label')(totalValue);
50
+ }
51
+ if (R.isEmpty(values)) {
52
+ return '';
53
+ }
54
+ var firstValue = R.head(values);
55
+ return (0, _src.dimensionValueDisplay)('label')(firstValue);
56
+ })(values);
57
+ };
58
+ };
59
+
60
+ var combinedValuesDisplay = exports.combinedValuesDisplay = function combinedValuesDisplay(display, values) {
61
+ if (display === 'both') {
62
+ return R.converge(function (_ids, labels) {
63
+ var ids = R.isEmpty(_ids) ? _ids : '(' + _ids + ')';
64
+ return R.isEmpty(ids) ? labels : ids + ' ' + labels;
65
+ }, [_combinedValuesDisplay('code'), _combinedValuesDisplay('label')])(values);
66
+ }
67
+ return _combinedValuesDisplay(display)(values);
68
+ };
@@ -11,6 +11,8 @@ var R = _interopRequireWildcard(_ramda);
11
11
 
12
12
  var _src = require('../../rules/src');
13
13
 
14
+ var _combinedValuesDisplay = require('./combinedValuesDisplay');
15
+
14
16
  var _constants = require('./constants');
15
17
 
16
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; } }
@@ -25,30 +27,21 @@ var getHeaderCombinations = exports.getHeaderCombinations = function getHeaderCo
25
27
 
26
28
  var header = (0, _src.dimensionValueDisplay)(display)(comb) + ':';
27
29
 
28
- var combinedDisplay = function combinedDisplay(_display, values) {
29
- if (_display === 'label') {
30
- return R.pipe(R.filter(function (val) {
31
- return R.propOr(true, 'display', val) && !R.includes(val.id, _constants.REJECTED_VALUE_IDS);
32
- }), R.map((0, _src.dimensionValueDisplay)(_display)), R.join(', '))(values);
33
- }
34
- return R.pipe(R.map((0, _src.dimensionValueDisplay)(_display)), R.join(', '))(values);
35
- };
36
-
37
30
  var label = R.pipe(R.reduce(function (_acc, concept) {
38
31
  var artefact = R.has(concept, indexedDimensions) ? R.prop(concept, indexedDimensions) : R.prop(concept, indexedAttributes);
39
- if (R.isNil(artefact) || !R.propOr(true, 'display', artefact || {})) {
32
+ if (R.isNil(artefact)) {
40
33
  return _acc;
41
34
  }
42
35
  var value = R.path(['values', 0], artefact);
43
36
  if (R.isNil(value)) {
44
37
  return _acc;
45
38
  }
39
+ if (R.has(concept, indexedAttributes) && (!R.propOr(true, 'display', value) || !R.propOr(true, 'artefact', value) || R.includes(value.id, _constants.REJECTED_VALUE_IDS))) {
40
+ return _acc;
41
+ }
46
42
  return R.append(value, _acc);
47
43
  }, []), function (values) {
48
- if (display === 'both') {
49
- return '(' + combinedDisplay('code', values) + ') ' + combinedDisplay('label', values);
50
- }
51
- return combinedDisplay(display, values);
44
+ return (0, _combinedValuesDisplay.combinedValuesDisplay)(display, values);
52
45
  })(comb.concepts || []);
53
46
  if (R.isEmpty(label)) {
54
47
  return acc;
@@ -61,7 +61,7 @@ var getFormat = function getFormat(freqDisplay) {
61
61
  if (freqDisplay === 'S') {
62
62
  return 'HH:mm:ss';
63
63
  }
64
- return 'MMM';
64
+ return 'YYYY-MMM';
65
65
  };
66
66
 
67
67
  var getEndDate = function getEndDate(start, mult, duration) {
@@ -75,26 +75,32 @@ var getEndDate = function getEndDate(start, mult, duration) {
75
75
  return dateFns.subSeconds(endDate, 1);
76
76
  };
77
77
 
78
- var computeName = function computeName(start, end, freqDisplay, locale) {
78
+ var computeName = function computeName(start, end, freqDisplay, locale, format) {
79
79
  var opts = { locale: (0, _date.getLocale)(locale) };
80
80
  var isSameDay = dateFns.isSameDay(start, end);
81
81
  var isSameYear = dateFns.isSameYear(start, end);
82
82
  if (freqDisplay === 'H' || freqDisplay === 'm' || freqDisplay === 'S') {
83
83
  var dayFormat = getFormat('D');
84
- var timeFormat = getFormat(freqDisplay);
85
- if (isSameDay) return dateFns.format(start, dayFormat, opts) + ' ' + dateFns.format(start, timeFormat, opts) + ' - ' + dateFns.format(end, timeFormat, opts);
86
- return dateFns.format(start, dayFormat + ' ' + timeFormat, opts) + ' - ' + dateFns.format(end, dayFormat + ' ' + timeFormat, opts);
84
+ if (isSameDay) return dateFns.format(start, dayFormat, opts) + ' ' + dateFns.format(start, format, opts) + ' - ' + dateFns.format(end, format, opts);
85
+ return dateFns.format(start, dayFormat + ' ' + format, opts) + ' - ' + dateFns.format(end, dayFormat + ' ' + format, opts);
87
86
  }
88
- if (freqDisplay === 'D' || freqDisplay === 'Y') {
89
- var _format = getFormat(freqDisplay);
90
- return dateFns.format(start, _format, opts) + ' - ' + dateFns.format(end, _format, opts);
87
+ if (freqDisplay !== 'M') {
88
+ return dateFns.format(start, format, opts) + ' - ' + dateFns.format(end, format, opts);
91
89
  }
92
- var yearFormat = getFormat('Y');
93
- var monthFormat = getFormat('M');
94
- if (isSameYear && locale === 'fr') {
95
- return dateFns.format(start, monthFormat, opts) + ' - ' + dateFns.format(end, monthFormat, opts) + ' ' + dateFns.format(start, yearFormat, opts);
90
+
91
+ if (isSameYear && !R.includes('-', format)) {
92
+ var yearFormatMatch = R.match(/([Y]+)/, format);
93
+ var monthFormatMatch = R.match(/([M]+|Mo)/, format);
94
+ var yearFormat = R.length(yearFormatMatch) >= 2 ? R.nth(1, yearFormatMatch) : null;
95
+ var monthFormat = R.length(monthFormatMatch) >= 2 ? R.nth(1, monthFormatMatch) : null;
96
+ var formattedYear = yearFormat ? dateFns.format(start, yearFormat, opts) : null;
97
+ var formattedMonths = monthFormat ? dateFns.format(start, monthFormat, opts) + ' - ' + dateFns.format(end, monthFormat, opts) : null;
98
+ if (monthFormat) {
99
+ return R.pipe(function (format) {
100
+ return yearFormat ? R.replace(yearFormat, formattedYear, format) : format;
101
+ }, R.replace(monthFormat, formattedMonths))(format);
102
+ }
96
103
  }
97
- var format = locale === 'fr' ? monthFormat + ' ' + yearFormat : yearFormat + '-' + monthFormat;
98
104
  return dateFns.format(start, format, opts) + ' - ' + dateFns.format(end, format, opts);
99
105
  };
100
106
 
@@ -107,7 +113,9 @@ var getStartDate = exports.getStartDate = function getStartDate(start) {
107
113
  };
108
114
 
109
115
  var refineTimePeriod = exports.refineTimePeriod = function refineTimePeriod(timePeriod, _ref) {
110
- var locale = _ref.locale;
116
+ var locale = _ref.locale,
117
+ _ref$monthlyFormat = _ref.monthlyFormat,
118
+ monthlyFormat = _ref$monthlyFormat === undefined ? 'YYYY-MMM' : _ref$monthlyFormat;
111
119
  var id = timePeriod.id;
112
120
 
113
121
  var split = R.split('/', id);
@@ -136,7 +144,8 @@ var refineTimePeriod = exports.refineTimePeriod = function refineTimePeriod(time
136
144
  var duration = !R.isEmpty(timeIndicator) && _duration === 'M' ? 'm' : _duration;
137
145
  var endDate = getEndDate(startDate, mult, duration);
138
146
  var freqDisplay = computeDisplayFreq(start, duration);
139
- var name = computeName((0, _date.dateWithoutTZ)(startDate), (0, _date.dateWithoutTZ)(endDate), freqDisplay, locale);
147
+ var format = freqDisplay === 'M' ? monthlyFormat : getFormat(freqDisplay);
148
+ var name = computeName((0, _date.dateWithoutTZ)(startDate), (0, _date.dateWithoutTZ)(endDate), freqDisplay, locale, format);
140
149
  return (0, _extends3.default)({}, timePeriod, {
141
150
  id: id,
142
151
  name: name,
@@ -9,49 +9,12 @@ var _ramda = require('ramda');
9
9
 
10
10
  var R = _interopRequireWildcard(_ramda);
11
11
 
12
- var _src = require('../../../rules/src');
13
-
14
- var _constants = require('../constants');
12
+ var _combinedValuesDisplay = require('../combinedValuesDisplay');
15
13
 
16
14
  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; } }
17
15
 
18
- var getRefinedMissinParentsLabels = R.pipe(R.propOr([], 'missingParents'), R.reduce(function (acc, par) {
19
- if (!R.propOr(true, 'display', par) || R.includes(par.id, _constants.REJECTED_VALUE_IDS)) {
20
- return acc;
21
- }
22
- return R.append((0, _src.dimensionValueDisplay)('label')(par), acc);
23
- }, []));
24
-
25
- var granularDisplay = function granularDisplay(display, value) {
26
- if (display === 'label') {
27
- return R.converge(function (missingParents, label) {
28
- return R.isEmpty(missingParents) ? label : R.join(' > ', R.append(label, missingParents));
29
- }, [getRefinedMissinParentsLabels, (0, _src.dimensionValueDisplay)(display)])(value);
30
- } else if (display === 'both') {
31
- return '(' + granularDisplay('code', value) + ') ' + granularDisplay('label', value);
32
- }
33
- return (0, _src.dimensionValueDisplay)(display)(value);
34
- };
35
-
36
- var combinedDisplay = function combinedDisplay(_display) {
37
- return R.pipe(R.reduce(function (acc, val) {
38
- if ((!R.propOr(true, 'display', val) || R.includes(val.id, _constants.REJECTED_VALUE_IDS)) && _display === 'label') {
39
- return acc;
40
- }
41
- return R.append(granularDisplay(_display, val), acc);
42
- }, []), R.join(', '));
43
- };
44
-
45
16
  var getTableLabelAccessor = exports.getTableLabelAccessor = function getTableLabelAccessor(display) {
46
- return function (item) {
47
- if (!R.is(Array, item)) {
48
- return granularDisplay(display, item);
49
- }
50
- if (display === 'both') {
51
- return R.converge(function (ids, labels) {
52
- return '(' + ids + ') ' + labels;
53
- }, [combinedDisplay('code'), combinedDisplay('label')])(item);
54
- }
55
- return combinedDisplay(display)(item);
17
+ return function (content) {
18
+ return R.is(Array, content) ? (0, _combinedValuesDisplay.combinedValuesDisplay)(display, content) : (0, _combinedValuesDisplay.singleValueDisplay)(display, content);
56
19
  };
57
20
  };
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.4.0",
4
+ "version": "17.6.0",
5
5
  "main": "lib/index.js",
6
6
  "author": "OECD",
7
7
  "license": "MIT",
@@ -56,7 +56,6 @@ export const dataTransformer = (dataNew, options = {}) => {
56
56
  end = reported.end;
57
57
  const reportTimeNote = getReportedTimePeriodNote(reportYearStart, start, end, options.frequency, options.isRtl);
58
58
  notes = R.isNil(reportTimeNote) ? notes : R.append(reportTimeNote, notes);
59
- //__indexPosition = dateFns.getTime(new Date(R.prop('start', value)));
60
59
  }
61
60
  if (isNaN(__indexPosition)) {
62
61
  __indexPosition = getCodeOrder({ annotations: valueAnnotations });
@@ -78,7 +77,7 @@ export const dataTransformer = (dataNew, options = {}) => {
78
77
  __indexPosition,
79
78
  __index,
80
79
  });
81
- return isTimeDimension ? refineTimePeriod(res, { locale }) : res;
80
+ return isTimeDimension ? refineTimePeriod(res, { locale, monthlyFormat: timeFormat }) : res;
82
81
  }),
83
82
  R.ifElse(
84
83
  R.always(isTimeDimension),
@@ -0,0 +1,66 @@
1
+ import * as R from 'ramda';
2
+ import { dimensionValueDisplay } from '../../rules/src';
3
+ import { REJECTED_VALUE_IDS } from './constants';
4
+
5
+ const getRefinedMissinParentsLabels = R.pipe(
6
+ R.propOr([], 'missingParents'),
7
+ R.reduce((acc, par) => {
8
+ if (!R.propOr(true, 'display', par) || R.includes(par.id, REJECTED_VALUE_IDS)) {
9
+ return acc;
10
+ }
11
+ return R.append(dimensionValueDisplay('label')(par), acc);
12
+ }, []),
13
+ );
14
+
15
+ 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
+ };
30
+
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);
54
+
55
+ export const combinedValuesDisplay = (display, values) => {
56
+ 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);
64
+ }
65
+ return _combinedValuesDisplay(display)(values);
66
+ };
@@ -1,5 +1,6 @@
1
1
  import * as R from 'ramda';
2
2
  import { dimensionValueDisplay } from '../../rules/src';
3
+ import { combinedValuesDisplay } from './combinedValuesDisplay';
3
4
  import { REJECTED_VALUE_IDS } from './constants';
4
5
 
5
6
  export const getHeaderCombinations = (combinations, dimensions, attributes, display) => {
@@ -13,40 +14,28 @@ export const getHeaderCombinations = (combinations, dimensions, attributes, disp
13
14
 
14
15
  const header = `${dimensionValueDisplay(display)(comb)}:`;
15
16
 
16
- const combinedDisplay = (_display, values) => {
17
- if (_display === 'label') {
18
- return R.pipe(
19
- R.filter(val => R.propOr(true, 'display', val) && !R.includes(val.id, REJECTED_VALUE_IDS)),
20
- R.map(dimensionValueDisplay(_display)),
21
- R.join(', ')
22
- )(values);
23
- }
24
- return R.pipe(R.map(dimensionValueDisplay(_display)), R.join(', '))(values);
25
- };
26
-
27
17
  const label = R.pipe(
28
18
  R.reduce(
29
19
  (_acc, concept) => {
30
20
  const artefact = R.has(concept, indexedDimensions)
31
21
  ? R.prop(concept, indexedDimensions)
32
22
  : R.prop(concept, indexedAttributes);
33
- if (R.isNil(artefact) || !R.propOr(true, 'display', artefact || {})) {
23
+ if (R.isNil(artefact)) {
34
24
  return _acc;
35
25
  }
36
26
  const value = R.path(['values', 0], artefact);
37
27
  if (R.isNil(value)) {
38
28
  return _acc;
39
29
  }
30
+ if (R.has(concept, indexedAttributes) && (!R.propOr(true, 'display', value)
31
+ || !R.propOr(true, 'artefact', value) || R.includes(value.id, REJECTED_VALUE_IDS))) {
32
+ return _acc;
33
+ }
40
34
  return R.append(value, _acc);
41
35
  },
42
36
  []
43
37
  ),
44
- values => {
45
- if (display === 'both') {
46
- return `(${combinedDisplay('code', values)}) ${combinedDisplay('label', values)}`
47
- }
48
- return combinedDisplay(display, values);
49
- }
38
+ values => combinedValuesDisplay(display, values)
50
39
  )(comb.concepts || []);
51
40
  if (R.isEmpty(label)) {
52
41
  return acc;
@@ -47,7 +47,7 @@ const getFormat = (freqDisplay) => {
47
47
  if (freqDisplay === 'S') {
48
48
  return 'HH:mm:ss';
49
49
  }
50
- return 'MMM';
50
+ return 'YYYY-MMM';
51
51
  }
52
52
 
53
53
  const getEndDate = (start, mult, duration) => {
@@ -61,27 +61,34 @@ const getEndDate = (start, mult, duration) => {
61
61
  return dateFns.subSeconds(endDate, 1);
62
62
  };
63
63
 
64
- const computeName = (start, end, freqDisplay, locale) => {
64
+ const computeName = (start, end, freqDisplay, locale, format) => {
65
65
  const opts = { locale: getLocale(locale) };
66
66
  const isSameDay = dateFns.isSameDay(start, end);
67
67
  const isSameYear = dateFns.isSameYear(start, end);
68
68
  if (freqDisplay === 'H' || freqDisplay === 'm' || freqDisplay === 'S') {
69
69
  const dayFormat = getFormat('D');
70
- const timeFormat = getFormat(freqDisplay);
71
70
  if (isSameDay)
72
- return `${dateFns.format(start, dayFormat, opts)} ${dateFns.format(start, timeFormat, opts)} - ${dateFns.format(end, timeFormat, opts)}`;
73
- return `${dateFns.format(start, `${dayFormat} ${timeFormat}`, opts)} - ${dateFns.format(end, `${dayFormat} ${timeFormat}`, opts)}`;
71
+ return `${dateFns.format(start, dayFormat, opts)} ${dateFns.format(start, format, opts)} - ${dateFns.format(end, format, opts)}`;
72
+ return `${dateFns.format(start, `${dayFormat} ${format}`, opts)} - ${dateFns.format(end, `${dayFormat} ${format}`, opts)}`;
74
73
  }
75
- if (freqDisplay === 'D' || freqDisplay === 'Y') {
76
- const format = getFormat(freqDisplay);
74
+ if (freqDisplay !== 'M') {
77
75
  return `${dateFns.format(start, format, opts)} - ${dateFns.format(end, format, opts)}`;
78
76
  }
79
- const yearFormat = getFormat('Y');
80
- const monthFormat = getFormat('M');
81
- if (isSameYear && locale === 'fr') {
82
- return `${dateFns.format(start, monthFormat, opts)} - ${dateFns.format(end, monthFormat, opts)} ${dateFns.format(start, yearFormat, opts)}`;
77
+
78
+ if (isSameYear && !R.includes('-', format)) {
79
+ const yearFormatMatch = R.match(/([Y]+)/, format);
80
+ const monthFormatMatch = R.match(/([M]+|Mo)/, format);
81
+ const yearFormat = R.length(yearFormatMatch) >= 2 ? R.nth(1, yearFormatMatch) : null;
82
+ const monthFormat = R.length(monthFormatMatch) >= 2 ? R.nth(1, monthFormatMatch) : null;
83
+ const formattedYear = yearFormat ? dateFns.format(start, yearFormat, opts) : null;
84
+ const formattedMonths = monthFormat ? `${dateFns.format(start, monthFormat, opts)} - ${dateFns.format(end, monthFormat, opts)}` : null;
85
+ if (monthFormat) {
86
+ return R.pipe(
87
+ format => yearFormat ? R.replace(yearFormat, formattedYear, format) : format,
88
+ R.replace(monthFormat, formattedMonths)
89
+ )(format);
90
+ }
83
91
  }
84
- const format = locale === 'fr' ? `${monthFormat} ${yearFormat}` : `${yearFormat}-${monthFormat}`;
85
92
  return `${dateFns.format(start, format, opts)} - ${dateFns.format(end, format, opts)}`;
86
93
  };
87
94
 
@@ -93,7 +100,7 @@ export const getStartDate = (start) => {
93
100
  return dateFns.addMinutes(date, -date.getTimezoneOffset());
94
101
  };
95
102
 
96
- export const refineTimePeriod = (timePeriod, { locale }) => {
103
+ export const refineTimePeriod = (timePeriod, { locale, monthlyFormat='YYYY-MMM' }) => {
97
104
  const { id } = timePeriod;
98
105
  const split = R.split('/', id);
99
106
  if (R.length(split) !== 2) {
@@ -111,7 +118,8 @@ export const refineTimePeriod = (timePeriod, { locale }) => {
111
118
  const duration = !R.isEmpty(timeIndicator) && _duration === 'M' ? 'm' : _duration;
112
119
  const endDate = getEndDate(startDate, mult, duration);
113
120
  const freqDisplay = computeDisplayFreq(start, duration);
114
- const name = computeName(dateWithoutTZ(startDate), dateWithoutTZ(endDate), freqDisplay, locale);
121
+ const format = freqDisplay === 'M' ? monthlyFormat : getFormat(freqDisplay);
122
+ const name = computeName(dateWithoutTZ(startDate), dateWithoutTZ(endDate), freqDisplay, locale, format);
115
123
  return ({
116
124
  ...timePeriod,
117
125
  id,
@@ -1,53 +1,9 @@
1
1
  import * as R from 'ramda';
2
- import { dimensionValueDisplay } from '../../../rules/src';
3
- import { REJECTED_VALUE_IDS } from '../constants';
2
+ import { combinedValuesDisplay, singleValueDisplay } from '../combinedValuesDisplay'
4
3
 
5
- const getRefinedMissinParentsLabels = R.pipe(
6
- R.propOr([], 'missingParents'),
7
- R.reduce((acc, par) => {
8
- if (!R.propOr(true, 'display', par) || R.includes(par.id, REJECTED_VALUE_IDS)) {
9
- return acc;
10
- }
11
- return R.append(dimensionValueDisplay('label')(par), acc);
12
- }, []),
13
- );
14
4
 
15
- const granularDisplay = (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 `(${granularDisplay('code', value)}) ${granularDisplay('label', value)}`;
27
- }
28
- return dimensionValueDisplay(display)(value);
29
- };
30
-
31
- const combinedDisplay = _display => 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(granularDisplay(_display, val), acc);
38
- }, []),
39
- R.join(', '),
40
- );
41
-
42
- export const getTableLabelAccessor = display => item => {
43
- if (!R.is(Array, item)) {
44
- return granularDisplay(display, item);
45
- }
46
- if (display === 'both') {
47
- return R.converge((ids, labels) => `(${ids}) ${labels}`, [
48
- combinedDisplay('code'),
49
- combinedDisplay('label'),
50
- ])(item);
51
- }
52
- return combinedDisplay(display)(item);
5
+ export const getTableLabelAccessor = display => content => {
6
+ return R.is(Array, content)
7
+ ? combinedValuesDisplay(display, content)
8
+ : singleValueDisplay(display, content);
53
9
  };
@@ -24,4 +24,39 @@ describe('getHeaderCombinations tests', () => {
24
24
  { header: 'comb 1:', label: 'dim 1 value' }
25
25
  ]);
26
26
  });
27
+ it('not display usecases', () => {
28
+ const dimensions = [
29
+ { id: 'd0', values: [{ id: 'd0v', name: 'd0 value', display: false }] },
30
+ { id: 'd1', values: [{ id: '_T', name: 'Total' }] },
31
+ { id: 'd2', values: [{ id: 'd2v', name: 'd2 value', display: false }] },
32
+ ];
33
+
34
+ const attributes = [
35
+ { id: 'a0', values: [{ id: 'a0v', name: 'a0 value', display: false }] },
36
+ { id: 'a1', values: [{ id: 'a1v', name: 'a1 value', display: false }] },
37
+ { id: 'a2', values: [{ id: '_T', name: 'Total' }] },
38
+ ];
39
+
40
+ const combinations = [
41
+ { id: 'comb0', name: 'combination 0', header: true, concepts: ['a0', 'a1', 'd0'] },
42
+ { id: 'comb1', name: 'combination 1', header: true, concepts: ['d0', 'd2', 'a3'] },
43
+ { id: 'comb2', name: 'combination 2', header: true, concepts: ['d0', 'd1', 'd2'] },
44
+ { id: 'comb3', name: 'combination 3', header: true, concepts: ['a0', 'a1', 'a2'] },
45
+ ];
46
+ expect(getHeaderCombinations(combinations, dimensions, attributes, 'label')).to.deep.equal([
47
+ { header: 'combination 0:', label: 'd0 value' },
48
+ { header: 'combination 1:', label: 'd0 value' },
49
+ { header: 'combination 2:', label: 'Total' },
50
+ ]);
51
+ expect(getHeaderCombinations(combinations, dimensions, attributes, 'code')).to.deep.equal([
52
+ { header: 'comb0:', label: 'd0v' },
53
+ { header: 'comb1:', label: 'd0v, d2v' },
54
+ { header: 'comb2:', label: 'd0v, _T, d2v' },
55
+ ]);
56
+ expect(getHeaderCombinations(combinations, dimensions, attributes, 'both')).to.deep.equal([
57
+ { header: '(comb0) combination 0:', label: '(d0v) d0 value' },
58
+ { header: '(comb1) combination 1:', label: '(d0v, d2v) d0 value' },
59
+ { header: '(comb2) combination 2:', label: '(d0v, _T, d2v) Total' },
60
+ ]);
61
+ })
27
62
  });
@@ -22,4 +22,29 @@ describe('getTableLabelAccessor tests', () => {
22
22
  it('not displayed single value', () => {
23
23
  expect(getTableLabelAccessor('both')(values[0])).to.deep.equal('(V0) Value 0');
24
24
  });
25
+ it('display _T label if all hidden', () => {
26
+ const _values = [
27
+ { id: 'v0', name: 'value 0', display: false },
28
+ { id: 'v1', name: 'value 1', display: false },
29
+ { id: '_T', name: 'Total' },
30
+ { id: 'v3', name: 'value 3', display: false },
31
+ ];
32
+ expect(getTableLabelAccessor('label')(_values)).to.deep.equal('Total');
33
+ expect(getTableLabelAccessor('both')(_values)).to.deep.equal('(v0, v1, _T, v3) Total');
34
+ });
35
+ it('display label first value if all hidden and no _T', () => {
36
+ const _values = [
37
+ { id: 'v0', name: 'value 0', display: false },
38
+ { id: 'v1', name: 'value 1', display: false },
39
+ { id: 'v2', name: 'value 2', display: false },
40
+ { id: 'v3', name: 'value 3', display: false },
41
+ ];
42
+ expect(getTableLabelAccessor('label')(_values)).to.deep.equal('value 0');
43
+ expect(getTableLabelAccessor('both')(_values)).to.deep.equal('(v0, v1, v2, v3) value 0');
44
+ });
45
+ it('empty case', () => {
46
+ expect(getTableLabelAccessor('label')([])).to.deep.equal('');
47
+ expect(getTableLabelAccessor('code')([])).to.deep.equal('');
48
+ expect(getTableLabelAccessor('both')([])).to.deep.equal('');
49
+ });
25
50
  });
@@ -26,7 +26,7 @@ describe('refineTimePeriod tests', () => {
26
26
  });
27
27
  });
28
28
  it('2 years range on March, fr', () => {
29
- expect(refineTimePeriod({ id: '2015-03/P2Y' }, { locale: 'fr' })).to.deep.equal({
29
+ expect(refineTimePeriod({ id: '2015-03/P2Y' }, { locale: 'fr', monthlyFormat: 'MMM YYYY' })).to.deep.equal({
30
30
  id: '2015-03/P2Y',
31
31
  name: 'mars 2015 - févr. 2017',
32
32
  start: '2015-03-01T00:00:00.000Z',
@@ -74,13 +74,29 @@ describe('refineTimePeriod tests', () => {
74
74
  });
75
75
  });
76
76
  it('3 months range, fr', () => {
77
- expect(refineTimePeriod({ id: '2015/P3M' }, { locale: 'fr' })).to.deep.equal({
77
+ expect(refineTimePeriod({ id: '2015/P3M' }, { locale: 'fr', monthlyFormat: 'MMM YYYY' })).to.deep.equal({
78
78
  id: '2015/P3M',
79
79
  name: 'janv. - mars 2015',
80
80
  start: '2015-01-01T00:00:00.000Z',
81
81
  end: '2015-03-31T23:59:59.000Z'
82
82
  });
83
83
  });
84
+ it('3 months range, fr, format = "YY Mo"', () => {
85
+ expect(refineTimePeriod({ id: '2015/P3M' }, { locale: 'fr', monthlyFormat: 'YY Mo' })).to.deep.equal({
86
+ id: '2015/P3M',
87
+ name: '15 1 - 3o',
88
+ start: '2015-01-01T00:00:00.000Z',
89
+ end: '2015-03-31T23:59:59.000Z'
90
+ });
91
+ });
92
+ it('3 months range, fr, format = "MMMM"', () => {
93
+ expect(refineTimePeriod({ id: '2015/P3M' }, { locale: 'fr', monthlyFormat: 'MMMM' })).to.deep.equal({
94
+ id: '2015/P3M',
95
+ name: 'janvier - mars',
96
+ start: '2015-01-01T00:00:00.000Z',
97
+ end: '2015-03-31T23:59:59.000Z'
98
+ });
99
+ });
84
100
  it('19 months range, en', () => {
85
101
  expect(refineTimePeriod({ id: '2015/P19M' }, { locale: 'en' })).to.deep.equal({
86
102
  id: '2015/P19M',
@@ -90,7 +106,7 @@ describe('refineTimePeriod tests', () => {
90
106
  });
91
107
  });
92
108
  it('19 months range, fr', () => {
93
- expect(refineTimePeriod({ id: '2015/P19M' }, { locale: 'fr' })).to.deep.equal({
109
+ expect(refineTimePeriod({ id: '2015/P19M' }, { locale: 'fr', monthlyFormat: 'MMM YYYY' })).to.deep.equal({
94
110
  id: '2015/P19M',
95
111
  name: 'janv. 2015 - juill. 2016',
96
112
  start: '2015-01-01T00:00:00.000Z',
@@ -106,7 +122,7 @@ describe('refineTimePeriod tests', () => {
106
122
  });
107
123
  });
108
124
  it('4 months range from April, fr', () => {
109
- expect(refineTimePeriod({ id: '2015-04/P4M' }, { locale: 'fr' })).to.deep.equal({
125
+ expect(refineTimePeriod({ id: '2015-04/P4M' }, { locale: 'fr', monthlyFormat: 'MMM YYYY' })).to.deep.equal({
110
126
  id: '2015-04/P4M',
111
127
  name: 'avr. - juill. 2015',
112
128
  start: '2015-04-01T00:00:00.000Z',
@@ -122,7 +138,7 @@ describe('refineTimePeriod tests', () => {
122
138
  });
123
139
  });
124
140
  it('2 months range from December, fr', () => {
125
- expect(refineTimePeriod({ id: '2015-12/P2M' }, { locale: 'fr' })).to.deep.equal({
141
+ expect(refineTimePeriod({ id: '2015-12/P2M' }, { locale: 'fr', monthlyFormat: 'MMM YYYY' })).to.deep.equal({
126
142
  id: '2015-12/P2M',
127
143
  name: 'déc. 2015 - janv. 2016',
128
144
  start: '2015-12-01T00:00:00.000Z',