FIX performance for project detail's page

This commit is contained in:
Jasder 2020-06-29 11:34:05 +08:00
parent 7ba94ee094
commit da57718743
4 changed files with 24 additions and 39 deletions

View File

@ -10,6 +10,7 @@ import RootTable from './RootTable';
import CoderRootFileDetail from './CoderRootFileDetail';
import { truncateCommitId } from '../common/util';
import RenderHtml from '../../components/render-html';
import Top from './DetailTop';
import axios from "axios";
/**
@ -42,7 +43,11 @@ class CoderRootDirectory extends Component {
readOnly: true,
zip_url:undefined,
tar_url:undefined,
chooseType:undefined
chooseType:undefined,
tags_count:undefined,
commits_count:undefined,
branches_count:undefined
}
}
changeAddress = (address) => {
@ -122,6 +127,9 @@ class CoderRootDirectory extends Component {
(last_commit.commit && last_commit.commit.author)),
zip_url: result.data.zip_url,
tar_url: result.data.tar_url,
tags_count: result.data.tags_count,
branches_count: result.data.branches_count,
commits_count: result.data.commits_count
});
if (entries && entries.length > 0) {
this.renderData(entries);
@ -440,14 +448,15 @@ class CoderRootDirectory extends Component {
let array = filePath && filePath.split("/");
return (
<Spin spinning={isSpin}>
<Top {...this.props} {...this.state}/>
<div className="main">
<div className="f-wrap-between mb20">
<div className="f-wrap-alignCenter">
<SelectBranch
repo_id={projectDetail && projectDetail.repo_id}
projectsId={projectsId}
<SelectBranch
repo_id={projectDetail && projectDetail.repo_id}
projectsId={projectsId}
branch={branch}
changeBranch={this.changeBranch}
changeBranch={this.changeBranch}
></SelectBranch>
{filePath && (

View File

@ -3,7 +3,6 @@ import { Route , Switch } from 'react-router-dom';
import Loadable from 'react-loadable';
import Loading from '../../Loading';
import Top from './DetailTop';
const CoderRootDirectory = Loadable({
@ -40,11 +39,9 @@ const Diff = Loadable({
})
class CoderRootIndex extends Component{
render(){
return(
<div>
<Top {...this.props} {...this.state}/>
<Switch {...this.props}>
<Route path="/projects/:projectsId/coders/commit"
render={
@ -68,7 +65,7 @@ class CoderRootIndex extends Component{
(props) => (<CoderRootVersionUpdate {...this.props} {...props} {...this.state} />)
}
></Route>
<Route path="/projects/:projectsId/coders/version"
render={
(props) => (<CoderRootVersion {...this.props} {...props} {...this.state} />)
@ -99,4 +96,4 @@ class CoderRootIndex extends Component{
)
}
}
export default CoderRootIndex;
export default CoderRootIndex;

View File

@ -186,7 +186,7 @@ class Detail extends Component {
// 关注和取消关注
focusFunc = (flag) => {
const { project_id } = this.state;
axios({
method: flag? 'delete' : 'post',
url: `/watchers/${flag? 'unfollow' : 'follow'}.json`,
@ -262,25 +262,7 @@ class Detail extends Component {
console.log(error);
})
}
// 获取分支列表
getBranch = (id) => {
const url = `/projects/${id}/branches.json`;
axios.get(url).then((result) => {
if (result && result.data.length > 0) {
const branchs = [];
result.data.map((item, key) => {
branchs.push({
index: key,
name: item.name
})
})
this.setState({
branchList: result.data,
branchs,
})
}
}).catch((error) => { })
}
// 同步镜像
synchronismMirror=()=>{
@ -299,7 +281,7 @@ class Detail extends Component {
isSpin:false
})
}
}).catch(error=>{
console.log(error);
})
@ -337,7 +319,6 @@ class Detail extends Component {
}
return (
<div>
<Spin spinning={isSpin}>
<div className="detailHeader-wrapper">
<div className="normal">
<div className="f-wrap-between mb15" style={{ position: "relative" }}>
@ -404,7 +385,6 @@ class Detail extends Component {
<li className={(url.indexOf("coders") > -1 || urlFlag) ? "active" : ""}>
<Link to={{ pathname: `/projects/${projectsId}/coders`, state }}>
<img alt="" src={img_1} width="18" />代码库
{ projectDetail && projectDetail.commits_count ? <span>{projectDetail.commits_count}</span>:""}
</Link>
</li>
<li className={(url.indexOf("orders") > -1 && !(url.indexOf("Milepost") > 0 || url.indexOf("meilpost") > 0 || url.indexOf("tags") > 0)) ? "active" : ""}>
@ -546,7 +526,7 @@ class Detail extends Component {
<Route path="/projects/:projectsId/merge/new"
render={
(props) => (<CreateMerge {...this.props} {...props} {...this.state} {...common}/>)
(props) => (<CreateMerge {...this.props} {...props} {...this.state} {...common} is_fork= {true}/>)
}
></Route>
@ -604,7 +584,6 @@ class Detail extends Component {
}
></Route>
</Switch>
</Spin>
</div>
)
}

View File

@ -3,22 +3,22 @@ import { Link } from 'react-router-dom';
class DetailTop extends Component {
render() {
const { projectDetail } = this.props;
const { projectDetail, tags_count, commits_count, branches_count } = this.props;
const { projectsId } = this.props.match.params;
const { pathname } = this.props.location;
return (
<p className="branch-wrapper">
<Link to={`/projects/${projectsId}/coders/commit`} className={pathname.indexOf("/coders/commit") > 0 ? "active" : ""}>
<i className="iconfont icon-tijiaojilu font-20 mr3 font-bd"></i>
<span>{projectDetail && projectDetail.commits_count}</span>
<span>{commits_count}</span>
</Link>
<Link to={`/projects/${projectsId}/coders/branch`} className={pathname.indexOf("/coders/branch") > 0 ? "active" : ""}>
<i className="iconfont icon-fenzhi1 font-18 mr3"></i>
<span>{projectDetail && projectDetail.branches_count}</span>
<span>{branches_count}</span>
</Link>
<Link to={`/projects/${projectsId}/coders/tag`} className={pathname.indexOf("/coders/tag") > 0 ? "active" : ""}>
<i className="iconfont icon-biaoqian3 font-18 mr3"></i>
<span>{projectDetail && projectDetail.issue_tags_count}</span>
<span>{tags_count}</span>
</Link>
<Link to={`/projects/${projectsId}/coders/version`} className={pathname.indexOf("/coders/version") > 0 ? "active" : ""}>
<i className="iconfont icon-fahangban font-18 mr3"></i>