2020-03-23 15:35:58 +01:00
|
|
|
/*
|
|
|
|
|
* MIT License
|
|
|
|
|
*
|
|
|
|
|
* Copyright (c) 2020-present Cloudogu GmbH and Contributors
|
|
|
|
|
*
|
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
|
*
|
|
|
|
|
* The above copyright notice and this permission notice shall be included in all
|
|
|
|
|
* copies or substantial portions of the Software.
|
|
|
|
|
*
|
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
|
* SOFTWARE.
|
|
|
|
|
*/
|
2019-10-20 18:02:52 +02:00
|
|
|
import React from "react";
|
|
|
|
|
import { connect } from "react-redux";
|
2020-01-08 13:40:07 +01:00
|
|
|
import { compose } from "redux";
|
2019-10-20 18:02:52 +02:00
|
|
|
import { withRouter } from "react-router-dom";
|
2019-10-23 15:47:08 +02:00
|
|
|
import { WithTranslation, withTranslation } from "react-i18next";
|
2019-10-20 18:02:52 +02:00
|
|
|
import { Changeset, Repository } from "@scm-manager/ui-types";
|
2019-10-23 15:47:08 +02:00
|
|
|
import { ErrorPage, Loading } from "@scm-manager/ui-components";
|
2018-09-25 15:08:57 +02:00
|
|
|
import {
|
|
|
|
|
fetchChangesetIfNeeded,
|
|
|
|
|
getChangeset,
|
|
|
|
|
getFetchChangesetFailure,
|
2019-10-20 18:02:52 +02:00
|
|
|
isFetchChangesetPending
|
|
|
|
|
} from "../modules/changesets";
|
|
|
|
|
import ChangesetDetails from "../components/changesets/ChangesetDetails";
|
2018-09-13 12:20:28 +02:00
|
|
|
|
2019-10-23 15:47:08 +02:00
|
|
|
type Props = WithTranslation & {
|
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;
|
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() {
|
2020-06-17 16:45:53 +02:00
|
|
|
const { fetchChangesetIfNeeded, repository, id } = this.props;
|
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
|
|
|
|
2020-06-17 16:45:53 +02:00
|
|
|
componentDidUpdate(prevProps: Props) {
|
|
|
|
|
const { fetchChangesetIfNeeded, repository, id } = this.props;
|
|
|
|
|
if (prevProps.id !== id) {
|
|
|
|
|
fetchChangesetIfNeeded(repository, id);
|
|
|
|
|
}
|
2020-06-15 12:44:43 +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) {
|
2019-10-21 10:57:56 +02:00
|
|
|
return <ErrorPage title={t("changesets.errorTitle")} subtitle={t("changesets.errorSubtitle")} error={error} />;
|
2018-09-25 15:08:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-08 13:40:07 +01:00
|
|
|
const mapStateToProps = (state: any, 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 {
|
2020-06-17 16:45:53 +02:00
|
|
|
id,
|
2019-10-19 16:38:07 +02:00
|
|
|
changeset,
|
|
|
|
|
error,
|
2019-10-20 18:02:52 +02:00
|
|
|
loading
|
2019-10-19 16:38:07 +02:00
|
|
|
};
|
2018-09-20 08:32:02 +02:00
|
|
|
};
|
|
|
|
|
|
2020-01-08 13:40:07 +01:00
|
|
|
const mapDispatchToProps = (dispatch: any) => {
|
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-20 18:02:52 +02:00
|
|
|
}
|
2018-09-20 15:43:12 +02:00
|
|
|
};
|
2018-09-20 08:32:02 +02:00
|
|
|
};
|
|
|
|
|
|
2020-01-08 13:40:07 +01:00
|
|
|
export default compose(
|
|
|
|
|
withRouter,
|
|
|
|
|
connect(mapStateToProps, mapDispatchToProps),
|
|
|
|
|
withTranslation("repos")
|
|
|
|
|
)(ChangesetView);
|