Merge pull request 'pr路由改造bugfix' (#159) from yuzhantian/forgeplus-react:feature_pull_routers into feature_router_v2

This commit is contained in:
baladiwei 2021-10-13 17:01:18 +08:00
commit a4902739f2
14 changed files with 118 additions and 56 deletions

View File

@ -426,7 +426,7 @@ function CoderDepot(props){
<div className="addOptionBtn">
{
baseOperate &&
<CheckProfile {...props} sureFunc={()=>urlLink(`/${owner}/${projectsId}/compare/${branchName || defaultBranch}`)} >+ 合并请求</CheckProfile>
<CheckProfile {...props} sureFunc={()=>urlLink(`/${owner}/${projectsId}/compare/master...${branchName || defaultBranch}`)} >+ 合并请求</CheckProfile>
}
{
baseOper &&

View File

@ -320,6 +320,9 @@ class Detail extends Component {
const url = `/${owner}/${projectsId}/detail.json`;
axios.get(url).then((result) => {
if (result && result.data) {
if (result.data.status === 404) {
this.props.history.push('/nopage');
}
this.setState({
projectDetail: result.data,
project_id: result.data.project_id,
@ -725,7 +728,7 @@ class Detail extends Component {
(props) => (<CreateMerge {...this.props} {...props} {...this.state} {...common} is_fork={true} />)
}
></Route>
<Route path="/:owner/:projectsId/pulls/:mergeId/updatemerge"
<Route path="/:owner/:projectsId/pulls/:mergeId/edit"
render={
(props) => (<UpdateMerge {...this.props} {...props} {...this.state} {...common} />)
}

View File

@ -91,7 +91,7 @@ function Index(props) {
<div className="treeabout">
{
(isManager || isDeveloper) && (projectDetail && projectDetail.type!==2) &&
<Link to={`/${owner}/${projectsId}/compare/${i.name}`} className="btn-83">+ 合并请求</Link>
<Link to={`/${owner}/${projectsId}/compare/master...${i.name}`} className="btn-83">+ 合并请求</Link>
}
<Dropdown overlay={menu(i.zip_url,i.tar_url)} trigger={['click']} placement="bottomRight">
<a className="btn-83 ml15">下载<i className="iconfont icon-sanjiaoxing-down font-14"></i></a>

View File

@ -121,6 +121,15 @@ class CreateMerge extends Component {
.get(url)
.then((result) => {
if (result) {
// 如果url上的分支不存在取默认值master
const noMergeBranch =
(result.data.branches || []).filter(
(branch) => branch.name === mergeBranch
).length === 0;
const noPullBranch =
(result.data.branches || []).filter(
(branch) => branch.name === pullBranch
).length === 0;
this.setState({
// isFork: result.data.is_fork,
projects_names: result.data.projects_names,
@ -132,11 +141,23 @@ class CreateMerge extends Component {
merge: mergeBranch,
pull: pullBranch,
});
if (!noMergeBranch && !noPullBranch) {
this.compareProject(result.data.id, branchParams);
} else {
const _message = [];
noMergeBranch && _message.push('目标分支不存在');
noPullBranch && _message.push('源分支不存在');
this.setState({
showMessage: true,
defaultMessage: _message.join(' , '),
isCompareSpin: false,
});
}
}
if (pullOwner !== mergeOwner) {
this.getBranchList(mergeOwner, projectId);
this.getBranchList(branchParams);
}
this.compareProject(result.data.id, branchParams);
this.setState({ isSpin: false });
})
.catch((error) => {
@ -192,15 +213,19 @@ class CreateMerge extends Component {
};
// 根据所有者、仓库名,获取分支列表,目前仅涉及目标仓库分支查询
getBranchList = (login, projectId) => {
getBranchList = ({ mergeOwner, projectId, mergeBranch }) => {
this.setState({ isSpin: true });
const url = `/${login}/${projectId}/pulls/get_branches.json`;
const url = `/${mergeOwner}/${projectId}/pulls/get_branches.json`;
axios
.get(url)
.then((result) => {
if (result) {
const noMergeBranch =
(result.data || []).filter((branch) => branch.name === mergeBranch)
.length === 0;
this.setState({
mergeBranches: result.data,
merge: noMergeBranch ? 'master' : mergeBranch,
});
}
this.setState({ isSpin: false });
@ -319,7 +344,7 @@ class CreateMerge extends Component {
return (
<div>
<Spin spinning={isSpin}>
<Spin spinning={isSpin || isCompareSpin}>
<div className="main">
<div className="merge-header width100 inline-block">
<div className="width40 pull-left">

View File

@ -228,7 +228,7 @@ class MergeDetail extends Component {
<div>
{
data && data.issue.user_permission ?
<Link to={`/${owner}/${projectsId}/pulls/${mergeid}/updatemerge`} className="color-blue fr">编辑</Link>
<Link to={`/${owner}/${projectsId}/pulls/${mergeid}/edit`} className="color-blue fr">编辑</Link>
: ''
}
</div>

View File

@ -196,7 +196,7 @@ class MergeItem extends Component {
>
<div className="grid-item mr15 color-grey-9">
<Link
to={`/${owner}/${projectsId}/pulls/${item.pull_request_id}/updatemerge`}
to={`/${owner}/${projectsId}/pulls/${item.pull_request_id}/edit`}
className="color-grey-9"
>
<i className="iconfont icon-bianji3 font-14 mr5"></i>

View File

@ -16,7 +16,7 @@ class MergeFooter extends Component {
constructor(props) {
super(props);
this.state = {
commitsData: undefined,
commitsData: [],
filesData: undefined,
isSpin: false,
activeKey: '1',
@ -28,6 +28,8 @@ class MergeFooter extends Component {
}
componentDidMount() {
this.Init();
// 便
this.props.bindFootRef && this.props.bindFootRef(this);
}
componentDidUpdate(prevProps) {
@ -35,11 +37,11 @@ class MergeFooter extends Component {
const newPathname = this.props.location.pathname;
const prevPathname = prevProps.location.pathname;
if (newPathname !== prevPathname) {
this.Init();
this.Init(true);
}
}
Init = () => {
Init = (isTabChange) => {
const { data, location, match } = this.props;
const { pathname } = location;
const { projectsId, owner, mergeId } = match.params;
@ -52,6 +54,9 @@ class MergeFooter extends Component {
activeKey = '3';
this.getFile(owner, projectsId, mergeId);
}
if (isTabChange && activeKey === '1') {
this.refreshComment();
}
this.setState({
activeKey: activeKey,
commitCount: data && data.commits_count,
@ -59,6 +64,14 @@ class MergeFooter extends Component {
});
};
bindCommentRef = (commentRef) => {
this.childComment = commentRef;
}
refreshComment = () => {
this.childComment && this.childComment.getjournalslist();
}
getCommit = (owner, projectsId, mergeId) => {
this.setState({ isSpin: true });
const url = `/${owner}/${projectsId}/pulls/${mergeId}/commits.json`;
@ -107,7 +120,7 @@ class MergeFooter extends Component {
filesCount,
commitCount,
filesData,
commitsData,
commitsData = [],
} = this.state;
// Comment0
@ -117,7 +130,7 @@ class MergeFooter extends Component {
);
return (
<div className="main" style={{ paddingTop: '0px' }}>
<div className="main mergeRequest" style={{ paddingTop: '0px' }}>
<Spin spinning={isSpin}>
<Tabs
activeKey={activeKey}
@ -143,8 +156,10 @@ class MergeFooter extends Component {
this.setState({ commentsTotalCount: commentsCount || 0 });
}}
{...this.props}
bindCommentRef={this.bindCommentRef}
/>
</TabPane>
{commitCount > 0 && (
<TabPane
tab={
<Link to={`/${owner}/${projectsId}/pulls/${mergeId}/commits`}>
@ -156,7 +171,7 @@ class MergeFooter extends Component {
}
key="2"
>
{commitsData && (
{commitsData.length > 0 && (
<Commits
{...this.props}
commits={commitsData}
@ -165,6 +180,8 @@ class MergeFooter extends Component {
></Commits>
)}
</TabPane>
)}
{filesCount > 0 && (
<TabPane
tab={
<Link to={`/${owner}/${projectsId}/pulls/${mergeId}/files`}>
@ -183,6 +200,7 @@ class MergeFooter extends Component {
owner={owner}
/>
</TabPane>
)}
</Tabs>
</Spin>
</div>

View File

@ -58,6 +58,11 @@ class MessageCount extends Component {
// this.clickBody();
};
bindFootRef = (footRef) => {
this.footRef = footRef;
}
clickBody=()=>{
document.body.addEventListener('click', e => {
let name = e.target.className;
@ -147,6 +152,8 @@ class MessageCount extends Component {
});
const { getDetail } = this.props;
getDetail && getDetail();
// 调用子组件的方法刷新评论列表
this.footRef && this.footRef.refreshComment();
} else {
this.setState({ SpinMerge: false });
}
@ -445,7 +452,7 @@ class MessageCount extends Component {
type="green"
ghost
className="ml20"
onClick={()=>{this.props.history.push(`/${owner}/${projectsId}/pulls/${mergeId}/updatemerge`);}}
onClick={()=>{this.props.history.push(`/${owner}/${projectsId}/pulls/${mergeId}/edit`);}}
>
编辑
</Button>
@ -566,6 +573,7 @@ class MessageCount extends Component {
order_id={data && data.issue.id}
{...this.props}
{...this.state}
bindFootRef={this.bindFootRef}
></MergeLinkFooter>
</div>
) : (

View File

@ -6,6 +6,11 @@ import "./merge.css";
import MergeForm from "./merge_form";
import MergeFooter from "./merge_footer";
const Option = Select.Option;
/**
* 此文件已废弃新文件为CreateMerge.js
* 2021.10.12
*/
class NewMerge extends Component {
constructor(props) {
super(props);

View File

@ -69,7 +69,7 @@ class UpdateMerge extends Component {
</Button>
<Select
defaultValue={data.is_original ? `${data.fork_project_user}:${pull}` : `${pull}`}
className="minW50 merge-flex1"
className="minW50 merge-flex1 flex1"
disabled
></Select>{" "}
</Input.Group>{" "}
@ -88,7 +88,7 @@ class UpdateMerge extends Component {
</Button>
<Select
defaultValue={data.is_original ? `${data.project_login}:${merge}` : `${merge}`}
className="minW50 merge-flex1"
className="minW50 merge-flex1 flex1"
disabled
></Select>{" "}
</Input.Group>{" "}

View File

@ -211,5 +211,6 @@ form .ant-cascader-picker, form .ant-select {
}
.mergeRequest .folders{
width: 72rem;
/* width: 72rem; */
width: 100%;
}

View File

@ -213,7 +213,7 @@ class merge extends Component {
checkOperation() {
const { projectsId,owner } = this.props.match.params;
this.props.history.push(`/${owner}/${projectsId}/compare`);
this.props.history.push(`/${owner}/${projectsId}/compare/master...master`);
}
render() {
const { projectsId , owner } = this.props.match.params;

View File

@ -12,7 +12,7 @@ class Nodata extends Component{
<h3>欢迎使用合并请求</h3>
<div className="color-grey-8">
合并请求可以帮助您与他人协作编写代码在使用之前请先创建一个 <Link className="color-blue" to={`/${owner}/${projectsId}/compare`}>合并请求</Link>
合并请求可以帮助您与他人协作编写代码在使用之前请先创建一个 <Link className="color-blue" to={`/${owner}/${projectsId}/compare/master...master`}>合并请求</Link>
</div>
</div>
</div>

View File

@ -35,6 +35,8 @@ class comments extends Component {
componentDidMount = () => {
this.getjournalslist();
// 给父组件绑定以使父组件可以使用组件内方法用于切换tab时重新请求评论列表、合并请求完之后重新请求评论列表
this.props.bindCommentRef && this.props.bindCommentRef(this);
};
//添加评论