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

129 lines
2.9 KiB
TypeScript
Raw Normal View History

import React from "react";
import { connect } from "react-redux";
import { compose } from "redux";
import { withRouter } from "react-router-dom";
import { WithTranslation, withTranslation } from "react-i18next";
2019-10-21 10:57:56 +02:00
import { Branch, Changeset, PagedCollection, Repository } from "@scm-manager/ui-types";
2019-02-01 10:50:05 +01:00
import {
ErrorNotification,
getPageFromMatch,
LinkPaginator,
ChangesetList,
2019-04-09 15:19:43 +02:00
Loading,
Notification
} from "@scm-manager/ui-components";
import {
fetchChangesets,
getChangesets,
getFetchChangesetsFailure,
isFetchChangesetsPending,
selectListAsCollection
} from "../modules/changesets";
2018-09-17 14:03:13 +02:00
type Props = WithTranslation & {
repository: Repository;
branch: Branch;
page: number;
2018-10-16 20:19:22 +02:00
// State props
changesets: Changeset[];
list: PagedCollection;
loading: boolean;
error: Error;
2018-10-16 20:19:22 +02:00
// Dispatch props
fetchChangesets: (p1: Repository, p2: Branch, p3: number) => void;
2018-10-16 20:19:22 +02:00
2018-10-17 14:11:28 +02:00
// context props
match: any;
};
2018-10-17 10:38:46 +02:00
class Changesets extends React.Component<Props> {
2018-09-17 14:03:13 +02:00
componentDidMount() {
2018-10-17 10:38:46 +02:00
const { fetchChangesets, repository, branch, page } = this.props;
2018-10-17 10:38:46 +02:00
fetchChangesets(repository, branch, page);
}
render() {
2019-04-09 15:19:43 +02:00
const { changesets, loading, error, t } = this.props;
if (error) {
2018-10-17 11:55:47 +02:00
return <ErrorNotification error={error} />;
}
if (loading) {
2018-09-18 16:51:31 +02:00
return <Loading />;
2018-09-17 14:03:13 +02:00
}
2018-10-17 11:55:47 +02:00
if (!changesets || changesets.length === 0) {
2019-04-09 15:19:43 +02:00
return (
<div className="panel-block">
2019-10-21 10:57:56 +02:00
<Notification type="info">{t("changesets.noChangesets")}</Notification>
2019-04-09 15:19:43 +02:00
</div>
);
}
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;
2019-02-01 10:50:05 +01:00
return (
<div className="panel-block">
<ChangesetList repository={repository} changesets={changesets} />
</div>
);
};
renderPaginator = () => {
2018-10-17 10:57:01 +02:00
const { page, list } = this.props;
2018-09-19 13:49:04 +02:00
if (list) {
2019-02-01 10:50:05 +01:00
return (
<div className="panel-footer">
<LinkPaginator page={page} collection={list} />
</div>
);
2018-09-19 13:49:04 +02:00
}
return null;
2018-09-17 14:03:13 +02:00
};
}
const mapDispatchToProps = dispatch => {
return {
2018-10-17 10:38:46 +02:00
fetchChangesets: (repo: Repository, branch: Branch, page: number) => {
dispatch(fetchChangesets(repo, branch, page));
}
2018-09-18 16:51:31 +02:00
};
2018-09-17 14:03:13 +02:00
};
const mapStateToProps = (state: any, ownProps: Props) => {
2018-10-17 10:38:46 +02:00
const { repository, branch, match } = 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);
2018-10-17 11:55:47 +02:00
const page = getPageFromMatch(match);
2018-10-17 10:38:46 +02:00
return {
changesets,
list,
page,
loading,
error
};
};
2018-10-17 10:38:46 +02:00
2018-10-17 11:55:47 +02:00
export default compose(
withTranslation("repos"),
2018-10-17 11:55:47 +02:00
withRouter,
2018-09-18 16:51:31 +02:00
connect(
mapStateToProps,
mapDispatchToProps
)
2018-10-17 11:55:47 +02:00
)(Changesets);