From da7ff8c7492bd74331c547f8d054fe0b1acbfef5 Mon Sep 17 00:00:00 2001 From: yuzhantian <2205129388@qq.com> Date: Sat, 9 Oct 2021 16:39:47 +0800 Subject: [PATCH 1/3] =?UTF-8?q?refactor:=20=E5=90=88=E5=B9=B6=E8=AF=B7?= =?UTF-8?q?=E6=B1=82=E8=B7=AF=E7=94=B1=E6=94=B9=E9=80=A0=E4=BB=A5=E5=8F=8A?= =?UTF-8?q?=E8=AF=84=E8=AE=BA=E6=95=B0=E9=87=8Fbug=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/forge/Activity/ActivityItem.js | 2 +- src/forge/Main/Detail.js | 12 +- src/forge/Merge/MergeItem.js | 4 +- src/forge/Merge/MergeLinkFooter.jsx | 192 ++++++++++++++++++++++++ src/forge/Merge/MessageCount.js | 20 +-- src/forge/Merge/merge_form.js | 4 +- src/forge/comments/children_comments.js | 18 ++- src/forge/comments/comments.js | 9 +- 8 files changed, 236 insertions(+), 25 deletions(-) create mode 100644 src/forge/Merge/MergeLinkFooter.jsx diff --git a/src/forge/Activity/ActivityItem.js b/src/forge/Activity/ActivityItem.js index 2b1ad3c8c..48a72e797 100644 --- a/src/forge/Activity/ActivityItem.js +++ b/src/forge/Activity/ActivityItem.js @@ -27,7 +27,7 @@ class ActivityItem extends Component { : // 如果是合并请求
- {item.name} + {item.name} {item.trend_type}
} diff --git a/src/forge/Main/Detail.js b/src/forge/Main/Detail.js index a1a741496..868ad06fb 100644 --- a/src/forge/Main/Detail.js +++ b/src/forge/Main/Detail.js @@ -727,7 +727,17 @@ class Detail extends Component { (props) => (@@ -175,7 +175,7 @@ class MergeItem extends Component { {item.journals_count ? ( {item.journals_count} diff --git a/src/forge/Merge/MergeLinkFooter.jsx b/src/forge/Merge/MergeLinkFooter.jsx new file mode 100644 index 000000000..104d2168b --- /dev/null +++ b/src/forge/Merge/MergeLinkFooter.jsx @@ -0,0 +1,192 @@ +import React, { Component } from 'react'; +import { Tabs, Spin } from 'antd'; +import { Link } from 'react-router-dom'; +import axios from 'axios'; + +import Commits from './Commits'; +import Comments from '../comments/comments'; +import Files from './Files'; + +import '../Order/order.css'; +import './merge.css'; + +const { TabPane } = Tabs; + +class MergeFooter extends Component { + constructor(props) { + super(props); + this.state = { + commitsData: undefined, + filesData: undefined, + isSpin: false, + activeKey: '1', + commitCount: 0, + filesCount: 0, + // 总评论数量,包含回复 + commentsTotalCount: 0, + }; + } + componentDidMount() { + this.Init(); + } + + componentDidUpdate(prevProps) { + // 解决切换tab后浏览器回退不刷新的问题、点击tab后url变化但tab未切换的问题 + const newPathname = this.props.location.pathname; + const prevPathname = prevProps.location.pathname; + if (newPathname !== prevPathname) { + this.Init(); + } + } + + Init = () => { + const { data, location, match } = this.props; + const { pathname } = location; + const { projectsId, owner, mergeId } = match.params; + + let activeKey = '1'; + if (pathname.indexOf('commits') > -1) { + activeKey = '2'; + this.getCommit(owner, projectsId, mergeId); + } else if (pathname.indexOf('files') > -1) { + activeKey = '3'; + this.getFile(owner, projectsId, mergeId); + } + this.setState({ + activeKey: activeKey, + commitCount: data && data.commits_count, + filesCount: data && data.files_count, + }); + }; + + getCommit = (owner, projectsId, mergeId) => { + this.setState({ isSpin: true }); + const url = `/${owner}/${projectsId}/pulls/${mergeId}/commits.json`; + axios + .get(url) + .then((result) => { + if (result) { + this.setState({ + commitsData: result.data.commits, + commitCount: result.data.commits_count, + }); + } + this.setState({ isSpin: false }); + }) + .catch((error) => { + this.setState({ isSpin: false }); + }); + }; + + getFile = (owner, projectsId, mergeId) => { + this.setState({ isSpin: true }); + const url = `/${owner}/${projectsId}/pulls/${mergeId}/files.json`; + axios + .get(url) + .then((result) => { + if (result) { + this.setState({ + filesData: result.data, + filesCount: result.data.files_count, + }); + } + this.setState({ isSpin: false }); + }) + .catch((error) => { + this.setState({ isSpin: false }); + }); + }; + + render() { + const { projectsId, owner, mergeId } = this.props.match.params; + + const { order_id, data = {} } = this.props; + const { + isSpin, + activeKey, + filesCount, + commitCount, + filesData, + commitsData, + } = this.state; + + // 评论数量优先取Comment组件中列表接口返回的,其次取合并请求详情接口中的,都没有取默认值0 + const commentsTotalCount = + this.state.commentsTotalCount || + (data.comments_total_count && parseInt(data.comments_total_count, 10)) || + 0; + + return ( +
如下文件有代码冲突:
-+
{i}
+ return{i}
}) } - +@@ -558,19 +555,18 @@ class MessageCount extends Component { 取消 -
+ )} -