2019-10-19 16:38:07 +02:00
|
|
|
import React from 'react';
|
|
|
|
|
import { connect } from 'react-redux';
|
|
|
|
|
import { withRouter } from 'react-router-dom';
|
|
|
|
|
import { Changeset, Repository } from '@scm-manager/ui-types';
|
2018-09-25 15:08:57 +02:00
|
|
|
import {
|
|
|
|
|
fetchChangesetIfNeeded,
|
|
|
|
|
getChangeset,
|
|
|
|
|
getFetchChangesetFailure,
|
2019-10-19 16:38:07 +02:00
|
|
|
isFetchChangesetPending,
|
|
|
|
|
} from '../modules/changesets';
|
|
|
|
|
import ChangesetDetails from '../components/changesets/ChangesetDetails';
|
|
|
|
|
import { translate } from 'react-i18next';
|
|
|
|
|
import { ErrorPage, Loading } from '@scm-manager/ui-components';
|
2018-09-13 12:20:28 +02:00
|
|
|
|
2018-09-20 08:32:02 +02:00
|
|
|
type Props = {
|
2019-10-19 16:38:07 +02:00
|
|
|
id: string;
|
|
|
|
|
changeset: Changeset;
|
|
|
|
|
repository: Repository;
|
|
|
|
|
loading: boolean;
|
|
|
|
|
error: Error;
|
|
|
|
|
fetchChangesetIfNeeded: (repository: Repository, id: string) => void;
|
|
|
|
|
match: any;
|
|
|
|
|
t: (p: 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
|
2019-10-19 16:38:07 +02:00
|
|
|
title={t('changesets.errorTitle')}
|
|
|
|
|
subtitle={t('changesets.errorSubtitle')}
|
2018-09-25 15:08:57 +02:00
|
|
|
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);
|
2019-10-19 16:38:07 +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));
|
2019-10-19 16:38:07 +02:00
|
|
|
},
|
2018-09-20 15:43:12 +02:00
|
|
|
};
|
2018-09-20 08:32:02 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default withRouter(
|
|
|
|
|
connect(
|
|
|
|
|
mapStateToProps,
|
2019-10-19 16:38:07 +02:00
|
|
|
mapDispatchToProps,
|
|
|
|
|
)(translate('repos')(ChangesetView)),
|
2018-09-20 08:32:02 +02:00
|
|
|
);
|