// @flow import React from "react"; import type { RepositoryCollection } from "@scm-manager/ui-types"; import { connect } from "react-redux"; import { fetchRepos, fetchReposByLink, fetchReposByPage, getFetchReposFailure, getRepositoryCollection, isAbleToCreateRepos, isFetchReposPending } from "../modules/repos"; import { translate } from "react-i18next"; import { Page, PageActions, Button, CreateButton, Paginator } from "@scm-manager/ui-components"; import RepositoryList from "../components/list"; import { withRouter } from "react-router-dom"; import type { History } from "history"; import { getRepositoriesLink } from "../../modules/indexResource"; type Props = { page: number, collection: RepositoryCollection, loading: boolean, error: Error, showCreateButton: boolean, reposLink: string, // dispatched functions fetchRepos: string => void, fetchReposByPage: (string, number) => void, fetchReposByLink: string => void, // context props t: string => string, history: History }; class Overview extends React.Component { componentDidMount() { this.props.fetchReposByPage(this.props.reposLink, this.props.page); } /** * reflect page transitions in the uri */ componentDidUpdate() { const { page, collection } = this.props; if (collection) { // backend starts paging by 0 const statePage: number = collection.page + 1; if (page !== statePage) { this.props.history.push(`/repos/${statePage}`); } } } render() { const { error, loading, t } = this.props; return ( {this.renderList()} {this.renderPageActionCreateButton()} ); } renderList() { const { collection, fetchReposByLink } = this.props; if (collection) { return (
{this.renderCreateButton()}
); } return null; } renderCreateButton() { const { showCreateButton, t } = this.props; if (showCreateButton) { return ( ); } return null; } renderPageActionCreateButton() { const { showCreateButton, t } = this.props; if (showCreateButton) { return (