forgeplus-react/src/forge/Merge/MessageCount.js

545 lines
18 KiB
JavaScript
Raw Normal View History

2020-06-05 16:24:37 +08:00
import React, { Component } from "react";
2020-11-05 11:31:26 +08:00
import { Tabs } from 'antd';
2020-06-05 16:24:37 +08:00
import { Link } from "react-router-dom";
2020-11-05 11:31:26 +08:00
import { AlignCenter } from '../Component/layout';
2020-06-05 16:24:37 +08:00
import axios from "axios";
import { getImageUrl } from "educoder";
import {
Form,
Input,
Spin,
Dropdown,
Icon,
Menu,
Select,
Tag,
2020-06-12 17:58:58 +08:00
Button,
Alert,
2020-06-05 16:24:37 +08:00
} from "antd";
import "./merge.css";
import RenderHtml from "../../components/render-html";
import "../Order/order.css";
2020-06-12 17:58:58 +08:00
import MergeFooter from "./merge_footer";
2020-04-26 16:07:51 +08:00
2020-04-13 17:45:36 +08:00
const Option = Select.Option;
2020-04-02 11:00:53 +08:00
const TextArea = Input.TextArea;
2020-03-16 14:12:11 +08:00
2020-05-07 10:10:13 +08:00
class MessageCount extends Component {
constructor(props) {
2020-03-16 14:12:11 +08:00
super(props);
2020-05-07 10:10:13 +08:00
this.state = {
data: undefined,
isSpin: false,
2020-06-12 17:58:58 +08:00
ismesrge: false,
2020-06-05 16:24:37 +08:00
buttonshow: "none",
mergename: "合并请求",
mergekey: "merge",
title: "",
body: "",
2020-05-07 10:10:13 +08:00
SpinFlag: true,
2020-04-30 10:34:06 +08:00
SpinMerge: false,
2020-06-05 16:24:37 +08:00
edit_spin: false,
2020-06-12 17:58:58 +08:00
pr_status: undefined,
2021-01-13 15:46:17 +08:00
pull_request:undefined,
2020-11-05 11:31:26 +08:00
copyVisible:false,
2020-06-05 16:24:37 +08:00
};
2020-03-16 14:12:11 +08:00
}
2020-05-07 10:10:13 +08:00
componentDidMount = () => {
2020-03-31 15:07:27 +08:00
this.setState({
2020-06-05 16:24:37 +08:00
SpinFlag: true,
});
2020-03-16 14:12:11 +08:00
this.getDetail();
2020-11-05 11:31:26 +08:00
// this.clickBody();
2020-06-05 16:24:37 +08:00
};
2020-11-05 11:31:26 +08:00
clickBody=()=>{
document.body.addEventListener('click', e => {
let name = e.target.className;
if(name.indexOf("notHide")>-1 || name.indexOf("ant-tabs-tab")>-1 || name==="ant-tabs-nav-scroll"){return;}
this.setState({
copyVisible:false
})
})
}
2020-03-16 14:12:11 +08:00
2020-05-07 10:10:13 +08:00
getDetail = () => {
2020-08-12 18:13:18 +08:00
const { projectsId, mergeId, owner } = this.props.match.params;
const url = `/${owner}/${projectsId}/pulls/${mergeId}.json`;
2020-06-05 16:24:37 +08:00
axios
.get(url)
.then((result) => {
2021-01-13 15:46:17 +08:00
if (result && result.data) {
2020-06-05 16:24:37 +08:00
this.setState({
data: result.data,
SpinFlag: false,
2021-01-13 15:46:17 +08:00
pr_status: result.data.pull_request && result.data.pull_request.status,
pull_request:result.data.pull_request
2020-06-05 16:24:37 +08:00
});
2020-06-12 17:58:58 +08:00
} else {
this.setState({ SpinFlag: false });
2020-06-05 16:24:37 +08:00
}
})
.catch((error) => {
2020-03-16 14:12:11 +08:00
this.setState({
2020-06-05 16:24:37 +08:00
SpinFlag: false,
});
console.log(error);
});
};
2020-03-16 14:12:11 +08:00
2020-05-07 10:10:13 +08:00
//关闭任务
2020-06-12 17:58:58 +08:00
closedetail = () => {
this.setState({ isSpin: true });
2020-08-12 18:13:18 +08:00
const { projectsId, mergeId , owner } = this.props.match.params;
const url = `/${owner}/${projectsId}/pulls/${mergeId}/refuse_merge.json`;
2020-06-05 16:24:37 +08:00
axios
2020-06-12 17:58:58 +08:00
.post(url)
2020-06-05 16:24:37 +08:00
.then((result) => {
if (result) {
2020-06-12 17:58:58 +08:00
this.setState({
isSpin: false,
pr_status: 2,
});
} else {
this.setState({
isSpin: false,
});
2020-06-05 16:24:37 +08:00
}
})
.catch((error) => {
2020-06-12 17:58:58 +08:00
this.setState({
isSpin: false,
});
2020-06-05 16:24:37 +08:00
console.log(error);
});
};
2020-03-16 14:12:11 +08:00
2020-05-07 10:10:13 +08:00
//合并请求
prmerge = () => {
this.setState({
2020-06-05 16:24:37 +08:00
SpinMerge: true,
});
2020-08-12 18:13:18 +08:00
const { projectsId , owner } = this.props.match.params;
2020-06-12 17:58:58 +08:00
const { data, title, body, mergekey, pr_status } = this.state;
2020-08-12 18:13:18 +08:00
const url = `/${owner}/${projectsId}/pulls/${data.pull_request.id}/pr_merge.json`;
2020-06-05 16:24:37 +08:00
axios
.post(url, {
project_id: projectsId,
id: data.pull_request.id,
do: mergekey,
body: body,
title: title,
2020-03-16 14:12:11 +08:00
})
2020-06-05 16:24:37 +08:00
.then((result) => {
if (result) {
this.setState({
SpinMerge: false,
2020-06-12 17:58:58 +08:00
pr_status: 1,
2020-06-05 16:24:37 +08:00
});
2020-06-12 17:58:58 +08:00
} else {
this.setState({ SpinMerge: false });
2020-06-05 16:24:37 +08:00
}
})
.catch((error) => {
this.setState({
SpinMerge: false,
});
console.log(error);
});
};
2020-05-07 10:10:13 +08:00
changtitlepr = (e) => {
this.setState({
2020-06-05 16:24:37 +08:00
title: e.target.value,
});
};
2020-03-16 14:12:11 +08:00
2020-05-07 10:10:13 +08:00
changbodypr = (e) => {
this.setState({
2020-06-05 16:24:37 +08:00
body: e.target.value,
});
};
2020-06-12 17:58:58 +08:00
2020-05-07 10:10:13 +08:00
submitmerge = () => {
if (this.state.mergekey === "rebase") {
2020-03-16 14:12:11 +08:00
this.setState({
2020-06-05 16:24:37 +08:00
buttonshow: "block",
2020-06-12 17:58:58 +08:00
ismesrge: true,
2020-06-05 16:24:37 +08:00
});
2020-05-07 10:10:13 +08:00
} else {
2020-03-16 14:12:11 +08:00
this.setState({
2020-06-05 16:24:37 +08:00
ismesrge: "block",
2020-06-12 17:58:58 +08:00
buttonshow: false,
2020-06-05 16:24:37 +08:00
});
2020-03-16 14:12:11 +08:00
}
2020-06-05 16:24:37 +08:00
};
2020-03-16 14:12:11 +08:00
2020-05-07 10:10:13 +08:00
nonemerge = () => {
this.setState({
2020-06-12 17:58:58 +08:00
ismesrge: false,
2020-06-05 16:24:37 +08:00
buttonshow: "none",
});
};
2020-05-07 10:10:13 +08:00
getOption = (e) => {
if (e.key === "rebase") {
this.setState({
mergename: e.item.props.value,
mergekey: e.key,
2020-06-05 16:24:37 +08:00
title: "",
body: "",
buttonshow: "block",
});
2020-05-07 10:10:13 +08:00
} else {
this.setState({
mergename: e.item.props.value,
mergekey: e.key,
2020-06-05 16:24:37 +08:00
title: "",
body: "",
2020-06-12 17:58:58 +08:00
ismesrge: true,
2020-06-05 16:24:37 +08:00
buttonshow: "block",
});
2020-05-07 10:10:13 +08:00
}
2020-06-05 16:24:37 +08:00
};
2020-03-16 14:12:11 +08:00
2020-05-07 10:10:13 +08:00
cancelSubmit = () => {
this.setState({
2020-06-05 16:24:37 +08:00
editMerge: false,
});
};
2020-04-13 17:45:36 +08:00
2020-04-28 17:23:34 +08:00
commentCtx = (v) => {
2020-12-15 18:01:16 +08:00
return <RenderHtml className="break_word_comments imageLayerParent" value={v} url={this.props.history.location}/>;
2020-03-25 15:14:20 +08:00
};
2020-06-12 17:58:58 +08:00
2020-11-05 11:31:26 +08:00
setCopyVisible=(e)=>{
e.stopPropagation();
this.setState({
copyVisible:true
})
}
copyItem =()=>{
return(
<div className="copyTab notHide">
<Tabs defaultActiveKey="1" className="notHide" animated={false} size={"small"}>
<Tabs.TabPane key="1" tab={<span className="notHide">HTTPS</span>}>{this.returnCopyUrl("https://gitee.com/44886/polhttp.git")}</Tabs.TabPane>
<Tabs.TabPane key="2" tab={<span className="notHide">SSH</span>}>{this.returnCopyUrl("https://gitee.com/44886/polssh.git")}</Tabs.TabPane>
</Tabs>
</div>
)
}
returnCopyUrl=(url)=>{
return(
<div className="df notHide">
<Input value={url} className="notHide" disabled={true}/>
<Button type="primary" ghost className="ml15 notHide">复制</Button>
</div>
)
}
2020-05-07 10:10:13 +08:00
render() {
2020-08-12 18:13:18 +08:00
const { projectsId, mergeId , owner } = this.props.match.params;
2020-07-03 17:01:58 +08:00
2020-06-05 16:24:37 +08:00
const {
data,
SpinMerge,
2020-06-12 17:58:58 +08:00
pr_status,
isSpin,
ismesrge,
SpinFlag,
2021-01-13 15:46:17 +08:00
copyVisible,
pull_request
2020-06-05 16:24:37 +08:00
} = this.state;
2020-07-03 17:01:58 +08:00
const { current_user, projectDetail } = this.props;
2020-03-16 14:12:11 +08:00
const menu = (
2020-05-07 10:10:13 +08:00
<Menu onClick={(e) => this.getOption(e)}>
2020-06-05 16:24:37 +08:00
<Menu.Item key={"merge"} value="合并请求">
合并请求
</Menu.Item>
<Menu.Item key={"rebase"} value="变基并合并">
变基并合并
</Menu.Item>
<Menu.Item key={"rebase-merge"} value="变基合并 --no-ff">
变基合并 --no-ff
</Menu.Item>
<Menu.Item key={"squash"} value="压缩提交并合并">
压缩提交并合并
</Menu.Item>
2020-03-16 14:12:11 +08:00
</Menu>
2020-06-05 16:24:37 +08:00
);
2021-01-13 15:46:17 +08:00
const permission = projectDetail && (projectDetail.permission === "Admin" || projectDetail.permission === "Owner" || projectDetail.permission === "Manager");
const userLogin = current_user && current_user.login;
const operate = userLogin && projectDetail && pr_status === 0 && permission;
2020-05-07 10:10:13 +08:00
return (
2021-01-13 15:46:17 +08:00
<div>
2020-06-12 17:58:58 +08:00
{data ? (
2020-06-05 16:24:37 +08:00
<div>
2020-06-12 17:58:58 +08:00
<div className="main">
<div>
<div className="grid-item-top pb20 border-1f">
<div>
<div className="ver-middle">
<span className="mr10 ver-middle">
<span className="font-18 fwb">
{data.issue.subject}
</span>
</span>
{data.pull_request && (
<Tag
className={`pr_tags_${data.pull_request.pull_request_staus}`}
>
{pr_status === 1
? "已合并"
: pr_status === 2
? "已拒绝"
: "开启的"}
</Tag>
)}
</div>
{
<div className="mt15">
2020-06-30 10:27:05 +08:00
<Tag className="pr-branch-tag">
2020-06-12 17:58:58 +08:00
<Link
2021-03-18 17:28:53 +08:00
to={`/projects/${owner}/${data.pull_request.is_original?data.project_identifier:projectsId}/tree/${data.pull_request.head}`}
2020-06-12 17:58:58 +08:00
className="ver-middle"
>
2020-06-30 10:08:36 +08:00
{data.pull_request.is_original ? data.pull_request.fork_project_user : data.issue.project_author_name}:{data.pull_request.head}
2020-06-12 17:58:58 +08:00
</Link>
</Tag>
<span className="mr8 ver-middle">
<i
className={
"iconfont icon-youjiang color-grey-c font-16"
}
></i>
</span>
2020-06-30 10:27:05 +08:00
<Tag className="pr-branch-tag">
2020-06-12 17:58:58 +08:00
<Link
2021-03-18 17:28:53 +08:00
to={`/projects/${owner}/${projectsId}/tree/${data.pull_request.base}`}
2020-06-12 17:58:58 +08:00
className="ver-middle"
>
2020-06-30 10:08:36 +08:00
{/* {data.pull_request.is_fork ? data.pull_request.base : `${data.pull_request.pull_request_user}:${data.pull_request.base}`} */}
{data.issue.project_author_name}:{data.pull_request.base}
2020-06-12 17:58:58 +08:00
</Link>
</Tag>
</div>
}
2020-06-05 16:24:37 +08:00
2020-06-12 17:58:58 +08:00
<div className="mt15">
<Link
to={`/users/${data.issue.author_login}`}
className="show-user-link"
2020-06-05 16:24:37 +08:00
>
2020-06-12 17:58:58 +08:00
<img
className="mr5"
src={getImageUrl(
`images/${data.issue.author_picture}`
)}
alt=""
width="24"
height="24"
/>
</Link>
<span className="ver-middle">
<span className="color-grey-8 mr5"></span>
<Link
to={`/users/${data.issue.author_login}`}
className="show-user-link color-blue"
>
{data.issue.author_name}
</Link>
<span className="ml5 color-grey-8">
{pr_status === 0
? "创建于"
: pr_status === 1
? "合并于"
: "更新于"}
</span>
<span className="color-grey-8 ml5">{data.pr_time}</span>
<span className="ml25">
<span className="color-grey-8">审查人员</span>
2020-06-12 18:46:55 +08:00
{data.issue.assign_user_name ? (
<Link
to={`/users/${data.issue.assign_user_login}`}
className="show-user-link color-blue"
>
{data.issue.assign_user_name}
</Link>
) : (
"--"
)}
2020-06-12 17:58:58 +08:00
</span>
<span className="ml25">
<span className="color-grey-8">里程碑</span>
<span className="color-grey-3">
{data.issue.version ? data.issue.version : "--"}
</span>
</span>
<span className="ml25">
<span className="color-grey-8">标签</span>
<span className="color-grey-3">
{data.issue.issue_tags &&
data.issue.issue_tags.length > 0
? data.issue.issue_tags[0].name
: "--"}
</span>
</span>
<span className="ml25">
<span className="color-grey-8">优先级</span>
<span className="color-grey-3">
{data.issue.priority ? data.issue.priority : "--"}
</span>
</span>
</span>
</div>
</div>
<div className="ml10">
2020-11-05 11:31:26 +08:00
<div className="mt15 text-right" style={{display:"flex",justifyContent:"flex-end"}}>
{/* <span className="composeButton">
<Dropdown overlay={this.copyItem()} visible={copyVisible} onClick={(e)=>this.setCopyVisible(e)}>
<span>复制</span>
</Dropdown>
<span>下载为<i className="iconfont icon-sanjiaoxing-down color-blue"></i></span>
</span> */}
2021-01-13 15:46:17 +08:00
{operate && (
2020-06-12 17:58:58 +08:00
<Button
2020-11-05 11:31:26 +08:00
type="green"
2020-06-12 17:58:58 +08:00
ghost
2020-11-05 11:31:26 +08:00
className="ml20"
2020-08-17 18:44:02 +08:00
onClick={()=>{this.props.history.push(`/projects/${owner}/${projectsId}/pulls/${mergeId}/UpdateMerge`);}}
2020-06-12 17:58:58 +08:00
>
编辑
</Button>
)}
2021-01-13 15:46:17 +08:00
{operate && (
2020-06-12 17:58:58 +08:00
<Button
type="danger"
ghost
onClick={() => this.closedetail()}
2020-11-05 11:31:26 +08:00
className="ml20"
2020-06-12 17:58:58 +08:00
loading={isSpin}
>
拒绝
</Button>
)}
</div>
</div>
</div>
2020-09-27 13:58:44 +08:00
{
data.issue.description ?
<div className="mt15">{this.commentCtx(data.issue.description)}</div>
:
<p className="color-grey-9 ml3 mr3 mt15">没有描述</p>
}
2020-06-05 16:24:37 +08:00
</div>
2020-06-12 17:58:58 +08:00
<div className="mt15">
{pr_status === 2 && (
<Alert
message="提示"
description="该合并请求已被拒绝"
type="error"
/>
)}
{pr_status === 1 && (
<Alert
message="提示"
description="该合并请求已被合并"
type="success"
/>
)}
2020-07-03 17:01:58 +08:00
{pr_status === 0 && projectDetail && projectDetail.permission !=="Reporter" && (
2020-06-12 17:58:58 +08:00
<Spin spinning={SpinFlag}>
2020-06-05 16:24:37 +08:00
<div
style={{
display:
2020-06-12 17:58:58 +08:00
this.state.mergekey === "rebase"
? this.state.buttonshow === "none"
? "block"
: "none"
: !ismesrge
? "block"
: "none",
2020-06-05 16:24:37 +08:00
}}
>
2020-06-12 17:58:58 +08:00
<p className="mb15">
<Dropdown.Button
overlay={menu}
type="primary"
onClick={this.submitmerge}
icon={<Icon type="caret-down" />}
2020-06-05 16:24:37 +08:00
>
2020-06-12 17:58:58 +08:00
{this.state.mergename}
</Dropdown.Button>
</p>
<Alert
message="该合并请求可以进行自动合并操作"
type="success"
showIcon
/>
</div>
<div>
<div
style={{
display: ismesrge ? "block" : "none",
marginTop: 15,
}}
>
<Input
placeholder="标题"
value={this.state.title}
onChange={this.changtitlepr}
/>
<TextArea
placeholder="请输入合并描述..."
style={{ height: "170px", marginTop: 20 }}
value={this.state.body}
onChange={this.changbodypr}
/>
2020-05-07 10:10:13 +08:00
</div>
2020-06-12 17:58:58 +08:00
<p
className="clearfix mt15"
style={{ display: this.state.buttonshow }}
>
<Spin spinning={SpinMerge}>
<Button type="primary" onClick={() => this.prmerge()}>
确认合并
</Button>
<Button
onClick={() => this.nonemerge()}
className="ml15"
>
取消
</Button>
</Spin>
</p>
2020-05-07 10:10:13 +08:00
</div>
2020-06-12 17:58:58 +08:00
</Spin>
)}
2020-06-05 16:24:37 +08:00
</div>
</div>
2020-05-07 10:10:13 +08:00
2020-11-06 18:41:23 +08:00
<MergeFooter
footer_type={true}
order_id={data && data.issue.id}
{...this.props}
{...this.state}
></MergeFooter>
2020-06-12 17:58:58 +08:00
</div>
) : (
""
)}
2020-03-16 14:12:11 +08:00
</div>
2020-06-05 16:24:37 +08:00
);
2020-03-16 14:12:11 +08:00
}
}
2020-06-05 16:24:37 +08:00
const MessageCountForm = Form.create({ name: "MessageCountForm" })(
MessageCount
);
export default MessageCountForm;