refactor: closes #1354

This commit is contained in:
LoadChange 2019-06-20 10:25:21 +08:00 committed by Asa
parent 490e93ddcf
commit 9381a10d1f
8 changed files with 49 additions and 40 deletions

View File

@ -109,13 +109,7 @@ class ClusterNodeList extends React.Component {
render() { render() {
const { locale = {} } = this.props; const { locale = {} } = this.props;
const { const { pubNoData, clusterNodeList, nodeIp, nodeIpPlaceholder, query } = locale;
pubNoData,
clusterNodeList,
nodeIp,
nodeIpPlaceholder,
query,
} = locale;
const { keyword, nowNamespaceName, nowNamespaceId } = this.state; const { keyword, nowNamespaceName, nowNamespaceId } = this.state;
const { init, getValue } = this.field; const { init, getValue } = this.field;
this.init = init; this.init = init;
@ -159,7 +153,9 @@ class ClusterNodeList extends React.Component {
<FormItem label=""> <FormItem label="">
<Button <Button
type="primary" type="primary"
onClick={() => this.setState({ currentPage: 1 }, () => this.queryClusterStateList())} onClick={() =>
this.setState({ currentPage: 1 }, () => this.queryClusterStateList())
}
style={{ marginRight: 10 }} style={{ marginRight: 10 }}
> >
{query} {query}

View File

@ -17,7 +17,6 @@ import { request } from '../../../globalLib';
import { Dialog, Form, Input, Switch, Select, Message, ConfigProvider } from '@alifd/next'; import { Dialog, Form, Input, Switch, Select, Message, ConfigProvider } from '@alifd/next';
import { DIALOG_FORM_LAYOUT, METADATA_SEPARATOR, METADATA_ENTER } from './constant'; import { DIALOG_FORM_LAYOUT, METADATA_SEPARATOR, METADATA_ENTER } from './constant';
import MonacoEditor from 'components/MonacoEditor'; import MonacoEditor from 'components/MonacoEditor';
import { replaceEnter, processMetaData } from 'utils/nacosutil';
@ConfigProvider.config @ConfigProvider.config
class EditClusterDialog extends React.Component { class EditClusterDialog extends React.Component {
@ -42,7 +41,9 @@ class EditClusterDialog extends React.Component {
show(_editCluster) { show(_editCluster) {
let editCluster = _editCluster; let editCluster = _editCluster;
const { metadata = {} } = editCluster; const { metadata = {} } = editCluster;
editCluster.metadataText = processMetaData(METADATA_ENTER)(metadata); if (Object.keys(metadata).length) {
editCluster.metadataText = JSON.stringify(metadata, null, '\t');
}
this.setState({ this.setState({
editCluster, editCluster,
editClusterDialogVisible: true, editClusterDialogVisible: true,
@ -69,7 +70,7 @@ class EditClusterDialog extends React.Component {
data: { data: {
serviceName, serviceName,
clusterName: name, clusterName: name,
metadata: replaceEnter(METADATA_SEPARATOR)(metadataText), metadata: metadataText,
checkPort: defaultCheckPort, checkPort: defaultCheckPort,
useInstancePort4Check: useIPPort4Check, useInstancePort4Check: useIPPort4Check,
healthChecker: JSON.stringify(healthChecker), healthChecker: JSON.stringify(healthChecker),
@ -163,7 +164,7 @@ class EditClusterDialog extends React.Component {
]} ]}
<Form.Item label={`${locale.metadata}:`}> <Form.Item label={`${locale.metadata}:`}>
<MonacoEditor <MonacoEditor
language={'properties'} language="json"
width={'100%'} width={'100%'}
height={200} height={200}
value={metadataText} value={metadataText}

View File

@ -17,7 +17,6 @@ import { request } from '../../../globalLib';
import { Dialog, Form, Input, Switch, Message, ConfigProvider } from '@alifd/next'; import { Dialog, Form, Input, Switch, Message, ConfigProvider } from '@alifd/next';
import { DIALOG_FORM_LAYOUT, METADATA_ENTER, METADATA_SEPARATOR } from './constant'; import { DIALOG_FORM_LAYOUT, METADATA_ENTER, METADATA_SEPARATOR } from './constant';
import MonacoEditor from 'components/MonacoEditor'; import MonacoEditor from 'components/MonacoEditor';
import { replaceEnter, processMetaData } from 'utils/nacosutil';
@ConfigProvider.config @ConfigProvider.config
class EditInstanceDialog extends React.Component { class EditInstanceDialog extends React.Component {
@ -45,7 +44,7 @@ class EditInstanceDialog extends React.Component {
let editInstance = _editInstance; let editInstance = _editInstance;
const { metadata = {} } = editInstance; const { metadata = {} } = editInstance;
if (Object.keys(metadata).length) { if (Object.keys(metadata).length) {
editInstance.metadataText = processMetaData(METADATA_ENTER)(metadata); editInstance.metadataText = JSON.stringify(metadata, null, '\t');
} }
this.setState({ editInstance, editInstanceDialogVisible: true }); this.setState({ editInstance, editInstanceDialogVisible: true });
} }
@ -68,7 +67,7 @@ class EditInstanceDialog extends React.Component {
ephemeral, ephemeral,
weight, weight,
enabled, enabled,
metadata: replaceEnter(METADATA_SEPARATOR)(metadataText), metadata: metadataText,
}, },
dataType: 'text', dataType: 'text',
beforeSend: () => openLoading(), beforeSend: () => openLoading(),
@ -127,7 +126,7 @@ class EditInstanceDialog extends React.Component {
</Form.Item> </Form.Item>
<Form.Item label={`${locale.metadata}:`}> <Form.Item label={`${locale.metadata}:`}>
<MonacoEditor <MonacoEditor
language={'properties'} language="json"
width={'100%'} width={'100%'}
height={200} height={200}
value={editInstance.metadataText} value={editInstance.metadataText}

View File

@ -17,7 +17,6 @@ import { request } from '../../../globalLib';
import { Dialog, Form, Input, Select, Message, ConfigProvider } from '@alifd/next'; import { Dialog, Form, Input, Select, Message, ConfigProvider } from '@alifd/next';
import { DIALOG_FORM_LAYOUT, METADATA_SEPARATOR, METADATA_ENTER } from './constant'; import { DIALOG_FORM_LAYOUT, METADATA_SEPARATOR, METADATA_ENTER } from './constant';
import MonacoEditor from 'components/MonacoEditor'; import MonacoEditor from 'components/MonacoEditor';
import { replaceEnter, processMetaData } from 'utils/nacosutil';
@ConfigProvider.config @ConfigProvider.config
class EditServiceDialog extends React.Component { class EditServiceDialog extends React.Component {
@ -44,7 +43,7 @@ class EditServiceDialog extends React.Component {
let editService = _editService; let editService = _editService;
const { metadata = {}, name } = editService; const { metadata = {}, name } = editService;
if (Object.keys(metadata).length) { if (Object.keys(metadata).length) {
editService.metadataText = processMetaData(METADATA_ENTER)(metadata); editService.metadataText = JSON.stringify(metadata, null, '\t');
} }
this.setState({ editService, editServiceDialogVisible: true, isCreate: !name }); this.setState({ editService, editServiceDialogVisible: true, isCreate: !name });
} }
@ -85,7 +84,7 @@ class EditServiceDialog extends React.Component {
serviceName: name, serviceName: name,
groupName: groupName || 'DEFAULT_GROUP', groupName: groupName || 'DEFAULT_GROUP',
protectThreshold, protectThreshold,
metadata: replaceEnter(METADATA_SEPARATOR)(metadataText), metadata: metadataText,
selector: JSON.stringify(selector), selector: JSON.stringify(selector),
}, },
dataType: 'text', dataType: 'text',
@ -181,7 +180,7 @@ class EditServiceDialog extends React.Component {
</Form.Item> </Form.Item>
<Form.Item label={`${locale.metadata}:`} {...formItemLayout}> <Form.Item label={`${locale.metadata}:`} {...formItemLayout}>
<MonacoEditor <MonacoEditor
language={'properties'} language="json"
width={'100%'} width={'100%'}
height={200} height={200}
value={metadataText} value={metadataText}

View File

@ -18,7 +18,7 @@ import { Input, Button, Card, ConfigProvider, Form, Loading, Message } from '@al
import EditServiceDialog from './EditServiceDialog'; import EditServiceDialog from './EditServiceDialog';
import EditClusterDialog from './EditClusterDialog'; import EditClusterDialog from './EditClusterDialog';
import InstanceTable from './InstanceTable'; import InstanceTable from './InstanceTable';
import { getParameter, processMetaData } from 'utils/nacosutil'; import { getParameter } from 'utils/nacosutil';
import MonacoEditor from 'components/MonacoEditor'; import MonacoEditor from 'components/MonacoEditor';
import { MONACO_READONLY_OPTIONS, METADATA_ENTER } from './constant'; import { MONACO_READONLY_OPTIONS, METADATA_ENTER } from './constant';
import './ServiceDetail.scss'; import './ServiceDetail.scss';
@ -95,7 +95,10 @@ class ServiceDetail extends React.Component {
const { locale = {} } = this.props; const { locale = {} } = this.props;
const { serviceName, groupName, loading, service = {}, clusters } = this.state; const { serviceName, groupName, loading, service = {}, clusters } = this.state;
const { metadata = {}, selector = {} } = service; const { metadata = {}, selector = {} } = service;
const metadataText = processMetaData(METADATA_ENTER)(metadata); let metadataText = '';
if (Object.keys(metadata).length) {
metadataText = JSON.stringify(metadata, null, '\t');
}
return ( return (
<div className="main-container service-detail"> <div className="main-container service-detail">
<Loading <Loading
@ -140,7 +143,7 @@ class ServiceDetail extends React.Component {
</FormItem> </FormItem>
<FormItem label={`${locale.metadata}:`}> <FormItem label={`${locale.metadata}:`}>
<MonacoEditor <MonacoEditor
language={'properties'} language="json"
width={'100%'} width={'100%'}
height={200} height={200}
value={metadataText} value={metadataText}

View File

@ -47,6 +47,18 @@ export const getParameter = (search, name) => {
return value; return value;
}; };
export const encodeKV = (text, separator) =>
text
.split('\r\n')
.filter(row => row.trim() && row.split('=').filter(kv => kv.trim()).length === 2)
.map(row =>
row
.split('=')
.map(kv => encodeURIComponent(kv.trim()))
.join('=')
)
.join(separator);
/** /**
* 将回车符和空格替换 * 将回车符和空格替换
* @param {*} separator 替换符 * @param {*} separator 替换符
@ -56,8 +68,7 @@ export const replaceEnter = (separator = ',') => text => {
return text; return text;
} }
return text return encodeKV(text, separator)
.replace(/\r\n/g, separator)
.replace(/[\r\n]/g, separator) .replace(/[\r\n]/g, separator)
.replace(/[\t\s]/g, ''); .replace(/[\t\s]/g, '');
}; };

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long