Skip to content

Commit c6acfa8

Browse files
committed
fix(editor): fixes "scheduleexception" misspelling and create stop bug
fixes #79, fixes #78
1 parent 0397bfc commit c6acfa8

File tree

3 files changed

+81
-58
lines changed

3 files changed

+81
-58
lines changed

lib/editor/components/EntityList.js

Lines changed: 65 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {Table, Column} from 'react-virtualized/dist/commonjs/Table'
66
import {AutoSizer} from 'react-virtualized/dist/commonjs/AutoSizer'
77

88
import {getConfigProperty} from '../../common/util/config'
9-
import {entityIsNew} from '../util/objects'
9+
import {componentToText, entityIsNew} from '../util/objects'
1010
import EntityListButtons from './EntityListButtons'
1111
import EntityListSecondaryActions from './EntityListSecondaryActions'
1212

@@ -31,8 +31,9 @@ export default class EntityList extends Component {
3131

3232
componentWillReceiveProps (nextProps) {
3333
let fromIndex, toIndex
34-
// set state indexes to undefined when active table (component) changes
3534
if (nextProps.activeComponent !== this.props.activeComponent) {
35+
// Set the state's from and to indexes to undefined when the active table
36+
// (i.e., component) changes.
3637
this.setState({fromIndex, toIndex})
3738
}
3839
}
@@ -49,15 +50,15 @@ export default class EntityList extends Component {
4950
typeof toIndex !== 'undefined' &&
5051
index >= fromIndex &&
5152
index <= toIndex
52-
if (this._getRow({index}) && (this._getRow({index}).isActive || isSelected)) {
53+
const row = this._getRow({index})
54+
if (row && (row.isActive || isSelected)) {
55+
// Set active color for selected rows
5356
rowStyle.backgroundColor = activeColor
5457
}
5558
return rowStyle
5659
}
5760

58-
updateIndexes = (fromIndex, toIndex) => {
59-
this.setState({fromIndex, toIndex})
60-
}
61+
updateIndexes = (fromIndex, toIndex) => this.setState({fromIndex, toIndex})
6162

6263
_getRow = ({index}) => this.props.list.get(index)
6364

@@ -87,10 +88,12 @@ export default class EntityList extends Component {
8788
}
8889
this.setState({fromIndex, toIndex})
8990
}
91+
9092
// TODO: add hover to row rendering
9193
// _rowRenderer (props) {
9294
//
9395
// }
96+
9497
render () {
9598
const {
9699
tableView,
@@ -102,7 +105,6 @@ export default class EntityList extends Component {
102105
sort,
103106
list
104107
} = this.props
105-
// console.debug(list, 'active', activeEntity)
106108
const createDisabled = list.findIndex(entityIsNew) !== -1
107109
const sidePadding = '5px'
108110
const panelWidth = !tableView ? `${width}px` : '100%'
@@ -128,52 +130,60 @@ export default class EntityList extends Component {
128130
activeIndex = list.findIndex(e => e.id === activeEntity.id)
129131
}
130132
const entityList = list.size
131-
? <AutoSizer disableWidth>
132-
{({ height }) => (
133-
<Table
134-
width={width - 5}
135-
height={height - HEADER_HEIGHT - 45} // some magical number that seems to work
136-
key={`${feedSource.id}-${activeComponent}-table`}
137-
disableHeader
138-
headerHeight={20}
139-
rowHeight={25}
140-
style={{outline: 'none'}}
141-
scrollToIndex={activeIndex}
142-
sortBy={sort.key}
143-
sortDirection={sort.direction}
144-
rowClassName='noselect'
145-
rowStyle={this._getRowStyle}
146-
rowCount={list.size}
147-
onRowClick={this._onRowClick}
148-
rowGetter={this._getRow}>
149-
<Column
150-
label='Name'
151-
dataKey='name'
152-
className='small entity-list-row'
133+
? <AutoSizer disableWidth>
134+
{({ height }) => (
135+
<Table
136+
width={width - 5}
137+
// some magical number for the height that seems to work
138+
height={height - HEADER_HEIGHT - 45}
139+
key={`${feedSource.id}-${activeComponent}-table`}
140+
disableHeader
141+
headerHeight={20}
142+
rowHeight={25}
153143
style={{outline: 'none'}}
154-
width={width - 5} />
155-
{/* Add hidden columns to allow for sorting of list */}
156-
{list.size && Object.keys(list.get(0)).map(key => {
157-
return (
158-
<Column
159-
key={key}
160-
label={key}
161-
dataKey={key}
162-
style={{display: 'none'}}
163-
width={0} />
164-
)
165-
})}
166-
</Table>
167-
)}
168-
</AutoSizer>
169-
: <div style={{marginTop: '20px'}} className='text-center'>
170-
<Button
171-
bsSize='small'
172-
disabled={createDisabled}
173-
onClick={this._onClickNew}>
174-
<Icon type='plus' /> Create first {activeComponent === 'scheduleexception' ? 'exception' : activeComponent}
175-
</Button>
176-
</div>
144+
scrollToIndex={activeIndex}
145+
sortBy={sort.key}
146+
sortDirection={sort.direction}
147+
rowClassName='noselect'
148+
rowStyle={this._getRowStyle}
149+
rowCount={list.size}
150+
onRowClick={this._onRowClick}
151+
rowGetter={this._getRow}>
152+
<Column
153+
label='Name'
154+
dataKey='name'
155+
className='small entity-list-row'
156+
style={{outline: 'none'}}
157+
width={width - 5} />
158+
{/* Add hidden columns to allow for sorting of list */}
159+
{list.size && Object.keys(list.get(0)).map(key => {
160+
return (
161+
<Column
162+
key={key}
163+
label={key}
164+
dataKey={key}
165+
style={{display: 'none'}}
166+
width={0} />
167+
)
168+
})}
169+
</Table>
170+
)}
171+
</AutoSizer>
172+
: activeComponent === 'stop'
173+
? <div
174+
style={{marginTop: '10px', marginRight: '5px', marginLeft: '5px'}}
175+
className='lead text-center'>
176+
<small>Right-click a location on map to create a new stop</small>
177+
</div>
178+
: <div style={{marginTop: '20px'}} className='text-center'>
179+
<Button
180+
bsSize='small'
181+
disabled={createDisabled}
182+
onClick={this._onClickNew}>
183+
<Icon type='plus' />{' '}
184+
Create first {componentToText(activeComponent)}
185+
</Button>
186+
</div>
177187
return (
178188
<div style={panelStyle}>
179189
<div style={headerStyle}>
@@ -207,7 +217,9 @@ export default class EntityList extends Component {
207217
<EntityListSecondaryActions {...this.props} />
208218
{!tableView
209219
? entityList
210-
: null // GtfsTable fully removed from repo, last available at fe29528569f5f64c23a49d2af0bd224f3d63d010
220+
// GtfsTable fully removed from repo, last available at commit
221+
// fe29528569f5f64c23a49d2af0bd224f3d63d010
222+
: null
211223
}
212224
</div>
213225
)

lib/editor/components/EntityListButtons.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import Icon from '@conveyal/woonerf/components/icon'
22
import React, {Component, PropTypes} from 'react'
33
import { ButtonGroup, Tooltip, OverlayTrigger, Button } from 'react-bootstrap'
44

5-
import {entityIsNew} from '../util/objects'
5+
import {componentToText, entityIsNew} from '../util/objects'
66

77
export default class EntityListButtons extends Component {
88
static propTypes = {
@@ -42,11 +42,12 @@ export default class EntityListButtons extends Component {
4242
updateIndexes
4343
} = this.props
4444
let fromIndex, toIndex
45+
const type = componentToText(activeComponent)
4546
if (activeEntity) {
4647
// Show modal and delete on confirmation
4748
showConfirmModal({
48-
title: `Delete ${activeComponent}?`,
49-
body: `Are you sure you want to delete this ${activeComponent}?`,
49+
title: `Delete ${type}?`,
50+
body: `Are you sure you want to delete this ${type}?`,
5051
onConfirm: () => {
5152
deleteEntity(feedSource.id, activeComponent, activeEntity.id)
5253
updateIndexes(fromIndex, toIndex)
@@ -55,8 +56,9 @@ export default class EntityListButtons extends Component {
5556
})
5657
} else {
5758
showConfirmModal({
58-
title: `Delete ${+toIndex - +fromIndex} ${activeComponent}s?`,
59-
body: `Are you sure you want to delete these ${toIndex - fromIndex} ${activeComponent}s?`,
59+
// FIXME: fix plural component text
60+
title: `Delete ${+toIndex - +fromIndex} ${type}s?`,
61+
body: `Are you sure you want to delete these ${toIndex - fromIndex} ${type}s?`,
6062
onConfirm: () => {
6163
for (var i = 0; i < list.length; i++) {
6264
if (list[i].isSelected) {

lib/editor/util/objects.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@ import snakeCaseKeys from 'snakecase-keys'
77

88
import type {Entity} from '../../types'
99

10+
export function componentToText (component: string): string {
11+
switch (component) {
12+
case 'scheduleexception':
13+
return 'exception'
14+
default:
15+
return component
16+
}
17+
}
18+
1019
export function entityIsNew (entity: Entity): boolean {
1120
return entity.id === ENTITY.NEW_ID || typeof entity.id === 'undefined'
1221
}

0 commit comments

Comments
 (0)