forked from Gitlink/forgeplus-react
处理页面刷新之后创建合并请求报错2.0
This commit is contained in:
parent
4b1bccd1cd
commit
58f7c984a2
|
@ -96,12 +96,7 @@ class CreateMerge extends Component {
|
|||
// 再获取对应的仓库列表、分支列表
|
||||
// 再调用比较接口
|
||||
const branchParams = getBranchParams(this.props.location.pathname);
|
||||
this.getMergeInfo(branchParams);
|
||||
//页面初始化时调用selectProjectName,给is_original、fork_project_id、merge_user_login赋值
|
||||
setTimeout(()=>{
|
||||
const init = this.state.projects_names && this.state.projects_names.filter((item)=>item.project_user_login === branchParams.mergeOwner);
|
||||
init && init[0] && this.selectProjectName(init[0].id,false);
|
||||
},500)
|
||||
this.getMergeInfo(branchParams,true);
|
||||
};
|
||||
|
||||
componentDidUpdate = (preProps) => {
|
||||
|
@ -115,15 +110,20 @@ class CreateMerge extends Component {
|
|||
};
|
||||
|
||||
//获取新建合并请求数据
|
||||
getMergeInfo = (branchParams) => {
|
||||
getMergeInfo = (branchParams,init) => {
|
||||
this.setState({ isSpin: true });
|
||||
const { pullOwner, pullBranch, mergeOwner, mergeBranch, projectId } =
|
||||
branchParams;
|
||||
const { pullOwner, pullBranch, mergeOwner, mergeBranch, projectId } = branchParams;
|
||||
const url = `/${pullOwner}/${projectId}/pulls/new.json`;
|
||||
axios
|
||||
.get(url)
|
||||
.then((result) => {
|
||||
if (result) {
|
||||
if(init){
|
||||
//页面初始化时调用selectProjectName,给is_original、fork_project_id、merge_user_login赋值
|
||||
const initUser = result.data.projects_names && result.data.projects_names.filter((item)=>item.project_user_login === branchParams.mergeOwner);
|
||||
initUser && initUser[0] && this.selectProjectName(initUser[0].id,false,{projects_names: result.data.projects_names,id: result.data.id});
|
||||
}
|
||||
this.setState({isSpin: false});
|
||||
// 如果url上的分支不存在,取默认值master
|
||||
const noMergeBranch =
|
||||
(result.data.branches || []).filter(
|
||||
|
@ -266,8 +266,8 @@ class CreateMerge extends Component {
|
|||
};
|
||||
|
||||
// 切换仓库响应事件,目前仅目标分支可切换仓库
|
||||
selectProjectName = (value, isChangeProject) => {
|
||||
const { projects_names, id } = this.state;
|
||||
selectProjectName = (value, isChangeProject, initPro) => {
|
||||
const { projects_names, id } = isChangeProject ? this.state : initPro;
|
||||
const { pullOwner, pullBranch } = getBranchParams(
|
||||
this.props.location.pathname
|
||||
);
|
||||
|
|
Loading…
Reference in New Issue