diff --git a/package.json b/package.json index 29039c02b..056a66b4e 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ "analyze-bundle": "webpack --profile --json --progress > .webpack-profile.json && webpack-bundle-analyzer .webpack-profile.json" }, "dependencies": { - "@dhis2/analytics": "^24.10.7", + "@dhis2/analytics": "^24.10.12", "@dhis2/app-runtime": "3.9.4", "@dhis2/app-runtime-adapter-d2": "^1.1.0", "@dhis2/app-service-datastore": "^1.0.0-beta.3", diff --git a/src/components/Root.js b/src/components/Root.js index e188b327f..fc920f717 100644 --- a/src/components/Root.js +++ b/src/components/Root.js @@ -8,6 +8,7 @@ import { D2Shim } from '@dhis2/app-runtime-adapter-d2'; import { CenteredContent, CircularLoader } from '@dhis2/ui'; import UserSettingsProvider, { UserSettingsCtx } from './UserSettingsProvider'; import SystemSettingsProvider from './SystemSettingsProvider'; +import SystemInfoProvider from './SystemInfoProvider'; import { apiVersion } from '../constants/settings'; import App from './app/App'; import { NAMESPACE } from '../util/analyticalObject'; @@ -65,18 +66,22 @@ const Root = ({ store }) => ( return ( - - - {({ keyUiLocale }) => { - if (!keyUiLocale) { - return null; - } - i18n.changeLanguage(keyUiLocale); - moment.locale(keyUiLocale); - return ; - }} - - + + + + {({ keyUiLocale }) => { + if (!keyUiLocale) { + return null; + } + i18n.changeLanguage( + keyUiLocale + ); + moment.locale(keyUiLocale); + return ; + }} + + + ); diff --git a/src/components/SystemInfoProvider.js b/src/components/SystemInfoProvider.js new file mode 100644 index 000000000..1641e4fa2 --- /dev/null +++ b/src/components/SystemInfoProvider.js @@ -0,0 +1,42 @@ +import { useDataEngine } from '@dhis2/app-runtime'; +import PropTypes from 'prop-types'; +import React, { useContext, useState, useEffect, createContext } from 'react'; + +const systemInfoQuery = { + resource: 'system/info', + params: { + fields: 'calendar', + }, +}; + +export const SystemInfoCtx = createContext({}); + +const SystemInfoProvider = ({ children }) => { + const [settings, setSettings] = useState({}); + const engine = useDataEngine(); + + useEffect(() => { + async function fetchData() { + const { systemInfo } = await engine.query({ + systemInfo: systemInfoQuery, + }); + + setSettings(systemInfo); + } + fetchData(); + }, []); + + return ( + + {children} + + ); +}; + +SystemInfoProvider.propTypes = { + children: PropTypes.node, +}; + +export default SystemInfoProvider; + +export const useSystemInfo = () => useContext(SystemInfoCtx); diff --git a/src/components/edit/LayerEdit.js b/src/components/edit/LayerEdit.js index 94fa43b6c..a178af262 100644 --- a/src/components/edit/LayerEdit.js +++ b/src/components/edit/LayerEdit.js @@ -19,6 +19,8 @@ import EarthEngineDialog from './earthEngine/EarthEngineDialog'; import { loadLayer, cancelLayer, setLayerLoading } from '../../actions/layers'; import { EARTH_ENGINE_LAYER } from '../../constants/layers'; import { useSystemSettings } from '../SystemSettingsProvider'; +import { useSystemInfo } from '../SystemInfoProvider'; +import { useUserSettings } from '../UserSettingsProvider'; import styles from './styles/LayerEdit.module.css'; const layerType = { @@ -42,6 +44,10 @@ const layerName = () => ({ const LayerEdit = ({ layer, cancelLayer, setLayerLoading, loadLayer }) => { const [isValidLayer, setIsValidLayer] = useState(false); const { keyAnalysisRelativePeriod } = useSystemSettings(); + const periodsSettings = { + locale: useUserSettings().keyUiLocale, + calendar: useSystemInfo().calendar, + }; const onValidateLayer = () => setIsValidLayer(true); @@ -89,6 +95,7 @@ const LayerEdit = ({ layer, cancelLayer, setLayerLoading, loadLayer }) => { diff --git a/src/components/edit/thematic/ThematicDialog.js b/src/components/edit/thematic/ThematicDialog.js index 976802042..08f92f396 100644 --- a/src/components/edit/thematic/ThematicDialog.js +++ b/src/components/edit/thematic/ThematicDialog.js @@ -96,6 +96,7 @@ export class ThematicDialog extends Component { startDate: PropTypes.string, endDate: PropTypes.string, periodType: PropTypes.string, + periodsSettings: PropTypes.object, renderingStrategy: PropTypes.string, thematicMapType: PropTypes.string, valueType: PropTypes.string, @@ -242,6 +243,7 @@ export class ThematicDialog extends Component { noDataColor, operand, periodType, + periodsSettings, settings, renderingStrategy, startDate, @@ -466,6 +468,7 @@ export class ThematicDialog extends Component { (!periodType && id)) && ( { - const { periodType } = this.props; + const { periodType, periodsSettings } = this.props; const year = this.state.year + change; this.setState({ year, - periods: getFixedPeriodsByType(periodType, year), + periods: getFixedPeriodsByType(periodType, year, periodsSettings), }); }; } diff --git a/src/util/periods.js b/src/util/periods.js index 8a0d29fb2..b8b9c13b1 100644 --- a/src/util/periods.js +++ b/src/util/periods.js @@ -9,8 +9,8 @@ const getYearOffsetFromNow = year => year - new Date(Date.now()).getFullYear(); export const getPeriodTypes = (hiddenPeriods = []) => periodTypes().filter(({ group }) => !hiddenPeriods.includes(group)); -export const getFixedPeriodsByType = (periodType, year) => { - const period = getFixedPeriodsOptionsById(periodType); +export const getFixedPeriodsByType = (periodType, year, periodsSettings) => { + const period = getFixedPeriodsOptionsById(periodType, periodsSettings); const offset = getYearOffsetFromNow(year); const reversePeriods = true; diff --git a/yarn.lock b/yarn.lock index a691e872f..94cbe3e28 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1849,13 +1849,13 @@ classnames "^2.3.1" prop-types "^15.7.2" -"@dhis2/analytics@^24.10.7": - version "24.10.7" - resolved "https://registry.yarnpkg.com/@dhis2/analytics/-/analytics-24.10.7.tgz#dcb8c265e4fa97952e9ae0dae7becb5f0c2d2687" - integrity sha512-yE3blq2L4IbmGt2ypNORgwIaTb1yvjCjdyxJA5/xH30aNDTqYPJQoyzo+U/KN1v8r495W39+C/s6GDbFBZ7j0A== +"@dhis2/analytics@^24.10.12": + version "24.10.12" + resolved "https://registry.yarnpkg.com/@dhis2/analytics/-/analytics-24.10.12.tgz#2eb0a466570aff572defc77aafd4710359079250" + integrity sha512-eqDCD1Is2XOdRTuDjnpoRImgVO8sa3AgqN8G0RSPnkrvg/ohqBvAkpir0RECDjLGkmYNuxTXkA/zCjc+m32RWQ== dependencies: "@dhis2/d2-ui-rich-text" "^7.4.0" - "@dhis2/multi-calendar-dates" "1.0.0" + "@dhis2/multi-calendar-dates" "^1.2.2" classnames "^2.3.1" d2-utilizr "^0.2.16" d3-color "^1.2.3" @@ -2043,6 +2043,15 @@ i18next "^10.3" moment "^2.24.0" +"@dhis2/d2-i18n@^1.1.3": + version "1.1.3" + resolved "https://registry.yarnpkg.com/@dhis2/d2-i18n/-/d2-i18n-1.1.3.tgz#ad73030f7cfceeed1b5bcaad86a9b336130bdfb1" + integrity sha512-vOu6RDNumOJM396mHt35bETk9ai9b6XJyAwlUy1HstUZNvfET61F8rjCmMuXZU6zJ8ELux8kMFqlH8IG0vDJmA== + dependencies: + "@types/i18next" "^11.9.0" + i18next "^10.3" + moment "^2.24.0" + "@dhis2/d2-ui-core@7.4.0", "@dhis2/d2-ui-core@^7.4.0": version "7.4.0" resolved "https://registry.yarnpkg.com/@dhis2/d2-ui-core/-/d2-ui-core-7.4.0.tgz#796afffbca4cf7f76a500d979e53c01abe8ebcb2" @@ -2103,12 +2112,13 @@ suggestions "^1.7.1" uuid "^9.0.0" -"@dhis2/multi-calendar-dates@1.0.0": - version "1.0.0" - resolved "https://registry.yarnpkg.com/@dhis2/multi-calendar-dates/-/multi-calendar-dates-1.0.0.tgz#bf7f49aecdffa9781837a5d60d56a094b74ab4df" - integrity sha512-IB9a+feuS6yE4lpZj/eZ9uBmpYI7Hxitl2Op0JjoRL4tP+p6uw4ns9cjoSdUeIU9sOAxVZV7oQqSyIw+9P6YjQ== +"@dhis2/multi-calendar-dates@^1.2.2": + version "1.2.3" + resolved "https://registry.yarnpkg.com/@dhis2/multi-calendar-dates/-/multi-calendar-dates-1.2.3.tgz#ef36bc80b34eaaa7f7cefa51b443528c019ff2d2" + integrity sha512-K3E9yAH/SPXi1O7RWuK7bznYTa1v3x4Ys0ihpMWnKH++OLMx76yK/1H1m9v7NgQvMry29ATQMJh0n/vJSg+EpA== dependencies: - "@js-temporal/polyfill" "^0.4.2" + "@dhis2/d2-i18n" "^1.1.3" + "@js-temporal/polyfill" "0.4.3" classnames "^2.3.2" "@dhis2/prop-types@^3.1.2": @@ -2575,13 +2585,13 @@ "@jridgewell/resolve-uri" "^3.0.3" "@jridgewell/sourcemap-codec" "^1.4.10" -"@js-temporal/polyfill@^0.4.2": - version "0.4.4" - resolved "https://registry.yarnpkg.com/@js-temporal/polyfill/-/polyfill-0.4.4.tgz#4c26b4a1a68c19155808363f520204712cfc2558" - integrity sha512-2X6bvghJ/JAoZO52lbgyAPFj8uCflhTo2g7nkFzEQdXd/D8rEeD4HtmTEpmtGCva260fcd66YNXBOYdnmHqSOg== +"@js-temporal/polyfill@0.4.3": + version "0.4.3" + resolved "https://registry.yarnpkg.com/@js-temporal/polyfill/-/polyfill-0.4.3.tgz#e8f8cf86745eb5050679c46a5ebedb9a9cc1f09b" + integrity sha512-6Fmjo/HlkyVCmJzAPnvtEWlcbQUSRhi8qlN9EtJA/wP7FqXsevLLrlojR44kzNzrRkpf7eDJ+z7b4xQD/Ycypw== dependencies: - jsbi "^4.3.0" - tslib "^2.4.1" + jsbi "^4.1.0" + tslib "^2.3.1" "@juggle/resize-observer@^3.3.1": version "3.3.1" @@ -3306,6 +3316,11 @@ dependencies: "@types/node" "*" +"@types/i18next@^11.9.0": + version "11.9.3" + resolved "https://registry.yarnpkg.com/@types/i18next/-/i18next-11.9.3.tgz#04d84c6539908ad69665d26d8967f942d1638550" + integrity sha512-snM7bMKy6gt7UYdpjsxycqSCAy0fr2JVPY0B8tJ2vp9bN58cE7C880k20PWFM4KXxQ3KsstKM8DLCawGCIH0tg== + "@types/istanbul-lib-coverage@*", "@types/istanbul-lib-coverage@^2.0.0", "@types/istanbul-lib-coverage@^2.0.1": version "2.0.3" resolved "https://registry.yarnpkg.com/@types/istanbul-lib-coverage/-/istanbul-lib-coverage-2.0.3.tgz#4ba8ddb720221f432e443bd5f9117fd22cfd4762" @@ -12073,7 +12088,7 @@ js-yaml@^4.1.0: dependencies: argparse "^2.0.1" -jsbi@^4.3.0: +jsbi@^4.1.0: version "4.3.0" resolved "https://registry.yarnpkg.com/jsbi/-/jsbi-4.3.0.tgz#b54ee074fb6fcbc00619559305c8f7e912b04741" integrity sha512-SnZNcinB4RIcnEyZqFPdGPVgrg2AcnykiBy0sHVJQKHYeaLUvi3Exj+iaPpLnFVkDPZIV4U0yvgC9/R4uEAZ9g== @@ -18199,10 +18214,10 @@ tslib@^2.0.1, tslib@^2.0.3: resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.2.0.tgz#fb2c475977e35e241311ede2693cee1ec6698f5c" integrity sha512-gS9GVHRU+RGn5KQM2rllAlR3dU6m7AcpJKdtH8gFvQiC4Otgk98XnmMU+nZenHt/+VhnBPWwgrJsyrdcw6i23w== -tslib@^2.4.1: - version "2.6.2" - resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.6.2.tgz#703ac29425e7b37cd6fd456e92404d46d1f3e4ae" - integrity sha512-AEYxH93jGFPn/a2iVAwW87VuUIkR1FVUKB77NwMF7nBTDkDrrT/Hpt/IrCJ0QXhW27jTBDcf5ZY7w6RiqTMw2Q== +tslib@^2.3.1: + version "2.6.3" + resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.6.3.tgz#0438f810ad7a9edcde7a241c3d80db693c8cbfe0" + integrity sha512-xNvxJEOUiWPGhUuUdQgAJPKOOJfGnIyKySOc09XkKsgdUV/3E2zvwZYdejjmRgPCgcym1juLH3226yA7sEFJKQ== tslib@~2.1.0: version "2.1.0"