2019-03-28 11:51:00 +01:00
|
|
|
// @flow
|
|
|
|
|
import React from "react";
|
2019-03-28 14:19:53 +01:00
|
|
|
import {
|
|
|
|
|
fetchBranches,
|
|
|
|
|
getBranches,
|
|
|
|
|
getFetchBranchesFailure,
|
2019-04-03 13:24:41 +02:00
|
|
|
isFetchBranchesPending
|
2019-04-02 09:27:34 +02:00
|
|
|
} from "../modules/branches";
|
2019-04-03 13:39:16 +02:00
|
|
|
import { orderBranches } from "../util/orderBranches";
|
2019-03-28 14:19:53 +01:00
|
|
|
import { connect } from "react-redux";
|
|
|
|
|
import type { Branch, Repository } from "@scm-manager/ui-types";
|
|
|
|
|
import { compose } from "redux";
|
|
|
|
|
import { translate } from "react-i18next";
|
2019-03-28 17:09:59 +01:00
|
|
|
import { withRouter } from "react-router-dom";
|
2019-03-28 14:19:53 +01:00
|
|
|
import {
|
2019-03-28 14:47:57 +01:00
|
|
|
CreateButton,
|
2019-03-28 14:19:53 +01:00
|
|
|
ErrorNotification,
|
|
|
|
|
Loading,
|
|
|
|
|
Subtitle
|
|
|
|
|
} from "@scm-manager/ui-components";
|
2019-03-28 17:09:59 +01:00
|
|
|
import BranchTable from "../components/BranchTable";
|
2019-03-28 11:51:00 +01:00
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
|
repository: Repository,
|
2019-03-28 17:09:59 +01:00
|
|
|
baseUrl: string,
|
2019-03-28 11:51:00 +01:00
|
|
|
loading: boolean,
|
|
|
|
|
error: Error,
|
|
|
|
|
branches: Branch[],
|
|
|
|
|
|
|
|
|
|
// dispatch props
|
2019-03-28 14:47:57 +01:00
|
|
|
showCreateButton: boolean,
|
2019-03-28 11:51:00 +01:00
|
|
|
fetchBranches: Repository => void,
|
|
|
|
|
|
|
|
|
|
// Context props
|
|
|
|
|
history: any,
|
|
|
|
|
match: any,
|
|
|
|
|
t: string => string
|
|
|
|
|
};
|
2019-03-29 14:24:54 +01:00
|
|
|
|
2019-03-28 11:51:00 +01:00
|
|
|
class BranchesOverview extends React.Component<Props> {
|
|
|
|
|
componentDidMount() {
|
2019-03-28 14:19:53 +01:00
|
|
|
const { fetchBranches, repository } = this.props;
|
2019-03-28 11:51:00 +01:00
|
|
|
fetchBranches(repository);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
render() {
|
2019-03-28 17:09:59 +01:00
|
|
|
const { baseUrl, loading, error, branches, t } = this.props;
|
2019-03-28 11:51:00 +01:00
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
|
return <ErrorNotification error={error} />;
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-29 14:54:18 +01:00
|
|
|
if (!branches || loading) {
|
2019-03-28 11:51:00 +01:00
|
|
|
return <Loading />;
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-29 14:54:18 +01:00
|
|
|
orderBranches(branches);
|
|
|
|
|
|
2019-03-28 14:19:53 +01:00
|
|
|
return (
|
|
|
|
|
<>
|
2019-03-28 17:09:59 +01:00
|
|
|
<Subtitle subtitle={t("branches.overview.title")} />
|
|
|
|
|
<BranchTable baseUrl={baseUrl} branches={branches} />
|
2019-03-28 14:47:57 +01:00
|
|
|
{this.renderCreateButton()}
|
2019-03-28 14:19:53 +01:00
|
|
|
</>
|
|
|
|
|
);
|
2019-03-28 11:51:00 +01:00
|
|
|
}
|
|
|
|
|
|
2019-03-28 14:47:57 +01:00
|
|
|
renderCreateButton() {
|
|
|
|
|
const { showCreateButton, t } = this.props;
|
2019-03-29 14:24:54 +01:00
|
|
|
if (showCreateButton || true) {
|
|
|
|
|
// TODO
|
2019-03-28 14:47:57 +01:00
|
|
|
return (
|
2019-03-29 14:24:54 +01:00
|
|
|
<CreateButton
|
|
|
|
|
label={t("branches.overview.createButton")}
|
|
|
|
|
link="./create"
|
|
|
|
|
/>
|
2019-03-28 14:47:57 +01:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2019-03-28 11:51:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const mapStateToProps = (state, ownProps) => {
|
|
|
|
|
const { repository } = ownProps;
|
|
|
|
|
const loading = isFetchBranchesPending(state, repository);
|
|
|
|
|
const error = getFetchBranchesFailure(state, repository);
|
|
|
|
|
const branches = getBranches(state, repository);
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
repository,
|
|
|
|
|
loading,
|
|
|
|
|
error,
|
|
|
|
|
branches
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const mapDispatchToProps = dispatch => {
|
|
|
|
|
return {
|
|
|
|
|
fetchBranches: (repository: Repository) => {
|
|
|
|
|
dispatch(fetchBranches(repository));
|
2019-03-28 14:19:53 +01:00
|
|
|
}
|
2019-03-28 11:51:00 +01:00
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default compose(
|
|
|
|
|
translate("repos"),
|
|
|
|
|
withRouter,
|
|
|
|
|
connect(
|
|
|
|
|
mapStateToProps,
|
|
|
|
|
mapDispatchToProps
|
|
|
|
|
)
|
|
|
|
|
)(BranchesOverview);
|