Skip to content

Commit 30ed9a2

Browse files
authored
[type:feature] adapt namesapce config export/import (#497)
* remove 'resource' button in namespacePlugin * fix es lint * fix namespace sync bug * namespace config import adapt * [type:feature]adapt_namespace_export * [type:feature]adapt_namespace_export
1 parent ca74ae6 commit 30ed9a2

File tree

4 files changed

+191
-4
lines changed

4 files changed

+191
-4
lines changed
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
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);

src/components/GlobalHeader/index.js

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import {
2929
import { connect } from "dva";
3030
import { withRouter } from "dva/router";
3131
import AddModal from "./AddModal";
32+
import ExportModal from "./ExportModal";
3233
import ImportResultModal from "./ImportResultModal";
3334
import styles from "./index.less";
3435
import { getCurrentLocale, getIntlContent } from "../../utils/IntlUtils";
@@ -226,10 +227,31 @@ class GlobalHeader extends PureComponent {
226227

227228
// export configs
228229
exportConfigClick = () => {
229-
const { dispatch } = this.props;
230-
dispatch({
231-
type: "common/exportAll",
230+
this.setState({
231+
popup: (
232+
<ExportModal
233+
disabled={false}
234+
handleOk={(values) => {
235+
const { dispatch } = this.props;
236+
dispatch({
237+
type: "common/exportAll",
238+
payload: values,
239+
callback: (res) => {
240+
this.closeModal(true);
241+
this.showImportRestlt(JSON.parse(res));
242+
},
243+
});
244+
}}
245+
handleCancel={() => {
246+
this.closeModal();
247+
}}
248+
/>
249+
),
232250
});
251+
// const { dispatch } = this.props;
252+
// dispatch({
253+
// type: "common/exportAll",
254+
// });
233255
};
234256

235257
checkAuth = (perms) => {
@@ -337,7 +359,7 @@ class GlobalHeader extends PureComponent {
337359
{this.checkAuth("system:manager:exportConfig") && (
338360
<div className={styles.item}>
339361
<Button onClick={this.exportConfigClick}>
340-
<Icon type="import" /> {getIntlContent("SHENYU.COMMON.EXPORT")}
362+
<Icon type="export" /> {getIntlContent("SHENYU.COMMON.EXPORT")}
341363
</Button>
342364
</div>
343365
)}

src/models/common.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,10 @@ export default {
256256
yield call(asyncConfigExport);
257257
},
258258

259+
*exportByNamespace(_, { call }) {
260+
yield call(asyncConfigExport);
261+
},
262+
259263
*import(params, { call }) {
260264
const { payload, callback } = params;
261265
const json = yield call(asyncConfigImport, payload);

src/services/api.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,16 @@ export async function asyncConfigExport() {
546546
});
547547
}
548548

549+
// export configs by namespace
550+
export async function asyncConfigExportByNamespace(params) {
551+
return download(
552+
`${baseUrl}/configs/exportByNamespace?namespaceId=${params.namespaceId}`,
553+
{
554+
method: `GET`,
555+
},
556+
);
557+
}
558+
549559
// import configs
550560
export async function asyncConfigImport(params) {
551561
const formData = new FormData();

0 commit comments

Comments
 (0)