mirror of https://github.com/openspug/spug
U 优化克隆发布配置
parent
e45104f12f
commit
214aa83760
|
@ -3,68 +3,56 @@
|
||||||
* Copyright (c) <spug.dev@gmail.com>
|
* Copyright (c) <spug.dev@gmail.com>
|
||||||
* Released under the AGPL-3.0 License.
|
* Released under the AGPL-3.0 License.
|
||||||
*/
|
*/
|
||||||
import React from 'react';
|
import React, { useState, useEffect } from 'react';
|
||||||
import { observer } from 'mobx-react';
|
import { observer } from 'mobx-react';
|
||||||
import { Cascader, Form, Alert } from 'antd';
|
import { Select, Form } from 'antd';
|
||||||
import envStore from 'pages/config/environment/store';
|
import envStore from 'pages/config/environment/store';
|
||||||
|
import { includes } from 'libs';
|
||||||
import store from './store';
|
import store from './store';
|
||||||
import lds from 'lodash';
|
import lds from 'lodash';
|
||||||
import { toJS } from "mobx";
|
|
||||||
|
|
||||||
@observer
|
export default observer(function (props) {
|
||||||
class CloneConfirm extends React.Component {
|
const [form] = Form.useForm()
|
||||||
handleLoadData = (selectedOptions) => {
|
const [apps] = useState(Object.values(store.records))
|
||||||
const targetOption = selectedOptions[selectedOptions.length - 1];
|
const [appId, setAppId] = useState()
|
||||||
if (targetOption.deploys === undefined) {
|
const [deploys, setDeploys] = useState([])
|
||||||
targetOption.loading = true;
|
|
||||||
store.loadDeploys(targetOption.value).then(() => targetOption.loading = false)
|
useEffect(() => {
|
||||||
|
if (appId) {
|
||||||
|
props.onChange(null)
|
||||||
|
form.setFieldsValue({env_id: undefined})
|
||||||
|
store.loadDeploys(appId)
|
||||||
|
.then(res => setDeploys(res))
|
||||||
}
|
}
|
||||||
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
|
}, [appId])
|
||||||
|
|
||||||
|
function handleChange(deployId) {
|
||||||
|
const deploy = lds.find(deploys, {id: deployId})
|
||||||
|
props.onChange(deploy)
|
||||||
}
|
}
|
||||||
|
|
||||||
handleData = records => {
|
|
||||||
return records.map(x => {
|
|
||||||
const option = {
|
|
||||||
label: x.name,
|
|
||||||
value: x.id,
|
|
||||||
deploys: x.deploys,
|
|
||||||
isLeaf: false
|
|
||||||
}
|
|
||||||
if (x.children) {
|
|
||||||
option.children = x.children
|
|
||||||
} else if (x.deploys) {
|
|
||||||
option.children = x.deploys.map(item => ({
|
|
||||||
label: lds.get(envStore.idMap, `${item.env_id}.name`),
|
|
||||||
value: JSON.stringify(item),
|
|
||||||
id: `${x.id},${item.env_id}`,
|
|
||||||
}))
|
|
||||||
}
|
|
||||||
return option
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
filter = (inputValue, path) => {
|
|
||||||
return path.some(option => option.label.toLowerCase().indexOf(inputValue.toLowerCase()) > -1);
|
|
||||||
}
|
|
||||||
|
|
||||||
render() {
|
|
||||||
const options = this.handleData(Object.values(toJS(store.records)));
|
|
||||||
return (
|
return (
|
||||||
<Form layout="vertical" style={{marginTop: 24}}>
|
<Form form={form} layout="vertical" style={{marginTop: 24}}>
|
||||||
<Form.Item
|
<Form.Item required label="克隆的应用">
|
||||||
required
|
<Select showSearch filterOption={(i, o) => includes(o.children, i)} placeholder="请选择要克隆的应用" onChange={setAppId}>
|
||||||
label="应用及环境"
|
{apps.map(item => (
|
||||||
help="克隆配置,将基于选择对象的配置来创建新的发布配置。"
|
<Select.Option key={item.id} value={item.id}>{item.name}</Select.Option>
|
||||||
extra={<Alert showIcon type="warning" message="使用搜索进行选择时可能需要选择两次。"/>}>
|
))}
|
||||||
<Cascader
|
</Select>
|
||||||
options={options}
|
</Form.Item>
|
||||||
placeholder="请选择目标应用及环境"
|
<Form.Item required name="env_id" label="克隆的环境">
|
||||||
loadData={this.handleLoadData}
|
<Select
|
||||||
onChange={this.props.onChange}
|
showSearch
|
||||||
showSearch={{filter: this.filter}}/>
|
filterOption={(i, o) => includes(o.children, i)}
|
||||||
|
placeholder="请选择要克隆的环境"
|
||||||
|
disabled={deploys.length === 0}
|
||||||
|
onChange={handleChange}>
|
||||||
|
{deploys.map(item => (
|
||||||
|
<Select.Option key={item.id} value={item.id}>{envStore.idMap[item.env_id]?.name}</Select.Option>
|
||||||
|
))}
|
||||||
|
</Select>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
</Form>
|
</Form>
|
||||||
)
|
)
|
||||||
}
|
})
|
||||||
}
|
|
||||||
|
|
||||||
export default CloneConfirm
|
|
|
@ -24,19 +24,18 @@ import lds from 'lodash';
|
||||||
function ComTable() {
|
function ComTable() {
|
||||||
function handleClone(e, id) {
|
function handleClone(e, id) {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
let cloneObj = null;
|
let deploy = null;
|
||||||
Modal.confirm({
|
Modal.confirm({
|
||||||
icon: <ExclamationCircleOutlined/>,
|
icon: <ExclamationCircleOutlined/>,
|
||||||
title: '选择克隆对象',
|
title: '选择克隆对象',
|
||||||
content: <CloneConfirm onChange={v => cloneObj = v[1]}/>,
|
content: <CloneConfirm onChange={v => deploy = v}/>,
|
||||||
onOk: () => {
|
onOk: () => {
|
||||||
if (!cloneObj) {
|
if (!deploy) {
|
||||||
message.error('请选择目标应用及环境')
|
message.error('请选择要克隆的应用及环境')
|
||||||
return Promise.reject()
|
return Promise.reject()
|
||||||
}
|
}
|
||||||
const info = JSON.parse(cloneObj);
|
deploy.env_id = undefined;
|
||||||
info.env_id = undefined;
|
store.showExtForm(null, id, deploy, true)
|
||||||
store.showExtForm(null, id, info, true)
|
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue