Skip to content

Commit de0af3a

Browse files
committed
feat(EntityList): add Edit Schedules button on calendar list view
1 parent 9f0de78 commit de0af3a

File tree

3 files changed

+110
-56
lines changed

3 files changed

+110
-56
lines changed

lib/editor/actions/active.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@ export function settingActiveGtfsEntity (feedSourceId, component, entityId, subC
4040
}
4141
}
4242

43+
export function enterTimetableEditor () {
44+
return function (dispatch, getState) {
45+
dispatch(setActiveGtfsEntity(getState().editor.data.active.feedSourceId, 'route', getState().editor.data.tables.route[0].id, 'trippattern', 'new', 'timetable'))
46+
}
47+
}
48+
4349
export function setActiveGtfsEntity (feedSourceId, component, entityId, subComponent, subEntityId, subSubComponent, subSubEntityId) {
4450
return function (dispatch, getState) {
4551
// TODO: figure out a good way to handle route changes without confirm window

lib/editor/components/EntityList.js

Lines changed: 36 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import React, {Component, PropTypes} from 'react'
2-
import { Button, Nav, NavItem } from 'react-bootstrap'
2+
import { Button } from 'react-bootstrap'
33
import {Icon} from '@conveyal/woonerf'
44
import { Table, Column } from 'react-virtualized'
55
import { shallowEqual } from 'react-pure-render'
66

7-
import VirtualizedEntitySelect from './VirtualizedEntitySelect'
87
import EntityListButtons from './EntityListButtons'
8+
import EntityListSecondaryActions from './EntityListSecondaryActions'
99
import { getEntityName } from '../util/gtfs'
1010

1111
export default class EntityList extends Component {
@@ -126,8 +126,19 @@ export default class EntityList extends Component {
126126
//
127127
// }
128128
render () {
129+
const {
130+
tableView,
131+
width,
132+
activeEntity,
133+
activeComponent,
134+
hasRoutes,
135+
feedSource,
136+
entities,
137+
newGtfsEntity,
138+
enterTimetableEditor
139+
} = this.props
129140
const sidePadding = '5px'
130-
const panelWidth = !this.props.tableView ? `${this.props.width}px` : '100%'
141+
const panelWidth = !tableView ? `${width}px` : '100%'
131142
const panelStyle = {
132143
width: panelWidth,
133144
height: '100%',
@@ -138,17 +149,15 @@ export default class EntityList extends Component {
138149
paddingRight: '0px',
139150
paddingLeft: sidePadding
140151
}
141-
const entArray = this.props.entities
142-
const activeEntity = this.props.activeEntity
143152
let activeIndex
144-
const list = entArray && entArray.length
145-
? entArray.map((entity, index) => {
153+
const list = entities && entities.length
154+
? entities.map((entity, index) => {
146155
if (activeEntity && entity.id === activeEntity.id) {
147156
activeIndex = index
148157
}
149158
const isActive = activeEntity && entity.id === activeEntity.id
150159
const isSelected = typeof this.state.fromIndex !== 'undefined' && typeof this.state.toIndex !== 'undefined' && index >= this.state.fromIndex && index <= this.state.toIndex
151-
const name = getEntityName(this.props.activeComponent, entity) || '[Unnamed]'
160+
const name = getEntityName(activeComponent, entity) || '[Unnamed]'
152161
return {name, id: entity.id, isActive, isSelected}
153162
}
154163
)
@@ -163,9 +172,9 @@ export default class EntityList extends Component {
163172
style={{outline: 'none'}}
164173
>
165174
<Table
166-
width={this.props.width - 5}
175+
width={width - 5}
167176
height={560}
168-
key={`${this.props.feedSource.id}-${this.props.activeComponent}-table`}
177+
key={`${feedSource.id}-${activeComponent}-table`}
169178
disableHeader
170179
headerHeight={20}
171180
rowHeight={25}
@@ -186,19 +195,19 @@ export default class EntityList extends Component {
186195
dataKey='name'
187196
className='small entity-list-row'
188197
style={{outline: 'none'}}
189-
width={this.props.width - 5}
198+
width={width - 5}
190199
/>
191200
</Table>
192201
</div>
193202
: <div style={{marginTop: '20px'}} className='text-center'>
194203
<Button
195204
bsSize='small'
196-
disabled={this.props.entities && this.props.entities.findIndex(e => e.id === 'new') !== -1}
205+
disabled={entities && entities.findIndex(e => e.id === 'new') !== -1}
197206
onClick={() => {
198-
this.props.newGtfsEntity(this.props.feedSource.id, this.props.activeComponent)
207+
newGtfsEntity(feedSource.id, activeComponent)
199208
}}
200209
>
201-
<Icon type='plus' /> Create first {this.props.activeComponent === 'scheduleexception' ? 'exception' : this.props.activeComponent}
210+
<Icon type='plus' /> Create first {activeComponent === 'scheduleexception' ? 'exception' : activeComponent}
202211
</Button>
203212
</div>
204213
return (
@@ -213,50 +222,21 @@ export default class EntityList extends Component {
213222
updateIndexes={this.updateIndexes}
214223
{...this.props}
215224
/>
225+
{activeComponent === 'calendar' || activeComponent === 'scheduleexception'
226+
? <Button
227+
style={{marginTop: '10px'}}
228+
block
229+
disabled={!hasRoutes}
230+
onClick={() => enterTimetableEditor()}
231+
>
232+
<Icon type='pencil' /> Edit schedules
233+
</Button>
234+
: null
235+
}
216236
{/* Table view button */}
217237
</div>
218-
{this.props.activeComponent === 'calendar' || this.props.activeComponent === 'scheduleexception'
219-
? <Nav style={{marginBottom: '5px'}} bsStyle='pills' justified activeKey={this.props.activeComponent} onSelect={this.handleSelect}>
220-
<NavItem
221-
eventKey={'calendar'}
222-
onClick={() => {
223-
if (this.props.activeComponent !== 'calendar') {
224-
// browserHistory.push(`/feed/${this.props.feedSource.id}/edit/calendar`)
225-
this.props.setActiveEntity(this.props.feedSource.id, 'calendar')
226-
}
227-
}}
228-
>
229-
Calendars
230-
</NavItem>
231-
<NavItem
232-
eventKey={'scheduleexception'}
233-
onClick={() => {
234-
if (this.props.activeComponent !== 'scheduleexception') {
235-
// browserHistory.push(`/feed/${this.props.feedSource.id}/edit/scheduleexception`)
236-
this.props.setActiveEntity(this.props.feedSource.id, 'scheduleexception')
237-
}
238-
}}
239-
>
240-
Exceptions
241-
</NavItem>
242-
</Nav>
243-
: this.props.activeComponent === 'stop' || this.props.activeComponent === 'route'
244-
? <VirtualizedEntitySelect
245-
value={this.props.activeEntity && this.props.activeEntity.id}
246-
optionRenderer={this._optionRenderer}
247-
component={this.props.activeComponent}
248-
entities={entArray}
249-
onChange={(value) => {
250-
if (!value) {
251-
this.props.setActiveEntity(this.props.feedSource.id, this.props.activeComponent)
252-
} else {
253-
this.props.setActiveEntity(this.props.feedSource.id, this.props.activeComponent, value.entity)
254-
}
255-
}}
256-
/>
257-
: null
258-
}
259-
{!this.props.tableView
238+
<EntityListSecondaryActions {...this.props} />
239+
{!tableView
260240
? entityList
261241
: null // GtfsTable fully removed from repo, last available at fe29528569f5f64c23a49d2af0bd224f3d63d010
262242
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import React, {PropTypes, Component} from 'react'
2+
import { Nav, NavItem } from 'react-bootstrap'
3+
4+
import VirtualizedEntitySelect from './VirtualizedEntitySelect'
5+
6+
export default class EntityListSecondaryActions extends Component {
7+
static propTypes = {
8+
activeComponent: PropTypes.string
9+
}
10+
render () {
11+
const {
12+
activeComponent,
13+
feedSource,
14+
setActiveEntity,
15+
activeEntity,
16+
entities
17+
} = this.props
18+
switch (activeComponent) {
19+
case 'calendar':
20+
case 'scheduleexception':
21+
return (
22+
<Nav style={{marginBottom: '5px'}} bsStyle='pills' justified activeKey={activeComponent} onSelect={this.handleSelect}>
23+
<NavItem
24+
eventKey={'calendar'}
25+
onClick={() => {
26+
if (activeComponent !== 'calendar') {
27+
// browserHistory.push(`/feed/${feedSource.id}/edit/calendar`)
28+
setActiveEntity(feedSource.id, 'calendar')
29+
}
30+
}}
31+
>
32+
Calendars
33+
</NavItem>
34+
<NavItem
35+
eventKey={'scheduleexception'}
36+
onClick={() => {
37+
if (activeComponent !== 'scheduleexception') {
38+
// browserHistory.push(`/feed/${feedSource.id}/edit/scheduleexception`)
39+
setActiveEntity(feedSource.id, 'scheduleexception')
40+
}
41+
}}
42+
>
43+
Exceptions
44+
</NavItem>
45+
</Nav>
46+
)
47+
case 'route':
48+
case 'stop':
49+
return (
50+
<VirtualizedEntitySelect
51+
value={activeEntity && activeEntity.id}
52+
optionRenderer={this._optionRenderer}
53+
component={activeComponent}
54+
entities={entities}
55+
onChange={(value) => {
56+
if (!value) {
57+
setActiveEntity(feedSource.id, activeComponent)
58+
} else {
59+
setActiveEntity(feedSource.id, activeComponent, value.entity)
60+
}
61+
}}
62+
/>
63+
)
64+
default:
65+
return null
66+
}
67+
}
68+
}

0 commit comments

Comments
 (0)