2020-03-23 15:35:58 +01:00
|
|
|
/*
|
|
|
|
|
* MIT License
|
|
|
|
|
*
|
|
|
|
|
* Copyright (c) 2020-present Cloudogu GmbH and Contributors
|
|
|
|
|
*
|
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
|
*
|
|
|
|
|
* The above copyright notice and this permission notice shall be included in all
|
|
|
|
|
* copies or substantial portions of the Software.
|
|
|
|
|
*
|
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
|
* SOFTWARE.
|
|
|
|
|
*/
|
2019-10-20 18:02:52 +02:00
|
|
|
import React from "react";
|
|
|
|
|
import { connect } from "react-redux";
|
2020-01-08 15:57:13 +01:00
|
|
|
import { RouteComponentProps, withRouter } from "react-router-dom";
|
2019-10-23 15:47:08 +02:00
|
|
|
import { WithTranslation, withTranslation } from "react-i18next";
|
2020-08-11 10:34:29 +02:00
|
|
|
import { RepositoryCollection } from "@scm-manager/ui-types";
|
2019-02-20 11:53:38 +01:00
|
|
|
import {
|
|
|
|
|
CreateButton,
|
2019-04-17 12:37:48 +02:00
|
|
|
LinkPaginator,
|
2020-01-08 15:57:13 +01:00
|
|
|
Notification,
|
|
|
|
|
OverviewPageActions,
|
|
|
|
|
Page,
|
|
|
|
|
PageActions,
|
2020-08-11 10:34:29 +02:00
|
|
|
urls
|
2019-10-20 18:02:52 +02:00
|
|
|
} from "@scm-manager/ui-components";
|
|
|
|
|
import { getRepositoriesLink } from "../../modules/indexResource";
|
2019-10-23 15:47:08 +02:00
|
|
|
import {
|
|
|
|
|
fetchReposByPage,
|
|
|
|
|
getFetchReposFailure,
|
|
|
|
|
getRepositoryCollection,
|
|
|
|
|
isAbleToCreateRepos,
|
|
|
|
|
isFetchReposPending
|
|
|
|
|
} from "../modules/repos";
|
|
|
|
|
import RepositoryList from "../components/list";
|
2018-07-31 16:32:16 +02:00
|
|
|
|
2020-01-08 15:57:13 +01:00
|
|
|
type Props = WithTranslation &
|
|
|
|
|
RouteComponentProps & {
|
|
|
|
|
loading: boolean;
|
|
|
|
|
error: Error;
|
|
|
|
|
showCreateButton: boolean;
|
|
|
|
|
collection: RepositoryCollection;
|
|
|
|
|
page: number;
|
|
|
|
|
reposLink: string;
|
2018-07-31 16:32:16 +02:00
|
|
|
|
2020-01-08 15:57:13 +01:00
|
|
|
// dispatched functions
|
|
|
|
|
fetchReposByPage: (link: string, page: number, filter?: string) => void;
|
|
|
|
|
};
|
2018-08-03 08:52:02 +02:00
|
|
|
|
2019-04-17 15:46:49 +02:00
|
|
|
class Overview extends React.Component<Props> {
|
2018-07-31 16:32:16 +02:00
|
|
|
componentDidMount() {
|
2020-08-11 10:34:29 +02:00
|
|
|
const { fetchReposByPage, reposLink, page, location } = this.props;
|
|
|
|
|
fetchReposByPage(reposLink, page, urls.getQueryStringFromLocation(location));
|
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) => {
|
2020-08-11 10:34:29 +02:00
|
|
|
const { loading, collection, page, reposLink, location, fetchReposByPage } = this.props;
|
|
|
|
|
if (collection && page && !loading) {
|
2019-04-17 15:46:49 +02:00
|
|
|
const statePage: number = collection.page + 1;
|
2019-04-17 16:35:17 +02:00
|
|
|
if (page !== statePage || prevProps.location.search !== location.search) {
|
2019-10-21 10:57:56 +02:00
|
|
|
fetchReposByPage(reposLink, page, urls.getQueryStringFromLocation(location));
|
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-19 13:22:17 +02:00
|
|
|
const { error, loading, showCreateButton, t } = this.props;
|
2020-08-07 08:49:02 +02:00
|
|
|
|
2018-07-31 16:32:16 +02:00
|
|
|
return (
|
2019-10-21 10:57:56 +02:00
|
|
|
<Page title={t("overview.title")} subtitle={t("overview.subtitle")} loading={loading} error={error}>
|
2019-04-09 14:47:37 +02:00
|
|
|
{this.renderOverview()}
|
2019-04-24 09:46:22 +02:00
|
|
|
<PageActions>
|
2020-08-11 10:34:29 +02:00
|
|
|
<OverviewPageActions
|
|
|
|
|
showCreateButton={showCreateButton}
|
|
|
|
|
link="repos"
|
|
|
|
|
label={t("overview.createButton")}
|
|
|
|
|
testId="repository-overview"
|
|
|
|
|
/>
|
2019-04-24 09:46:22 +02:00
|
|
|
</PageActions>
|
2018-07-31 16:32:16 +02:00
|
|
|
</Page>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-09 14:47:37 +02:00
|
|
|
renderRepositoryList() {
|
2019-04-18 11:42:09 +02:00
|
|
|
const { collection, page, location, t } = this.props;
|
2019-04-09 14:47:37 +02:00
|
|
|
|
|
|
|
|
if (collection._embedded && collection._embedded.repositories.length > 0) {
|
2018-07-31 16:32:16 +02:00
|
|
|
return (
|
2019-04-17 12:37:48 +02:00
|
|
|
<>
|
2018-08-01 14:56:24 +02:00
|
|
|
<RepositoryList repositories={collection._embedded.repositories} />
|
2019-10-21 10:57:56 +02:00
|
|
|
<LinkPaginator collection={collection} page={page} filter={urls.getQueryStringFromLocation(location)} />
|
2019-04-09 14:47:37 +02:00
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
}
|
2019-10-21 10:57:56 +02:00
|
|
|
return <Notification type="info">{t("overview.noRepositories")}</Notification>;
|
2019-04-09 14:47:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
renderOverview() {
|
|
|
|
|
const { collection } = this.props;
|
|
|
|
|
if (collection) {
|
|
|
|
|
return (
|
2019-04-17 14:27:17 +02:00
|
|
|
<>
|
2019-04-09 14:47:37 +02:00
|
|
|
{this.renderRepositoryList()}
|
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) {
|
2019-10-21 10:57:56 +02:00
|
|
|
return <CreateButton label={t("overview.createButton")} link="/repos/create" />;
|
2019-02-26 10:34:56 +01:00
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2019-04-17 12:37:48 +02:00
|
|
|
}
|
2018-08-01 14:56:24 +02:00
|
|
|
|
2020-01-08 13:40:07 +01:00
|
|
|
const mapStateToProps = (state: any, ownProps: Props) => {
|
2019-04-17 12:37:48 +02:00
|
|
|
const { match } = ownProps;
|
2018-07-31 16:32:16 +02:00
|
|
|
const collection = getRepositoryCollection(state);
|
2020-08-11 10:34:29 +02:00
|
|
|
const loading = isFetchReposPending(state);
|
2018-08-01 10:00:53 +02:00
|
|
|
const error = getFetchReposFailure(state);
|
2019-04-18 11:42:09 +02:00
|
|
|
const page = urls.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,
|
2019-10-20 18:02:52 +02:00
|
|
|
reposLink
|
2018-07-31 16:32:16 +02:00
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
2020-01-08 13:40:07 +01:00
|
|
|
const mapDispatchToProps = (dispatch: any) => {
|
2018-07-31 16:32:16 +02:00
|
|
|
return {
|
2019-04-17 16:42:27 +02:00
|
|
|
fetchReposByPage: (link: string, page: number, filter?: string) => {
|
2019-04-10 17:25:36 +02:00
|
|
|
dispatch(fetchReposByPage(link, page, filter));
|
2019-10-20 18:02:52 +02:00
|
|
|
}
|
2018-07-31 16:32:16 +02:00
|
|
|
};
|
|
|
|
|
};
|
2020-01-08 13:40:07 +01:00
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(withTranslation("repos")(withRouter(Overview)));
|