2018-09-17 14:03:13 +02:00
|
|
|
import React from "react"
|
|
|
|
|
import {connect} from "react-redux";
|
2018-09-17 17:20:17 +02:00
|
|
|
import {Loading} from "@scm-manager/ui-components";
|
2018-09-17 14:03:13 +02:00
|
|
|
|
|
|
|
|
import {
|
|
|
|
|
fetchChangesetsByNamespaceAndName, fetchChangesetsByNamespaceNameAndBranch,
|
2018-09-17 17:20:17 +02:00
|
|
|
getChangesets, isFetchChangesetsPending,
|
2018-09-17 14:03:13 +02:00
|
|
|
} from "../modules/changesets";
|
2018-09-17 16:31:19 +02:00
|
|
|
import type { History } from "history";
|
2018-09-17 14:03:13 +02:00
|
|
|
import {fetchBranchesByNamespaceAndName, getBranchNames} from "../../repos/modules/branches";
|
|
|
|
|
import type {Repository} from "@scm-manager/ui-types";
|
|
|
|
|
import ChangesetTable from "../components/ChangesetTable";
|
|
|
|
|
import DropDown from "../components/DropDown";
|
2018-09-17 16:31:19 +02:00
|
|
|
import {withRouter} from "react-router-dom";
|
2018-09-17 14:03:13 +02:00
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
|
repository: Repository,
|
|
|
|
|
branchName: string,
|
|
|
|
|
history: History,
|
|
|
|
|
fetchChangesetsByNamespaceNameAndBranch: (namespace: string, name: string, branch: string) => void
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Changesets extends React.Component<State, Props> {
|
|
|
|
|
constructor(props) {
|
|
|
|
|
super(props);
|
2018-09-17 16:31:19 +02:00
|
|
|
this.state = {
|
|
|
|
|
};
|
2018-09-17 14:03:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
|
const {namespace, name} = this.props.repository;
|
2018-09-17 16:31:19 +02:00
|
|
|
const branchName = this.props.match.params.branch;
|
|
|
|
|
if (branchName) {
|
|
|
|
|
this.props.fetchChangesetsByNamespaceNameAndBranch(namespace, name, branchName);
|
|
|
|
|
} else {
|
|
|
|
|
this.props.fetchChangesetsByNamespaceAndName(namespace, name);
|
|
|
|
|
}
|
2018-09-17 14:03:13 +02:00
|
|
|
this.props.fetchBranchesByNamespaceAndName(namespace, name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
render() {
|
2018-09-17 17:20:17 +02:00
|
|
|
const {changesets, branchNames, loading} = this.props;
|
2018-09-17 16:31:19 +02:00
|
|
|
const branch = this.props.match.params.branch;
|
2018-09-17 17:20:17 +02:00
|
|
|
if (loading || !changesets) {
|
|
|
|
|
return <Loading />
|
2018-09-17 14:03:13 +02:00
|
|
|
}
|
|
|
|
|
if (branchNames) {
|
|
|
|
|
return <div>
|
2018-09-17 16:31:19 +02:00
|
|
|
<DropDown options={branchNames} preselectedOption={branch} optionSelected={branch => this.branchChanged(branch)}/>
|
2018-09-17 14:03:13 +02:00
|
|
|
<ChangesetTable changesets={changesets}/>
|
|
|
|
|
</div>;
|
|
|
|
|
} else {
|
|
|
|
|
return <ChangesetTable changesets={changesets}/>
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
branchChanged = (branchName: string) => {
|
2018-09-17 16:31:19 +02:00
|
|
|
const { history, repository } = this.props;
|
|
|
|
|
history.push(`/repo/${repository.namespace}/${repository.name}/history/${branchName}`);
|
2018-09-17 14:03:13 +02:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const mapStateToProps = (state, ownProps: Props) => {
|
|
|
|
|
const {namespace, name} = ownProps.repository;
|
|
|
|
|
return {
|
2018-09-17 17:20:17 +02:00
|
|
|
loading: isFetchChangesetsPending(namespace, name, state),
|
|
|
|
|
changesets: getChangesets(state, namespace, name, ownProps.match.params.branch),
|
2018-09-17 14:03:13 +02:00
|
|
|
branchNames: getBranchNames(namespace, name, state)
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const mapDispatchToProps = dispatch => {
|
|
|
|
|
return {
|
|
|
|
|
fetchChangesetsByNamespaceAndName: (namespace: string, name: string) => {
|
|
|
|
|
dispatch(fetchChangesetsByNamespaceAndName(namespace, name));
|
|
|
|
|
},
|
|
|
|
|
fetchChangesetsByNamespaceNameAndBranch: (namespace: string, name: string, branch: string) => {
|
|
|
|
|
dispatch(fetchChangesetsByNamespaceNameAndBranch(namespace, name, branch));
|
|
|
|
|
},
|
|
|
|
|
fetchBranchesByNamespaceAndName: (namespace: string, name: string) => {
|
|
|
|
|
dispatch(fetchBranchesByNamespaceAndName(namespace, name));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2018-09-17 16:31:19 +02:00
|
|
|
export default withRouter(connect(
|
2018-09-17 14:03:13 +02:00
|
|
|
mapStateToProps,
|
|
|
|
|
mapDispatchToProps
|
2018-09-17 16:31:19 +02:00
|
|
|
)(Changesets));
|