Skip to content

Commit 0042661

Browse files
start table select component
1 parent c64a033 commit 0042661

File tree

4 files changed

+177
-11
lines changed

4 files changed

+177
-11
lines changed

gtfs.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -233,12 +233,12 @@
233233
text: Not possible (2)
234234
columnWidth: 12
235235
helpContent: "The wheelchair_boarding field identifies whether wheelchair boardings are possible from the specified stop or station. The field can have the following values:"
236-
- name: "stop_area_id"
237-
required: false
238-
inputType: GTFS_STOP_AREA
239-
bulkEditEnabled: true
240-
columnWidth: 12
241-
helpContent: "The area_id field defines the area that this stop belongs to. This is used to group stops together in a logical way, such as all stops in a particular neighborhood or district. If this stop is not part of an area, leave this field blank."
236+
# - name: "stop_area_id"
237+
# required: false
238+
# inputType: GTFS_STOP_AREA
239+
# bulkEditEnabled: true
240+
# columnWidth: 12
241+
# helpContent: "The area_id field defines the area that this stop belongs to. This is used to group stops together in a logical way, such as all stops in a particular neighborhood or district. If this stop is not part of an area, leave this field blank."
242242

243243
- id: route
244244
name: routes.txt

lib/editor/components/EntityListSecondaryActions.js

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ import React, {Component} from 'react'
44
import { Nav, NavItem } from 'react-bootstrap'
55

66
import * as activeActions from '../actions/active'
7-
import VirtualizedEntitySelect from './VirtualizedEntitySelect'
8-
97
import type {Entity, Feed} from '../../types'
108

9+
import VirtualizedEntitySelect from './VirtualizedEntitySelect'
10+
import VirtualizedTableSelect from './VirtualizedTableSelect'
11+
1112
type Props = {
1213
activeComponent: string,
1314
activeEntity: Entity,
@@ -97,6 +98,13 @@ export default class EntityListSecondaryActions extends Component<Props> {
9798
}
9899
}
99100

101+
_onTableSelect = (option: any) => {
102+
console.log('onTableSelect::::::', option)
103+
if (this.props.activeComponent !== option.value) {
104+
this.props.setActiveEntity(this.props.feedSource.id, option.value)
105+
}
106+
}
107+
100108
render () {
101109
const {
102110
activeComponent,
@@ -135,6 +143,27 @@ export default class EntityListSecondaryActions extends Component<Props> {
135143
entities={entities}
136144
onChange={this._onChangeEntity} />
137145
)
146+
case 'fareproduct':
147+
case 'faremedia':
148+
case 'faretransferrule':
149+
case 'farelegrule':
150+
case 'area':
151+
console.log('entities::::::', entities)
152+
const faresv2Tables = [
153+
'faremedia',
154+
'fareproduct',
155+
'faretransferrule',
156+
'farelegrule',
157+
'area'
158+
]
159+
return (
160+
<VirtualizedTableSelect
161+
value={activeEntity && activeEntity.id}
162+
optionRenderer={this._optionRenderer}
163+
component={activeComponent}
164+
entities={faresv2Tables}
165+
onChange={this._onTableSelect} />
166+
)
138167
default:
139168
return null
140169
}
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
// @flow
2+
3+
import React, {Component} from 'react'
4+
import VirtualizedSelect from 'react-virtualized-select'
5+
6+
// FARE-TODO: clean up this file!!!!
7+
// import {getEntityName} from '../util/gtfs'
8+
9+
import type {Entity, Style} from '../../types'
10+
11+
export type EntityOption = {
12+
entity: Entity,
13+
label: string,
14+
value: string
15+
}
16+
17+
type Props = {
18+
clearable?: boolean,
19+
component: string,
20+
entities: Array<any>,
21+
// entityKey: string,
22+
onChange: any => void,
23+
optionRenderer?: Function,
24+
style?: Style,
25+
value?: any
26+
}
27+
28+
type State = {
29+
options: Array<any>,
30+
value: any
31+
}
32+
33+
export default class VirtualizedEntitySelect extends Component<Props, State> {
34+
static defaultProps = {
35+
clearable: true
36+
// entityKey: 'id'
37+
}
38+
39+
componentWillMount () {
40+
this.setState({
41+
value: this.props.value,
42+
options: []
43+
})
44+
}
45+
46+
/**
47+
* This component can hold a large number of options, so its
48+
* shouldComponentUpdate method checks only for changes in state (i.e., the
49+
* selected value) and a change in length of its entities.
50+
*/
51+
// shouldComponentUpdate (nextProps, nextState) {
52+
// if (nextState.value !== this.state.value || this.state.options.length !== nextState.options.length) {
53+
// return true
54+
// }
55+
// const nextEntities = nextProps.entities || []
56+
// const currentEntities = this.props.entities || []
57+
// if (nextEntities.length !== currentEntities.length) {
58+
// console.log('entities length changed', nextEntities, currentEntities)
59+
// return true
60+
// }
61+
// return false
62+
// }
63+
64+
componentWillReceiveProps (nextProps: Props) {
65+
if (this.state.value !== nextProps.value && typeof this.props.value !== 'undefined') {
66+
this.setState({value: nextProps.value})
67+
}
68+
}
69+
70+
_onChange = (value: any) => {
71+
const {onChange} = this.props
72+
this.setState({value})
73+
onChange && onChange(value)
74+
}
75+
76+
_entityToOption = (entity: any) => {
77+
// const {entityKey} = this.props
78+
return {
79+
value: entity,
80+
label: entity,
81+
entity
82+
}
83+
}
84+
85+
render () {
86+
const {
87+
clearable,
88+
component,
89+
entities,
90+
optionRenderer,
91+
style
92+
} = this.props
93+
const {value} = this.state
94+
let disabled = false
95+
let placeholder = `Select ${component}...`
96+
let options = []
97+
if (entities.length > 30000) {
98+
console.warn(`Entity list too large (count=${entities.length}). Disabling entity selector.`)
99+
disabled = true
100+
placeholder = 'Selector disabled. List is too large.'
101+
} else {
102+
options = entities
103+
.filter(e => {
104+
if (e.id < 0) {
105+
console.warn(`Entity has a negative id, which indicates an unsaved entity that should not be selectable. Filtering out of selector.`, e)
106+
return false
107+
} else return e
108+
})
109+
.map(this._entityToOption)
110+
}
111+
return (
112+
<VirtualizedSelect
113+
placeholder={placeholder}
114+
options={options}
115+
searchable
116+
disabled={disabled}
117+
clearable={clearable}
118+
onChange={this._onChange}
119+
value={value}
120+
style={style}
121+
optionRenderer={optionRenderer} />
122+
)
123+
}
124+
}

lib/editor/util/ui.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,16 +77,17 @@ export const GTFS_ICONS = [
7777
{
7878
id: 'fareproduct',
7979
tableName: 'fareproduct',
80-
icon: 'shopping-cart',
80+
icon: 'money',
8181
addable: true,
82-
title: 'FARE PRODUCT TEST TITLE',
83-
label: 'V2: Products'
82+
title: 'Fares (v2)',
83+
label: 'Fares (v2)'
8484
},
8585
{
8686
id: 'faremedia',
8787
tableName: 'faremedia',
8888
icon: 'id-card',
8989
addable: true,
90+
hideSidebar: true,
9091
title: 'FARE MEDIA TEST TITLE',
9192
label: 'V2: Media'
9293
},
@@ -95,6 +96,7 @@ export const GTFS_ICONS = [
9596
tableName: 'faretransferrule',
9697
icon: 'link',
9798
addable: true,
99+
hideSidebar: true,
98100
title: 'FARE TRANSFER RULE TEST TITLE',
99101
label: 'V2: Transfer Rules'
100102
},
@@ -103,6 +105,7 @@ export const GTFS_ICONS = [
103105
tableName: 'farelegrule',
104106
icon: 'book',
105107
addable: true,
108+
hideSidebar: true,
106109
title: 'FARE LEG RULE TEST TITLE',
107110
label: 'V2: Leg Rules'
108111
},
@@ -111,8 +114,18 @@ export const GTFS_ICONS = [
111114
tableName: 'area',
112115
icon: 'map',
113116
addable: true,
117+
hideSidebar: true,
114118
title: 'AREAS TEST TITLE',
115119
label: 'V2: Areas'
120+
},
121+
{
122+
id: 'stoparea',
123+
tableName: 'stoparea',
124+
icon: 'map-marker',
125+
addable: true,
126+
hideSidebar: true,
127+
title: 'STOP AREAS TEST TITLE',
128+
label: 'V2: Stop Areas'
116129
}
117130
]
118131

0 commit comments

Comments
 (0)