-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathselect-feed-and-routes.js
64 lines (54 loc) · 1.6 KB
/
select-feed-and-routes.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/** Select routes without selecting patterns */
import React, {Component, PropTypes} from 'react'
import Select from 'react-select'
import {Group as FormGroup} from './components/input'
export default class SelectFeedAndRoutes extends Component {
static propTypes = {
feeds: PropTypes.array.isRequired,
onChange: PropTypes.func.isRequired,
selectedFeed: PropTypes.object,
selectedRouteId: PropTypes.string
}
state = {
feeds: [],
routes: []
}
selectFeed = (feed) => {
this.props.onChange({ feed: feed && feed.value, routes: null })
}
selectRoute = (route) => {
this.props.onChange({ feed: this.props.selectedFeed.id, routes: !route || route.value === '' ? null : [ route.value ] })
}
render () {
const {feeds, selectedFeed} = this.props
const value = selectedFeed ? selectedFeed.id : undefined
return (
<div>
<FormGroup>
<Select
name='Feed'
onChange={this.selectFeed}
options={feeds.map((f) => { return { value: f.id, label: f.id } })}
placeholder='Select feed'
value={value}
/>
</FormGroup>
{selectedFeed && this.renderRoutes()}
</div>
)
}
renderRoutes () {
const {selectedFeed, selectedRouteId} = this.props
return (
<FormGroup>
<Select
name='Route'
onChange={this.selectRoute}
options={selectedFeed.routes.map((r) => { return { value: r.route_id, label: r.label } })}
placeholder='Select route'
value={selectedRouteId}
/>
</FormGroup>
)
}
}