Skip to content

Commit

Permalink
fix: bump analytics to 24.10.12 and use periodSettings
Browse files Browse the repository at this point in the history
  • Loading branch information
BRaimbault committed Jul 2, 2024
1 parent 8417371 commit 7304118
Show file tree
Hide file tree
Showing 8 changed files with 113 additions and 40 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
29 changes: 17 additions & 12 deletions src/components/Root.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -65,18 +66,22 @@ const Root = ({ store }) => (
return (
<DataStoreProvider namespace={NAMESPACE}>
<SystemSettingsProvider>
<UserSettingsProvider>
<UserSettingsCtx.Consumer>
{({ keyUiLocale }) => {
if (!keyUiLocale) {
return null;
}
i18n.changeLanguage(keyUiLocale);
moment.locale(keyUiLocale);
return <App />;
}}
</UserSettingsCtx.Consumer>
</UserSettingsProvider>
<SystemInfoProvider>
<UserSettingsProvider>
<UserSettingsCtx.Consumer>
{({ keyUiLocale }) => {
if (!keyUiLocale) {
return null;
}
i18n.changeLanguage(
keyUiLocale
);
moment.locale(keyUiLocale);
return <App />;
}}
</UserSettingsCtx.Consumer>
</UserSettingsProvider>
</SystemInfoProvider>
</SystemSettingsProvider>
</DataStoreProvider>
);
Expand Down
42 changes: 42 additions & 0 deletions src/components/SystemInfoProvider.js
Original file line number Diff line number Diff line change
@@ -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 (
<SystemInfoCtx.Provider value={settings}>
{children}
</SystemInfoCtx.Provider>
);
};

SystemInfoProvider.propTypes = {
children: PropTypes.node,
};

export default SystemInfoProvider;

export const useSystemInfo = () => useContext(SystemInfoCtx);
7 changes: 7 additions & 0 deletions src/components/edit/LayerEdit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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);

Expand Down Expand Up @@ -89,6 +95,7 @@ const LayerEdit = ({ layer, cancelLayer, setLayerLoading, loadLayer }) => {
<LayerDialog
{...layer}
defaultPeriod={keyAnalysisRelativePeriod}
periodsSettings={periodsSettings}
validateLayer={isValidLayer}
onLayerValidation={onLayerValidation}
/>
Expand Down
3 changes: 3 additions & 0 deletions src/components/edit/thematic/ThematicDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -242,6 +243,7 @@ export class ThematicDialog extends Component {
noDataColor,
operand,
periodType,
periodsSettings,
settings,
renderingStrategy,
startDate,
Expand Down Expand Up @@ -466,6 +468,7 @@ export class ThematicDialog extends Component {
(!periodType && id)) && (
<PeriodSelect
periodType={periodType}
periodsSettings={periodsSettings}
period={period}
onChange={setPeriod}
className={styles.periodSelect}
Expand Down
9 changes: 5 additions & 4 deletions src/components/periods/PeriodSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class PeriodSelect extends Component {
id: PropTypes.string.isRequired,
startDate: PropTypes.string,
}),
periodsSettings: PropTypes.object,
onChange: PropTypes.func.isRequired,
className: PropTypes.string,
errorText: PropTypes.string,
Expand Down Expand Up @@ -103,12 +104,12 @@ class PeriodSelect extends Component {
}

setPeriods() {
const { periodType, period } = this.props;
const { periodType, periodsSettings, period } = this.props;
const year = this.state.year || getYear(period && period.startDate);
let periods;

if (periodType) {
periods = getFixedPeriodsByType(periodType, year);
periods = getFixedPeriodsByType(periodType, year, periodsSettings);
} else if (period) {
periods = [period]; // If period is loaded in favorite
}
Expand All @@ -125,12 +126,12 @@ class PeriodSelect extends Component {
};

changeYear = change => {
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),
});
};
}
Expand Down
4 changes: 2 additions & 2 deletions src/util/periods.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
57 changes: 36 additions & 21 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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/[email protected]", "@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"
Expand Down Expand Up @@ -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":
Expand Down Expand Up @@ -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/[email protected].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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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==
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 7304118

Please sign in to comment.