forked from AdguardTeam/AdGuardHome
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- client: Add default mode in the DNS settings
- Loading branch information
1 parent
539ccb2
commit 92a4a6a
Showing
5 changed files
with
136 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,83 +1,112 @@ | ||
import React, { Component } from 'react'; | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { withTranslation } from 'react-i18next'; | ||
import cn from 'classnames'; | ||
import { useTranslation } from 'react-i18next'; | ||
|
||
import Form from './Form'; | ||
import Card from '../../../ui/Card'; | ||
import { DNS_REQUEST_OPTIONS } from '../../../../helpers/constants'; | ||
|
||
const getInitialDnsRequestOption = ({ | ||
parallel_requests, | ||
fastest_addr, | ||
}) => { | ||
if (parallel_requests) { | ||
return DNS_REQUEST_OPTIONS.PARALLEL_REQUESTS; | ||
} | ||
if (fastest_addr) { | ||
return DNS_REQUEST_OPTIONS.FASTEST_ADDR; | ||
} | ||
return DNS_REQUEST_OPTIONS.LOAD_BALANCING; | ||
}; | ||
|
||
const Upstream = (props) => { | ||
const [t] = useTranslation(); | ||
|
||
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 handleSubmit = ({ bootstrap_dns, upstream_dns, dnsRequestOption }) => { | ||
let options; | ||
|
||
switch (dnsRequestOption) { | ||
case DNS_REQUEST_OPTIONS.PARALLEL_REQUESTS: | ||
options = { | ||
[DNS_REQUEST_OPTIONS.PARALLEL_REQUESTS]: true, | ||
[DNS_REQUEST_OPTIONS.FASTEST_ADDR]: false, | ||
}; | ||
break; | ||
case DNS_REQUEST_OPTIONS.FASTEST_ADDR: | ||
options = { | ||
[DNS_REQUEST_OPTIONS.PARALLEL_REQUESTS]: false, | ||
[DNS_REQUEST_OPTIONS.FASTEST_ADDR]: true, | ||
}; | ||
break; | ||
case DNS_REQUEST_OPTIONS.LOAD_BALANCING: | ||
options = { | ||
[DNS_REQUEST_OPTIONS.PARALLEL_REQUESTS]: false, | ||
[DNS_REQUEST_OPTIONS.FASTEST_ADDR]: false, | ||
}; | ||
break; | ||
default: | ||
break; | ||
} | ||
|
||
const formattedValues = { | ||
bootstrap_dns, | ||
upstream_dns, | ||
[dnsRequestOption]: true, | ||
[disabledOption]: false, | ||
...options, | ||
}; | ||
|
||
this.props.setDnsConfig(formattedValues); | ||
props.setDnsConfig(formattedValues); | ||
}; | ||
|
||
handleTest = (values) => { | ||
this.props.testUpstream(values); | ||
const handleTest = (values) => { | ||
props.testUpstream(values); | ||
}; | ||
|
||
render() { | ||
const { | ||
t, | ||
processingTestUpstream, | ||
dnsConfig: { | ||
upstream_dns, | ||
bootstrap_dns, | ||
fastest_addr, | ||
parallel_requests, | ||
processingSetConfig, | ||
}, | ||
} = this.props; | ||
|
||
const dnsRequestOption = cn({ | ||
parallel_requests, | ||
const { | ||
processingTestUpstream, | ||
dnsConfig: { | ||
upstream_dns, | ||
bootstrap_dns, | ||
fastest_addr, | ||
}); | ||
parallel_requests, | ||
processingSetConfig, | ||
}, | ||
} = props; | ||
|
||
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> | ||
const dnsRequestOption = getInitialDnsRequestOption({ | ||
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={handleTest} | ||
onSubmit={handleSubmit} | ||
processingTestUpstream={processingTestUpstream} | ||
processingSetConfig={processingSetConfig} | ||
/> | ||
</div> | ||
</Card> | ||
); | ||
} | ||
} | ||
</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); | ||
export default Upstream; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters