From f940af3369d7907c81c6427a83ef519c3bac7e71 Mon Sep 17 00:00:00 2001 From: Florian Scholdei Date: Wed, 3 Apr 2019 15:19:54 +0200 Subject: [PATCH] outsourced single branch routing to branchroot --- .../repos/branches/components/BranchView.js | 32 +++++ .../repos/branches/containers/BranchRoot.js | 117 ++++++++++++++++++ .../repos/branches/containers/BranchView.js | 99 --------------- scm-ui/src/repos/containers/ChangesetsRoot.js | 4 +- scm-ui/src/repos/containers/RepositoryRoot.js | 13 +- 5 files changed, 157 insertions(+), 108 deletions(-) create mode 100644 scm-ui/src/repos/branches/components/BranchView.js delete mode 100644 scm-ui/src/repos/branches/containers/BranchView.js diff --git a/scm-ui/src/repos/branches/components/BranchView.js b/scm-ui/src/repos/branches/components/BranchView.js new file mode 100644 index 0000000000..a7dd7dbd4b --- /dev/null +++ b/scm-ui/src/repos/branches/components/BranchView.js @@ -0,0 +1,32 @@ +// @flow +import React from "react"; +import BranchDetail from "./BranchDetail"; +import { ExtensionPoint } from "@scm-manager/ui-extensions"; +import type { Repository, Branch } from "@scm-manager/ui-types"; + +type Props = { + repository: Repository, + branch: Branch +}; + +class BranchView extends React.Component { + render() { + const { repository, branch } = this.props; + + return ( +
+ +
+
+ +
+
+ ); + } +} + +export default BranchView; diff --git a/scm-ui/src/repos/branches/containers/BranchRoot.js b/scm-ui/src/repos/branches/containers/BranchRoot.js index e69de29bb2..22b7011968 100644 --- a/scm-ui/src/repos/branches/containers/BranchRoot.js +++ b/scm-ui/src/repos/branches/containers/BranchRoot.js @@ -0,0 +1,117 @@ +//@flow +import React from "react"; +import BranchView from "../components/BranchView"; +import { connect } from "react-redux"; +import { Redirect, Route, Switch, withRouter } from "react-router-dom"; +import { translate } from "react-i18next"; +import type { Repository, Branch } from "@scm-manager/ui-types"; +import { + fetchBranch, + getBranch, + getFetchBranchFailure, + isFetchBranchPending +} from "../modules/branches"; +import { ErrorPage, Loading } from "@scm-manager/ui-components"; +import CreateBranch from "./CreateBranch"; +import type { History } from "history"; + +type Props = { + repository: Repository, + branchName: string, + branch: Branch, + loading: boolean, + error?: Error, + + // context props + t: string => string, + history: History, + match: any, + + // dispatch functions + fetchBranch: (repository: Repository, branchName: string) => void +}; + +class BranchRoot extends React.Component { + componentDidMount() { + const { fetchBranch, repository, branchName } = this.props; + + fetchBranch(repository, branchName); + } + + stripEndingSlash = (url: string) => { + if (url.endsWith("/")) { + return url.substring(0, url.length - 1); + } + return url; + }; + + matchedUrl = () => { + return this.stripEndingSlash(this.props.match.url); + }; + + render() { + const { repository, branch, loading, error, t } = this.props; + + if (error) { + return ( + + ); + } + + if (loading || !branch) { + return ; + } + + const url = this.matchedUrl(); + + return ( + + + ( + + )} + /> + } + /> + + ); + } +} + +const mapStateToProps = (state, ownProps) => { + const { repository } = ownProps; + const branchName = decodeURIComponent(ownProps.match.params.branch); + const branch = getBranch(state, repository, branchName); + const loading = isFetchBranchPending(state, repository, branchName); + const error = getFetchBranchFailure(state, repository, branchName); + return { + repository, + branchName, + branch, + loading, + error + }; +}; + +const mapDispatchToProps = dispatch => { + return { + fetchBranch: (repository: Repository, branchName: string) => { + dispatch(fetchBranch(repository, branchName)); + } + }; +}; + +export default withRouter( + connect( + mapStateToProps, + mapDispatchToProps + )(translate("repos")(BranchRoot)) +); diff --git a/scm-ui/src/repos/branches/containers/BranchView.js b/scm-ui/src/repos/branches/containers/BranchView.js deleted file mode 100644 index 5e7fa9610a..0000000000 --- a/scm-ui/src/repos/branches/containers/BranchView.js +++ /dev/null @@ -1,99 +0,0 @@ -// @flow -import React from "react"; -import BranchDetail from "../components/BranchDetail"; -import { ExtensionPoint } from "@scm-manager/ui-extensions"; -import type { Repository, Branch } from "@scm-manager/ui-types"; -import { connect } from "react-redux"; -import { translate } from "react-i18next"; -import { withRouter } from "react-router-dom"; -import { - fetchBranch, - getBranch, - getFetchBranchFailure, - isFetchBranchPending -} from "../modules/branches"; -import { ErrorPage, Loading } from "@scm-manager/ui-components"; - -type Props = { - repository: Repository, - branchName: string, - loading: boolean, - error?: Error, - branch?: Branch, - - // dispatch functions - fetchBranch: (repository: Repository, branchName: string) => void, - - // context props - t: string => string -}; - -class BranchView extends React.Component { - componentDidMount() { - const { fetchBranch, repository, branchName } = this.props; - - fetchBranch(repository, branchName); - } - - render() { - const { loading, error, t, repository, branch } = this.props; - - if (error) { - return ( - - ); - } - - if (!branch || loading) { - return ; - } - - return ( -
- -
-
- -
-
- ); - } -} - -const mapStateToProps = (state, ownProps) => { - const { repository } = ownProps; - const branchName = decodeURIComponent(ownProps.match.params.branch); - const branch = getBranch(state, repository, branchName); - const loading = isFetchBranchPending(state, repository, branchName); - const error = getFetchBranchFailure(state, repository, branchName); - return { - repository, - branchName, - branch, - loading, - error - }; -}; - -const mapDispatchToProps = dispatch => { - return { - fetchBranch: (repository: Repository, branchName: string) => { - dispatch(fetchBranch(repository, branchName)); - } - }; -}; - -export default withRouter( - connect( - mapStateToProps, - mapDispatchToProps - )(translate("repos")(BranchView)) -); diff --git a/scm-ui/src/repos/containers/ChangesetsRoot.js b/scm-ui/src/repos/containers/ChangesetsRoot.js index c4f40e0d74..c4c310d94d 100644 --- a/scm-ui/src/repos/containers/ChangesetsRoot.js +++ b/scm-ui/src/repos/containers/ChangesetsRoot.js @@ -40,7 +40,7 @@ type Props = { t: string => string }; -class BranchRoot extends React.Component { +class ChangesetsRoot extends React.Component { componentDidMount() { this.props.fetchBranches(this.props.repository); } @@ -146,4 +146,4 @@ export default compose( mapStateToProps, mapDispatchToProps ) -)(BranchRoot); +)(ChangesetsRoot); diff --git a/scm-ui/src/repos/containers/RepositoryRoot.js b/scm-ui/src/repos/containers/RepositoryRoot.js index 8c481f1adc..418b43d144 100644 --- a/scm-ui/src/repos/containers/RepositoryRoot.js +++ b/scm-ui/src/repos/containers/RepositoryRoot.js @@ -24,14 +24,13 @@ import { translate } from "react-i18next"; import RepositoryDetails from "../components/RepositoryDetails"; import EditRepo from "./EditRepo"; import BranchesOverview from "../branches/containers/BranchesOverview"; -import BranchView from "../branches/containers/BranchView"; import CreateBranch from "../branches/containers/CreateBranch"; import Permissions from "../permissions/containers/Permissions"; import type { History } from "history"; import EditRepoNavLink from "../components/EditRepoNavLink"; - -import BranchRoot from "./ChangesetsRoot"; +import BranchRoot from "../branches/containers/BranchRoot"; +import ChangesetsRoot from "./ChangesetsRoot"; import ChangesetView from "./ChangesetView"; import PermissionsNavLink from "../components/PermissionsNavLink"; import Sources from "../sources/containers/Sources"; @@ -168,7 +167,7 @@ class RepositoryRoot extends React.Component { ( - { )} /> ( - @@ -187,7 +186,7 @@ class RepositoryRoot extends React.Component { ( -