@@ -6,16 +6,31 @@ import {FormControl} from 'react-bootstrap'
66import EditableTextField from '../../common/components/EditableTextField'
77import { getRouteName } from '../../editor/util/gtfs'
88import GtfsSearch from '../../gtfs/components/gtfs-search'
9+ import type { GtfsSpecField as GtfsPlusFieldType , GtfsRoute , GtfsStop } from '../../types'
910
1011import type { Props as GtfsPlusTableProps } from './GtfsPlusTable'
11- import type { GtfsSpecField as GtfsPlusFieldType , GtfsRoute , GtfsStop } from '../../types'
1212
1313type Props = GtfsPlusTableProps & {
1414 currentValue : any ,
1515 field : GtfsPlusFieldType ,
1616 row : number
1717}
1818
19+ // Maps subcategories to categories, shown as strings to avoid conversion ambiguities.
20+ const routeSubcategoryToCategory = {
21+ '0' : '0' ,
22+ '1' : '1' ,
23+ '2' : '1' ,
24+ '3' : '1' ,
25+ '4' : '2' ,
26+ '5' : '2' ,
27+ '6' : '2' ,
28+ '7' : '3' ,
29+ '8' : '3' ,
30+ '9' : '3' ,
31+ '10' : '4'
32+ }
33+
1934export default class GtfsPlusField extends Component < Props > {
2035 _onChangeRoute = ( { route} : { route : GtfsRoute } ) => {
2136 const { field, receiveGtfsEntities, row : rowIndex , table, updateGtfsPlusField} = this . props
@@ -42,7 +57,8 @@ export default class GtfsPlusField extends Component<Props> {
4257 }
4358
4459 render ( ) {
45- const { currentValue , feedVersion, field, getGtfsEntity} = this . props
60+ const { currentValue , data, feedVersion, field, getGtfsEntity} = this . props
61+ let filterOptions
4662 switch ( field . inputType ) {
4763 case 'TEXT' :
4864 case 'GTFS_TRIP' :
@@ -54,12 +70,22 @@ export default class GtfsPlusField extends Component<Props> {
5470 value = { currentValue }
5571 onChange = { this . _onChangeValue } />
5672 )
73+ case 'GTFS_PLUS_ROUTE_SUBCATEGORY' :
74+ filterOptions = ( option ) => routeSubcategoryToCategory [ option . value ] === data . category
75+ // FIXME:
76+ // eslint-disable-next-line no-fallthrough
5777 case 'DROPDOWN ':
5878 const { options} = field
5979 if ( ! options ) {
6080 console . warn ( `GTFS+ field has no options defined.` , field )
6181 return null
6282 }
83+
84+ // console.log(options)
85+ console . log ( data )
86+ const filteredOptions = filterOptions ? options . filter ( filterOptions ) : options
87+ console . log ( filteredOptions )
88+
6389 // NOTE: client has requested that GTFS+ fields be case insensitive
6490 // (hence the toUpperCase call)
6591 const option = currentValue &&
@@ -69,15 +95,15 @@ export default class GtfsPlusField extends Component<Props> {
6995 value = { option ? option . value : '' }
7096 onChange = { this . _onChange } >
7197 { /* Add field for empty string value if that is not an allowable option so that user selection triggers onChange */ }
72- { options . findIndex ( option => option . value === '' ) === - 1
98+ { filteredOptions . findIndex ( option => option . value === '' ) === - 1
7399 ? < option
74100 disabled
75101 value = '' >
76102 { field . required ? '-- select an option --' : '(optional)' }
77103 </ option >
78104 : null
79105 }
80- { options . map ( option => {
106+ { filteredOptions . map ( option => {
81107 // NOTE: client has requested that GTFS+ fields be case
82108 // insensitive (hence the toLowerCase call)
83109 return < option value = { option . value } key = { option . value } >
0 commit comments