Determine branch for which to show changesets via URL

This commit is contained in:
Philipp Czora
2018-09-17 16:31:19 +02:00
parent 2be854e3d2
commit c5da25a1b4
3 changed files with 25 additions and 22 deletions

View File

@@ -4,15 +4,17 @@ import React from "react";
type Props = {
options: string[],
optionSelected: string => void
optionSelected: string => void,
preselectedOption: string
}
class DropDown extends React.Component<Props> {
render() {
const {options} = this.props;
return <select onChange={this.change}>
const {options, preselectedOption} = this.props;
return <select value={preselectedOption} onChange={this.change}>
{options.map(option => {
return <option key={option} value={option}>{option}</option>
return <option key={option}
value={option}>{option}</option>
})}
</select>
}

View File

@@ -5,11 +5,12 @@ import {
fetchChangesetsByNamespaceAndName, fetchChangesetsByNamespaceNameAndBranch,
getChangesets,
} from "../modules/changesets";
import {translate} from "react-i18next";
import type { History } from "history";
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";
type Props = {
repository: Repository,
@@ -18,30 +19,34 @@ type Props = {
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 = {};
this.state = {
};
}
componentDidMount() {
const {namespace, name} = this.props.repository;
this.props.fetchChangesetsByNamespaceNameAndBranch(namespace, name, this.props.branchName);
const branchName = this.props.match.params.branch;
if (branchName) {
this.props.fetchChangesetsByNamespaceNameAndBranch(namespace, name, branchName);
} else {
this.props.fetchChangesetsByNamespaceAndName(namespace, name);
}
this.props.fetchBranchesByNamespaceAndName(namespace, name);
}
render() {
const {changesets, branchNames} = this.props;
const branch = this.props.match.params.branch;
if (changesets === null) {
return null
}
if (branchNames) {
return <div>
<DropDown options={branchNames} optionSelected={this.branchChanged}/>
<DropDown options={branchNames} preselectedOption={branch} optionSelected={branch => this.branchChanged(branch)}/>
<ChangesetTable changesets={changesets}/>
</div>;
} else {
@@ -51,16 +56,16 @@ class Changesets extends React.Component<State, Props> {
}
branchChanged = (branchName: string) => {
this.props.history.push(branchName)
const { history, repository } = this.props;
history.push(`/repo/${repository.namespace}/${repository.name}/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),
changesets: getChangesets(namespace, name, ownProps.match.params.branch, state),
branchNames: getBranchNames(namespace, name, state)
}
};
@@ -79,7 +84,7 @@ const mapDispatchToProps = dispatch => {
}
};
export default connect(
export default withRouter(connect(
mapStateToProps,
mapDispatchToProps
)(Changesets);
)(Changesets));

View File

@@ -103,13 +103,9 @@ class RepositoryRoot extends React.Component<Props> {
component={() => <Edit repository={repository}/>}
/>
<Route
path={`${url}/history`}
component={() => <Changesets repository={repository} branchName={"master"} history={this.props.history}/>}
path={`${url}/history/:branch`}
component={() => <Changesets repository={repository}/>}
/>
{/*<Route*/}
{/*path={`${url}/history/:branchName`}*/}
{/*component={() => <Changesets repository={repository} branchName={} history={this.props.history}/>}*/}
{/*/>*/}
</div>
<div className="column">
<Navigation>