@dhis2/analytics 24.9.0-alpha.1 → 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,3 +1,10 @@
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
+
1
8
  # [24.9.0-alpha.1](https://github.com/dhis2/analytics/compare/v24.8.0...v24.9.0-alpha.1) (2023-02-23)
2
9
 
3
10
 
@@ -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,8 +7,6 @@ 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
10
  var _multiCalendarDates = require("@dhis2/multi-calendar-dates");
13
11
 
14
12
  var _ui = require("@dhis2/ui");
@@ -45,44 +43,18 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
45
43
 
46
44
  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); }
47
45
 
48
- const userSettingsQuery = {
49
- userSettings: {
50
- resource: 'userSettings',
51
- params: {
52
- key: ['keyUiLocale']
53
- }
54
- }
55
- };
56
-
57
46
  const PeriodTransfer = _ref => {
58
47
  let {
59
48
  onSelect,
60
49
  dataTest,
61
50
  initialSelectedPeriods,
62
51
  rightFooter,
63
- excludedPeriodTypes
52
+ excludedPeriodTypes,
53
+ periodsSettings
64
54
  } = _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
- };
83
55
  const defaultRelativePeriodType = excludedPeriodTypes.includes(_index2.MONTHLY) ? (0, _relativePeriods.getRelativePeriodsOptionsById)(_index2.QUARTERLY) : (0, _relativePeriods.getRelativePeriodsOptionsById)(_index2.MONTHLY);
84
56
  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)
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)
86
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
87
59
 
88
60
  const defaultFixedPeriodYear = now.eraYear || now.year;
@@ -210,7 +182,11 @@ const PeriodTransfer = _ref => {
210
182
 
211
183
  PeriodTransfer.defaultProps = {
212
184
  initialSelectedPeriods: [],
213
- excludedPeriodTypes: []
185
+ excludedPeriodTypes: [],
186
+ periodsSettings: {
187
+ calendar: 'gregory',
188
+ locale: 'en'
189
+ }
214
190
  };
215
191
  PeriodTransfer.propTypes = {
216
192
  onSelect: _propTypes.default.func.isRequired,
@@ -220,6 +196,10 @@ PeriodTransfer.propTypes = {
220
196
  id: _propTypes.default.string,
221
197
  name: _propTypes.default.string
222
198
  })),
199
+ periodsSettings: _propTypes.default.shape({
200
+ calendar: _propTypes.default.string,
201
+ locale: _propTypes.default.string
202
+ }),
223
203
  rightFooter: _propTypes.default.node
224
204
  };
225
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;
@@ -8,19 +8,6 @@ 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);
24
11
  describe('The Period Selector component', () => {
25
12
  let props;
26
13
  let shallowPeriodTransfer;
@@ -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
  `;
@@ -1,7 +1,16 @@
1
+ import { useConfig, useDataQuery } from '@dhis2/app-runtime';
1
2
  import PropTypes from 'prop-types';
2
3
  import React from 'react';
3
4
  import { DIMENSION_ID_PERIOD } from '../../modules/predefinedDimensions.js';
4
5
  import PeriodTransfer from './PeriodTransfer.js';
6
+ const userSettingsQuery = {
7
+ userSettings: {
8
+ resource: 'userSettings',
9
+ params: {
10
+ key: ['keyUiLocale']
11
+ }
12
+ }
13
+ };
5
14
 
6
15
  const PeriodDimension = _ref => {
7
16
  let {
@@ -10,6 +19,24 @@ const PeriodDimension = _ref => {
10
19
  rightFooter,
11
20
  excludedPeriodTypes
12
21
  } = _ref;
22
+ const {
23
+ systemInfo
24
+ } = useConfig();
25
+ const result = useDataQuery(userSettingsQuery);
26
+ const {
27
+ calendar = 'gregory'
28
+ } = systemInfo;
29
+ const {
30
+ data: {
31
+ userSettings: {
32
+ keyUiLocale: locale
33
+ } = {}
34
+ } = {}
35
+ } = result;
36
+ const periodsSettings = {
37
+ calendar,
38
+ locale
39
+ };
13
40
 
14
41
  const selectPeriods = periods => {
15
42
  onSelect({
@@ -23,7 +50,8 @@ const PeriodDimension = _ref => {
23
50
  initialSelectedPeriods: selectedPeriods,
24
51
  rightFooter: rightFooter,
25
52
  dataTest: 'period-dimension',
26
- excludedPeriodTypes: excludedPeriodTypes
53
+ excludedPeriodTypes: excludedPeriodTypes,
54
+ periodsSettings: periodsSettings
27
55
  });
28
56
  };
29
57
 
@@ -2,7 +2,6 @@ import _JSXStyle from "styled-jsx/style";
2
2
 
3
3
  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); }
4
4
 
5
- import { useConfig, useDataQuery } from '@dhis2/app-runtime';
6
5
  import { getNowInCalendar } from '@dhis2/multi-calendar-dates';
7
6
  import { TabBar, Tab, Transfer } from '@dhis2/ui';
8
7
  import PropTypes from 'prop-types';
@@ -18,14 +17,6 @@ import RelativePeriodFilter from './RelativePeriodFilter.js';
18
17
  import { getFixedPeriodsOptionsById } from './utils/fixedPeriods.js';
19
18
  import { MONTHLY, QUARTERLY } from './utils/index.js';
20
19
  import { getRelativePeriodsOptionsById } from './utils/relativePeriods.js';
21
- const userSettingsQuery = {
22
- userSettings: {
23
- resource: 'userSettings',
24
- params: {
25
- key: ['keyUiLocale']
26
- }
27
- }
28
- };
29
20
 
30
21
  const PeriodTransfer = _ref => {
31
22
  let {
@@ -33,29 +24,12 @@ const PeriodTransfer = _ref => {
33
24
  dataTest,
34
25
  initialSelectedPeriods,
35
26
  rightFooter,
36
- excludedPeriodTypes
27
+ excludedPeriodTypes,
28
+ periodsSettings
37
29
  } = _ref;
38
- const {
39
- systemInfo
40
- } = useConfig();
41
- const result = useDataQuery(userSettingsQuery);
42
- const {
43
- calendar = 'gregory'
44
- } = systemInfo;
45
- const {
46
- data: {
47
- userSettings: {
48
- keyUiLocale: locale
49
- } = {}
50
- } = {}
51
- } = result;
52
- const periodsSettings = {
53
- calendar,
54
- locale
55
- };
56
30
  const defaultRelativePeriodType = excludedPeriodTypes.includes(MONTHLY) ? getRelativePeriodsOptionsById(QUARTERLY) : getRelativePeriodsOptionsById(MONTHLY);
57
31
  const defaultFixedPeriodType = excludedPeriodTypes.includes(MONTHLY) ? getFixedPeriodsOptionsById(QUARTERLY, periodsSettings) : getFixedPeriodsOptionsById(MONTHLY, periodsSettings);
58
- const now = 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)
32
+ const now = 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)
59
33
  // 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
60
34
 
61
35
  const defaultFixedPeriodYear = now.eraYear || now.year;
@@ -183,7 +157,11 @@ const PeriodTransfer = _ref => {
183
157
 
184
158
  PeriodTransfer.defaultProps = {
185
159
  initialSelectedPeriods: [],
186
- excludedPeriodTypes: []
160
+ excludedPeriodTypes: [],
161
+ periodsSettings: {
162
+ calendar: 'gregory',
163
+ locale: 'en'
164
+ }
187
165
  };
188
166
  PeriodTransfer.propTypes = {
189
167
  onSelect: PropTypes.func.isRequired,
@@ -193,6 +171,10 @@ PeriodTransfer.propTypes = {
193
171
  id: PropTypes.string,
194
172
  name: PropTypes.string
195
173
  })),
174
+ periodsSettings: PropTypes.shape({
175
+ calendar: PropTypes.string,
176
+ locale: PropTypes.string
177
+ }),
196
178
  rightFooter: PropTypes.node
197
179
  };
198
180
  export default PeriodTransfer;
@@ -1,6 +1,19 @@
1
1
  import { shallow } from 'enzyme';
2
2
  import React from 'react';
3
3
  import PeriodDimension from '../PeriodDimension.js';
4
+ jest.mock('@dhis2/app-runtime', () => ({
5
+ useConfig: () => ({
6
+ systemInfo: {}
7
+ }),
8
+ useDataQuery: () => ({
9
+ data: {
10
+ userSettings: {
11
+ keyUiLocale: 'en'
12
+ }
13
+ }
14
+ })
15
+ }));
16
+ afterEach(jest.clearAllMocks);
4
17
  describe('The Period Dimension component', () => {
5
18
  let props;
6
19
  let shallowPeriodDimension;
@@ -1,19 +1,6 @@
1
1
  import { shallow } from 'enzyme';
2
2
  import React from 'react';
3
3
  import PeriodTransfer from '../PeriodTransfer.js';
4
- jest.mock('@dhis2/app-runtime', () => ({
5
- useConfig: () => ({
6
- systemInfo: {}
7
- }),
8
- useDataQuery: () => ({
9
- data: {
10
- userSettings: {
11
- keyUiLocale: 'en'
12
- }
13
- }
14
- })
15
- }));
16
- afterEach(jest.clearAllMocks);
17
4
  describe('The Period Selector component', () => {
18
5
  let props;
19
6
  let shallowPeriodTransfer;
@@ -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
  `;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dhis2/analytics",
3
- "version": "24.9.0-alpha.1",
3
+ "version": "24.9.0",
4
4
  "main": "./build/cjs/index.js",
5
5
  "module": "./build/es/index.js",
6
6
  "exports": {