diff --git a/client/src/__locales/en.json b/client/src/__locales/en.json index 050bb69b..2df2d93b 100644 --- a/client/src/__locales/en.json +++ b/client/src/__locales/en.json @@ -503,6 +503,7 @@ "statistics_clear_confirm": "Are you sure you want to clear statistics?", "statistics_retention_confirm": "Are you sure you want to change statistics retention? If you decrease the interval value, some data will be lost", "statistics_cleared": "Statistics successfully cleared", + "statistics_enable": "Enable statistics", "interval_hours": "{{count}} hour", "interval_hours_plural": "{{count}} hours", "filters_configuration": "Filters configuration", diff --git a/client/src/components/Settings/StatsConfig/Form.js b/client/src/components/Settings/StatsConfig/Form.js index 60a5ae86..cf8da0ac 100644 --- a/client/src/components/Settings/StatsConfig/Form.js +++ b/client/src/components/Settings/StatsConfig/Form.js @@ -4,14 +4,12 @@ import { Field, reduxForm } from 'redux-form'; import { Trans, withTranslation } from 'react-i18next'; import flow from 'lodash/flow'; -import { renderRadioField, toNumber } from '../../../helpers/form'; -import { FORM_NAME, STATS_INTERVALS_DAYS } from '../../../helpers/constants'; +import { renderRadioField, toNumber, CheckboxField } from '../../../helpers/form'; +import { FORM_NAME, STATS_INTERVALS_DAYS, DISABLED_STATS_INTERVAL } from '../../../helpers/constants'; import '../FormButton.css'; const getIntervalTitle = (interval, t) => { switch (interval) { - case 0: - return t('disabled'); case 1: return t('interval_24_hour'); default: @@ -19,24 +17,36 @@ const getIntervalTitle = (interval, t) => { } }; -const getIntervalFields = (processing, t, toNumber) => STATS_INTERVALS_DAYS.map((interval) => ); - const Form = (props) => { const { - handleSubmit, processing, submitting, invalid, handleReset, processingReset, t, + handleSubmit, + change, + processing, + submitting, + invalid, + handleReset, + processingReset, + t, } = props; return (
+
+ { + if (event.target.checked) { + change('interval', STATS_INTERVALS_DAYS[0]); + } else { + change('interval', DISABLED_STATS_INTERVAL); + } + }} + /> +
@@ -45,7 +55,23 @@ const Form = (props) => {
- {getIntervalFields(processing, t, toNumber)} + {STATS_INTERVALS_DAYS.map((interval) => ( + { + if (event.target.checked) { + change('enabled', true); + } + }} + /> + ))}
diff --git a/client/src/components/Settings/StatsConfig/index.js b/client/src/components/Settings/StatsConfig/index.js index c413d2a7..06f0179a 100644 --- a/client/src/components/Settings/StatsConfig/index.js +++ b/client/src/components/Settings/StatsConfig/index.js @@ -8,13 +8,14 @@ import Form from './Form'; class StatsConfig extends Component { handleFormSubmit = (values) => { const { t, interval: prevInterval } = this.props; + const config = { interval: values.interval }; - if (values.interval < prevInterval) { + if (config.interval < prevInterval) { if (window.confirm(t('statistics_retention_confirm'))) { - this.props.setStatsConfig(values); + this.props.setStatsConfig(config); } } else { - this.props.setStatsConfig(values); + this.props.setStatsConfig(config); } }; @@ -39,7 +40,10 @@ class StatsConfig extends Component { >