//@flow import React from "react"; import { fetchRepoByName, getFetchRepoFailure, getRepository, isFetchRepoPending } from "../modules/repos"; import { connect } from "react-redux"; import { Route, Switch } from "react-router-dom"; import type { Repository } from "@scm-manager/ui-types"; import { ErrorPage, Loading, Navigation, SubNavigation, NavLink, Page, Section } from "@scm-manager/ui-components"; import { translate } from "react-i18next"; import RepositoryDetails from "../components/RepositoryDetails"; import GeneralRepo from "./GeneralRepo"; import Permissions from "../permissions/containers/Permissions"; import type { History } from "history"; import GeneralRepoNavLink from "../components/GeneralRepoNavLink"; import BranchRoot from "./ChangesetsRoot"; import ChangesetView from "./ChangesetView"; import PermissionsNavLink from "../components/PermissionsNavLink"; import Sources from "../sources/containers/Sources"; import RepositoryNavLink from "../components/RepositoryNavLink"; import { getRepositoriesLink } from "../../modules/indexResource"; import { ExtensionPoint } from "@scm-manager/ui-extensions"; type Props = { namespace: string, name: string, repository: Repository, loading: boolean, error: Error, repoLink: string, // dispatch functions fetchRepoByName: (link: string, namespace: string, name: string) => void, // context props t: string => string, history: History, match: any }; class RepositoryRoot extends React.Component { componentDidMount() { const { fetchRepoByName, namespace, name, repoLink } = this.props; fetchRepoByName(repoLink, namespace, name); } stripEndingSlash = (url: string) => { if (url.endsWith("/")) { return url.substring(0, url.length - 2); } return url; }; matchedUrl = () => { return this.stripEndingSlash(this.props.match.url); }; matches = (route: any) => { const url = this.matchedUrl(); const regex = new RegExp(`${url}(/branches)?/?[^/]*/changesets?.*`); return route.location.pathname.match(regex); }; render() { const { loading, error, repository, t } = this.props; if (error) { return ( ); } if (!repository || loading) { return ; } const url = this.matchedUrl(); const extensionProps = { repository, url }; return (
} /> } /> ( )} /> } /> ( )} /> ( )} /> ( )} /> ( )} />
); } } const mapStateToProps = (state, ownProps) => { const { namespace, name } = ownProps.match.params; const repository = getRepository(state, namespace, name); const loading = isFetchRepoPending(state, namespace, name); const error = getFetchRepoFailure(state, namespace, name); const repoLink = getRepositoriesLink(state); return { namespace, name, repository, loading, error, repoLink }; }; const mapDispatchToProps = dispatch => { return { fetchRepoByName: (link: string, namespace: string, name: string) => { dispatch(fetchRepoByName(link, namespace, name)); } }; }; export default connect( mapStateToProps, mapDispatchToProps )(translate("repos")(RepositoryRoot));