Skip to content

Commit 461bef7

Browse files
committed
fix(editor): fix pattern direction icons/text
fixes #80
1 parent c6acfa8 commit 461bef7

File tree

2 files changed

+83
-31
lines changed

2 files changed

+83
-31
lines changed

lib/common/components/OptionButton.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, {PropTypes, Component} from 'react'
2-
import {Button} from 'react-bootstrap'
2+
import {Button, OverlayTrigger} from 'react-bootstrap'
33

44
export default class OptionButton extends Component {
55
static propTypes = {
@@ -16,13 +16,25 @@ export default class OptionButton extends Component {
1616
}
1717

1818
render () {
19-
return (
19+
const {children, tooltip} = this.props
20+
const button = (
2021
<Button
2122
{...this.props}
2223
href='#' // required for button width to appear correctly
2324
onClick={this._onClick}>
24-
{this.props.children}
25+
{children}
2526
</Button>
2627
)
28+
if (tooltip) {
29+
return (
30+
<OverlayTrigger
31+
placement='bottom'
32+
overlay={tooltip}>
33+
{button}
34+
</OverlayTrigger>
35+
)
36+
} else {
37+
return button
38+
}
2739
}
2840
}

lib/editor/components/pattern/EditSchedulePanel.js

Lines changed: 68 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import Icon from '@conveyal/woonerf/components/icon'
22
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'
44

55
import OptionButton from '../../../common/components/OptionButton'
66
import {ENTITY} from '../../constants'
77

8+
// Outbound is zero, inbound is one.
89
const DIRECTIONS = [0, 1]
910

1011
export default class EditSchedulePanel extends Component {
@@ -18,45 +19,70 @@ export default class EditSchedulePanel extends Component {
1819

1920
_editTimetables = () => {
2021
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+
)
2230
}
2331

2432
_isDirectionOutbound = dir => dir === DIRECTIONS[0]
2533

2634
_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')
2938
}
3039

3140
_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
3350
const useFrequency = key !== 'timetables' ? 1 : 0
3451
const unselectedOption = key === 'timetables' ? 'frequencies' : 'timetables'
3552
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.`,
3856
onConfirm: () => {
3957
// Update and save useFrequency field
4058
updateActiveEntity(activePattern, 'trippattern', {useFrequency})
4159
saveActiveEntity('trippattern')
4260
// Then, delete all trips for the pattern.
43-
.then(() => deleteAllTripsForPattern(feedSource.id, activePattern.patternId))
61+
.then(() => deleteAllTripsForPattern(feedSource.id, patternId))
4462
}
4563
})
4664
}
4765

4866
render () {
4967
const {activePattern, activePatternId} = this.props
68+
if (!activePattern) return null
69+
const {
70+
directionId,
71+
name,
72+
patternStops,
73+
tripCount,
74+
useFrequency
75+
} = activePattern
5076
const timetableOptions = [
5177
<span><Icon type='table' /> Use timetables</span>,
5278
<span><Icon type='clock-o' /> Use frequencies</span>
5379
]
5480
const editSchedulesDisabled = activePatternId === ENTITY.NEW_ID ||
55-
(activePattern && activePattern.patternStops && activePattern.patternStops.length === 0)
81+
patternStops.length === 0
5682
return (
5783
<div>
5884
<h4 className='line'>
59-
Schedules {`(${activePattern.tripCount} trip${activePattern.tripCount !== 1 ? 's' : ''})`}
85+
Schedules {`(${tripCount} trip${tripCount !== 1 ? 's' : ''})`}
6086
</h4>
6187
<FormGroup style={{marginTop: '5px'}}>
6288
<ButtonGroup className='pull-right'>
@@ -65,37 +91,51 @@ export default class EditSchedulePanel extends Component {
6591
pullRight
6692
style={{width: '170px'}}
6793
bsSize='small'
68-
title={activePattern.useFrequency ? timetableOptions[1] : timetableOptions[0]}
94+
title={useFrequency ? timetableOptions[1] : timetableOptions[0]}
6995
id='frequency-dropdown'>
7096
<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]}
7399
</MenuItem>
74100
</DropdownButton>
75101
</ButtonGroup>
76-
<ControlLabel style={{marginTop: '3px'}}><small>Type</small></ControlLabel>
102+
<ControlLabel
103+
style={{marginTop: '3px'}}>
104+
<small>Type</small>
105+
</ControlLabel>
77106
</FormGroup>
78107
<FormGroup style={{marginTop: '5px'}}>
79108
<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+
})}
93130
</ButtonGroup>
94131
<ControlLabel><small>Direction</small></ControlLabel>
95132
</FormGroup>
96133
<Button
97134
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}`}
99139
block
100140
bsSize='small'
101141
onClick={this._editTimetables}>

0 commit comments

Comments
 (0)