//@flow import React from "react"; import { deleteRepo, fetchRepo, getFetchRepoFailure, getRepository, isFetchRepoPending } from "../modules/repos"; import { connect } from "react-redux"; import { Route } from "react-router-dom"; import type { Repository } from "@scm-manager/ui-types"; import { ErrorPage, Loading, Navigation, NavLink, Page, Section } from "@scm-manager/ui-components"; import { translate } from "react-i18next"; import RepositoryDetails from "../components/RepositoryDetails"; import DeleteNavAction from "../components/DeleteNavAction"; import Edit from "../containers/Edit"; import type { History } from "history"; import EditNavLink from "../components/EditNavLink"; import BranchChooser from "./BranchChooser"; import Changesets from "./Changesets"; import BranchRoot from "./BranchRoot"; type Props = { namespace: string, name: string, repository: Repository, loading: boolean, error: Error, // dispatch functions fetchRepo: (namespace: string, name: string) => void, deleteRepo: (repository: Repository, () => void) => void, // context props t: string => string, history: History, match: any }; class RepositoryRoot extends React.Component { componentDidMount() { const { fetchRepo, namespace, name } = this.props; fetchRepo(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); }; deleted = () => { this.props.history.push("/repos"); }; delete = (repository: Repository) => { this.props.deleteRepo(repository, this.deleted); }; matches = (route: any) => { const url = this.matchedUrl(); const regex = new RegExp( `${url}(/branches)?/?[a-zA-Z0-9_%]*/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(); // TODO: Changesets need to be adjusted (i.e. sub-routes need to be handled in sub-components) 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); return { namespace, name, repository, loading, error }; }; const mapDispatchToProps = dispatch => { return { fetchRepo: (namespace: string, name: string) => { dispatch(fetchRepo(namespace, name)); }, deleteRepo: (repository: Repository, callback: () => void) => { dispatch(deleteRepo(repository, callback)); } }; }; export default connect( mapStateToProps, mapDispatchToProps )(translate("repos")(RepositoryRoot));