diff --git a/client/src/__locales/en.json b/client/src/__locales/en.json index f1178b81..0e82a444 100644 --- a/client/src/__locales/en.json +++ b/client/src/__locales/en.json @@ -206,6 +206,8 @@ "anonymize_client_ip": "Anonymize client IP", "anonymize_client_ip_desc": "Don't save the full IP address of the client in logs and statistics", "dns_config": "DNS server configuration", + "dns_cache_config": "DNS cache configuration", + "dns_cache_config_desc": "Here you can configure DNS cache", "blocking_mode": "Blocking mode", "default": "Default", "nxdomain": "NXDOMAIN", @@ -491,5 +493,16 @@ "list_updated": "{{count}} list updated", "list_updated_plural": "{{count}} lists updated", "dnssec_enable": "Enable DNSSEC", - "dnssec_enable_desc": "Set DNSSEC flag in the outcoming DNS queries and check the result (DNSSEC-enabled resolver is required)" + "dnssec_enable_desc": "Set DNSSEC flag in the outcoming DNS queries and check the result (DNSSEC-enabled resolver is required)", + "cache_size": "Cache size", + "cache_size_desc": "DNS cache size (in bytes)", + "cache_ttl_min_override": "Override minimum TTL", + "cache_ttl_max_override": "Override maximum TTL", + "enter_cache_size": "Enter cache size", + "enter_cache_ttl_min_override": "Enter minimum TTL", + "enter_cache_ttl_max_override": "Enter maximum TTL", + "cache_ttl_min_override_desc": "Override TTL value (minimum) received from upstream server. This value can't larger than 3600 (1 hour)", + "cache_ttl_max_override_desc": "Override TTL value (maximum) received from upstream server", + "min_exceeds_max_value": "Minimum value exceeds maximum value", + "value_not_larger_than": "Value can't be larger than {{maximum}}" } diff --git a/client/src/components/Settings/Dns/Cache/Form.js b/client/src/components/Settings/Dns/Cache/Form.js new file mode 100644 index 00000000..c1314e89 --- /dev/null +++ b/client/src/components/Settings/Dns/Cache/Form.js @@ -0,0 +1,100 @@ +import React from 'react'; +import PropTypes from 'prop-types'; +import { Field, reduxForm } from 'redux-form'; +import { Trans, useTranslation } from 'react-i18next'; +import { shallowEqual, useSelector } from 'react-redux'; +import { + biggerOrEqualZero, + maxValue, + renderInputField, + required, + toNumber, +} from '../../../../helpers/form'; +import { FORM_NAME } from '../../../../helpers/constants'; + +const maxValue3600 = maxValue(3600); + +const getInputFields = ({ required, maxValue3600 }) => [{ + name: 'cache_size', + title: 'cache_size', + description: 'cache_size_desc', + placeholder: 'enter_cache_size', + validate: required, +}, +{ + name: 'cache_ttl_min', + title: 'cache_ttl_min_override', + description: 'cache_ttl_min_override_desc', + placeholder: 'enter_cache_ttl_min_override', + max: 3600, + validate: maxValue3600, +}, +{ + name: 'cache_ttl_max', + title: 'cache_ttl_max_override', + description: 'cache_ttl_max_override_desc', + placeholder: 'enter_cache_ttl_max_override', +}]; + +const Form = ({ + handleSubmit, submitting, invalid, +}) => { + const { t } = useTranslation(); + + const { processingSetConfig } = useSelector((state) => state.dnsConfig, shallowEqual); + const { + cache_ttl_max, cache_ttl_min, + } = useSelector((state) => state.form[FORM_NAME.CACHE].values, shallowEqual); + + const minExceedsMax = cache_ttl_min > cache_ttl_max; + + const INPUTS_FIELDS = getInputFields({ + required, + maxValue3600, + }); + + return
; +}; + +Form.propTypes = { + handleSubmit: PropTypes.func.isRequired, + submitting: PropTypes.bool.isRequired, + invalid: PropTypes.bool.isRequired, +}; + +export default reduxForm({ form: FORM_NAME.CACHE })(Form); diff --git a/client/src/components/Settings/Dns/Cache/index.js b/client/src/components/Settings/Dns/Cache/index.js new file mode 100644 index 00000000..22b8b7b6 --- /dev/null +++ b/client/src/components/Settings/Dns/Cache/index.js @@ -0,0 +1,42 @@ +import React from 'react'; +import { useTranslation } from 'react-i18next'; +import { shallowEqual, useDispatch, useSelector } from 'react-redux'; +import Card from '../../../ui/Card'; +import Form from './Form'; +import { setDnsConfig } from '../../../../actions/dnsConfig'; +import { selectCompletedFields } from '../../../../helpers/helpers'; + +const CacheConfig = () => { + const { t } = useTranslation(); + const dispatch = useDispatch(); + const { + cache_size, cache_ttl_max, cache_ttl_min, + } = useSelector((state) => state.dnsConfig, shallowEqual); + + const handleFormSubmit = (values) => { + const completedFields = selectCompletedFields(values); + dispatch(setDnsConfig(completedFields)); + }; + + return ( +