diff --git a/src/components/GlobalHeader/AddModal.js b/src/components/GlobalHeader/AddModal.js index 5b4bccd6a..71dab4db8 100644 --- a/src/components/GlobalHeader/AddModal.js +++ b/src/components/GlobalHeader/AddModal.js @@ -15,10 +15,11 @@ * limitations under the License. */ -import React, { Component, forwardRef, Fragment } from "react"; -import { Modal, Form, Button } from "antd"; +import React, { Component, forwardRef } from "react"; +import { Modal, Form, Button, Dropdown, Menu, Icon } from "antd"; import { connect } from "dva"; import { getIntlContent } from "../../utils/IntlUtils"; +import { defaultNamespaceId } from "../_utils/utils"; const FormItem = Form.Item; const ChooseFile = forwardRef(({ onChange, file }, ref) => { @@ -45,23 +46,81 @@ const ChooseFile = forwardRef(({ onChange, file }, ref) => { ); }); + +const NamespaceSelector = forwardRef( + ({ onChange, currentNamespaceId, namespaces }) => { + const handleNamespaceChange = (value) => { + onChange(value.key); + }; + return ( + + {namespaces.map((namespace) => { + let isCurrentNamespace = + currentNamespaceId === namespace.namespaceId; + return ( + + {namespace.name} + + ); + })} + + } + > + + + ); + }, +); + @connect(({ global }) => ({ platform: global.platform, + namespaces: global.namespaces, })) class AddModal extends Component { + constructor(props) { + super(props); + + this.state = { + currentNamespaceId: defaultNamespaceId, + }; + } + handleSubmit = (e) => { const { form, handleOk } = this.props; e.preventDefault(); form.validateFieldsAndScroll((err, values) => { if (!err) { - let { file } = values; - handleOk({ file }); + let { namespace, file } = values; + handleOk({ namespace, file }); } }); }; + handleNamespacesValueChange = (value) => { + this.setState({ currentNamespaceId: value }); + }; + render() { - let { handleCancel, form, config, file } = this.props; + let { handleCancel, form, config, file, namespaces } = this.props; + let { currentNamespaceId } = this.state; const { getFieldDecorator } = form; const formItemLayout = { labelCol: { @@ -87,6 +146,26 @@ class AddModal extends Component { onCancel={handleCancel} >
+ + {getFieldDecorator("namespace", { + rules: [ + { + required: true, + }, + ], + initialValue: currentNamespaceId, + valuePropName: "namespace", + })( + , + )} + { + // export configs + exportConfigClick = () => { const { dispatch } = this.props; dispatch({ type: "common/exportAll", @@ -273,7 +273,7 @@ class GlobalHeader extends PureComponent { {getIntlContent("SHENYU.GLOBALHEADER.CHANGE.PASSWORD")} {this.checkAuth("system:manager:exportConfig") && ( - + {getIntlContent("SHENYU.COMMON.EXPORT")} )} @@ -327,6 +327,20 @@ class GlobalHeader extends PureComponent { )} + {this.checkAuth("system:manager:importConfig") && ( +
+ +
+ )} + {this.checkAuth("system:manager:exportConfig") && ( +
+ +
+ )}