@dhis2/analytics 24.8.0 → 24.9.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.
package/CHANGELOG.md CHANGED
@@ -1,8 +1,48 @@
1
- # [24.8.0](https://github.com/dhis2/analytics/compare/v24.7.0...v24.8.0) (2023-02-16)
1
+ # [24.9.0](https://github.com/dhis2/analytics/compare/v24.8.0...v24.9.0) (2023-02-24)
2
+
3
+
4
+ ### Features
5
+
6
+ * merge multi-calendar support from alpha to master ([#1434](https://github.com/dhis2/analytics/issues/1434)) ([3cdac8f](https://github.com/dhis2/analytics/commit/3cdac8fdefc7a15a3fef0940183ca92f03b0f57c))
7
+
8
+ # [24.9.0-alpha.1](https://github.com/dhis2/analytics/compare/v24.8.0...v24.9.0-alpha.1) (2023-02-23)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * bump multi-calendar-dates to avoid jest config change ([3e5892a](https://github.com/dhis2/analytics/commit/3e5892aa88a087dde3405a518625f4c6e637d17e))
14
+ * ensure date falls back to year if no eraYear present ([2a197d5](https://github.com/dhis2/analytics/commit/2a197d57be8ac2af6dbe331dd8f11ab9069afa5d))
15
+
16
+
17
+ ### Features
18
+
19
+ * localise fixed periods according to user settings ([c640c90](https://github.com/dhis2/analytics/commit/c640c90ce2d1944a14706507284af43c7480fa2a))
20
+ * use multi-calendar-dates library to generate fixed periods ([acc3801](https://github.com/dhis2/analytics/commit/acc380156092f888cfa55f70b4bade1c6516d034))
21
+
22
+ # [24.5.0-alpha.3](https://github.com/dhis2/analytics/compare/v24.5.0-alpha.2...v24.5.0-alpha.3) (2023-02-23)
2
23
 
3
24
 
4
25
  ### Features
5
26
 
27
+ * localise fixed periods according to user settings ([c640c90](https://github.com/dhis2/analytics/commit/c640c90ce2d1944a14706507284af43c7480fa2a))
28
+
29
+ # [24.5.0-alpha.2](https://github.com/dhis2/analytics/compare/v24.5.0-alpha.1...v24.5.0-alpha.2) (2023-02-14)
30
+
31
+
32
+ ### Bug Fixes
33
+
34
+ * bump multi-calendar-dates to avoid jest config change ([3e5892a](https://github.com/dhis2/analytics/commit/3e5892aa88a087dde3405a518625f4c6e637d17e))
35
+
36
+ # [24.5.0-alpha.1](https://github.com/dhis2/analytics/compare/v24.4.2...v24.5.0-alpha.1) (2023-02-07)
37
+
38
+
39
+ ### Bug Fixes
40
+
41
+ * ensure date falls back to year if no eraYear present ([2a197d5](https://github.com/dhis2/analytics/commit/2a197d57be8ac2af6dbe331dd8f11ab9069afa5d))
42
+
43
+ # [24.8.0](https://github.com/dhis2/analytics/compare/v24.7.0...v24.8.0) (2023-02-16)
44
+
45
+
6
46
  * add prop for controlling user org unit selector DHIS2-14744 ([#1430](https://github.com/dhis2/analytics/issues/1430)) ([02d3057](https://github.com/dhis2/analytics/commit/02d3057c7c090e293ba7c3057720f491e71457ec))
7
47
 
8
48
  # [24.7.0](https://github.com/dhis2/analytics/compare/v24.6.0...v24.7.0) (2023-02-15)
@@ -5,6 +5,8 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
 
8
+ var _appRuntime = require("@dhis2/app-runtime");
9
+
8
10
  var _propTypes = _interopRequireDefault(require("prop-types"));
9
11
 
10
12
  var _react = _interopRequireDefault(require("react"));
@@ -15,6 +17,15 @@ var _PeriodTransfer = _interopRequireDefault(require("./PeriodTransfer.js"));
15
17
 
16
18
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
19
 
20
+ const userSettingsQuery = {
21
+ userSettings: {
22
+ resource: 'userSettings',
23
+ params: {
24
+ key: ['keyUiLocale']
25
+ }
26
+ }
27
+ };
28
+
18
29
  const PeriodDimension = _ref => {
19
30
  let {
20
31
  onSelect,
@@ -22,6 +33,24 @@ const PeriodDimension = _ref => {
22
33
  rightFooter,
23
34
  excludedPeriodTypes
24
35
  } = _ref;
36
+ const {
37
+ systemInfo
38
+ } = (0, _appRuntime.useConfig)();
39
+ const result = (0, _appRuntime.useDataQuery)(userSettingsQuery);
40
+ const {
41
+ calendar = 'gregory'
42
+ } = systemInfo;
43
+ const {
44
+ data: {
45
+ userSettings: {
46
+ keyUiLocale: locale
47
+ } = {}
48
+ } = {}
49
+ } = result;
50
+ const periodsSettings = {
51
+ calendar,
52
+ locale
53
+ };
25
54
 
26
55
  const selectPeriods = periods => {
27
56
  onSelect({
@@ -35,7 +64,8 @@ const PeriodDimension = _ref => {
35
64
  initialSelectedPeriods: selectedPeriods,
36
65
  rightFooter: rightFooter,
37
66
  dataTest: 'period-dimension',
38
- excludedPeriodTypes: excludedPeriodTypes
67
+ excludedPeriodTypes: excludedPeriodTypes,
68
+ periodsSettings: periodsSettings
39
69
  });
40
70
  };
41
71
 
@@ -7,6 +7,8 @@ exports.default = void 0;
7
7
 
8
8
  var _style = _interopRequireDefault(require("styled-jsx/style"));
9
9
 
10
+ var _multiCalendarDates = require("@dhis2/multi-calendar-dates");
11
+
10
12
  var _ui = require("@dhis2/ui");
11
13
 
12
14
  var _propTypes = _interopRequireDefault(require("prop-types"));
@@ -47,11 +49,15 @@ const PeriodTransfer = _ref => {
47
49
  dataTest,
48
50
  initialSelectedPeriods,
49
51
  rightFooter,
50
- excludedPeriodTypes
52
+ excludedPeriodTypes,
53
+ periodsSettings
51
54
  } = _ref;
52
55
  const defaultRelativePeriodType = excludedPeriodTypes.includes(_index2.MONTHLY) ? (0, _relativePeriods.getRelativePeriodsOptionsById)(_index2.QUARTERLY) : (0, _relativePeriods.getRelativePeriodsOptionsById)(_index2.MONTHLY);
53
- const defaultFixedPeriodType = excludedPeriodTypes.includes(_index2.MONTHLY) ? (0, _fixedPeriods.getFixedPeriodsOptionsById)(_index2.QUARTERLY) : (0, _fixedPeriods.getFixedPeriodsOptionsById)(_index2.MONTHLY);
54
- const defaultFixedPeriodYear = new Date().getFullYear();
56
+ const defaultFixedPeriodType = excludedPeriodTypes.includes(_index2.MONTHLY) ? (0, _fixedPeriods.getFixedPeriodsOptionsById)(_index2.QUARTERLY, periodsSettings) : (0, _fixedPeriods.getFixedPeriodsOptionsById)(_index2.MONTHLY, periodsSettings);
57
+ const now = (0, _multiCalendarDates.getNowInCalendar)(periodsSettings.calendar); // use ".eraYear" rather than ".year" because in Ethiopian calendar, eraYear is what our users expect to see (for other calendars, it doesn't matter)
58
+ // there is still a pending decision in Temporal regarding which era to use by default: https://github.com/js-temporal/temporal-polyfill/blob/9350ee7dd0d29f329fc097debf923a517c32f813/lib/calendar.ts#L1964
59
+
60
+ const defaultFixedPeriodYear = now.eraYear || now.year;
55
61
 
56
62
  const fixedPeriodConfig = year => ({
57
63
  offset: year - defaultFixedPeriodYear,
@@ -73,7 +79,7 @@ const PeriodTransfer = _ref => {
73
79
  const onIsRelativeClick = state => {
74
80
  if (state !== isRelative) {
75
81
  setIsRelative(state);
76
- setAllPeriods(state ? (0, _relativePeriods.getRelativePeriodsOptionsById)(relativeFilter.periodType).getPeriods() : (0, _fixedPeriods.getFixedPeriodsOptionsById)(fixedFilter.periodType).getPeriods(fixedPeriodConfig(Number(fixedFilter.year))));
82
+ setAllPeriods(state ? (0, _relativePeriods.getRelativePeriodsOptionsById)(relativeFilter.periodType).getPeriods() : (0, _fixedPeriods.getFixedPeriodsOptionsById)(fixedFilter.periodType, periodsSettings).getPeriods(fixedPeriodConfig(Number(fixedFilter.year))));
77
83
  }
78
84
  };
79
85
 
@@ -126,7 +132,7 @@ const PeriodTransfer = _ref => {
126
132
 
127
133
  const onSelectFixedPeriods = filter => {
128
134
  setFixedFilter(filter);
129
- setAllPeriods((0, _fixedPeriods.getFixedPeriodsOptionsById)(filter.periodType).getPeriods(fixedPeriodConfig(Number(filter.year))));
135
+ setAllPeriods((0, _fixedPeriods.getFixedPeriodsOptionsById)(filter.periodType, periodsSettings).getPeriods(fixedPeriodConfig(Number(filter.year)), periodsSettings));
130
136
  };
131
137
 
132
138
  const renderEmptySelection = () => /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement("p", {
@@ -176,7 +182,11 @@ const PeriodTransfer = _ref => {
176
182
 
177
183
  PeriodTransfer.defaultProps = {
178
184
  initialSelectedPeriods: [],
179
- excludedPeriodTypes: []
185
+ excludedPeriodTypes: [],
186
+ periodsSettings: {
187
+ calendar: 'gregory',
188
+ locale: 'en'
189
+ }
180
190
  };
181
191
  PeriodTransfer.propTypes = {
182
192
  onSelect: _propTypes.default.func.isRequired,
@@ -186,6 +196,10 @@ PeriodTransfer.propTypes = {
186
196
  id: _propTypes.default.string,
187
197
  name: _propTypes.default.string
188
198
  })),
199
+ periodsSettings: _propTypes.default.shape({
200
+ calendar: _propTypes.default.string,
201
+ locale: _propTypes.default.string
202
+ }),
189
203
  rightFooter: _propTypes.default.node
190
204
  };
191
205
  var _default = PeriodTransfer;
@@ -8,6 +8,19 @@ var _PeriodDimension = _interopRequireDefault(require("../PeriodDimension.js"));
8
8
 
9
9
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10
10
 
11
+ jest.mock('@dhis2/app-runtime', () => ({
12
+ useConfig: () => ({
13
+ systemInfo: {}
14
+ }),
15
+ useDataQuery: () => ({
16
+ data: {
17
+ userSettings: {
18
+ keyUiLocale: 'en'
19
+ }
20
+ }
21
+ })
22
+ }));
23
+ afterEach(jest.clearAllMocks);
11
24
  describe('The Period Dimension component', () => {
12
25
  let props;
13
26
  let shallowPeriodDimension;
@@ -6,6 +6,12 @@ exports[`The Period Dimension component matches the snapshot 1`] = `
6
6
  excludedPeriodTypes={Array []}
7
7
  initialSelectedPeriods={Array []}
8
8
  onSelect={[Function]}
9
+ periodsSettings={
10
+ Object {
11
+ "calendar": "gregory",
12
+ "locale": "en",
13
+ }
14
+ }
9
15
  rightFooter={<React.Fragment />}
10
16
  />
11
17
  `;