badguardhome/client/src/components/Settings/Dns/Upstream/index.js
Artem Baskal 383507bc0c + client: Allow Fastest IP address and Parallel requests to toggle each other: Merge pull request #619 in DNS/adguard-home from feature/1678 to master
Close #1678

Squashed commit of the following:

commit 9251ed0f1b58426104d1b9bdaa4b7af5f92be83e
Author: ArtemBaskal <a.baskal@adguard.com>
Date:   Thu May 21 18:25:18 2020 +0300

    + client: Allow `Fastest IP address` and `Parallel requests` to toggle each other
2020-05-25 19:41:04 +03:00

84 lines
2.5 KiB
JavaScript

import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { withTranslation } from 'react-i18next';
import cn from 'classnames';
import Form from './Form';
import Card from '../../../ui/Card';
import { DNS_REQUEST_OPTIONS } from '../../../../helpers/constants';
class Upstream extends Component {
handleSubmit = ({ bootstrap_dns, upstream_dns, dnsRequestOption }) => {
const disabledOption = dnsRequestOption === DNS_REQUEST_OPTIONS.PARALLEL_REQUESTS
? DNS_REQUEST_OPTIONS.FASTEST_ADDR
: DNS_REQUEST_OPTIONS.PARALLEL_REQUESTS;
const formattedValues = {
bootstrap_dns,
upstream_dns,
[dnsRequestOption]: true,
[disabledOption]: false,
};
this.props.setDnsConfig(formattedValues);
};
handleTest = (values) => {
this.props.testUpstream(values);
};
render() {
const {
t,
processingTestUpstream,
dnsConfig: {
upstream_dns,
bootstrap_dns,
fastest_addr,
parallel_requests,
processingSetConfig,
},
} = this.props;
const dnsRequestOption = cn({
parallel_requests,
fastest_addr,
});
return (
<Card
title={t('upstream_dns')}
subtitle={t('upstream_dns_hint')}
bodyType="card-body box-body--settings"
>
<div className="row">
<div className="col">
<Form
initialValues={{
upstream_dns,
bootstrap_dns,
dnsRequestOption,
}}
testUpstream={this.handleTest}
onSubmit={this.handleSubmit}
processingTestUpstream={processingTestUpstream}
processingSetConfig={processingSetConfig}
/>
</div>
</div>
</Card>
);
}
}
Upstream.propTypes = {
testUpstream: PropTypes.func.isRequired,
processingTestUpstream: PropTypes.bool.isRequired,
t: PropTypes.func.isRequired,
dnsConfig: PropTypes.object.isRequired,
setDnsConfig: PropTypes.func.isRequired,
};
export default withTranslation()(Upstream);