Full rework of the query log Squashed commit of the following: commit e8a72eb223551f17e637136713dae03accf8ab9e Author: Andrey Meshkov <am@adguard.com> Date: Thu Jun 18 00:31:53 2020 +0300 fix race in whois test commit 801d28197f888fa21f83c9a0b49e3c9472c08513 Merge: 9d9787fdb1c951fb
Author: Andrey Meshkov <am@adguard.com> Date: Thu Jun 18 00:28:13 2020 +0300 Merge branch 'master' into feature/1421 commit 9d9787fd79b17f76c7baed52c12ac462fd00a5e4 Merge: 4ce337ca 08e238ab Author: Andrey Meshkov <am@adguard.com> Date: Thu Jun 18 00:27:32 2020 +0300 Merge commit 4ce337ca7aec163edf87a038bb25fb44e64f8613 Author: Andrey Meshkov <am@adguard.com> Date: Thu Jun 18 00:22:49 2020 +0300 -(home): fix whois test commit 08e238ab0e723b1e354f58245e9a8d5017b392c9 Author: ArtemBaskal <a.baskal@adguard.com> Date: Thu Jun 18 00:13:41 2020 +0300 Add comments commit 5f108065952bcc25dce1c2eee3f9401d2641a6e9 Author: ArtemBaskal <a.baskal@adguard.com> Date: Wed Jun 17 23:47:50 2020 +0300 Make tooltip position absolute for touch commit 4c30a583165e5d007d4b01b657de8751a7bd8c7b Author: ArtemBaskal <a.baskal@adguard.com> Date: Wed Jun 17 20:39:44 2020 +0300 Prevent scroll hide for touch devices commit 62da97931f5921613762614717c62c77ddb6b8db Author: ArtemBaskal <a.baskal@adguard.com> Date: Wed Jun 17 20:06:24 2020 +0300 Review changes: ipad tooltip commit 12dddcca8caca51c157b5d25dfa3ca03ba7f0c06 Author: ArtemBaskal <a.baskal@adguard.com> Date: Wed Jun 17 16:59:16 2020 +0300 Add close tooltip event for ipad commit 62191e41d5bf67317f9f1dc6c6af08cbabb4bf90 Author: ArtemBaskal <a.baskal@adguard.com> Date: Wed Jun 17 16:39:40 2020 +0300 Add success toast on logs refresh commit 2ebdd6a8124269d737c8060c3247aaf35d85cb8b Author: ArtemBaskal <a.baskal@adguard.com> Date: Wed Jun 17 16:01:37 2020 +0300 Fix pagination commit 5820c92bacd93d05a3d66d42ee95f099e1c5d9e9 Author: ArtemBaskal <a.baskal@adguard.com> Date: Wed Jun 17 11:31:15 2020 +0300 Revert "Render table in chunks" This reverts commit cdfcd849ccddc1bc35591edac7904129431470c9. commit cdfcd849ccddc1bc35591edac7904129431470c9 Author: ArtemBaskal <a.baskal@adguard.com> Date: Tue Jun 16 18:42:18 2020 +0300 Render table in chunks commit cc8c5e64274bf6e806e2e8a4bf305af745c3ed2a Author: ArtemBaskal <a.baskal@adguard.com> Date: Tue Jun 16 17:35:24 2020 +0300 Add pagination button hover effect commit f7e134091a1556784a5fea9d83c50353536126ef Author: ArtemBaskal <a.baskal@adguard.com> Date: Tue Jun 16 16:28:00 2020 +0300 Make loader position absolute commit a7b887b57d903f1f7ac967b861b5cc677728efc4 Author: ArtemBaskal <a.baskal@adguard.com> Date: Tue Jun 16 15:42:20 2020 +0300 Ignore clients find without params commit ecb322fefd4a161d79f28d17fe27827ee91701e4 Author: ArtemBaskal <a.baskal@adguard.com> Date: Tue Jun 16 15:30:48 2020 +0300 Styles changes commit 9323ce3938bf04e1290eade09201ba0790a250c0 Author: ArtemBaskal <a.baskal@adguard.com> Date: Tue Jun 16 14:32:23 2020 +0300 Review styles changes commit e0faa04ba3643f01b2ca99524cdd52b0731725c7 Merge: 9857682315e71435
Author: ArtemBaskal <a.baskal@adguard.com> Date: Tue Jun 16 12:08:45 2020 +0300 Merge branch '1421-new-qlog-v2' into feature/1421 commit 9857682371e8d9a3a91933cfb58a26b3470675d9 Author: ArtemBaskal <a.baskal@adguard.com> Date: Mon Jun 15 18:32:02 2020 +0300 Fix response cell ... and 88 more commits
377 lines
13 KiB
JavaScript
377 lines
13 KiB
JavaScript
import React, { useState } from 'react';
|
|
import { connect } from 'react-redux';
|
|
import PropTypes from 'prop-types';
|
|
import {
|
|
Field, FieldArray, reduxForm, formValueSelector,
|
|
} from 'redux-form';
|
|
import { Trans, withTranslation } from 'react-i18next';
|
|
import flow from 'lodash/flow';
|
|
import Select from 'react-select';
|
|
|
|
import i18n from '../../../i18n';
|
|
import Tabs from '../../ui/Tabs';
|
|
import Examples from '../Dns/Upstream/Examples';
|
|
import { toggleAllServices } from '../../../helpers/helpers';
|
|
import {
|
|
required,
|
|
clientId,
|
|
renderInputField,
|
|
renderGroupField,
|
|
renderSelectField,
|
|
renderServiceField,
|
|
} from '../../../helpers/form';
|
|
import { FORM_NAME, SERVICES } from '../../../helpers/constants';
|
|
import './Service.css';
|
|
|
|
const settingsCheckboxes = [
|
|
{
|
|
name: 'use_global_settings',
|
|
placeholder: 'client_global_settings',
|
|
},
|
|
{
|
|
name: 'filtering_enabled',
|
|
placeholder: 'block_domain_use_filters_and_hosts',
|
|
},
|
|
{
|
|
name: 'safebrowsing_enabled',
|
|
placeholder: 'use_adguard_browsing_sec',
|
|
},
|
|
{
|
|
name: 'parental_enabled',
|
|
placeholder: 'use_adguard_parental',
|
|
},
|
|
{
|
|
name: 'safesearch_enabled',
|
|
placeholder: 'enforce_safe_search',
|
|
},
|
|
];
|
|
const validate = (values) => {
|
|
const errors = {};
|
|
const { name, ids } = values;
|
|
errors.name = required(name);
|
|
|
|
if (ids && ids.length) {
|
|
const idArrayErrors = [];
|
|
ids.forEach((id, idx) => {
|
|
idArrayErrors[idx] = required(id) || clientId(id);
|
|
});
|
|
|
|
if (idArrayErrors.length) {
|
|
errors.ids = idArrayErrors;
|
|
}
|
|
}
|
|
return errors;
|
|
};
|
|
|
|
const renderFieldsWrapper = (placeholder, buttonTitle) => function cell(row) {
|
|
const {
|
|
fields,
|
|
} = row;
|
|
return (
|
|
<div className="form__group">
|
|
{fields.map((ip, index) => (
|
|
<div key={index} className="mb-1">
|
|
<Field
|
|
name={ip}
|
|
component={renderGroupField}
|
|
type="text"
|
|
className="form-control"
|
|
placeholder={placeholder}
|
|
isActionAvailable={index !== 0}
|
|
removeField={() => fields.remove(index)}
|
|
normalizeOnBlur={(data) => data.trim()}
|
|
/>
|
|
</div>
|
|
))}
|
|
<button
|
|
type="button"
|
|
className="btn btn-link btn-block btn-sm"
|
|
onClick={() => fields.push()}
|
|
title={buttonTitle}
|
|
>
|
|
<svg className="icon icon--small">
|
|
<use xlinkHref="#plus" />
|
|
</svg>
|
|
</button>
|
|
</div>
|
|
);
|
|
};
|
|
|
|
// Should create function outside of component to prevent component re-renders
|
|
const renderFields = renderFieldsWrapper(i18n.t('form_enter_id'), i18n.t('form_add_id'));
|
|
|
|
const renderMultiselect = (props) => {
|
|
const { input, placeholder, options } = props;
|
|
|
|
return (
|
|
<Select
|
|
{...input}
|
|
options={options}
|
|
className="basic-multi-select"
|
|
classNamePrefix="select"
|
|
onChange={(value) => input.onChange(value)}
|
|
onBlur={() => input.onBlur(input.value)}
|
|
placeholder={placeholder}
|
|
blurInputOnSelect={false}
|
|
isMulti
|
|
/>
|
|
);
|
|
};
|
|
|
|
renderMultiselect.propTypes = {
|
|
input: PropTypes.object.isRequired,
|
|
placeholder: PropTypes.string,
|
|
options: PropTypes.array,
|
|
};
|
|
|
|
let Form = (props) => {
|
|
const {
|
|
t,
|
|
handleSubmit,
|
|
reset,
|
|
change,
|
|
pristine,
|
|
submitting,
|
|
useGlobalSettings,
|
|
useGlobalServices,
|
|
toggleClientModal,
|
|
processingAdding,
|
|
processingUpdating,
|
|
invalid,
|
|
tagsOptions,
|
|
} = props;
|
|
|
|
const [activeTabLabel, setActiveTabLabel] = useState('settings');
|
|
|
|
const tabs = {
|
|
settings: {
|
|
title: 'settings',
|
|
component: <div label="settings" title={props.t('main_settings')}>
|
|
{settingsCheckboxes.map((setting) => (
|
|
<div className="form__group" key={setting.name}>
|
|
<Field
|
|
name={setting.name}
|
|
type="checkbox"
|
|
component={renderSelectField}
|
|
placeholder={t(setting.placeholder)}
|
|
disabled={
|
|
setting.name !== 'use_global_settings'
|
|
? useGlobalSettings
|
|
: false
|
|
}
|
|
/>
|
|
</div>
|
|
))}
|
|
</div>,
|
|
},
|
|
block_services: {
|
|
title: 'block_services',
|
|
component: <div label="services" title={props.t('block_services')}>
|
|
<div className="form__group">
|
|
<Field
|
|
name="use_global_blocked_services"
|
|
type="checkbox"
|
|
component={renderServiceField}
|
|
placeholder={t('blocked_services_global')}
|
|
modifier="service--global"
|
|
/>
|
|
<div className="row mb-4">
|
|
<div className="col-6">
|
|
<button
|
|
type="button"
|
|
className="btn btn-secondary btn-block"
|
|
disabled={useGlobalServices}
|
|
onClick={() => toggleAllServices(SERVICES, change, true)}
|
|
>
|
|
<Trans>block_all</Trans>
|
|
</button>
|
|
</div>
|
|
<div className="col-6">
|
|
<button
|
|
type="button"
|
|
className="btn btn-secondary btn-block"
|
|
disabled={useGlobalServices}
|
|
onClick={() => toggleAllServices(SERVICES, change, false)}
|
|
>
|
|
<Trans>unblock_all</Trans>
|
|
</button>
|
|
</div>
|
|
</div>
|
|
<div className="services">
|
|
{SERVICES.map((service) => (
|
|
<Field
|
|
key={service.id}
|
|
icon={`service_${service.id}`}
|
|
name={`blocked_services.${service.id}`}
|
|
type="checkbox"
|
|
component={renderServiceField}
|
|
placeholder={service.name}
|
|
disabled={useGlobalServices}
|
|
/>
|
|
))}
|
|
</div>
|
|
</div>
|
|
</div>,
|
|
},
|
|
upstream_dns: {
|
|
title: 'upstream_dns',
|
|
component: <div label="upstream" title={props.t('upstream_dns')}>
|
|
<div className="form__desc mb-3">
|
|
<Trans components={[<a href="#dns" key="0">link</a>]}>
|
|
upstream_dns_client_desc
|
|
</Trans>
|
|
</div>
|
|
<Field
|
|
id="upstreams"
|
|
name="upstreams"
|
|
component="textarea"
|
|
type="text"
|
|
className="form-control form-control--textarea mb-5"
|
|
placeholder={t('upstream_dns')}
|
|
/>
|
|
<Examples />
|
|
</div>,
|
|
},
|
|
};
|
|
|
|
const activeTab = tabs[activeTabLabel].component;
|
|
|
|
return (
|
|
<form onSubmit={handleSubmit}>
|
|
<div className="modal-body">
|
|
<div className="form__group mb-0">
|
|
<div className="form__group">
|
|
<Field
|
|
id="name"
|
|
name="name"
|
|
component={renderInputField}
|
|
type="text"
|
|
className="form-control"
|
|
placeholder={t('form_client_name')}
|
|
normalizeOnBlur={(data) => data.trim()}
|
|
/>
|
|
</div>
|
|
|
|
<div className="form__group mb-4">
|
|
<div className="form__label">
|
|
<strong className="mr-3">
|
|
<Trans>tags_title</Trans>
|
|
</strong>
|
|
</div>
|
|
<div className="form__desc mt-0 mb-2">
|
|
<Trans components={[
|
|
<a href="https://github.com/AdguardTeam/AdGuardHome/wiki/Hosts-Blocklists#ctag"
|
|
key="0">link</a>,
|
|
]}>
|
|
tags_desc
|
|
</Trans>
|
|
</div>
|
|
<Field
|
|
name="tags"
|
|
component={renderMultiselect}
|
|
placeholder={t('form_select_tags')}
|
|
options={tagsOptions}
|
|
/>
|
|
</div>
|
|
|
|
<div className="form__group">
|
|
<div className="form__label">
|
|
<strong className="mr-3">
|
|
<Trans>client_identifier</Trans>
|
|
</strong>
|
|
</div>
|
|
<div className="form__desc mt-0">
|
|
<Trans
|
|
components={[
|
|
<a href="#dhcp" key="0">
|
|
link
|
|
</a>,
|
|
]}
|
|
>
|
|
client_identifier_desc
|
|
</Trans>
|
|
</div>
|
|
</div>
|
|
|
|
<div className="form__group">
|
|
<FieldArray
|
|
name="ids"
|
|
component={renderFields}
|
|
/>
|
|
</div>
|
|
</div>
|
|
|
|
<Tabs controlClass="form" tabs={tabs} activeTabLabel={activeTabLabel}
|
|
setActiveTabLabel={setActiveTabLabel}>
|
|
{activeTab}
|
|
</Tabs>
|
|
</div>
|
|
|
|
<div className="modal-footer">
|
|
<div className="btn-list">
|
|
<button
|
|
type="button"
|
|
className="btn btn-secondary btn-standard"
|
|
disabled={submitting}
|
|
onClick={() => {
|
|
reset();
|
|
toggleClientModal();
|
|
}}
|
|
>
|
|
<Trans>cancel_btn</Trans>
|
|
</button>
|
|
<button
|
|
type="submit"
|
|
className="btn btn-success btn-standard"
|
|
disabled={
|
|
submitting
|
|
|| invalid
|
|
|| pristine
|
|
|| processingAdding
|
|
|| processingUpdating
|
|
}
|
|
>
|
|
<Trans>save_btn</Trans>
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</form>
|
|
);
|
|
};
|
|
|
|
Form.propTypes = {
|
|
pristine: PropTypes.bool.isRequired,
|
|
handleSubmit: PropTypes.func.isRequired,
|
|
reset: PropTypes.func.isRequired,
|
|
change: PropTypes.func.isRequired,
|
|
submitting: PropTypes.bool.isRequired,
|
|
toggleClientModal: PropTypes.func.isRequired,
|
|
useGlobalSettings: PropTypes.bool,
|
|
useGlobalServices: PropTypes.bool,
|
|
t: PropTypes.func.isRequired,
|
|
processingAdding: PropTypes.bool.isRequired,
|
|
processingUpdating: PropTypes.bool.isRequired,
|
|
invalid: PropTypes.bool.isRequired,
|
|
tagsOptions: PropTypes.array.isRequired,
|
|
};
|
|
|
|
const selector = formValueSelector(FORM_NAME.CLIENT);
|
|
|
|
Form = connect((state) => {
|
|
const useGlobalSettings = selector(state, 'use_global_settings');
|
|
const useGlobalServices = selector(state, 'use_global_blocked_services');
|
|
return {
|
|
useGlobalSettings,
|
|
useGlobalServices,
|
|
};
|
|
})(Form);
|
|
|
|
export default flow([
|
|
withTranslation(),
|
|
reduxForm({
|
|
form: FORM_NAME.CLIENT,
|
|
enableReinitialize: true,
|
|
validate,
|
|
}),
|
|
])(Form);
|