2018-09-19 13:49:04 +02:00
|
|
|
// @flow
|
2018-09-17 14:03:13 +02:00
|
|
|
|
2018-10-10 19:26:29 +02:00
|
|
|
import React from "react";
|
2018-10-11 09:45:46 +02:00
|
|
|
import { withRouter } from "react-router-dom";
|
|
|
|
|
import type {
|
|
|
|
|
Branch,
|
|
|
|
|
Changeset,
|
|
|
|
|
PagedCollection,
|
|
|
|
|
Repository
|
|
|
|
|
} from "@scm-manager/ui-types";
|
2018-09-17 14:03:13 +02:00
|
|
|
import {
|
2018-10-10 19:26:29 +02:00
|
|
|
fetchChangesetsByBranch,
|
2018-10-04 19:08:11 +02:00
|
|
|
fetchChangesetsByBranchAndPage,
|
2018-10-09 16:24:19 +02:00
|
|
|
getChangesets,
|
2018-10-04 19:08:11 +02:00
|
|
|
getFetchChangesetsFailure,
|
|
|
|
|
isFetchChangesetsPending,
|
|
|
|
|
selectListAsCollection
|
2018-09-17 14:03:13 +02:00
|
|
|
} from "../modules/changesets";
|
2018-10-11 09:45:46 +02:00
|
|
|
import { connect } from "react-redux";
|
2018-09-27 16:29:33 +02:00
|
|
|
import ChangesetList from "../components/changesets/ChangesetList";
|
2018-10-11 09:45:46 +02:00
|
|
|
import { ErrorPage, LinkPaginator, Loading } from "@scm-manager/ui-components";
|
2018-10-11 17:29:50 +02:00
|
|
|
import { translate } from "react-i18next";
|
2018-09-17 14:03:13 +02:00
|
|
|
|
|
|
|
|
type Props = {
|
2018-10-10 19:26:29 +02:00
|
|
|
fetchChangesetsByBranch: (Repository, Branch) => void,
|
2018-10-08 17:34:11 +02:00
|
|
|
fetchChangesetsByBranchAndPage: (Repository, Branch, number) => void,
|
2018-10-10 19:26:29 +02:00
|
|
|
repository: Repository, //TODO: Do we really need/want this here?
|
|
|
|
|
branch: Branch,
|
2018-10-04 19:08:11 +02:00
|
|
|
changesets: Changeset[],
|
|
|
|
|
loading: boolean,
|
2018-10-10 19:26:29 +02:00
|
|
|
match: any,
|
|
|
|
|
list: PagedCollection,
|
2018-10-11 17:29:50 +02:00
|
|
|
error: Error,
|
|
|
|
|
t: string => string
|
2018-09-27 16:29:33 +02:00
|
|
|
};
|
|
|
|
|
|
2018-10-09 16:24:19 +02:00
|
|
|
type State = {};
|
2018-09-17 14:03:13 +02:00
|
|
|
|
2018-10-12 16:07:24 +02:00
|
|
|
class Changesets extends React.Component<Props, State> {
|
2018-09-17 14:03:13 +02:00
|
|
|
componentDidMount() {
|
2018-09-18 16:51:31 +02:00
|
|
|
const {
|
2018-10-10 19:26:29 +02:00
|
|
|
fetchChangesetsByBranch,
|
|
|
|
|
fetchChangesetsByBranchAndPage,
|
2018-10-05 17:13:12 +02:00
|
|
|
repository,
|
|
|
|
|
branch,
|
2018-10-10 19:26:29 +02:00
|
|
|
match
|
2018-09-18 16:51:31 +02:00
|
|
|
} = this.props;
|
2018-10-12 16:07:24 +02:00
|
|
|
|
|
|
|
|
console.log("branch");
|
|
|
|
|
console.log(branch);
|
2018-10-10 19:26:29 +02:00
|
|
|
const { page } = match.params;
|
|
|
|
|
if (!page) {
|
|
|
|
|
fetchChangesetsByBranch(repository, branch);
|
2018-09-17 16:31:19 +02:00
|
|
|
} else {
|
2018-10-10 19:26:29 +02:00
|
|
|
fetchChangesetsByBranchAndPage(repository, branch, page);
|
2018-09-20 16:28:41 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-17 14:03:13 +02:00
|
|
|
render() {
|
2018-10-12 16:07:24 +02:00
|
|
|
const { repository, branch, changesets, loading, error, t } = this.props;
|
|
|
|
|
|
|
|
|
|
if (!repository || !branch) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2018-10-10 19:26:29 +02:00
|
|
|
|
2018-09-27 16:29:33 +02:00
|
|
|
if (error) {
|
2018-10-10 19:26:29 +02:00
|
|
|
return (
|
|
|
|
|
<ErrorPage
|
2018-10-11 17:29:50 +02:00
|
|
|
title={t("changesets.error-title")}
|
|
|
|
|
subtitle={t("changesets.error-title")}
|
2018-10-10 19:26:29 +02:00
|
|
|
error={error}
|
|
|
|
|
/>
|
|
|
|
|
);
|
2018-09-27 16:29:33 +02:00
|
|
|
}
|
|
|
|
|
|
2018-10-10 19:26:29 +02:00
|
|
|
if (loading) {
|
2018-09-18 16:51:31 +02:00
|
|
|
return <Loading />;
|
2018-09-17 14:03:13 +02:00
|
|
|
}
|
2018-10-10 19:26:29 +02:00
|
|
|
if (!changesets || changesets.length === 0) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2018-09-18 16:51:31 +02:00
|
|
|
return (
|
2018-10-10 19:26:29 +02:00
|
|
|
<>
|
2018-10-04 15:52:17 +02:00
|
|
|
{this.renderList()}
|
2018-09-19 13:49:04 +02:00
|
|
|
{this.renderPaginator()}
|
2018-10-10 19:26:29 +02:00
|
|
|
</>
|
2018-09-18 16:51:31 +02:00
|
|
|
);
|
2018-09-18 09:22:08 +02:00
|
|
|
}
|
|
|
|
|
|
2018-10-04 15:52:17 +02:00
|
|
|
renderList = () => {
|
2018-10-10 19:26:29 +02:00
|
|
|
const { repository, changesets } = this.props;
|
|
|
|
|
return <ChangesetList repository={repository} changesets={changesets} />;
|
2018-09-18 09:22:08 +02:00
|
|
|
};
|
|
|
|
|
|
2018-10-10 19:26:29 +02:00
|
|
|
renderPaginator = () => {
|
2018-09-19 13:49:04 +02:00
|
|
|
const { list } = this.props;
|
|
|
|
|
if (list) {
|
2018-10-10 19:26:29 +02:00
|
|
|
return <LinkPaginator collection={list} />;
|
2018-09-19 13:49:04 +02:00
|
|
|
}
|
|
|
|
|
return null;
|
2018-09-17 14:03:13 +02:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const mapDispatchToProps = dispatch => {
|
|
|
|
|
return {
|
2018-10-10 19:26:29 +02:00
|
|
|
fetchChangesetsByBranch: (repo: Repository, branch: Branch) => {
|
|
|
|
|
dispatch(fetchChangesetsByBranch(repo, branch));
|
2018-09-17 14:03:13 +02:00
|
|
|
},
|
2018-09-20 16:28:41 +02:00
|
|
|
fetchChangesetsByBranchAndPage: (
|
2018-10-10 19:26:29 +02:00
|
|
|
repo: Repository,
|
2018-10-08 17:34:11 +02:00
|
|
|
branch: Branch,
|
2018-09-20 16:28:41 +02:00
|
|
|
page: number
|
2018-09-18 16:51:31 +02:00
|
|
|
) => {
|
2018-10-10 19:26:29 +02:00
|
|
|
dispatch(fetchChangesetsByBranchAndPage(repo, branch, page));
|
2018-09-17 14:03:13 +02:00
|
|
|
}
|
2018-09-18 16:51:31 +02:00
|
|
|
};
|
2018-09-17 14:03:13 +02:00
|
|
|
};
|
|
|
|
|
|
2018-10-10 19:26:29 +02:00
|
|
|
const mapStateToProps = (state: any, ownProps: Props) => {
|
|
|
|
|
const { repository, branch } = ownProps;
|
|
|
|
|
const changesets = getChangesets(state, repository, branch);
|
|
|
|
|
const loading = isFetchChangesetsPending(state, repository, branch);
|
|
|
|
|
const error = getFetchChangesetsFailure(state, repository, branch);
|
|
|
|
|
const list = selectListAsCollection(state, repository, branch);
|
|
|
|
|
return { changesets, list, loading, error };
|
|
|
|
|
};
|
2018-09-18 16:51:31 +02:00
|
|
|
export default withRouter(
|
|
|
|
|
connect(
|
|
|
|
|
mapStateToProps,
|
|
|
|
|
mapDispatchToProps
|
2018-10-12 16:07:24 +02:00
|
|
|
)(translate("repos")(Changesets))
|
2018-09-18 16:51:31 +02:00
|
|
|
);
|