Restructured Changeset Component

WIP
This commit is contained in:
Philipp Czora
2018-09-17 14:03:13 +02:00
parent 2931877c9f
commit 4cb644f9f8
8 changed files with 167 additions and 89 deletions

View File

@@ -0,0 +1,85 @@
import React from "react"
import {connect} from "react-redux";
import {
fetchChangesetsByNamespaceAndName, fetchChangesetsByNamespaceNameAndBranch,
getChangesets,
} from "../modules/changesets";
import {translate} from "react-i18next";
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";
type Props = {
repository: Repository,
branchName: string,
history: History,
fetchChangesetsByNamespaceNameAndBranch: (namespace: string, name: string, branch: string) => void
}
type State = {
branchName: string
}
class Changesets extends React.Component<State, Props> {
constructor(props) {
super(props);
this.state = {};
}
componentDidMount() {
const {namespace, name} = this.props.repository;
this.props.fetchChangesetsByNamespaceNameAndBranch(namespace, name, this.props.branchName);
this.props.fetchBranchesByNamespaceAndName(namespace, name);
}
render() {
const {changesets, branchNames} = this.props;
if (changesets === null) {
return null
}
if (branchNames) {
return <div>
<DropDown options={branchNames} optionSelected={this.branchChanged}/>
<ChangesetTable changesets={changesets}/>
</div>;
} else {
return <ChangesetTable changesets={changesets}/>
}
}
branchChanged = (branchName: string) => {
this.props.history.push("./history/" + branchName)
};
}
const mapStateToProps = (state, ownProps: Props) => {
console.log("mapStateToProps ownProps: ", ownProps);
const {namespace, name} = ownProps.repository;
return {
changesets: getChangesets(namespace, name, ownProps.branchName, state),
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 connect(
mapStateToProps,
mapDispatchToProps
)(Changesets);