mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-06 21:45:43 +01:00
47 lines
1.1 KiB
JavaScript
47 lines
1.1 KiB
JavaScript
|
|
// @flow
|
||
|
|
|
||
|
|
import React from "react";
|
||
|
|
import type { Branch } from "@scm-manager/ui-types";
|
||
|
|
import DropDown from "../components/DropDown";
|
||
|
|
|
||
|
|
type Props = {
|
||
|
|
branches: Branch[], // TODO: Use generics?
|
||
|
|
selected?: Branch => void
|
||
|
|
};
|
||
|
|
|
||
|
|
type State = { selectedBranch?: Branch };
|
||
|
|
class BranchSelector extends React.Component<Props, State> {
|
||
|
|
constructor(props: Props) {
|
||
|
|
super(props);
|
||
|
|
this.state = {};
|
||
|
|
}
|
||
|
|
render() {
|
||
|
|
const { branches } = this.props;
|
||
|
|
if (branches) {
|
||
|
|
return (
|
||
|
|
<>
|
||
|
|
<DropDown
|
||
|
|
options={branches.map(b => b.name)}
|
||
|
|
optionSelected={this.branchSelected}
|
||
|
|
preselectedOption={
|
||
|
|
this.state.selectedBranch ? this.state.selectedBranch.name : ""
|
||
|
|
}
|
||
|
|
/>
|
||
|
|
</>
|
||
|
|
);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
branchSelected = (branchName: string) => {
|
||
|
|
const { branches, selected } = this.props;
|
||
|
|
const branch = branches.find(b => b.name === branchName);
|
||
|
|
|
||
|
|
if (branch) {
|
||
|
|
selected(branch);
|
||
|
|
this.setState({ selectedBranch: branch });
|
||
|
|
}
|
||
|
|
};
|
||
|
|
}
|
||
|
|
|
||
|
|
export default BranchSelector;
|