Skip to content

Commit

Permalink
Remove textarea comma splitting
Browse files Browse the repository at this point in the history
  • Loading branch information
ArtemBaskal committed Jul 14, 2020
1 parent bb34797 commit a4db6b4
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 29 deletions.
6 changes: 3 additions & 3 deletions client/src/actions/dnsConfig.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createAction } from 'redux-actions';

import apiClient from '../api/Api';
import { normalizeTextarea } from '../helpers/helpers';
import { splitByNewLine } from '../helpers/helpers';
import { addErrorToast, addSuccessToast } from './toasts';

export const getDnsConfigRequest = createAction('GET_DNS_CONFIG_REQUEST');
Expand Down Expand Up @@ -30,11 +30,11 @@ export const setDnsConfig = (config) => async (dispatch) => {

let hasDnsSettings = false;
if (Object.prototype.hasOwnProperty.call(data, 'bootstrap_dns')) {
data.bootstrap_dns = normalizeTextarea(config.bootstrap_dns);
data.bootstrap_dns = splitByNewLine(config.bootstrap_dns);
hasDnsSettings = true;
}
if (Object.prototype.hasOwnProperty.call(data, 'upstream_dns')) {
data.upstream_dns = normalizeTextarea(config.upstream_dns);
data.upstream_dns = splitByNewLine(config.upstream_dns);
hasDnsSettings = true;
}

Expand Down
6 changes: 3 additions & 3 deletions client/src/actions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { createAction } from 'redux-actions';
import i18next from 'i18next';
import axios from 'axios';

import { isVersionGreater, normalizeTextarea, sortClients } from '../helpers/helpers';
import { isVersionGreater, splitByNewLine, sortClients } from '../helpers/helpers';
import { CHECK_TIMEOUT, SETTINGS_NAMES } from '../helpers/constants';
import { getTlsStatus } from './encryption';
import apiClient from '../api/Api';
Expand Down Expand Up @@ -279,8 +279,8 @@ export const testUpstream = (config) => async (dispatch) => {
dispatch(testUpstreamRequest());
try {
const values = { ...config };
values.bootstrap_dns = normalizeTextarea(values.bootstrap_dns);
values.upstream_dns = normalizeTextarea(values.upstream_dns);
values.bootstrap_dns = splitByNewLine(values.bootstrap_dns);
values.upstream_dns = splitByNewLine(values.upstream_dns);

const upstreamResponse = await apiClient.testUpstream(values);
const testMessages = Object.keys(upstreamResponse)
Expand Down
4 changes: 2 additions & 2 deletions client/src/components/Settings/Clients/ClientsTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Trans, withTranslation } from 'react-i18next';
import ReactTable from 'react-table';

import { MODAL_TYPE } from '../../../helpers/constants';
import { normalizeTextarea } from '../../../helpers/helpers';
import { splitByNewLine } from '../../../helpers/helpers';
import Card from '../../ui/Card';
import Modal from './Modal';
import CellWrap from '../../ui/CellWrap';
Expand All @@ -30,7 +30,7 @@ class ClientsTable extends Component {
}

if (values.upstreams && typeof values.upstreams === 'string') {
config.upstreams = normalizeTextarea(values.upstreams);
config.upstreams = splitByNewLine(values.upstreams);
} else {
config.upstreams = [];
}
Expand Down
4 changes: 2 additions & 2 deletions client/src/components/Settings/Dns/Access/Form.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Trans, withTranslation } from 'react-i18next';
import flow from 'lodash/flow';
import { renderTextareaField } from '../../../../helpers/form';
import {
trimLines,
trimMultilineString,
removeEmptyLines,
} from '../../../../helpers/helpers';
import { FORM_NAME } from '../../../../helpers/constants';
Expand All @@ -21,7 +21,7 @@ const fields = [
id: 'disallowed_clients',
title: 'access_disallowed_title',
subtitle: 'access_disallowed_desc',
normalizeOnBlur: trimLines,
normalizeOnBlur: trimMultilineString,
},
{
id: 'blocked_hosts',
Expand Down
13 changes: 9 additions & 4 deletions client/src/components/Settings/Dns/Upstream/Form.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import { Trans, useTranslation } from 'react-i18next';
import classnames from 'classnames';

import Examples from './Examples';
import { renderRadioField } from '../../../../helpers/form';
import { renderRadioField, renderTextareaField } from '../../../../helpers/form';
import { DNS_REQUEST_OPTIONS, FORM_NAME } from '../../../../helpers/constants';
import { testUpstream } from '../../../../actions';
import { removeEmptyLines } from '../../../../helpers/helpers';

const getInputFields = () => [{
// eslint-disable-next-line react/display-name
Expand All @@ -17,9 +18,10 @@ const getInputFields = () => [{
</label>,
name: 'upstream_dns',
type: 'text',
component: 'textarea',
component: renderTextareaField,
className: 'form-control form-control--textarea font-monospace',
placeholder: 'upstream_dns',
normalizeOnBlur: removeEmptyLines,
},
{
name: 'upstream_mode',
Expand Down Expand Up @@ -69,7 +71,8 @@ const Form = ({
return <form onSubmit={handleSubmit}>
<div className="row">
{INPUT_FIELDS.map(({
name, component, type, className, placeholder, getTitle, subtitle, disabled, value,
name, component, type, className, placeholder,
getTitle, subtitle, disabled, value, normalizeOnBlur,
}) => <div className="col-12 mb-4" key={placeholder}>
{typeof getTitle === 'function' && getTitle()}
<Field
Expand All @@ -82,6 +85,7 @@ const Form = ({
placeholder={t(placeholder)}
subtitle={t(subtitle)}
disabled={processingSetConfig || processingTestUpstream || disabled}
normalizeOnBlur={normalizeOnBlur}
/>
</div>)}
<div className="col-12">
Expand All @@ -101,11 +105,12 @@ const Form = ({
<Field
id="bootstrap_dns"
name="bootstrap_dns"
component="textarea"
component={renderTextareaField}
type="text"
className="form-control form-control--textarea form-control--textarea-small font-monospace"
placeholder={t('bootstrap_dns')}
disabled={processingSetConfig}
normalizeOnBlur={removeEmptyLines}
/>
</div>
</div>
Expand Down
16 changes: 1 addition & 15 deletions client/src/helpers/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -306,20 +306,6 @@ export const redirectToCurrentProtocol = (values, httpPort = 80) => {
}
};

/**
* @param {string} text
* @returns []string
*/
export const normalizeTextarea = (text) => {
if (!text) {
return [];
}

return text.replace(/[;, ]/g, '\n')
.split('\n')
.filter((n) => n);
};

/**
* @param {string} text
* @returns []string
Expand All @@ -331,7 +317,7 @@ export const splitByNewLine = (text) => text.split('\n')
* @param {string} text
* @returns {string}
*/
export const trimLines = (text) => normalizeTextarea(text)
export const trimMultilineString = (text) => splitByNewLine(text)
.map((line) => line.trim()).join('\n');

/**
Expand Down

0 comments on commit a4db6b4

Please sign in to comment.