@@ -6,7 +6,7 @@ import {Table, Column} from 'react-virtualized/dist/commonjs/Table'
66import { AutoSizer } from 'react-virtualized/dist/commonjs/AutoSizer'
77
88import { getConfigProperty } from '../../common/util/config'
9- import { entityIsNew } from '../util/objects'
9+ import { componentToText , entityIsNew } from '../util/objects'
1010import EntityListButtons from './EntityListButtons'
1111import 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 )
0 commit comments