2019-03-28 17:09:59 +01:00
|
|
|
// @flow
|
|
|
|
|
import React from "react";
|
2019-03-29 10:02:53 +01:00
|
|
|
import BranchDetailTable from "../components/BranchDetailTable";
|
2019-03-28 17:09:59 +01:00
|
|
|
import { ExtensionPoint } from "@scm-manager/ui-extensions";
|
|
|
|
|
import type { Repository, Branch } from "@scm-manager/ui-types";
|
2019-03-29 13:52:19 +01:00
|
|
|
import { connect } from "react-redux";
|
|
|
|
|
import { translate } from "react-i18next";
|
|
|
|
|
import { withRouter } from "react-router-dom";
|
|
|
|
|
import {
|
|
|
|
|
fetchBranchByName,
|
|
|
|
|
getFetchBranchFailure,
|
|
|
|
|
isFetchBranchPending
|
|
|
|
|
} from "../../modules/branches";
|
|
|
|
|
import { ErrorPage, Loading } from "@scm-manager/ui-components";
|
2019-03-28 17:09:59 +01:00
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
|
repository: Repository,
|
2019-03-29 13:52:19 +01:00
|
|
|
branchName: string,
|
|
|
|
|
loading: boolean,
|
|
|
|
|
error: Error,
|
|
|
|
|
branch: Branch,
|
|
|
|
|
|
|
|
|
|
// dispatch functions
|
|
|
|
|
fetchBranchByName: (repository: Repository, branchName: string) => void,
|
|
|
|
|
|
|
|
|
|
// context props
|
|
|
|
|
t: string => string
|
2019-03-28 17:09:59 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class BranchView extends React.Component<Props> {
|
2019-03-29 13:52:19 +01:00
|
|
|
componentDidMount() {
|
|
|
|
|
const { fetchBranchByName, repository, branchName } = this.props;
|
|
|
|
|
|
|
|
|
|
fetchBranchByName(repository, branchName);
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-28 17:09:59 +01:00
|
|
|
render() {
|
2019-03-29 13:52:19 +01:00
|
|
|
const { loading, error, t, repository, branch } = this.props;
|
|
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
|
return (
|
|
|
|
|
<ErrorPage
|
|
|
|
|
title={t("branches.errorTitle")}
|
|
|
|
|
subtitle={t("branches.errorSubtitle")}
|
|
|
|
|
error={error}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!branch || loading) {
|
|
|
|
|
return <Loading />;
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-28 17:09:59 +01:00
|
|
|
return (
|
|
|
|
|
<div>
|
|
|
|
|
<BranchDetailTable repository={repository} branch={branch} />
|
|
|
|
|
<hr />
|
|
|
|
|
<div className="content">
|
|
|
|
|
<ExtensionPoint
|
|
|
|
|
name="repos.branch-details.information"
|
|
|
|
|
renderAll={true}
|
2019-03-29 13:52:19 +01:00
|
|
|
props={{ repository, branch }}
|
2019-03-28 17:09:59 +01:00
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-29 10:02:53 +01:00
|
|
|
const mapStateToProps = (state, ownProps) => {
|
|
|
|
|
const { repository } = ownProps;
|
2019-03-29 13:52:19 +01:00
|
|
|
const branchName = decodeURIComponent(ownProps.match.params.branch);
|
|
|
|
|
const loading = isFetchBranchPending(state, repository, branchName);
|
|
|
|
|
const error = getFetchBranchFailure(state, repository, branchName);
|
2019-03-29 10:02:53 +01:00
|
|
|
return {
|
|
|
|
|
repository,
|
2019-03-29 13:52:19 +01:00
|
|
|
branchName,
|
|
|
|
|
loading,
|
|
|
|
|
error
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const mapDispatchToProps = dispatch => {
|
|
|
|
|
return {
|
|
|
|
|
fetchBranchByName: (repository: string, branchName: string) => {
|
|
|
|
|
dispatch(fetchBranchByName(repository, branchName));
|
|
|
|
|
}
|
2019-03-29 10:02:53 +01:00
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
2019-03-29 13:52:19 +01:00
|
|
|
export default withRouter(
|
|
|
|
|
connect(
|
|
|
|
|
mapStateToProps,
|
|
|
|
|
mapDispatchToProps
|
|
|
|
|
)(translate("repos")(BranchView))
|
|
|
|
|
);
|