Skip to content

Commit 1eefea5

Browse files
initial support for stop_area_ids on stop entities
1 parent 0042661 commit 1eefea5

File tree

8 files changed

+107
-37
lines changed

8 files changed

+107
-37
lines changed

gtfs.yml

Lines changed: 6 additions & 19 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_ids"
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
@@ -1159,19 +1159,6 @@
11591159
- name: area_id
11601160
required: true
11611161
inputType: GTFS_ID
1162-
- name: area_name
1163-
required: false
1164-
inputType: TEXT
1165-
- id: stoparea
1166-
name: stop_areas.txt
1167-
helpContent: Areas that can be used to define fare zones for stops.
1168-
fields:
1169-
- name: area_id
1170-
required: true
1171-
inputType: GTFS_AREA
1172-
- name: stop_id
1173-
required: true
1174-
inputType: GTFS_STOP
11751162
- name: area_name
11761163
required: false
11771164
inputType: TEXT

lib/editor/actions/editor.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -552,11 +552,6 @@ export function fetchBaseGtfs ({
552552
stop_lon
553553
zone_id # needed for fares
554554
}
555-
stop_area (limit: -1) {
556-
id
557-
stop_id
558-
area_id
559-
}
560555
}
561556
}
562557
`

lib/editor/components/EditorInput.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import type {EditorTables} from '../../types/reducers'
2121

2222
import ColorField from './ColorField'
2323
import FareProductSelect from './FareProductSelect'
24+
import StopAreasSelector from './StopAreasSelector'
2425
import RouteTypeSelect from './RouteTypeSelect'
2526
import VirtualizedEntitySelect from './VirtualizedEntitySelect'
2627
import ZoneSelect from './ZoneSelect'
@@ -420,18 +421,18 @@ export default class EditorInput extends React.Component<Props> {
420421
</FormGroup>
421422
)
422423
case 'GTFS_STOP_AREA':
423-
const stopAreas = getTableById(tableData, 'area').map(stopArea => ({
424-
value: stopArea.area_id,
425-
label: stopArea.area_name || stopArea.area_id
426-
}))
424+
const areas = getTableById(tableData, 'area')
425+
const stops = getTableById(tableData, 'stop')
427426
return (
428427
<FormGroup {...formProps}>
429428
{basicLabel}
430-
<Select
429+
<StopAreasSelector
431430
clearable
432431
onChange={this._onSelectChange}
433-
value={currentValue}
434-
options={stopAreas} />
432+
currentValue={currentValue}
433+
areas={areas}
434+
stops={stops}
435+
processFieldChange={this._processFieldChange} />
435436
</FormGroup>
436437
)
437438
default:
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
// @flow
2+
3+
// $FlowFixMe React hook bindings not picked up
4+
import React, { useState } from 'react'
5+
import Icon from '@conveyal/woonerf/components/icon'
6+
import { Button } from 'react-bootstrap'
7+
8+
import type { GtfsStop } from '../../types'
9+
10+
import VirtualizedEntitySelect from './VirtualizedEntitySelect'
11+
12+
type Props = {
13+
currentValue: Array<string> | string,
14+
processFieldChange: (val: any) => void,
15+
stops: Array<GtfsStop>
16+
}
17+
18+
const StopAreasSelector = ({ currentValue, processFieldChange, stops }: Props) => {
19+
const [dropdownShowing, setDropdownShowing] = useState(false)
20+
const getStationOrLocationName =
21+
(haltId) => {
22+
const entity =
23+
stops.find((stop) => stop.stop_id === haltId)
24+
const name = entity && entity.stop_name ? entity.stop_name : ''
25+
const codeOrId = entity && entity.stop_code ? entity.stop_code : haltId
26+
return `${name} (${codeOrId})`
27+
}
28+
29+
const deleteHalt = (haltId) => {
30+
if (typeof currentValue === 'string') return
31+
32+
processFieldChange(
33+
currentValue.filter(id => id !== haltId)
34+
)
35+
}
36+
37+
return (
38+
<>
39+
<div style={{
40+
display: 'grid',
41+
gap: 5,
42+
gridTemplateColumns: '6fr 1fr',
43+
marginBottom: 5
44+
}}>
45+
{currentValue && typeof currentValue !== 'string' &&
46+
currentValue.map((l) => (
47+
<React.Fragment key={l}>
48+
<span>{getStationOrLocationName(l)}</span>
49+
<Button bsSize='small' bsStyle='danger' style={{padding: '0 2px', margin: '0 1ch'}} onClick={() => deleteHalt(l)}>
50+
<Icon type='trash' />
51+
</Button>
52+
</React.Fragment>
53+
))}
54+
</div>
55+
{!dropdownShowing && !(stops.length === 0) && <Button
56+
block
57+
bsSize='small'
58+
onClick={() => setDropdownShowing(true)}
59+
>
60+
<Icon type='plus' /> Add stop or location by name
61+
</Button>}
62+
{dropdownShowing && <VirtualizedEntitySelect
63+
component={'stop or location'}
64+
entityKey={'stop_or_location_id'}
65+
entities={[
66+
...stops
67+
// $FlowFixMe Flow struggles with union types
68+
].filter((stopOrLocation: GtfsStop) => {
69+
return !currentValue || !currentValue.includes(
70+
// $FlowFixMe making this flow compatible would introduce a lot of unneeded code
71+
stopOrLocation.stop_id || stopOrLocation.location_id
72+
)
73+
})}
74+
onChange={(change) => {
75+
processFieldChange([
76+
...(currentValue || []),
77+
change.entity.stop_id || change.entity.location_id
78+
])
79+
setDropdownShowing(false)
80+
}}
81+
/>}
82+
</>
83+
)
84+
}
85+
86+
export default StopAreasSelector

lib/editor/reducers/data.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ export const defaultState = {
4141
routes: [],
4242
schedule_exceptions: [],
4343
stops: [],
44-
stop_area: [],
4544
trip_counts: {
4645
pattern_id: [],
4746
route_id: [],

lib/editor/util/gtfs.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ export const COMPONENT_LIST = [
3636
{ id: 'faremedia', tableName: 'fare_media' },
3737
{ id: 'faretransferrule', tableName: 'fare_transfer_rule' },
3838
{ id: 'farelegrule', tableName: 'fare_leg_rule' },
39-
{ id: 'area', tableName: 'area' },
40-
{ id: 'stoparea', tableName: 'stop_areas' }
39+
{ id: 'area', tableName: 'area' }
4140
]
4241

4342
export function getTableById (tableData: any, id?: string, emptyArrayOnNull: boolean = true): any {
@@ -380,3 +379,7 @@ export function gtfsSort (a: Entity, b: Entity): number {
380379
if (aName.toLowerCase() > bName.toLowerCase()) return 1
381380
return 0
382381
}
382+
383+
export function isComponentFaresv2 (component: string): boolean {
384+
return ['fareproduct', 'faremedia', 'faretransferrule', 'farelegrule'].includes(component)
385+
}

lib/editor/util/ui.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ export const GTFS_ICONS = [
7979
tableName: 'fareproduct',
8080
icon: 'money',
8181
addable: true,
82-
title: 'Fares (v2)',
83-
label: 'Fares (v2)'
82+
title: 'Fares v2',
83+
label: 'Fares v2'
8484
},
8585
{
8686
id: 'faremedia',

lib/types/reducers.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,6 @@ export type EditorTables = {
153153
id: number,
154154
name: string
155155
}>,
156-
stop_area: Array<{}>,
157156
stops: Array<{
158157
id: number,
159158
stop_code: string,

0 commit comments

Comments
 (0)