Files
SCM-Manager/scm-ui/src/repos/containers/Changesets.js

133 lines
3.2 KiB
JavaScript
Raw Normal View History

2018-09-19 13:49:04 +02:00
// @flow
2018-09-17 14:03:13 +02:00
import React from "react";
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 {
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";
import { connect } from "react-redux";
import ChangesetList from "../components/changesets/ChangesetList";
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 = {
fetchChangesetsByBranch: (Repository, Branch) => void,
2018-10-08 17:34:11 +02:00
fetchChangesetsByBranchAndPage: (Repository, Branch, number) => void,
repository: Repository, //TODO: Do we really need/want this here?
branch: Branch,
2018-10-04 19:08:11 +02:00
changesets: Changeset[],
loading: boolean,
match: any,
list: PagedCollection,
2018-10-11 17:29:50 +02:00
error: Error,
t: string => string
};
2018-10-09 16:24:19 +02:00
type State = {};
2018-09-17 14:03:13 +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 {
fetchChangesetsByBranch,
fetchChangesetsByBranchAndPage,
repository,
branch,
match
2018-09-18 16:51:31 +02:00
} = this.props;
console.log("branch");
console.log(branch);
const { page } = match.params;
if (!page) {
fetchChangesetsByBranch(repository, branch);
} else {
fetchChangesetsByBranchAndPage(repository, branch, page);
}
}
2018-09-17 14:03:13 +02:00
render() {
const { repository, branch, changesets, loading, error, t } = this.props;
if (!repository || !branch) {
return null;
}
if (error) {
return (
<ErrorPage
2018-10-11 17:29:50 +02:00
title={t("changesets.error-title")}
subtitle={t("changesets.error-title")}
error={error}
/>
);
}
if (loading) {
2018-09-18 16:51:31 +02:00
return <Loading />;
2018-09-17 14:03:13 +02:00
}
if (!changesets || changesets.length === 0) {
return null;
}
2018-09-18 16:51:31 +02:00
return (
<>
{this.renderList()}
2018-09-19 13:49:04 +02:00
{this.renderPaginator()}
</>
2018-09-18 16:51:31 +02:00
);
}
renderList = () => {
const { repository, changesets } = this.props;
return <ChangesetList repository={repository} changesets={changesets} />;
};
renderPaginator = () => {
2018-09-19 13:49:04 +02:00
const { list } = this.props;
if (list) {
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 {
fetchChangesetsByBranch: (repo: Repository, branch: Branch) => {
dispatch(fetchChangesetsByBranch(repo, branch));
2018-09-17 14:03:13 +02:00
},
fetchChangesetsByBranchAndPage: (
repo: Repository,
2018-10-08 17:34:11 +02:00
branch: Branch,
page: number
2018-09-18 16:51:31 +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
};
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
)(translate("repos")(Changesets))
2018-09-18 16:51:31 +02:00
);