forgeplus-react/src/forge/DevOps/opsDetail.jsx

115 lines
3.4 KiB
React
Raw Normal View History

2020-08-09 22:39:58 +08:00
import React, { useEffect, useState, useRef, useContext } from "react";
2020-07-31 20:15:28 +08:00
import "./ops.scss";
import { FlexAJ, AlignCenter } from "../Component/layout";
import { Tags } from "../Component/OpsStatus";
import SplitPane from "react-split-pane";
import LeftPanel from "./OpsDetailLeftpanel";
import RightPanel from "./OpsDetailRightpanel";
import axios from "axios";
import { Spin } from "antd";
2020-08-09 22:39:58 +08:00
import { Link } from "react-router-dom";
2020-07-13 15:17:28 +08:00
2020-07-31 20:15:28 +08:00
export default (props) => {
const [data, setData] = useState(undefined);
2020-08-27 15:15:03 +08:00
const [stageN, setStageN] = useState(undefined);
const [stepN, setStepN] = useState(undefined);
2020-08-26 16:09:27 +08:00
const [rightSpin, setRightSpin] = useState(false);
2020-07-31 20:15:28 +08:00
const [spinning, setSpinning] = useState(true);
2020-07-10 15:42:57 +08:00
2020-07-31 20:15:28 +08:00
let projectId = props.match.params.projectId;
2020-08-26 16:09:27 +08:00
let owner = props.match.params.owner;
2020-07-31 20:15:28 +08:00
let opsId = props.match.params.opsId;
useEffect(() => {
if (opsId && projectId) {
Init();
}
}, [opsId]);
2020-08-09 22:39:58 +08:00
function Init() {
2020-08-26 16:09:27 +08:00
const url = `/${owner}/${projectId}/builds/${opsId}.json`;
axios.get(url).then((result) => {
if (result && result.data) {
setSpinning(false);
setData(result.data);
}
})
.catch((error) => {
console.log(error);
setSpinning(false);
});
}
// 重新构建
function repeatSet(e,type,number) {
if(type==="repeat"){
// 重新构建
const url = `/${owner}/${projectId}/builds/${number}/restart.json`;
axios.post(url).then((result) => {
2020-08-09 22:39:58 +08:00
if (result && result.data) {
2020-08-26 16:09:27 +08:00
props.showNotification("工作流正在重新构建!");
props.history.push(`/projects/${owner}/${projectId}/devops/${result.data.number}/detail`);
2020-08-09 22:39:58 +08:00
}
})
.catch((error) => {
console.log(error);
});
2020-08-26 16:09:27 +08:00
}else{
// 撤销构建
const url = `/${owner}/${projectId}/builds/${number}/stop.json`;
axios.delete(url).then((result) => {
2020-08-09 22:39:58 +08:00
if (result) {
2020-08-26 16:09:27 +08:00
props.showNotification("撤销构建成功!");
2020-08-09 22:39:58 +08:00
Init();
}
})
.catch((error) => {
console.log(error);
});
2020-08-26 16:09:27 +08:00
}
}
2020-08-27 15:15:03 +08:00
function chooseSteps(pre,sub){
if(pre && sub){
setStepN(sub);
setStageN(pre);
2020-08-26 16:09:27 +08:00
setRightSpin(true);
}
2020-07-31 20:15:28 +08:00
}
return (
<Spin spinning={spinning}>
<div className="opsDetailPanel">
<FlexAJ className="opsInfos">
<AlignCenter>
<span>#{data && data.number}</span>
<span className="ml10">{data && data.message}</span>
{Tags(`${data && data.status}`)}
</AlignCenter>
2020-08-09 22:39:58 +08:00
<Link
style={{ color: "#ddd" }}
2020-08-26 16:09:27 +08:00
to={`/projects/${owner}/${projectId}/devops/list`}
2020-08-09 22:39:58 +08:00
>
2020-08-26 16:09:27 +08:00
<i className="iconfont icon-yiguanbi font-15 mr5"></i>退出
2020-07-31 20:15:28 +08:00
</Link>
</FlexAJ>
<div className="opsSection">
<SplitPane
className="outer-split-pane"
split="vertical"
minSize={468}
maxSize={-350}
defaultSize="40%"
>
<section className="leftSection">
2020-08-26 16:09:27 +08:00
<LeftPanel data={data} repeatSet={repeatSet} chooseSteps={chooseSteps} />
2020-07-31 20:15:28 +08:00
</section>
<section className="rightSection">
2020-08-27 15:15:03 +08:00
<RightPanel data={data} rightSpin={rightSpin} stepN={stepN} stageN={stageN} owner={owner} projectId={projectId} opsId={opsId} />
2020-07-31 20:15:28 +08:00
</section>
</SplitPane>
</div>
2020-07-13 15:17:28 +08:00
</div>
2020-07-31 20:15:28 +08:00
</Spin>
);
};