- client: 1954 Make menu items position stable Close #1954 Squashed commit of the following: commit 24bc6faa1e45cef79e3ba83ad5d595c305e0c816 Merge: a4b07aaed3f5b407Author: ArtemBaskal <a.baskal@adguard.com> Date: Thu Aug 13 10:51:47 2020 +0300 Merge branch 'master' into fix/1954 commit a4b07aae4b3b56d60cc95f669e6c179659d904ce Author: ArtemBaskal <a.baskal@adguard.com> Date: Wed Aug 5 15:20:26 2020 +0300 Review changes commit 250cdc9b10f93664ed2c1f53d57295dba78e6a99 Merge: 32003f1939f2d5c4Author: ArtemBaskal <a.baskal@adguard.com> Date: Wed Aug 5 15:18:40 2020 +0300 Merge branch 'master' into fix/1954 commit 32003f19c6e2dda056fa6ae51f6721ea350016d1 Author: ArtemBaskal <a.baskal@adguard.com> Date: Mon Aug 3 13:36:23 2020 +0300 - client: 1954 Make menu items position stable
161 lines
5.6 KiB
JavaScript
161 lines
5.6 KiB
JavaScript
import React, { Component, Fragment } from 'react';
|
|
import PropTypes from 'prop-types';
|
|
import { withTranslation } from 'react-i18next';
|
|
|
|
import StatsConfig from './StatsConfig';
|
|
import LogsConfig from './LogsConfig';
|
|
import FiltersConfig from './FiltersConfig';
|
|
|
|
import Checkbox from '../ui/Checkbox';
|
|
import Loading from '../ui/Loading';
|
|
import PageTitle from '../ui/PageTitle';
|
|
import Card from '../ui/Card';
|
|
import { getObjectKeysSorted } from '../../helpers/helpers';
|
|
import './Settings.css';
|
|
|
|
const ORDER_KEY = 'order';
|
|
|
|
const SETTINGS = {
|
|
safebrowsing: {
|
|
enabled: false,
|
|
title: 'use_adguard_browsing_sec',
|
|
subtitle: 'use_adguard_browsing_sec_hint',
|
|
[ORDER_KEY]: 0,
|
|
},
|
|
parental: {
|
|
enabled: false,
|
|
title: 'use_adguard_parental',
|
|
subtitle: 'use_adguard_parental_hint',
|
|
[ORDER_KEY]: 1,
|
|
},
|
|
safesearch: {
|
|
enabled: false,
|
|
title: 'enforce_safe_search',
|
|
subtitle: 'enforce_save_search_hint',
|
|
[ORDER_KEY]: 2,
|
|
},
|
|
};
|
|
|
|
class Settings extends Component {
|
|
componentDidMount() {
|
|
this.props.initSettings(SETTINGS);
|
|
this.props.getStatsConfig();
|
|
this.props.getLogsConfig();
|
|
this.props.getFilteringStatus();
|
|
}
|
|
|
|
renderSettings = (settings) => getObjectKeysSorted(settings, ORDER_KEY)
|
|
.map((key) => {
|
|
const setting = settings[key];
|
|
const { enabled } = setting;
|
|
return <Checkbox
|
|
{...setting}
|
|
key={key}
|
|
handleChange={() => this.props.toggleSetting(key, enabled)}
|
|
/>;
|
|
});
|
|
|
|
render() {
|
|
const {
|
|
settings,
|
|
setStatsConfig,
|
|
resetStats,
|
|
stats,
|
|
queryLogs,
|
|
setLogsConfig,
|
|
clearLogs,
|
|
filtering,
|
|
setFiltersConfig,
|
|
t,
|
|
} = this.props;
|
|
|
|
const isDataReady = !settings.processing
|
|
&& !stats.processingGetConfig
|
|
&& !queryLogs.processingGetConfig;
|
|
|
|
return (
|
|
<Fragment>
|
|
<PageTitle title={t('general_settings')} />
|
|
{!isDataReady && <Loading />}
|
|
{isDataReady && (
|
|
<div className="content">
|
|
<div className="row">
|
|
<div className="col-md-12">
|
|
<Card bodyType="card-body box-body--settings">
|
|
<div className="form">
|
|
<FiltersConfig
|
|
initialValues={{
|
|
interval: filtering.interval,
|
|
enabled: filtering.enabled,
|
|
}}
|
|
processing={filtering.processingSetConfig}
|
|
setFiltersConfig={setFiltersConfig}
|
|
/>
|
|
{this.renderSettings(settings.settingsList)}
|
|
</div>
|
|
</Card>
|
|
</div>
|
|
<div className="col-md-12">
|
|
<LogsConfig
|
|
enabled={queryLogs.enabled}
|
|
interval={queryLogs.interval}
|
|
anonymize_client_ip={queryLogs.anonymize_client_ip}
|
|
processing={queryLogs.processingSetConfig}
|
|
processingClear={queryLogs.processingClear}
|
|
setLogsConfig={setLogsConfig}
|
|
clearLogs={clearLogs}
|
|
/>
|
|
</div>
|
|
<div className="col-md-12">
|
|
<StatsConfig
|
|
interval={stats.interval}
|
|
processing={stats.processingSetConfig}
|
|
processingReset={stats.processingReset}
|
|
setStatsConfig={setStatsConfig}
|
|
resetStats={resetStats}
|
|
/>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
)}
|
|
</Fragment>
|
|
);
|
|
}
|
|
}
|
|
|
|
Settings.propTypes = {
|
|
initSettings: PropTypes.func.isRequired,
|
|
settings: PropTypes.object.isRequired,
|
|
toggleSetting: PropTypes.func.isRequired,
|
|
getStatsConfig: PropTypes.func.isRequired,
|
|
setStatsConfig: PropTypes.func.isRequired,
|
|
resetStats: PropTypes.func.isRequired,
|
|
setFiltersConfig: PropTypes.func.isRequired,
|
|
getFilteringStatus: PropTypes.func.isRequired,
|
|
t: PropTypes.func.isRequired,
|
|
getLogsConfig: PropTypes.func,
|
|
setLogsConfig: PropTypes.func,
|
|
clearLogs: PropTypes.func,
|
|
stats: PropTypes.shape({
|
|
processingGetConfig: PropTypes.bool,
|
|
interval: PropTypes.number,
|
|
processingSetConfig: PropTypes.bool,
|
|
processingReset: PropTypes.bool,
|
|
}),
|
|
queryLogs: PropTypes.shape({
|
|
enabled: PropTypes.bool,
|
|
interval: PropTypes.number,
|
|
anonymize_client_ip: PropTypes.bool,
|
|
processingSetConfig: PropTypes.bool,
|
|
processingClear: PropTypes.bool,
|
|
processingGetConfig: PropTypes.bool,
|
|
}),
|
|
filtering: PropTypes.shape({
|
|
interval: PropTypes.number,
|
|
enabled: PropTypes.bool,
|
|
processingSetConfig: PropTypes.bool,
|
|
}),
|
|
};
|
|
|
|
export default withTranslation()(Settings);
|