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

498 lines
16 KiB
JavaScript
Raw Normal View History

2020-06-05 16:24:37 +08:00
import React, { Component } from "react";
import { Link } from "react-router-dom";
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,
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-06-05 16:24:37 +08:00
};
2020-03-16 14:12:11 +08:00
2020-05-07 10:10:13 +08:00
getDetail = () => {
const { projectsId, mergeId } = this.props.match.params;
2020-03-16 14:12:11 +08:00
const url = `/projects/${projectsId}/pull_requests/${mergeId}.json`;
2020-06-05 16:24:37 +08:00
axios
.get(url)
.then((result) => {
if (result) {
this.setState({
data: result.data,
SpinFlag: false,
2020-06-12 17:58:58 +08:00
pr_status: result.data.pull_request.status,
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 });
const { projectsId, mergeId } = this.props.match.params;
const url = `/projects/${projectsId}/pull_requests/${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-05-07 10:10:13 +08:00
const { projectsId } = this.props.match.params;
2020-06-12 17:58:58 +08:00
const { data, title, body, mergekey, pr_status } = this.state;
2020-05-07 10:10:13 +08:00
const url = `/projects/${projectsId}/pull_requests/${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-06-05 16:24:37 +08:00
return <RenderHtml className="break_word_comments" value={v} />;
2020-03-25 15:14:20 +08:00
};
2020-06-12 17:58:58 +08:00
2020-05-07 10:10:13 +08:00
render() {
const { projectsId, mergeId } = this.props.match.params;
2020-06-05 16:24:37 +08:00
const {
data,
SpinMerge,
2020-06-12 17:58:58 +08:00
pr_status,
isSpin,
ismesrge,
SpinFlag,
2020-06-05 16:24:37 +08:00
} = this.state;
2020-03-16 14:12:11 +08:00
const { current_user } = this.props;
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
);
2020-03-16 14:12:11 +08:00
2020-05-07 10:10:13 +08:00
return (
2020-06-12 17:58:58 +08:00
<div className="">
{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">
<Tag>
<Link
2020-06-30 10:08:36 +08:00
to={`projects/${data.pull_request.is_original?data.pull_request.fork_project_id:projectsId}/coders?branch=${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>
<Tag>
<Link
to={`projects/${projectsId}/coders?branch=${data.pull_request.base}`}
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">
<div className="mt15 text-right">
{current_user &&
pr_status !== 2 &&
(data.issue.author_login === current_user.login ||
data.issue.user_permission) && (
<Button
type="success"
ghost
href={`/projects/${projectsId}/merge/${mergeId}/UpdateMerge`}
>
编辑
</Button>
)}
{data.issue.user_permission && pr_status === 0 && (
<Button
type="danger"
ghost
onClick={() => this.closedetail()}
className="ml15"
loading={isSpin}
>
拒绝
</Button>
)}
</div>
</div>
</div>
<div className="mt15">
{data.issue.description &&
data.issue.description.length > 0 ? (
this.commentCtx(data.issue.description)
2020-06-05 16:24:37 +08:00
) : (
2020-06-12 17:58:58 +08:00
<span className="color-grey-9 ml3 mr3">没有描述</span>
2020-06-05 16:24:37 +08:00
)}
</div>
</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"
/>
)}
{pr_status === 0 && data.issue.user_permission && (
<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-06-12 17:58:58 +08:00
<div className=" main">
<MergeFooter
footer_type="show"
order_id={data && data.issue.id}
{...this.props}
{...this.state}
></MergeFooter>
2020-06-05 16:24:37 +08:00
</div>
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;