Files
SCM-Manager/scm-ui/src/changesets/containers/Changesets.js

93 lines
2.9 KiB
JavaScript
Raw Normal View History

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";
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";
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);
this.state = {
};
2018-09-17 14:03:13 +02:00
}
componentDidMount() {
const {namespace, name} = this.props.repository;
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;
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>
<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) => {
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));
}
}
};
export default withRouter(connect(
2018-09-17 14:03:13 +02:00
mapStateToProps,
mapDispatchToProps
)(Changesets));