Select current revision in selector if it is a branch

This commit is contained in:
René Pfeuffer
2018-10-23 11:24:23 +02:00
parent 0834420e4b
commit fa7626619c
2 changed files with 9 additions and 1 deletions

View File

@@ -17,6 +17,7 @@ const styles = {
type Props = { type Props = {
branches: Branch[], // TODO: Use generics? branches: Branch[], // TODO: Use generics?
selected: (branch?: Branch) => void, selected: (branch?: Branch) => void,
selectedBranch: string,
// context props // context props
classes: Object, classes: Object,
@@ -31,6 +32,12 @@ class BranchSelector extends React.Component<Props, State> {
this.state = {}; this.state = {};
} }
componentDidMount() {
this.props.branches
.filter(branch => branch.name === this.props.selectedBranch)
.forEach(branch => this.setState({ selectedBranch: branch }));
}
render() { render() {
const { branches, classes, t } = this.props; const { branches, classes, t } = this.props;

View File

@@ -79,11 +79,12 @@ class Sources extends React.Component<Props> {
} }
renderBranchSelector = () => { renderBranchSelector = () => {
const { repository, branches } = this.props; const { repository, branches, revision } = this.props;
if (repository._links.branches) { if (repository._links.branches) {
return ( return (
<BranchSelector <BranchSelector
branches={branches} branches={branches}
selectedBranch={revision}
selected={(b: Branch) => { selected={(b: Branch) => {
this.branchSelected(b); this.branchSelected(b);
}} }}