Skip to content

Commit

Permalink
Merge branch 'master' into 3507-doc-migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
ainar-g committed Aug 27, 2021
2 parents 8293a6f + e5c7387 commit c177bfe
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 22 deletions.
1 change: 1 addition & 0 deletions client/src/__locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
60 changes: 43 additions & 17 deletions client/src/components/Settings/StatsConfig/Form.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,49 @@ 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:
return t('interval_days', { count: interval });
}
};

const getIntervalFields = (processing, t, toNumber) => STATS_INTERVALS_DAYS.map((interval) => <Field
key={interval}
name="interval"
type="radio"
component={renderRadioField}
value={interval}
placeholder={getIntervalTitle(interval, t)}
normalize={toNumber}
disabled={processing}
/>);

const Form = (props) => {
const {
handleSubmit, processing, submitting, invalid, handleReset, processingReset, t,
handleSubmit,
change,
processing,
submitting,
invalid,
handleReset,
processingReset,
t,
} = props;

return (
<form onSubmit={handleSubmit}>
<div className="form__group form__group--settings">
<Field
name="enabled"
type="checkbox"
component={CheckboxField}
placeholder={t('statistics_enable')}
disabled={processing}
onChange={(event) => {
if (event.target.checked) {
change('interval', STATS_INTERVALS_DAYS[0]);
} else {
change('interval', DISABLED_STATS_INTERVAL);
}
}}
/>
</div>
<label className="form__label form__label--with-desc">
<Trans>statistics_retention</Trans>
</label>
Expand All @@ -45,7 +55,23 @@ const Form = (props) => {
</div>
<div className="form__group form__group--settings mt-2">
<div className="custom-controls-stacked">
{getIntervalFields(processing, t, toNumber)}
{STATS_INTERVALS_DAYS.map((interval) => (
<Field
key={interval}
name="interval"
type="radio"
component={renderRadioField}
value={interval}
placeholder={getIntervalTitle(interval, t)}
normalize={toNumber}
disabled={processing}
onChange={(event) => {
if (event.target.checked) {
change('enabled', true);
}
}}
/>
))}
</div>
</div>
<div className="mt-5">
Expand Down
12 changes: 8 additions & 4 deletions client/src/components/Settings/StatsConfig/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
};

Expand All @@ -39,7 +40,10 @@ class StatsConfig extends Component {
>
<div className="form">
<Form
initialValues={{ interval }}
initialValues={{
interval,
enabled: !!interval,
}}
onSubmit={this.handleFormSubmit}
processing={processing}
processingReset={processingReset}
Expand Down
3 changes: 2 additions & 1 deletion client/src/helpers/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,8 @@ export const ENCRYPTION_SOURCE = {
export const FILTERED = 'Filtered';
export const NOT_FILTERED = 'NotFiltered';

export const STATS_INTERVALS_DAYS = [0, 1, 7, 30, 90];
export const DISABLED_STATS_INTERVAL = 0;
export const STATS_INTERVALS_DAYS = [1, 7, 30, 90];

export const QUERY_LOG_INTERVALS_DAYS = [0.25, 1, 7, 30, 90];

Expand Down

0 comments on commit c177bfe

Please sign in to comment.