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

View File

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

View File

@ -91,7 +91,7 @@ function Index(props) {
<div className="treeabout"> <div className="treeabout">
{ {
(isManager || isDeveloper) && (projectDetail && projectDetail.type!==2) && (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"> <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> <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) .get(url)
.then((result) => { .then((result) => {
if (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({ this.setState({
// isFork: result.data.is_fork, // isFork: result.data.is_fork,
projects_names: result.data.projects_names, projects_names: result.data.projects_names,
@ -132,11 +141,23 @@ class CreateMerge extends Component {
merge: mergeBranch, merge: mergeBranch,
pull: pullBranch, 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) { if (pullOwner !== mergeOwner) {
this.getBranchList(mergeOwner, projectId); this.getBranchList(branchParams);
} }
this.compareProject(result.data.id, branchParams);
this.setState({ isSpin: false }); this.setState({ isSpin: false });
}) })
.catch((error) => { .catch((error) => {
@ -192,15 +213,19 @@ class CreateMerge extends Component {
}; };
// 根据所有者、仓库名,获取分支列表,目前仅涉及目标仓库分支查询 // 根据所有者、仓库名,获取分支列表,目前仅涉及目标仓库分支查询
getBranchList = (login, projectId) => { getBranchList = ({ mergeOwner, projectId, mergeBranch }) => {
this.setState({ isSpin: true }); this.setState({ isSpin: true });
const url = `/${login}/${projectId}/pulls/get_branches.json`; const url = `/${mergeOwner}/${projectId}/pulls/get_branches.json`;
axios axios
.get(url) .get(url)
.then((result) => { .then((result) => {
if (result) { if (result) {
const noMergeBranch =
(result.data || []).filter((branch) => branch.name === mergeBranch)
.length === 0;
this.setState({ this.setState({
mergeBranches: result.data, mergeBranches: result.data,
merge: noMergeBranch ? 'master' : mergeBranch,
}); });
} }
this.setState({ isSpin: false }); this.setState({ isSpin: false });
@ -319,7 +344,7 @@ class CreateMerge extends Component {
return ( return (
<div> <div>
<Spin spinning={isSpin}> <Spin spinning={isSpin || isCompareSpin}>
<div className="main"> <div className="main">
<div className="merge-header width100 inline-block"> <div className="merge-header width100 inline-block">
<div className="width40 pull-left"> <div className="width40 pull-left">

View File

@ -228,7 +228,7 @@ class MergeDetail extends Component {
<div> <div>
{ {
data && data.issue.user_permission ? 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> </div>

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -12,7 +12,7 @@ class Nodata extends Component{
<h3>欢迎使用合并请求</h3> <h3>欢迎使用合并请求</h3>
<div className="color-grey-8"> <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> </div>
</div> </div>

View File

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