@dhis2/analytics 24.8.0 → 24.9.0-alpha.1

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,41 @@
1
- # [24.8.0](https://github.com/dhis2/analytics/compare/v24.7.0...v24.8.0) (2023-02-16)
1
+ # [24.9.0-alpha.1](https://github.com/dhis2/analytics/compare/v24.8.0...v24.9.0-alpha.1) (2023-02-23)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * bump multi-calendar-dates to avoid jest config change ([3e5892a](https://github.com/dhis2/analytics/commit/3e5892aa88a087dde3405a518625f4c6e637d17e))
7
+ * ensure date falls back to year if no eraYear present ([2a197d5](https://github.com/dhis2/analytics/commit/2a197d57be8ac2af6dbe331dd8f11ab9069afa5d))
8
+
9
+
10
+ ### Features
11
+
12
+ * localise fixed periods according to user settings ([c640c90](https://github.com/dhis2/analytics/commit/c640c90ce2d1944a14706507284af43c7480fa2a))
13
+ * use multi-calendar-dates library to generate fixed periods ([acc3801](https://github.com/dhis2/analytics/commit/acc380156092f888cfa55f70b4bade1c6516d034))
14
+
15
+ # [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
16
 
3
17
 
4
18
  ### Features
5
19
 
20
+ * localise fixed periods according to user settings ([c640c90](https://github.com/dhis2/analytics/commit/c640c90ce2d1944a14706507284af43c7480fa2a))
21
+
22
+ # [24.5.0-alpha.2](https://github.com/dhis2/analytics/compare/v24.5.0-alpha.1...v24.5.0-alpha.2) (2023-02-14)
23
+
24
+
25
+ ### Bug Fixes
26
+
27
+ * bump multi-calendar-dates to avoid jest config change ([3e5892a](https://github.com/dhis2/analytics/commit/3e5892aa88a087dde3405a518625f4c6e637d17e))
28
+
29
+ # [24.5.0-alpha.1](https://github.com/dhis2/analytics/compare/v24.4.2...v24.5.0-alpha.1) (2023-02-07)
30
+
31
+
32
+ ### Bug Fixes
33
+
34
+ * ensure date falls back to year if no eraYear present ([2a197d5](https://github.com/dhis2/analytics/commit/2a197d57be8ac2af6dbe331dd8f11ab9069afa5d))
35
+
36
+ # [24.8.0](https://github.com/dhis2/analytics/compare/v24.7.0...v24.8.0) (2023-02-16)
37
+
38
+
6
39
  * 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
40
 
8
41
  # [24.7.0](https://github.com/dhis2/analytics/compare/v24.6.0...v24.7.0) (2023-02-15)
@@ -7,6 +7,10 @@ exports.default = void 0;
7
7
 
8
8
  var _style = _interopRequireDefault(require("styled-jsx/style"));
9
9
 
10
+ var _appRuntime = require("@dhis2/app-runtime");
11
+
12
+ var _multiCalendarDates = require("@dhis2/multi-calendar-dates");
13
+
10
14
  var _ui = require("@dhis2/ui");
11
15
 
12
16
  var _propTypes = _interopRequireDefault(require("prop-types"));
@@ -41,6 +45,15 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
41
45
 
42
46
  function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
43
47
 
48
+ const userSettingsQuery = {
49
+ userSettings: {
50
+ resource: 'userSettings',
51
+ params: {
52
+ key: ['keyUiLocale']
53
+ }
54
+ }
55
+ };
56
+
44
57
  const PeriodTransfer = _ref => {
45
58
  let {
46
59
  onSelect,
@@ -49,9 +62,30 @@ const PeriodTransfer = _ref => {
49
62
  rightFooter,
50
63
  excludedPeriodTypes
51
64
  } = _ref;
65
+ const {
66
+ systemInfo
67
+ } = (0, _appRuntime.useConfig)();
68
+ const result = (0, _appRuntime.useDataQuery)(userSettingsQuery);
69
+ const {
70
+ calendar = 'gregory'
71
+ } = systemInfo;
72
+ const {
73
+ data: {
74
+ userSettings: {
75
+ keyUiLocale: locale
76
+ } = {}
77
+ } = {}
78
+ } = result;
79
+ const periodsSettings = {
80
+ calendar,
81
+ locale
82
+ };
52
83
  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();
84
+ const defaultFixedPeriodType = excludedPeriodTypes.includes(_index2.MONTHLY) ? (0, _fixedPeriods.getFixedPeriodsOptionsById)(_index2.QUARTERLY, periodsSettings) : (0, _fixedPeriods.getFixedPeriodsOptionsById)(_index2.MONTHLY, periodsSettings);
85
+ const now = (0, _multiCalendarDates.getNowInCalendar)(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)
86
+ // 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
87
+
88
+ const defaultFixedPeriodYear = now.eraYear || now.year;
55
89
 
56
90
  const fixedPeriodConfig = year => ({
57
91
  offset: year - defaultFixedPeriodYear,
@@ -73,7 +107,7 @@ const PeriodTransfer = _ref => {
73
107
  const onIsRelativeClick = state => {
74
108
  if (state !== isRelative) {
75
109
  setIsRelative(state);
76
- setAllPeriods(state ? (0, _relativePeriods.getRelativePeriodsOptionsById)(relativeFilter.periodType).getPeriods() : (0, _fixedPeriods.getFixedPeriodsOptionsById)(fixedFilter.periodType).getPeriods(fixedPeriodConfig(Number(fixedFilter.year))));
110
+ setAllPeriods(state ? (0, _relativePeriods.getRelativePeriodsOptionsById)(relativeFilter.periodType).getPeriods() : (0, _fixedPeriods.getFixedPeriodsOptionsById)(fixedFilter.periodType, periodsSettings).getPeriods(fixedPeriodConfig(Number(fixedFilter.year))));
77
111
  }
78
112
  };
79
113
 
@@ -126,7 +160,7 @@ const PeriodTransfer = _ref => {
126
160
 
127
161
  const onSelectFixedPeriods = filter => {
128
162
  setFixedFilter(filter);
129
- setAllPeriods((0, _fixedPeriods.getFixedPeriodsOptionsById)(filter.periodType).getPeriods(fixedPeriodConfig(Number(filter.year))));
163
+ setAllPeriods((0, _fixedPeriods.getFixedPeriodsOptionsById)(filter.periodType, periodsSettings).getPeriods(fixedPeriodConfig(Number(filter.year)), periodsSettings));
130
164
  };
131
165
 
132
166
  const renderEmptySelection = () => /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement("p", {
@@ -8,6 +8,19 @@ var _PeriodTransfer = _interopRequireDefault(require("../PeriodTransfer.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 Selector component', () => {
12
25
  let props;
13
26
  let shallowPeriodTransfer;