|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one or more |
| 3 | + * contributor license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright ownership. |
| 5 | + * The ASF licenses this file to You under the Apache License, Version 2.0 |
| 6 | + * (the "License"); you may not use this file except in compliance with |
| 7 | + * the License. You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | + |
| 18 | +import React, { Component, forwardRef } from "react"; |
| 19 | +import { Modal, Form, Button, Dropdown, Menu, Icon } from "antd"; |
| 20 | +import { connect } from "dva"; |
| 21 | +import { getIntlContent } from "../../utils/IntlUtils"; |
| 22 | +import { defaultNamespaceId } from "../_utils/utils"; |
| 23 | + |
| 24 | +const FormItem = Form.Item; |
| 25 | + |
| 26 | +const NamespaceSelector = forwardRef( |
| 27 | + ({ onChange, currentNamespaceId, namespaces }) => { |
| 28 | + const handleNamespaceChange = (value) => { |
| 29 | + onChange(value.key); |
| 30 | + }; |
| 31 | + return ( |
| 32 | + <Dropdown |
| 33 | + overlay={ |
| 34 | + <Menu onClick={handleNamespaceChange}> |
| 35 | + {namespaces.map((namespace) => { |
| 36 | + let isCurrentNamespace = |
| 37 | + currentNamespaceId === namespace.namespaceId; |
| 38 | + return ( |
| 39 | + <Menu.Item |
| 40 | + key={namespace.namespaceId} |
| 41 | + disabled={isCurrentNamespace} |
| 42 | + > |
| 43 | + <span>{namespace.name}</span> |
| 44 | + </Menu.Item> |
| 45 | + ); |
| 46 | + })} |
| 47 | + </Menu> |
| 48 | + } |
| 49 | + > |
| 50 | + <Button> |
| 51 | + <a |
| 52 | + className="ant-dropdown-link" |
| 53 | + style={{ fontWeight: "bold" }} |
| 54 | + onClick={(e) => e.preventDefault()} |
| 55 | + > |
| 56 | + {`${getIntlContent("SHENYU.SYSTEM.NAMESPACE")} / ${ |
| 57 | + namespaces.find( |
| 58 | + (namespace) => currentNamespaceId === namespace.namespaceId, |
| 59 | + )?.name |
| 60 | + } `} |
| 61 | + </a> |
| 62 | + <Icon type="down" /> |
| 63 | + </Button> |
| 64 | + </Dropdown> |
| 65 | + ); |
| 66 | + }, |
| 67 | +); |
| 68 | + |
| 69 | +@connect(({ global }) => ({ |
| 70 | + platform: global.platform, |
| 71 | + namespaces: global.namespaces, |
| 72 | +})) |
| 73 | +class ExportModal extends Component { |
| 74 | + constructor(props) { |
| 75 | + super(props); |
| 76 | + |
| 77 | + this.state = { |
| 78 | + currentNamespaceId: defaultNamespaceId, |
| 79 | + }; |
| 80 | + } |
| 81 | + |
| 82 | + handleSubmit = (e) => { |
| 83 | + const { form, handleOk } = this.props; |
| 84 | + e.preventDefault(); |
| 85 | + form.validateFieldsAndScroll((err, values) => { |
| 86 | + if (!err) { |
| 87 | + let { namespace, file } = values; |
| 88 | + handleOk({ namespace, file }); |
| 89 | + } |
| 90 | + }); |
| 91 | + }; |
| 92 | + |
| 93 | + handleNamespacesValueChange = (value) => { |
| 94 | + this.setState({ currentNamespaceId: value }); |
| 95 | + }; |
| 96 | + |
| 97 | + render() { |
| 98 | + let { handleCancel, form, config, namespaces } = this.props; |
| 99 | + let { currentNamespaceId } = this.state; |
| 100 | + const { getFieldDecorator } = form; |
| 101 | + const formItemLayout = { |
| 102 | + labelCol: { |
| 103 | + sm: { span: 7 }, |
| 104 | + }, |
| 105 | + wrapperCol: { |
| 106 | + sm: { span: 17 }, |
| 107 | + }, |
| 108 | + }; |
| 109 | + if (config) { |
| 110 | + config = JSON.parse(config); |
| 111 | + } |
| 112 | + |
| 113 | + return ( |
| 114 | + <Modal |
| 115 | + width={520} |
| 116 | + centered |
| 117 | + title={getIntlContent("SHENYU.COMMON.EXPORT")} |
| 118 | + visible |
| 119 | + okText={getIntlContent("SHENYU.COMMON.SURE")} |
| 120 | + cancelText={getIntlContent("SHENYU.COMMON.CALCEL")} |
| 121 | + onOk={this.handleSubmit} |
| 122 | + onCancel={handleCancel} |
| 123 | + > |
| 124 | + <Form onSubmit={this.handleSubmit} className="login-form"> |
| 125 | + <FormItem |
| 126 | + {...formItemLayout} |
| 127 | + label={getIntlContent("SHENYU.SYSTEM.NAMESPACE")} |
| 128 | + > |
| 129 | + {getFieldDecorator("namespace", { |
| 130 | + rules: [ |
| 131 | + { |
| 132 | + required: true, |
| 133 | + }, |
| 134 | + ], |
| 135 | + initialValue: currentNamespaceId, |
| 136 | + valuePropName: "namespace", |
| 137 | + })( |
| 138 | + <NamespaceSelector |
| 139 | + onChange={this.handleNamespacesValueChange} |
| 140 | + currentNamespaceId={currentNamespaceId} |
| 141 | + namespaces={namespaces} |
| 142 | + />, |
| 143 | + )} |
| 144 | + </FormItem> |
| 145 | + </Form> |
| 146 | + </Modal> |
| 147 | + ); |
| 148 | + } |
| 149 | +} |
| 150 | + |
| 151 | +export default Form.create()(ExportModal); |
0 commit comments