main
js 41 lines 945 Bytes
Raw
1 import getVersionTags from '../tags';
2
3 const React = window.React;
4
5 class VersionPicker extends React.Component {
6 constructor(props, context) {
7 super(props, context);
8 const version = props.version || 'local';
9 const versions = [version];
10 this.state = {versions};
11 }
12
13 componentWillMount() {
14 getVersionTags().then(tags => {
15 let versions = tags.map(tag => tag.name.slice(1));
16 versions = [`local`, ...versions];
17 this.setState({versions});
18 });
19 }
20
21 onChange = event => {
22 this.props.onChange(event.target.value);
23 };
24
25 render() {
26 const {version, id, name} = this.props;
27 const {versions} = this.state;
28
29 return (
30 <select id={id} name={name} value={version} onChange={this.onChange}>
31 {versions.map(version => (
32 <option key={version} value={version}>
33 {version}
34 </option>
35 ))}
36 </select>
37 );
38 }
39 }
40
41 export default VersionPicker;