+ client: handle time interval for statistics
This commit is contained in:
71
client/src/components/Settings/StatsConfig/Form.js
Normal file
71
client/src/components/Settings/StatsConfig/Form.js
Normal file
@@ -0,0 +1,71 @@
|
||||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { Field, reduxForm } from 'redux-form';
|
||||
import { Trans, withNamespaces } from 'react-i18next';
|
||||
import flow from 'lodash/flow';
|
||||
|
||||
import { renderRadioField, toNumber } from '../../../helpers/form';
|
||||
import { STATS_INTERVALS } from '../../../helpers/constants';
|
||||
|
||||
const getIntervalFields = (processing, t, handleChange, toNumber) =>
|
||||
STATS_INTERVALS.map((interval) => {
|
||||
const title = interval === 1
|
||||
? t('interval_24_hour')
|
||||
: t('interval_days', { value: interval });
|
||||
|
||||
return (
|
||||
<Field
|
||||
key={interval}
|
||||
name="interval"
|
||||
type="radio"
|
||||
component={renderRadioField}
|
||||
value={interval}
|
||||
placeholder={title}
|
||||
onChange={handleChange}
|
||||
normalize={toNumber}
|
||||
disabled={processing}
|
||||
/>
|
||||
);
|
||||
});
|
||||
|
||||
const Form = (props) => {
|
||||
const {
|
||||
handleSubmit, handleChange, processing, t,
|
||||
} = props;
|
||||
|
||||
return (
|
||||
<form onSubmit={handleSubmit}>
|
||||
<div className="row">
|
||||
<div className="col-12">
|
||||
<label className="form__label" htmlFor="server_name">
|
||||
<Trans>time_period</Trans>
|
||||
</label>
|
||||
</div>
|
||||
<div className="col-12">
|
||||
<div className="form__group">
|
||||
<div className="custom-controls-stacked">
|
||||
{getIntervalFields(processing, t, handleChange, toNumber)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
);
|
||||
};
|
||||
|
||||
Form.propTypes = {
|
||||
handleSubmit: PropTypes.func.isRequired,
|
||||
handleChange: PropTypes.func,
|
||||
change: PropTypes.func.isRequired,
|
||||
submitting: PropTypes.bool.isRequired,
|
||||
invalid: PropTypes.bool.isRequired,
|
||||
processing: PropTypes.bool.isRequired,
|
||||
t: PropTypes.func.isRequired,
|
||||
};
|
||||
|
||||
export default flow([
|
||||
withNamespaces(),
|
||||
reduxForm({
|
||||
form: 'logConfigForm',
|
||||
}),
|
||||
])(Form);
|
||||
49
client/src/components/Settings/StatsConfig/index.js
Normal file
49
client/src/components/Settings/StatsConfig/index.js
Normal file
@@ -0,0 +1,49 @@
|
||||
import React, { Component } from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { withNamespaces } from 'react-i18next';
|
||||
import debounce from 'lodash/debounce';
|
||||
|
||||
import { DEBOUNCE_TIMEOUT } from '../../../helpers/constants';
|
||||
import Form from './Form';
|
||||
import Card from '../../ui/Card';
|
||||
|
||||
class StatsConfig extends Component {
|
||||
handleFormChange = debounce((values) => {
|
||||
this.props.setStatsConfig(values);
|
||||
}, DEBOUNCE_TIMEOUT);
|
||||
|
||||
render() {
|
||||
const {
|
||||
t,
|
||||
interval,
|
||||
processing,
|
||||
} = this.props;
|
||||
|
||||
return (
|
||||
<Card
|
||||
title={t('stats_params')}
|
||||
bodyType="card-body box-body--settings"
|
||||
>
|
||||
<div className="form">
|
||||
<Form
|
||||
initialValues={{
|
||||
interval,
|
||||
}}
|
||||
onSubmit={this.handleFormChange}
|
||||
onChange={this.handleFormChange}
|
||||
processing={processing}
|
||||
/>
|
||||
</div>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
StatsConfig.propTypes = {
|
||||
interval: PropTypes.number.isRequired,
|
||||
processing: PropTypes.bool.isRequired,
|
||||
setStatsConfig: PropTypes.func.isRequired,
|
||||
t: PropTypes.func.isRequired,
|
||||
};
|
||||
|
||||
export default withNamespaces()(StatsConfig);
|
||||
Reference in New Issue
Block a user