import React, { useEffect } from 'react'; import PropTypes from 'prop-types'; import { change, Field, formValueSelector, reduxForm, } from 'redux-form'; import { connect } from 'react-redux'; import { Trans, withTranslation } from 'react-i18next'; import flow from 'lodash/flow'; import { CheckboxField, toFloatNumber, renderTextareaField, renderInputField, renderRadioField, } from '../../../helpers/form'; import { trimLinesAndRemoveEmpty } from '../../../helpers/helpers'; import { FORM_NAME, QUERY_LOG_INTERVALS_DAYS, HOUR, DAY, RETENTION_CUSTOM, RETENTION_CUSTOM_INPUT, RETENTION_RANGE, CUSTOM_INTERVAL, } from '../../../helpers/constants'; import '../FormButton.css'; const getIntervalTitle = (interval, t) => { switch (interval) { case RETENTION_CUSTOM: return t('settings_custom'); case 6 * HOUR: return t('interval_6_hour'); case DAY: return t('interval_24_hour'); default: return t('interval_days', { count: interval / DAY }); } }; const getIntervalFields = (processing, t, toNumber) => QUERY_LOG_INTERVALS_DAYS.map((interval) => ( )); let Form = (props) => { const { handleSubmit, submitting, invalid, processing, processingClear, handleClear, t, interval, customInterval, dispatch, } = props; useEffect(() => { if (QUERY_LOG_INTERVALS_DAYS.includes(interval)) { dispatch(change(FORM_NAME.LOG_CONFIG, CUSTOM_INTERVAL, null)); } }, [interval]); return (
{!QUERY_LOG_INTERVALS_DAYS.includes(interval) && (
{t('custom_rotation_input')}
)} {getIntervalFields(processing, t, toFloatNumber)}
ignore_domains_desc_query
); }; Form.propTypes = { handleSubmit: PropTypes.func.isRequired, handleClear: PropTypes.func.isRequired, submitting: PropTypes.bool.isRequired, invalid: PropTypes.bool.isRequired, processing: PropTypes.bool.isRequired, processingClear: PropTypes.bool.isRequired, t: PropTypes.func.isRequired, interval: PropTypes.number, customInterval: PropTypes.number, dispatch: PropTypes.func.isRequired, }; const selector = formValueSelector(FORM_NAME.LOG_CONFIG); Form = connect((state) => { const interval = selector(state, 'interval'); const customInterval = selector(state, CUSTOM_INTERVAL); return { interval, customInterval, }; })(Form); export default flow([ withTranslation(), reduxForm({ form: FORM_NAME.LOG_CONFIG }), ])(Form);