2018-09-13 12:20:28 +02:00
|
|
|
//@flow
|
|
|
|
|
import React from "react";
|
2018-09-20 08:32:02 +02:00
|
|
|
import { connect } from "react-redux";
|
|
|
|
|
import { withRouter } from "react-router-dom";
|
2018-09-25 15:08:57 +02:00
|
|
|
import type { Changeset, Repository } from "@scm-manager/ui-types";
|
|
|
|
|
import {
|
|
|
|
|
fetchChangesetIfNeeded,
|
|
|
|
|
getChangeset,
|
|
|
|
|
getFetchChangesetFailure,
|
|
|
|
|
isFetchChangesetPending
|
|
|
|
|
} from "../modules/changesets";
|
|
|
|
|
import ChangesetDetails from "../components/ChangesetDetails";
|
|
|
|
|
import { translate } from "react-i18next";
|
|
|
|
|
import { Loading, ErrorPage } from "@scm-manager/ui-components";
|
2018-09-13 12:20:28 +02:00
|
|
|
|
2018-09-20 08:32:02 +02:00
|
|
|
type Props = {
|
2018-09-20 15:43:12 +02:00
|
|
|
id: string,
|
|
|
|
|
changeset: Changeset,
|
|
|
|
|
repository: Repository,
|
2018-09-25 15:08:57 +02:00
|
|
|
loading: boolean,
|
|
|
|
|
error: Error,
|
2018-10-09 11:35:02 +02:00
|
|
|
fetchChangesetIfNeeded: (repository: Repository, id: string) => void,
|
2018-09-25 15:08:57 +02:00
|
|
|
match: any,
|
|
|
|
|
t: string => string
|
2018-09-20 08:32:02 +02:00
|
|
|
};
|
|
|
|
|
|
2018-09-25 15:08:57 +02:00
|
|
|
class ChangesetView extends React.Component<Props> {
|
2018-09-20 08:32:02 +02:00
|
|
|
componentDidMount() {
|
2018-09-20 15:43:12 +02:00
|
|
|
const { fetchChangesetIfNeeded, repository } = this.props;
|
2018-09-20 08:32:02 +02:00
|
|
|
const id = this.props.match.params.id;
|
2018-10-09 11:35:02 +02:00
|
|
|
fetchChangesetIfNeeded(repository, id);
|
2018-09-20 08:32:02 +02:00
|
|
|
}
|
2018-09-13 12:20:28 +02:00
|
|
|
|
|
|
|
|
render() {
|
2018-09-27 11:56:04 +02:00
|
|
|
const { changeset, loading, error, t, repository } = this.props;
|
2018-09-25 15:08:57 +02:00
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
|
return (
|
|
|
|
|
<ErrorPage
|
|
|
|
|
title={t("changeset-error.title")}
|
|
|
|
|
subtitle={t("changeset-error.subtitle")}
|
|
|
|
|
error={error}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!changeset || loading) return <Loading />;
|
2018-09-20 08:32:02 +02:00
|
|
|
|
2018-10-09 11:32:56 +02:00
|
|
|
return <ChangesetDetails changeset={changeset} repository={repository} />;
|
2018-09-13 12:20:28 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-20 08:32:02 +02:00
|
|
|
const mapStateToProps = (state, ownProps: Props) => {
|
2018-10-09 11:35:02 +02:00
|
|
|
const repository = ownProps.repository;
|
2018-09-25 15:08:57 +02:00
|
|
|
const id = ownProps.match.params.id;
|
2018-10-09 11:35:02 +02:00
|
|
|
const changeset = getChangeset(state, repository, id);
|
|
|
|
|
const loading = isFetchChangesetPending(state, repository, id);
|
|
|
|
|
const error = getFetchChangesetFailure(state, repository, id);
|
2018-09-25 15:08:57 +02:00
|
|
|
return { changeset, error, loading };
|
2018-09-20 08:32:02 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const mapDispatchToProps = dispatch => {
|
2018-09-20 15:43:12 +02:00
|
|
|
return {
|
2018-10-09 11:35:02 +02:00
|
|
|
fetchChangesetIfNeeded: (repository: Repository, id: string) => {
|
|
|
|
|
dispatch(fetchChangesetIfNeeded(repository, id));
|
2018-09-20 15:43:12 +02:00
|
|
|
}
|
|
|
|
|
};
|
2018-09-20 08:32:02 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default withRouter(
|
|
|
|
|
connect(
|
|
|
|
|
mapStateToProps,
|
|
|
|
|
mapDispatchToProps
|
2018-09-25 15:08:57 +02:00
|
|
|
)(translate("changesets")(ChangesetView))
|
2018-09-20 08:32:02 +02:00
|
|
|
);
|