处理页面刷新之后创建合并请求报错2.0

This commit is contained in:
谢思 2021-11-22 17:12:20 +08:00
parent 4b1bccd1cd
commit 58f7c984a2
1 changed files with 11 additions and 11 deletions

View File

@ -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
);