@dhis2/analytics 21.8.2 → 21.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.
@@ -147,20 +147,6 @@
147
147
  "Fixed periods": "Fixed periods",
148
148
  "Selected Periods": "Selected Periods",
149
149
  "No periods selected": "No periods selected",
150
- "January": "January",
151
- "February": "February",
152
- "March": "March",
153
- "April": "April",
154
- "May": "May",
155
- "June": "June",
156
- "July": "July",
157
- "August": "August",
158
- "September": "September",
159
- "October": "October",
160
- "November": "November",
161
- "December": "December",
162
- "Week {{weekNumber}}": "Week {{weekNumber}}",
163
- "Bi-Week {{biWeekNumber}}": "Bi-Week {{biWeekNumber}}",
164
150
  "Daily": "Daily",
165
151
  "Weekly": "Weekly",
166
152
  "Weekly (Start Wednesday)": "Weekly (Start Wednesday)",
@@ -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 = ({
7
16
  onSelect,
@@ -9,6 +18,25 @@ const PeriodDimension = ({
9
18
  rightFooter,
10
19
  excludedPeriodTypes
11
20
  }) => {
21
+ const {
22
+ systemInfo
23
+ } = useConfig();
24
+ const result = useDataQuery(userSettingsQuery);
25
+ const {
26
+ calendar = 'gregory'
27
+ } = systemInfo;
28
+ const {
29
+ data: {
30
+ userSettings: {
31
+ keyUiLocale: locale
32
+ } = {}
33
+ } = {}
34
+ } = result;
35
+ const periodsSettings = {
36
+ calendar,
37
+ locale
38
+ };
39
+
12
40
  const selectPeriods = periods => {
13
41
  onSelect({
14
42
  dimensionId: DIMENSION_ID_PERIOD,
@@ -21,7 +49,8 @@ const PeriodDimension = ({
21
49
  initialSelectedPeriods: selectedPeriods,
22
50
  rightFooter: rightFooter,
23
51
  dataTest: 'period-dimension',
24
- excludedPeriodTypes: excludedPeriodTypes
52
+ excludedPeriodTypes: excludedPeriodTypes,
53
+ periodsSettings: periodsSettings
25
54
  });
26
55
  };
27
56
 
@@ -2,6 +2,7 @@ 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 { getNowInCalendar } from '@dhis2/multi-calendar-dates';
5
6
  import { TabBar, Tab, Transfer } from '@dhis2/ui';
6
7
  import PropTypes from 'prop-types';
7
8
  import React, { useState } from 'react';
@@ -22,11 +23,15 @@ const PeriodTransfer = ({
22
23
  dataTest,
23
24
  initialSelectedPeriods,
24
25
  rightFooter,
25
- excludedPeriodTypes
26
+ excludedPeriodTypes,
27
+ periodsSettings
26
28
  }) => {
27
29
  const defaultRelativePeriodType = excludedPeriodTypes.includes(MONTHLY) ? getRelativePeriodsOptionsById(QUARTERLY) : getRelativePeriodsOptionsById(MONTHLY);
28
- const defaultFixedPeriodType = excludedPeriodTypes.includes(MONTHLY) ? getFixedPeriodsOptionsById(QUARTERLY) : getFixedPeriodsOptionsById(MONTHLY);
29
- const defaultFixedPeriodYear = new Date().getFullYear();
30
+ const defaultFixedPeriodType = excludedPeriodTypes.includes(MONTHLY) ? getFixedPeriodsOptionsById(QUARTERLY, periodsSettings) : getFixedPeriodsOptionsById(MONTHLY, periodsSettings);
31
+ 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)
32
+ // 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
33
+
34
+ const defaultFixedPeriodYear = now.eraYear || now.year;
30
35
 
31
36
  const fixedPeriodConfig = year => ({
32
37
  offset: year - defaultFixedPeriodYear,
@@ -48,7 +53,7 @@ const PeriodTransfer = ({
48
53
  const onIsRelativeClick = state => {
49
54
  if (state !== isRelative) {
50
55
  setIsRelative(state);
51
- setAllPeriods(state ? getRelativePeriodsOptionsById(relativeFilter.periodType).getPeriods() : getFixedPeriodsOptionsById(fixedFilter.periodType).getPeriods(fixedPeriodConfig(Number(fixedFilter.year))));
56
+ setAllPeriods(state ? getRelativePeriodsOptionsById(relativeFilter.periodType).getPeriods() : getFixedPeriodsOptionsById(fixedFilter.periodType, periodsSettings).getPeriods(fixedPeriodConfig(Number(fixedFilter.year))));
52
57
  }
53
58
  };
54
59
 
@@ -101,7 +106,7 @@ const PeriodTransfer = ({
101
106
 
102
107
  const onSelectFixedPeriods = filter => {
103
108
  setFixedFilter(filter);
104
- setAllPeriods(getFixedPeriodsOptionsById(filter.periodType).getPeriods(fixedPeriodConfig(Number(filter.year))));
109
+ setAllPeriods(getFixedPeriodsOptionsById(filter.periodType, periodsSettings).getPeriods(fixedPeriodConfig(Number(filter.year)), periodsSettings));
105
110
  };
106
111
 
107
112
  const renderEmptySelection = () => /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("p", {
@@ -147,7 +152,11 @@ const PeriodTransfer = ({
147
152
 
148
153
  PeriodTransfer.defaultProps = {
149
154
  initialSelectedPeriods: [],
150
- excludedPeriodTypes: []
155
+ excludedPeriodTypes: [],
156
+ periodsSettings: {
157
+ calendar: 'gregory',
158
+ locale: 'en'
159
+ }
151
160
  };
152
161
  PeriodTransfer.propTypes = {
153
162
  onSelect: PropTypes.func.isRequired,
@@ -157,6 +166,10 @@ PeriodTransfer.propTypes = {
157
166
  id: PropTypes.string,
158
167
  name: PropTypes.string
159
168
  })),
169
+ periodsSettings: PropTypes.shape({
170
+ calendar: PropTypes.string,
171
+ locale: PropTypes.string
172
+ }),
160
173
  rightFooter: PropTypes.node
161
174
  };
162
175
  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;
@@ -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
  `;