diff --git a/package.json b/package.json index bf844ecc8..7a9c5e3af 100644 --- a/package.json +++ b/package.json @@ -53,6 +53,7 @@ "react-virtualized-select": "^3.1.3", "reduce-reducers": "^0.1.2", "redux": "^3.7.2", + "redux-batched-actions": "^0.4.1", "redux-form": "^7.4.2", "redux-thunk": "^2.3.0", "reselect": "^4.0.0", diff --git a/source/Provider.js b/source/Provider.js index 4f3631306..b8973c5e7 100644 --- a/source/Provider.js +++ b/source/Provider.js @@ -11,6 +11,7 @@ import { applyMiddleware, compose, createStore } from 'redux' import thunk from 'redux-thunk' import computeThemeColours from 'Ui/themeColours' import { getIframeOption, inIframe } from './utils' +import { enableBatching } from 'redux-batched-actions' let initialStore = { themeColours: computeThemeColours(getIframeOption('couleur')) @@ -50,7 +51,7 @@ export default class Layout extends PureComponent { ) ) this.store = createStore( - reducers, + enableBatching(reducers), { ...initialStore, ...this.props.initialStore }, storeEnhancer ) diff --git a/source/components/PeriodSwitch.js b/source/components/PeriodSwitch.js index cd70f0ba2..b69903d34 100644 --- a/source/components/PeriodSwitch.js +++ b/source/components/PeriodSwitch.js @@ -2,9 +2,16 @@ import React from 'react' import { Trans, translate } from 'react-i18next' import { Field } from 'redux-form' import './PeriodSwitch.css' -import { reduxForm } from 'redux-form' -import { compose } from 'ramda' +import { reduxForm, change } from 'redux-form' +import { compose, map, filter, toPairs } from 'ramda' import emoji from 'react-easy-emoji' +import { batchActions } from 'redux-batched-actions' +import { connect } from 'react-redux' +import { + situationSelector, + flatRulesSelector +} from 'Selectors/analyseSelectors' +import { findRuleByDottedName, nestedSituationToPathMap } from 'Engine/rules' export default compose( reduxForm({ @@ -12,12 +19,29 @@ export default compose( destroyOnUnmount: false, initialValues: { période: 'mois' } }), - translate() -)(function PeriodSwitch() { + translate(), + connect( + state => ({ + rules: flatRulesSelector(state), + situation: nestedSituationToPathMap(situationSelector(state)) + }), + dispatch => ({ + batchPeriodChange: actions => dispatch(batchActions(actions)) + }) + ) +)(function PeriodSwitch({ situation, rules, batchPeriodChange }) { return (