2018-07-31 16:32:16 +02:00
|
|
|
// @flow
|
|
|
|
|
import React from "react";
|
|
|
|
|
|
2018-09-05 14:32:49 +02:00
|
|
|
import type { RepositoryCollection } from "@scm-manager/ui-types";
|
2018-07-31 16:32:16 +02:00
|
|
|
|
|
|
|
|
import { connect } from "react-redux";
|
2018-08-02 16:09:58 +02:00
|
|
|
import {
|
|
|
|
|
fetchRepos,
|
|
|
|
|
fetchReposByLink,
|
|
|
|
|
fetchReposByPage,
|
|
|
|
|
getFetchReposFailure,
|
|
|
|
|
getRepositoryCollection,
|
2018-08-03 08:52:02 +02:00
|
|
|
isAbleToCreateRepos,
|
2018-08-02 16:09:58 +02:00
|
|
|
isFetchReposPending
|
|
|
|
|
} from "../modules/repos";
|
2018-07-31 16:32:16 +02:00
|
|
|
import { translate } from "react-i18next";
|
2019-02-20 11:53:38 +01:00
|
|
|
import {
|
|
|
|
|
Page,
|
|
|
|
|
PageActions,
|
|
|
|
|
Button,
|
|
|
|
|
CreateButton,
|
2019-04-17 12:37:48 +02:00
|
|
|
LinkPaginator,
|
|
|
|
|
getPageFromMatch
|
2019-02-20 11:53:38 +01:00
|
|
|
} from "@scm-manager/ui-components";
|
2018-08-06 10:08:28 +02:00
|
|
|
import RepositoryList from "../components/list";
|
2018-08-02 16:09:58 +02:00
|
|
|
import { withRouter } from "react-router-dom";
|
2018-08-01 14:56:24 +02:00
|
|
|
import type { History } from "history";
|
2018-10-09 16:46:39 +02:00
|
|
|
import { getRepositoriesLink } from "../../modules/indexResource";
|
2019-04-17 12:37:48 +02:00
|
|
|
import queryString from "query-string";
|
2018-07-31 16:32:16 +02:00
|
|
|
|
|
|
|
|
type Props = {
|
2018-08-01 14:56:24 +02:00
|
|
|
page: number,
|
2018-07-31 16:32:16 +02:00
|
|
|
collection: RepositoryCollection,
|
2018-08-01 10:00:53 +02:00
|
|
|
loading: boolean,
|
|
|
|
|
error: Error,
|
2018-08-03 08:52:02 +02:00
|
|
|
showCreateButton: boolean,
|
2018-10-09 16:46:39 +02:00
|
|
|
reposLink: string,
|
2018-07-31 16:32:16 +02:00
|
|
|
|
2019-04-17 12:37:48 +02:00
|
|
|
// context props
|
|
|
|
|
t: string => string,
|
|
|
|
|
history: History,
|
|
|
|
|
location: any,
|
|
|
|
|
|
2018-07-31 16:32:16 +02:00
|
|
|
// dispatched functions
|
2018-10-09 16:46:39 +02:00
|
|
|
fetchRepos: string => void,
|
2019-04-17 12:37:48 +02:00
|
|
|
fetchReposByPage: (link: string, page: number, filter?: any) => void,
|
|
|
|
|
fetchReposByLink: string => void
|
|
|
|
|
};
|
2018-08-03 08:52:02 +02:00
|
|
|
|
2019-04-17 12:37:48 +02:00
|
|
|
type State = {
|
|
|
|
|
page: number
|
2018-07-31 16:32:16 +02:00
|
|
|
};
|
|
|
|
|
|
2019-04-17 12:37:48 +02:00
|
|
|
class Overview extends React.Component<Props, State> {
|
|
|
|
|
constructor(props: Props) {
|
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
|
|
this.state = {
|
|
|
|
|
page: -1
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-31 16:32:16 +02:00
|
|
|
componentDidMount() {
|
2019-04-17 12:37:48 +02:00
|
|
|
const { fetchReposByPage, reposLink, page } = this.props;
|
|
|
|
|
fetchReposByPage(reposLink, page, this.getQueryString());
|
|
|
|
|
this.setState({ page: page });
|
2018-07-31 16:32:16 +02:00
|
|
|
}
|
2018-08-01 14:56:24 +02:00
|
|
|
|
2019-04-17 12:37:48 +02:00
|
|
|
componentDidUpdate = (prevProps: Props) => {
|
|
|
|
|
const {
|
|
|
|
|
collection,
|
|
|
|
|
page,
|
|
|
|
|
location,
|
|
|
|
|
fetchReposByPage,
|
|
|
|
|
reposLink
|
|
|
|
|
} = this.props;
|
|
|
|
|
if (collection && page) {
|
|
|
|
|
if (
|
|
|
|
|
page !== this.state.page ||
|
|
|
|
|
prevProps.location.search !== location.search
|
|
|
|
|
) {
|
|
|
|
|
fetchReposByPage(reposLink, page, this.getQueryString());
|
|
|
|
|
this.setState({ page: page });
|
2018-08-01 14:56:24 +02:00
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 12:37:48 +02:00
|
|
|
};
|
2018-08-01 14:56:24 +02:00
|
|
|
|
2018-07-31 16:32:16 +02:00
|
|
|
render() {
|
2019-04-17 12:37:48 +02:00
|
|
|
const { error, loading, history, t } = this.props;
|
2018-07-31 16:32:16 +02:00
|
|
|
return (
|
2018-08-02 16:09:58 +02:00
|
|
|
<Page
|
|
|
|
|
title={t("overview.title")}
|
|
|
|
|
subtitle={t("overview.subtitle")}
|
|
|
|
|
loading={loading}
|
|
|
|
|
error={error}
|
2019-04-10 17:25:36 +02:00
|
|
|
filter={filter => {
|
2019-04-17 12:37:48 +02:00
|
|
|
history.push("/repos/?q=" + filter);
|
2019-04-10 17:25:36 +02:00
|
|
|
}}
|
2018-08-02 16:09:58 +02:00
|
|
|
>
|
2018-07-31 16:32:16 +02:00
|
|
|
{this.renderList()}
|
2019-02-26 10:34:56 +01:00
|
|
|
{this.renderPageActionCreateButton()}
|
2018-07-31 16:32:16 +02:00
|
|
|
</Page>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
renderList() {
|
2019-04-17 12:37:48 +02:00
|
|
|
const { collection, page } = this.props;
|
2018-07-31 16:32:16 +02:00
|
|
|
if (collection) {
|
|
|
|
|
return (
|
2019-04-17 12:37:48 +02:00
|
|
|
<>
|
2018-08-01 14:56:24 +02:00
|
|
|
<RepositoryList repositories={collection._embedded.repositories} />
|
2019-04-17 12:37:48 +02:00
|
|
|
<LinkPaginator
|
|
|
|
|
collection={collection}
|
|
|
|
|
page={page}
|
|
|
|
|
filter={this.getQueryString()}
|
|
|
|
|
/>
|
2018-08-03 08:52:02 +02:00
|
|
|
{this.renderCreateButton()}
|
2019-04-17 12:37:48 +02:00
|
|
|
</>
|
2018-07-31 16:32:16 +02:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2018-08-03 08:52:02 +02:00
|
|
|
|
|
|
|
|
renderCreateButton() {
|
|
|
|
|
const { showCreateButton, t } = this.props;
|
|
|
|
|
if (showCreateButton) {
|
|
|
|
|
return (
|
2019-02-26 10:34:56 +01:00
|
|
|
<CreateButton label={t("overview.createButton")} link="/repos/create" />
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
renderPageActionCreateButton() {
|
|
|
|
|
const { showCreateButton, t } = this.props;
|
|
|
|
|
if (showCreateButton) {
|
|
|
|
|
return (
|
|
|
|
|
<PageActions>
|
|
|
|
|
<Button
|
2019-02-25 14:16:45 +01:00
|
|
|
label={t("overview.createButton")}
|
|
|
|
|
link="/repos/create"
|
2019-02-26 10:34:56 +01:00
|
|
|
color="primary"
|
2019-02-25 14:16:45 +01:00
|
|
|
/>
|
2019-02-26 10:34:56 +01:00
|
|
|
</PageActions>
|
2018-08-03 08:52:02 +02:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2018-07-31 16:32:16 +02:00
|
|
|
|
2019-04-17 12:37:48 +02:00
|
|
|
getQueryString = () => {
|
|
|
|
|
const { location } = this.props;
|
|
|
|
|
return location.search ? queryString.parse(location.search).q : null;
|
|
|
|
|
};
|
|
|
|
|
}
|
2018-08-01 14:56:24 +02:00
|
|
|
|
2018-07-31 16:32:16 +02:00
|
|
|
const mapStateToProps = (state, ownProps) => {
|
2019-04-17 12:37:48 +02:00
|
|
|
const { match } = ownProps;
|
2018-07-31 16:32:16 +02:00
|
|
|
const collection = getRepositoryCollection(state);
|
2018-08-01 10:00:53 +02:00
|
|
|
const loading = isFetchReposPending(state);
|
|
|
|
|
const error = getFetchReposFailure(state);
|
2019-04-17 12:37:48 +02:00
|
|
|
const page = getPageFromMatch(match);
|
2018-08-03 08:52:02 +02:00
|
|
|
const showCreateButton = isAbleToCreateRepos(state);
|
2018-10-09 16:46:39 +02:00
|
|
|
const reposLink = getRepositoriesLink(state);
|
2018-07-31 16:32:16 +02:00
|
|
|
return {
|
2018-08-01 10:00:53 +02:00
|
|
|
collection,
|
|
|
|
|
loading,
|
2018-08-03 08:52:02 +02:00
|
|
|
error,
|
2019-04-17 12:37:48 +02:00
|
|
|
page,
|
|
|
|
|
showCreateButton,
|
|
|
|
|
reposLink
|
2018-07-31 16:32:16 +02:00
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const mapDispatchToProps = dispatch => {
|
|
|
|
|
return {
|
2018-10-09 16:46:39 +02:00
|
|
|
fetchRepos: (link: string) => {
|
|
|
|
|
dispatch(fetchRepos(link));
|
2018-08-01 14:56:24 +02:00
|
|
|
},
|
2019-04-17 12:37:48 +02:00
|
|
|
fetchReposByPage: (link: string, page: number, filter?: any) => {
|
2019-04-10 17:25:36 +02:00
|
|
|
dispatch(fetchReposByPage(link, page, filter));
|
2018-08-01 14:56:24 +02:00
|
|
|
},
|
|
|
|
|
fetchReposByLink: (link: string) => {
|
2018-08-02 16:09:58 +02:00
|
|
|
dispatch(fetchReposByLink(link));
|
2018-07-31 16:32:16 +02:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
export default connect(
|
|
|
|
|
mapStateToProps,
|
|
|
|
|
mapDispatchToProps
|
2018-08-01 14:56:24 +02:00
|
|
|
)(translate("repos")(withRouter(Overview)));
|