1
1
import Icon from '@conveyal/woonerf/components/icon'
2
2
import React , { Component , PropTypes } from 'react'
3
- import { Button , FormGroup , ControlLabel , ButtonGroup , DropdownButton , MenuItem } from 'react-bootstrap'
3
+ import { Button , FormGroup , ControlLabel , ButtonGroup , DropdownButton , MenuItem , Tooltip } from 'react-bootstrap'
4
4
5
5
import OptionButton from '../../../common/components/OptionButton'
6
6
import { ENTITY } from '../../constants'
7
7
8
+ // Outbound is zero, inbound is one.
8
9
const DIRECTIONS = [ 0 , 1 ]
9
10
10
11
export default class EditSchedulePanel extends Component {
@@ -18,45 +19,70 @@ export default class EditSchedulePanel extends Component {
18
19
19
20
_editTimetables = ( ) => {
20
21
const { setActiveEntity, feedSource, activeEntity, activePattern} = this . props
21
- setActiveEntity ( feedSource . id , 'route' , activeEntity , 'trippattern' , activePattern , 'timetable' )
22
+ setActiveEntity (
23
+ feedSource . id ,
24
+ 'route' ,
25
+ activeEntity ,
26
+ 'trippattern' ,
27
+ activePattern ,
28
+ 'timetable'
29
+ )
22
30
}
23
31
24
32
_isDirectionOutbound = dir => dir === DIRECTIONS [ 0 ]
25
33
26
34
_onChangeDirection = directionId => {
27
- this . props . updateActiveEntity ( this . props . activePattern , 'trippattern' , { directionId} )
28
- this . props . saveActiveEntity ( 'trippattern' )
35
+ const { activePattern, saveActiveEntity, updateActiveEntity} = this . props
36
+ updateActiveEntity ( activePattern , 'trippattern' , { directionId} )
37
+ saveActiveEntity ( 'trippattern' )
29
38
}
30
39
31
40
_onChangeUseFrequency = key => {
32
- const { activePattern, deleteAllTripsForPattern, feedSource, saveActiveEntity, showConfirmModal, updateActiveEntity} = this . props
41
+ const {
42
+ activePattern,
43
+ deleteAllTripsForPattern,
44
+ feedSource,
45
+ saveActiveEntity,
46
+ showConfirmModal,
47
+ updateActiveEntity
48
+ } = this . props
49
+ const { name, patternId} = activePattern
33
50
const useFrequency = key !== 'timetables' ? 1 : 0
34
51
const unselectedOption = key === 'timetables' ? 'frequencies' : 'timetables'
35
52
showConfirmModal ( {
36
- title : `Use ${ key } for ${ activePattern . name } ?` ,
37
- body : `Are you sure you want to use ${ key } for this trip pattern? Any trips created using ${ unselectedOption } will be lost.` ,
53
+ title : `Use ${ key } for ${ name } ?` ,
54
+ body : `Are you sure you want to use ${ key } for this trip pattern?
55
+ Any trips created using ${ unselectedOption } will be lost.` ,
38
56
onConfirm : ( ) => {
39
57
// Update and save useFrequency field
40
58
updateActiveEntity ( activePattern , 'trippattern' , { useFrequency} )
41
59
saveActiveEntity ( 'trippattern' )
42
60
// Then, delete all trips for the pattern.
43
- . then ( ( ) => deleteAllTripsForPattern ( feedSource . id , activePattern . patternId ) )
61
+ . then ( ( ) => deleteAllTripsForPattern ( feedSource . id , patternId ) )
44
62
}
45
63
} )
46
64
}
47
65
48
66
render ( ) {
49
67
const { activePattern, activePatternId} = this . props
68
+ if ( ! activePattern ) return null
69
+ const {
70
+ directionId,
71
+ name,
72
+ patternStops,
73
+ tripCount,
74
+ useFrequency
75
+ } = activePattern
50
76
const timetableOptions = [
51
77
< span > < Icon type = 'table' /> Use timetables</ span > ,
52
78
< span > < Icon type = 'clock-o' /> Use frequencies</ span >
53
79
]
54
80
const editSchedulesDisabled = activePatternId === ENTITY . NEW_ID ||
55
- ( activePattern && activePattern . patternStops && activePattern . patternStops . length === 0 )
81
+ patternStops . length === 0
56
82
return (
57
83
< div >
58
84
< h4 className = 'line' >
59
- Schedules { `(${ activePattern . tripCount } trip${ activePattern . tripCount !== 1 ? 's' : '' } )` }
85
+ Schedules { `(${ tripCount } trip${ tripCount !== 1 ? 's' : '' } )` }
60
86
</ h4 >
61
87
< FormGroup style = { { marginTop : '5px' } } >
62
88
< ButtonGroup className = 'pull-right' >
@@ -65,37 +91,51 @@ export default class EditSchedulePanel extends Component {
65
91
pullRight
66
92
style = { { width : '170px' } }
67
93
bsSize = 'small'
68
- title = { activePattern . useFrequency ? timetableOptions [ 1 ] : timetableOptions [ 0 ] }
94
+ title = { useFrequency ? timetableOptions [ 1 ] : timetableOptions [ 0 ] }
69
95
id = 'frequency-dropdown' >
70
96
< MenuItem
71
- eventKey = { activePattern . useFrequency ? 'timetables' : 'frequencies' } >
72
- { activePattern . useFrequency ? timetableOptions [ 0 ] : timetableOptions [ 1 ] }
97
+ eventKey = { useFrequency ? 'timetables' : 'frequencies' } >
98
+ { useFrequency ? timetableOptions [ 0 ] : timetableOptions [ 1 ] }
73
99
</ MenuItem >
74
100
</ DropdownButton >
75
101
</ ButtonGroup >
76
- < ControlLabel style = { { marginTop : '3px' } } > < small > Type</ small > </ ControlLabel >
102
+ < ControlLabel
103
+ style = { { marginTop : '3px' } } >
104
+ < small > Type</ small >
105
+ </ ControlLabel >
77
106
</ FormGroup >
78
107
< FormGroup style = { { marginTop : '5px' } } >
79
108
< ButtonGroup className = 'pull-right' >
80
- { DIRECTIONS . map ( dir => (
81
- < OptionButton
82
- key = { dir }
83
- active = { activePattern . directionId === dir }
84
- value = { dir }
85
- bsSize = 'small'
86
- style = { { width : '85px' } }
87
- name = { dir }
88
- title = { this . _isDirectionOutbound ( ) ? 'Outbound (0)' : 'Inbound (1)' }
89
- onClick = { this . _onChangeDirection } >
90
- < Icon type = { this . _isDirectionOutbound ( ) ? 'sign-out' : 'sign-in' } />
91
- </ OptionButton >
92
- ) ) }
109
+ { DIRECTIONS . map ( dir => {
110
+ const isOutbound = this . _isDirectionOutbound ( dir )
111
+ return (
112
+ < OptionButton
113
+ key = { dir }
114
+ active = { directionId === dir }
115
+ value = { dir }
116
+ bsSize = 'small'
117
+ style = { { width : '85px' } }
118
+ name = { dir }
119
+ tooltip = {
120
+ < Tooltip
121
+ id = { `tooltip-dir-${ dir } ` } >
122
+ { isOutbound ? 'Outbound (0)' : 'Inbound (1)' }
123
+ </ Tooltip >
124
+ }
125
+ onClick = { this . _onChangeDirection } >
126
+ < Icon type = { isOutbound ? 'sign-out' : 'sign-in' } />
127
+ </ OptionButton >
128
+ )
129
+ } ) }
93
130
</ ButtonGroup >
94
131
< ControlLabel > < small > Direction</ small > </ ControlLabel >
95
132
</ FormGroup >
96
133
< Button
97
134
disabled = { editSchedulesDisabled }
98
- title = { editSchedulesDisabled ? `Must add stops to pattern before editing schedules for ${ activePattern . name } ` : `Edit schedules for ${ activePattern . name } ` }
135
+ // FIXME: Should this be a tooltip for a better user experience?
136
+ title = { editSchedulesDisabled
137
+ ? `Must add stops to pattern before editing schedules for ${ name } `
138
+ : `Edit schedules for ${ name } ` }
99
139
block
100
140
bsSize = 'small'
101
141
onClick = { this . _editTimetables } >
0 commit comments