@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 +34 -1
- package/build/cjs/components/PeriodDimension/PeriodTransfer.js +38 -4
- package/build/cjs/components/PeriodDimension/__tests__/PeriodSelector.spec.js +13 -0
- package/build/cjs/components/PeriodDimension/utils/fixedPeriods.js +207 -478
- package/build/cjs/locales/en/translations.json +0 -14
- package/build/es/components/PeriodDimension/PeriodTransfer.js +35 -4
- package/build/es/components/PeriodDimension/__tests__/PeriodSelector.spec.js +13 -0
- package/build/es/components/PeriodDimension/utils/fixedPeriods.js +205 -477
- package/build/es/locales/en/translations.json +0 -14
- package/package.json +2 -1
|
@@ -182,20 +182,6 @@
|
|
|
182
182
|
"Fixed periods": "Fixed periods",
|
|
183
183
|
"Selected Periods": "Selected Periods",
|
|
184
184
|
"No periods selected": "No periods selected",
|
|
185
|
-
"January": "January",
|
|
186
|
-
"February": "February",
|
|
187
|
-
"March": "March",
|
|
188
|
-
"April": "April",
|
|
189
|
-
"May": "May",
|
|
190
|
-
"June": "June",
|
|
191
|
-
"July": "July",
|
|
192
|
-
"August": "August",
|
|
193
|
-
"September": "September",
|
|
194
|
-
"October": "October",
|
|
195
|
-
"November": "November",
|
|
196
|
-
"December": "December",
|
|
197
|
-
"Week {{weekNumber}}": "Week {{weekNumber}}",
|
|
198
|
-
"Bi-Week {{biWeekNumber}}": "Bi-Week {{biWeekNumber}}",
|
|
199
185
|
"Daily": "Daily",
|
|
200
186
|
"Weekly": "Weekly",
|
|
201
187
|
"Weekly (Start Wednesday)": "Weekly (Start Wednesday)",
|
|
@@ -2,6 +2,8 @@ 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
|
+
import { getNowInCalendar } from '@dhis2/multi-calendar-dates';
|
|
5
7
|
import { TabBar, Tab, Transfer } from '@dhis2/ui';
|
|
6
8
|
import PropTypes from 'prop-types';
|
|
7
9
|
import React, { useState } from 'react';
|
|
@@ -16,6 +18,14 @@ import RelativePeriodFilter from './RelativePeriodFilter.js';
|
|
|
16
18
|
import { getFixedPeriodsOptionsById } from './utils/fixedPeriods.js';
|
|
17
19
|
import { MONTHLY, QUARTERLY } from './utils/index.js';
|
|
18
20
|
import { getRelativePeriodsOptionsById } from './utils/relativePeriods.js';
|
|
21
|
+
const userSettingsQuery = {
|
|
22
|
+
userSettings: {
|
|
23
|
+
resource: 'userSettings',
|
|
24
|
+
params: {
|
|
25
|
+
key: ['keyUiLocale']
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
};
|
|
19
29
|
|
|
20
30
|
const PeriodTransfer = _ref => {
|
|
21
31
|
let {
|
|
@@ -25,9 +35,30 @@ const PeriodTransfer = _ref => {
|
|
|
25
35
|
rightFooter,
|
|
26
36
|
excludedPeriodTypes
|
|
27
37
|
} = _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
|
+
};
|
|
28
56
|
const defaultRelativePeriodType = excludedPeriodTypes.includes(MONTHLY) ? getRelativePeriodsOptionsById(QUARTERLY) : getRelativePeriodsOptionsById(MONTHLY);
|
|
29
|
-
const defaultFixedPeriodType = excludedPeriodTypes.includes(MONTHLY) ? getFixedPeriodsOptionsById(QUARTERLY) : getFixedPeriodsOptionsById(MONTHLY);
|
|
30
|
-
const
|
|
57
|
+
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)
|
|
59
|
+
// 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
|
+
|
|
61
|
+
const defaultFixedPeriodYear = now.eraYear || now.year;
|
|
31
62
|
|
|
32
63
|
const fixedPeriodConfig = year => ({
|
|
33
64
|
offset: year - defaultFixedPeriodYear,
|
|
@@ -49,7 +80,7 @@ const PeriodTransfer = _ref => {
|
|
|
49
80
|
const onIsRelativeClick = state => {
|
|
50
81
|
if (state !== isRelative) {
|
|
51
82
|
setIsRelative(state);
|
|
52
|
-
setAllPeriods(state ? getRelativePeriodsOptionsById(relativeFilter.periodType).getPeriods() : getFixedPeriodsOptionsById(fixedFilter.periodType).getPeriods(fixedPeriodConfig(Number(fixedFilter.year))));
|
|
83
|
+
setAllPeriods(state ? getRelativePeriodsOptionsById(relativeFilter.periodType).getPeriods() : getFixedPeriodsOptionsById(fixedFilter.periodType, periodsSettings).getPeriods(fixedPeriodConfig(Number(fixedFilter.year))));
|
|
53
84
|
}
|
|
54
85
|
};
|
|
55
86
|
|
|
@@ -102,7 +133,7 @@ const PeriodTransfer = _ref => {
|
|
|
102
133
|
|
|
103
134
|
const onSelectFixedPeriods = filter => {
|
|
104
135
|
setFixedFilter(filter);
|
|
105
|
-
setAllPeriods(getFixedPeriodsOptionsById(filter.periodType).getPeriods(fixedPeriodConfig(Number(filter.year))));
|
|
136
|
+
setAllPeriods(getFixedPeriodsOptionsById(filter.periodType, periodsSettings).getPeriods(fixedPeriodConfig(Number(filter.year)), periodsSettings));
|
|
106
137
|
};
|
|
107
138
|
|
|
108
139
|
const renderEmptySelection = () => /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("p", {
|
|
@@ -1,6 +1,19 @@
|
|
|
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);
|
|
4
17
|
describe('The Period Selector component', () => {
|
|
5
18
|
let props;
|
|
6
19
|
let shallowPeriodTransfer;
|