forgeplus-react/src/forge/Server/reposyncer/component/addTaskModal.jsx

109 lines
4.8 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import React, {useEffect, useState} from 'react';
import { Button, Modal, Input, Select, message, Form } from 'antd';
import axios from 'axios';
import { branchForm, confirmInfo1, confirmInfo2, synchronizeTips } from './editStore';
import gitHub from '../../img/github.png';
import gitee from '../../img/gitee.png';
import '../index.scss';
function DeleteBox({owner, projectsId, visible, setVisible, branchList, reload, form, sync_repositories_unique=[], repositoriesBranch}) {
const { getFieldDecorator, validateFields , resetFields, getFieldsValue, setFieldsValue } = form;
// 选择仓库类型
const [platform, setPlatform] = useState();
// 已添加的仓库类型
const repoTypes = sync_repositories_unique.map(item=>{return item.type})
const {external_branch_name, gitlink_branch_name, first_sync_direction} = getFieldsValue();
const showConfrimContent = external_branch_name && gitlink_branch_name && first_sync_direction;
const externalRepoBySelected = platform && sync_repositories_unique.filter(item=>item.type.includes(platform))[0]
const externalRepoInfo = {
address: externalRepoBySelected && externalRepoBySelected.external_repo_address,
branchName: external_branch_name,
type: platform
}
const gitlinkRepoInfo = {
address: `${window.location.origin}/${owner}/${projectsId}.git`,
branchName: gitlink_branch_name,
type: "gitlink"
}
useEffect(()=>{
if(repoTypes.length === 1){
setPlatform(repoTypes[0].split("::")[1])
}
}, [repoTypes.toString()])
// 新建同步分支点击函数
function createNew(){
validateFields((error,values)=>{
if(!error){
const sync_repository = sync_repositories_unique.filter(item=>item.type === `SyncRepositories::${platform}`)[0]
axios.post(`/v1/${owner}/${projectsId}/sync_repositories/create_branch`, {
...values,
sync_repository_ids: sync_repository && sync_repository.sync_repository_ids.toString()
}).then(res=>{
if(res && res.data.message === "success"){
resetFields()
setVisible(false);
message.success('新建成功');
reload()
}
})
}
})
}
const formItemLayout = {
labelCol: { span: 5 },
wrapperCol: { span: 18 },
}
return(
<Modal
title="新建同步分支"
visible={visible}
onCancel={()=>{setVisible(false)}}
footer={<div><Button style={{width: '104px', height:'36px'}} onClick={()=>{setVisible(false)}}>取消</Button><Button type="primary" style={{width: '104px', height:'36px', marginLeft: '40px'}} onClick={createNew}></Button></div>}
width={650}
className="reposyncerModal"
>
<Form {...formItemLayout}>
{repoTypes.length > 1 && <Form.Item label="同步仓库平台" className="storeFormItem">
{getFieldDecorator("type",{
rules:[{required:true,message:`请选择同步仓库平台`}],
})(
<Select placeholder="请选择同步仓库平台" onChange={(value)=>{
setPlatform(value);
}}>
<Select.Option value="Github" disabled={!repositoriesBranch["Github"]}><img src={gitHub} alt="" className="storeLogo mr5"/>Github{!repositoriesBranch["Github"] && "获取分支列表失败请检查token是否有效"}</Select.Option>
<Select.Option value="Gitee" disabled={!repositoriesBranch["Gitee"]}><img src={gitee} alt="" className="storeLogo mr5"/>Gitee{!repositoriesBranch["Gitee"] && "获取分支列表失败请检查token是否有效"}</Select.Option>
</Select>
)}
</Form.Item>}
{platform && <div className='directionByAddTaskModal'>
<Form.Item label="首次同步方向:">
{getFieldDecorator("first_sync_direction",{
rules:[{required:true,message:"请选择首次同步方向"}]
})(
<Select placeholder="请选择首次同步方向" onChange={()=>{
resetFields(["external_branch_name", "gitlink_branch_name"]);
}}>
<Select.Option value="2">{platform}同步至GitLink</Select.Option>
<Select.Option value="1">GitLink同步至{platform}</Select.Option>
</Select>
)}
</Form.Item>
{synchronizeTips(platform)}
</div>}
{platform && first_sync_direction && branchForm(getFieldDecorator, setFieldsValue, {}, first_sync_direction, first_sync_direction === "2" ? repositoriesBranch[platform] : branchList, platform, {})}
</Form>
{showConfrimContent && <div className='pt15'>
{confirmInfo1()}
{confirmInfo2({
mainBranch: first_sync_direction === "1" ? gitlinkRepoInfo : externalRepoInfo,
branch: first_sync_direction === "1" ? externalRepoInfo : gitlinkRepoInfo
})}
</div>}
</Modal>
)
}
export default Form.create()(DeleteBox);