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

122 lines
3.1 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,
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-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,
error: Error
2018-09-18 16:51:31 +02:00
};
2018-09-17 14:03:13 +02:00
type State = {};
2018-09-19 17:18:24 +02:00
class ChangesetContainer extends React.Component<Props, State> {
2018-09-17 14:03:13 +02:00
componentDidMount() {
console.log("Component did mount");
2018-09-18 16:51:31 +02:00
const {
fetchChangesetsByBranch,
fetchChangesetsByBranchAndPage,
repository,
branch,
match
2018-09-18 16:51:31 +02:00
} = this.props;
const { page } = match.params;
if (!page) {
fetchChangesetsByBranch(repository, branch);
} else {
fetchChangesetsByBranchAndPage(repository, branch, page);
}
}
2018-09-17 14:03:13 +02:00
render() {
2018-09-18 16:51:31 +02:00
const { changesets, loading, error } = this.props;
// TODO: i18n
if (error) {
return (
<ErrorPage
title={"Failed loading branches"}
subtitle={"Somethin went wrong"}
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;
console.log(list);
2018-09-19 13:49:04 +02:00
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
)(ChangesetContainer)
2018-09-18 16:51:31 +02:00
);