From a5d07cc2cd471e8102772e99450741078c716036 Mon Sep 17 00:00:00 2001 From: Florian Scholdei Date: Thu, 28 Mar 2019 11:51:00 +0100 Subject: [PATCH] added branches overview and navlink --- scm-ui/public/locales/de/repos.json | 1 + scm-ui/public/locales/en/repos.json | 1 + .../src/repos/containers/BranchesOverview.js | 98 +++++++++++++++++++ scm-ui/src/repos/containers/RepositoryRoot.js | 17 ++++ 4 files changed, 117 insertions(+) create mode 100644 scm-ui/src/repos/containers/BranchesOverview.js diff --git a/scm-ui/public/locales/de/repos.json b/scm-ui/public/locales/de/repos.json index 141d58d1d2..dc444f59ff 100644 --- a/scm-ui/public/locales/de/repos.json +++ b/scm-ui/public/locales/de/repos.json @@ -26,6 +26,7 @@ "menu": { "navigationLabel": "Repository Navigation", "informationNavLink": "Informationen", + "branchesNavLink": "Branches", "historyNavLink": "Commits", "sourcesNavLink": "Sources", "settingsNavLink": "Einstellungen", diff --git a/scm-ui/public/locales/en/repos.json b/scm-ui/public/locales/en/repos.json index f10c771d96..d888d73c29 100644 --- a/scm-ui/public/locales/en/repos.json +++ b/scm-ui/public/locales/en/repos.json @@ -26,6 +26,7 @@ "menu": { "navigationLabel": "Repository Navigation", "informationNavLink": "Information", + "branchesNavLink": "Branches", "historyNavLink": "Commits", "sourcesNavLink": "Sources", "settingsNavLink": "Settings", diff --git a/scm-ui/src/repos/containers/BranchesOverview.js b/scm-ui/src/repos/containers/BranchesOverview.js new file mode 100644 index 0000000000..d13449eeb6 --- /dev/null +++ b/scm-ui/src/repos/containers/BranchesOverview.js @@ -0,0 +1,98 @@ +// @flow +import React from "react"; +import {fetchBranches, getBranches, getFetchBranchesFailure, isFetchBranchesPending} from "../modules/branches"; +import {connect} from "react-redux"; +import type {Branch, Repository} from "@scm-manager/ui-types"; +import {compose} from "redux"; +import {translate} from "react-i18next"; +import {withRouter} from "react-router-dom"; +import {ErrorNotification, Loading} from "@scm-manager/ui-components"; + +type Props = { + repository: Repository, + loading: boolean, + error: Error, + branches: Branch[], + + // dispatch props + fetchBranches: Repository => void, + + // Context props + history: any, + match: any, + t: string => string +}; +class BranchesOverview extends React.Component { + componentDidMount() { + const { + fetchBranches, + repository + } = this.props; + + fetchBranches(repository); + } + + render() { + const { + loading, + error, + } = this.props; + + if (error) { + return ; + } + + if (loading) { + return ; + } + + return <>{this.renderBranches()}; + } + + renderBranches() { + const { branches } = this.props; + + let branchesList = null; + if (branches) { + branchesList = ( +
    + {branches.map((branch, index) => { + return
  • {branch.name}
  • ; + })} +
+ ); + } + return branchesList; + } +} + +const mapStateToProps = (state, ownProps) => { + const { repository } = ownProps; + const loading = isFetchBranchesPending(state, repository); + const error = getFetchBranchesFailure(state, repository); + const branches = getBranches(state, repository); + + return { + repository, + loading, + error, + branches + }; +}; + +const mapDispatchToProps = dispatch => { + return { + fetchBranches: (repository: Repository) => { + dispatch(fetchBranches(repository)); + }, + }; +}; + +export default compose( + translate("repos"), + withRouter, + connect( + mapStateToProps, + mapDispatchToProps + ) +)(BranchesOverview); diff --git a/scm-ui/src/repos/containers/RepositoryRoot.js b/scm-ui/src/repos/containers/RepositoryRoot.js index c5be3bd9d0..535d678e12 100644 --- a/scm-ui/src/repos/containers/RepositoryRoot.js +++ b/scm-ui/src/repos/containers/RepositoryRoot.js @@ -22,6 +22,7 @@ import { import { translate } from "react-i18next"; import RepositoryDetails from "../components/RepositoryDetails"; import EditRepo from "./EditRepo"; +import BranchesOverview from "./BranchesOverview"; import CreateBranch from "./CreateBranch"; import Permissions from "../permissions/containers/Permissions"; @@ -171,6 +172,14 @@ class RepositoryRoot extends React.Component { /> )} /> + ( + + )} + /> ( @@ -199,6 +208,14 @@ class RepositoryRoot extends React.Component { icon="fas fa-info-circle" label={t("repositoryRoot.menu.informationNavLink")} /> +