From 82345bc0e26218b0e7109b0ade4d92968c02365a Mon Sep 17 00:00:00 2001 From: jsers Date: Sat, 9 May 2020 11:17:30 +0800 Subject: [PATCH] feat: add plugin collect page --- web/src/locales/en.ts | 6 + web/src/locales/zh.ts | 6 + .../Collect/CollectForm/PLUGINForm.tsx | 145 ++++++++++++++++++ .../Monitor/Collect/CollectForm/PORTForm.tsx | 2 +- .../Monitor/Collect/CollectForm/index.tsx | 2 + web/src/pages/Monitor/Collect/config.tsx | 1 + 6 files changed, 161 insertions(+), 1 deletion(-) create mode 100644 web/src/pages/Monitor/Collect/CollectForm/PLUGINForm.tsx diff --git a/web/src/locales/en.ts b/web/src/locales/en.ts index faab88a7..c580d2f1 100644 --- a/web/src/locales/en.ts +++ b/web/src/locales/en.ts @@ -236,6 +236,12 @@ export default { 'collect.proc.type.name': 'Process Name', 'collect.proc.type.input.pattern.msg': 'Cannot contain Chinese', + 'collect.plugin': 'Plugin', + 'collect.plugin.name.placeholder': 'Description of the collection', + 'collect.plugin.filepath': 'FilePath', + 'collect.plugin.params': 'Params', + 'collect.plugin.filepath.placeholder': 'The absolute path of the plugin', + 'graph.subscribe': 'Subscribe', 'graph.subscribe.node': 'Node', 'graph.subscribe.screen': 'Screen', diff --git a/web/src/locales/zh.ts b/web/src/locales/zh.ts index 18b5418c..83a1a64d 100644 --- a/web/src/locales/zh.ts +++ b/web/src/locales/zh.ts @@ -237,6 +237,12 @@ export default { 'collect.proc.type.name': '进程名', 'collect.proc.type.input.pattern.msg': '不能包含中文', + 'collect.plugin': '插件', + 'collect.plugin.name.placeholder': '对采集配置的说明', + 'collect.plugin.filepath': '文件路径', + 'collect.plugin.params': '参数', + 'collect.plugin.filepath.placeholder': '待执行插件所在的绝对路径', + 'graph.subscribe': '订阅图表', 'graph.subscribe.node': '所属节点', 'graph.subscribe.screen': '选择大盘', diff --git a/web/src/pages/Monitor/Collect/CollectForm/PLUGINForm.tsx b/web/src/pages/Monitor/Collect/CollectForm/PLUGINForm.tsx new file mode 100644 index 00000000..de67966a --- /dev/null +++ b/web/src/pages/Monitor/Collect/CollectForm/PLUGINForm.tsx @@ -0,0 +1,145 @@ +import React, { useState } from 'react'; +import { Link } from 'react-router-dom'; +import _ from 'lodash'; +import { Button, Form, Select, Input, TreeSelect } from 'antd'; +import { injectIntl, FormattedMessage } from 'react-intl'; +import { renderTreeNodes } from '@cpts/Layout/utils'; +import { nameRule, interval } from '../config'; + + +const FormItem = Form.Item; +const { Option } = Select; +const formItemLayout = { + labelCol: { span: 6 }, + wrapperCol: { span: 14 }, +}; +const defaultFormData = { + collect_type: 'plugin', + timeout: 3, + step: 10, +}; + +const getInitialValues = (initialValues: any) => { + return _.assignIn({}, defaultFormData, _.cloneDeep(initialValues)); +} + +const CollectForm = (props: any) => { + const initialValues = getInitialValues(props.initialValues); + const { getFieldProps, getFieldDecorator } = props.form; + + getFieldDecorator('collect_type', { + initialValue: initialValues.collect_type, + }); + + const [submitLoading, setSubmitLoading] = useState(false); + + const handleSubmit = (e: any) => { + e.preventDefault(); + props.form.validateFields((errors: any, values: any) => { + if (errors) { + console.error(errors); + return; + } + setSubmitLoading(true); + props.onSubmit(values).catch(() => { + setSubmitLoading(false); + }); + }); + } + + return ( +
+ } + > + { + getFieldDecorator('nid', { + initialValue: initialValues.nid, + rules: [{ required: true }], + })( + + {renderTreeNodes(props.treeData)} + , + ) + } + + }> + + + }> + + + }> + + + }> + {} + + }> + + + + + + +
+ ); +} + +export default Form.create()(injectIntl(CollectForm)); diff --git a/web/src/pages/Monitor/Collect/CollectForm/PORTForm.tsx b/web/src/pages/Monitor/Collect/CollectForm/PORTForm.tsx index 08167f0e..ab755b2c 100644 --- a/web/src/pages/Monitor/Collect/CollectForm/PORTForm.tsx +++ b/web/src/pages/Monitor/Collect/CollectForm/PORTForm.tsx @@ -61,7 +61,7 @@ class CollectForm extends Component { render() { const { form } = this.props; const initialValues = this.getInitialValues(); - const { getFieldDecorator, getFieldProps } = form!; + const { getFieldDecorator, getFieldProps } = form! as any; const service = _.chain(initialValues.tags).split(',').filter(item => item.indexOf('service=') === 0).head().split('service=').last().value(); getFieldProps('collect_type', { initialValue: initialValues.collect_type, diff --git a/web/src/pages/Monitor/Collect/CollectForm/index.tsx b/web/src/pages/Monitor/Collect/CollectForm/index.tsx index 9bb03b35..b8a0d3d5 100644 --- a/web/src/pages/Monitor/Collect/CollectForm/index.tsx +++ b/web/src/pages/Monitor/Collect/CollectForm/index.tsx @@ -1,9 +1,11 @@ import LOGForm from './LOGForm'; import PORTForm from './PORTForm'; import PROCForm from './PROCForm'; +import PLUGINForm from './PLUGINForm'; export default { log: LOGForm, port: PORTForm, proc: PROCForm, + plugin: PLUGINForm, }; diff --git a/web/src/pages/Monitor/Collect/config.tsx b/web/src/pages/Monitor/Collect/config.tsx index 527f819d..f6a93a09 100644 --- a/web/src/pages/Monitor/Collect/config.tsx +++ b/web/src/pages/Monitor/Collect/config.tsx @@ -2,6 +2,7 @@ export const typeMap: any = { log: '日志', port: '端口', proc: '进程', + plugin: '插件', }; export const interval = [10, 30, 60, 120, 300, 600, 1800, 3600]; export const nameRule = { -- GitLab