2019-10-20 18:02:52 +02:00
|
|
|
import React from "react";
|
|
|
|
|
import { withRouter } from "react-router-dom";
|
2019-10-19 16:38:07 +02:00
|
|
|
import {
|
2019-02-01 10:50:05 +01:00
|
|
|
Branch,
|
|
|
|
|
Changeset,
|
|
|
|
|
PagedCollection,
|
2019-10-20 18:02:52 +02:00
|
|
|
Repository
|
|
|
|
|
} from "@scm-manager/ui-types";
|
2018-09-17 14:03:13 +02:00
|
|
|
import {
|
2018-10-17 10:38:46 +02:00
|
|
|
fetchChangesets,
|
2018-10-09 16:24:19 +02:00
|
|
|
getChangesets,
|
2018-10-04 19:08:11 +02:00
|
|
|
getFetchChangesetsFailure,
|
|
|
|
|
isFetchChangesetsPending,
|
2019-10-20 18:02:52 +02:00
|
|
|
selectListAsCollection
|
|
|
|
|
} from "../modules/changesets";
|
2018-10-17 10:38:46 +02:00
|
|
|
|
2019-10-20 18:02:52 +02:00
|
|
|
import { connect } from "react-redux";
|
2019-02-01 10:50:05 +01:00
|
|
|
import {
|
|
|
|
|
ErrorNotification,
|
|
|
|
|
getPageFromMatch,
|
|
|
|
|
LinkPaginator,
|
|
|
|
|
ChangesetList,
|
2019-04-09 15:19:43 +02:00
|
|
|
Loading,
|
2019-10-20 18:02:52 +02:00
|
|
|
Notification
|
|
|
|
|
} from "@scm-manager/ui-components";
|
|
|
|
|
import { compose } from "redux";
|
|
|
|
|
import { translate } from "react-i18next";
|
2018-09-17 14:03:13 +02:00
|
|
|
|
|
|
|
|
type Props = {
|
2019-10-19 16:38:07 +02:00
|
|
|
repository: Repository;
|
|
|
|
|
branch: Branch;
|
|
|
|
|
page: number;
|
2018-10-16 20:19:22 +02:00
|
|
|
|
|
|
|
|
// State props
|
2019-10-19 16:38:07 +02:00
|
|
|
changesets: Changeset[];
|
|
|
|
|
list: PagedCollection;
|
|
|
|
|
loading: boolean;
|
|
|
|
|
error: Error;
|
2018-10-16 20:19:22 +02:00
|
|
|
|
|
|
|
|
// Dispatch props
|
2019-10-19 16:38:07 +02:00
|
|
|
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
|
2019-10-19 16:38:07 +02:00
|
|
|
match: any;
|
|
|
|
|
t: (p: string) => string;
|
2018-09-27 16:29:33 +02:00
|
|
|
};
|
|
|
|
|
|
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-09-20 16:28:41 +02:00
|
|
|
|
2018-10-17 10:38:46 +02:00
|
|
|
fetchChangesets(repository, branch, page);
|
|
|
|
|
}
|
2018-10-16 17:04:28 +02:00
|
|
|
|
|
|
|
|
render() {
|
2019-04-09 15:19:43 +02:00
|
|
|
const { changesets, loading, error, t } = this.props;
|
2018-10-16 17:04:28 +02:00
|
|
|
|
2018-09-27 16:29:33 +02:00
|
|
|
if (error) {
|
2018-10-17 11:55:47 +02:00
|
|
|
return <ErrorNotification 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-17 11:55:47 +02:00
|
|
|
|
2018-10-10 19:26:29 +02:00
|
|
|
if (!changesets || changesets.length === 0) {
|
2019-04-09 15:19:43 +02:00
|
|
|
return (
|
|
|
|
|
<div className="panel-block">
|
|
|
|
|
<Notification type="info">
|
2019-10-20 18:02:52 +02:00
|
|
|
{t("changesets.noChangesets")}
|
2019-04-09 15:19:43 +02:00
|
|
|
</Notification>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
2018-10-10 19:26:29 +02:00
|
|
|
}
|
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;
|
2019-02-01 10:50:05 +01:00
|
|
|
return (
|
|
|
|
|
<div className="panel-block">
|
|
|
|
|
<ChangesetList repository={repository} changesets={changesets} />
|
|
|
|
|
</div>
|
|
|
|
|
);
|
2018-09-18 09:22:08 +02:00
|
|
|
};
|
|
|
|
|
|
2018-10-10 19:26:29 +02:00
|
|
|
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));
|
2019-10-20 18:02:52 +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) => {
|
2018-10-17 10:38:46 +02:00
|
|
|
const { repository, branch, match } = ownProps;
|
2018-10-10 19:26:29 +02:00
|
|
|
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
|
|
|
|
2019-10-19 16:38:07 +02:00
|
|
|
return {
|
|
|
|
|
changesets,
|
|
|
|
|
list,
|
|
|
|
|
page,
|
|
|
|
|
loading,
|
2019-10-20 18:02:52 +02:00
|
|
|
error
|
2019-10-19 16:38:07 +02:00
|
|
|
};
|
2018-10-10 19:26:29 +02:00
|
|
|
};
|
2018-10-17 10:38:46 +02:00
|
|
|
|
2018-10-17 11:55:47 +02:00
|
|
|
export default compose(
|
2019-10-20 18:02:52 +02:00
|
|
|
translate("repos"),
|
2018-10-17 11:55:47 +02:00
|
|
|
withRouter,
|
2018-09-18 16:51:31 +02:00
|
|
|
connect(
|
|
|
|
|
mapStateToProps,
|
2019-10-20 18:02:52 +02:00
|
|
|
mapDispatchToProps
|
|
|
|
|
)
|
2018-10-17 11:55:47 +02:00
|
|
|
)(Changesets);
|