Skip to content

Commit 84583ce

Browse files
edit and delete stop_area_ids with new component
1 parent 1eefea5 commit 84583ce

File tree

3 files changed

+57
-37
lines changed

3 files changed

+57
-37
lines changed

lib/editor/components/EditorInput.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ export default class EditorInput extends React.Component<Props> {
7070
onChange,
7171
updateActiveGtfsEntity
7272
} = this.props
73+
console.log('processing field change::::', field.name, val)
7374
onChange && onChange(val)
7475
updateActiveGtfsEntity && activeEntity && updateActiveGtfsEntity({
7576
component: activeComponent,
@@ -111,6 +112,7 @@ export default class EditorInput extends React.Component<Props> {
111112
}
112113
}
113114

115+
/* eslint-disable complexity */
114116
render () {
115117
const {
116118
activeEntity,
@@ -423,16 +425,22 @@ export default class EditorInput extends React.Component<Props> {
423425
case 'GTFS_STOP_AREA':
424426
const areas = getTableById(tableData, 'area')
425427
const stops = getTableById(tableData, 'stop')
428+
let stopAreaIds: Array<string> = []
429+
if (activeComponent === 'stop' &&
430+
activeEntity &&
431+
activeEntity.stop_area_ids &&
432+
typeof activeEntity.stop_area_ids === 'string') {
433+
stopAreaIds = activeEntity.stop_area_ids.split('§').filter(Boolean)
434+
}
426435
return (
427436
<FormGroup {...formProps}>
428437
{basicLabel}
429438
<StopAreasSelector
430-
clearable
431-
onChange={this._onSelectChange}
432-
currentValue={currentValue}
439+
currentValue={stopAreaIds}
433440
areas={areas}
434441
stops={stops}
435-
processFieldChange={this._processFieldChange} />
442+
processFieldChange={this._processFieldChange}
443+
/>
436444
</FormGroup>
437445
)
438446
default:

lib/editor/components/StopAreasSelector.js

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,35 +5,41 @@ import React, { useState } from 'react'
55
import Icon from '@conveyal/woonerf/components/icon'
66
import { Button } from 'react-bootstrap'
77

8-
import type { GtfsStop } from '../../types'
8+
import type { GtfsArea, GtfsStop } from '../../types'
99

1010
import VirtualizedEntitySelect from './VirtualizedEntitySelect'
1111

1212
type Props = {
13+
areas: Array<GtfsArea>,
1314
currentValue: Array<string> | string,
1415
processFieldChange: (val: any) => void,
1516
stops: Array<GtfsStop>
1617
}
1718

18-
const StopAreasSelector = ({ currentValue, processFieldChange, stops }: Props) => {
19+
const StopAreasSelector = ({ currentValue, areas, processFieldChange, stops }: Props) => {
1920
const [dropdownShowing, setDropdownShowing] = useState(false)
20-
const getStationOrLocationName =
21-
(haltId) => {
21+
const getStopOrAreaName =
22+
(entityId) => {
2223
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})`
24+
stops.find((stop) => stop.stop_id === entityId) ||
25+
areas.find((area) => area.area_id === entityId)
26+
// const name = entity && (entity.stop_name || entity.area_name) ? (entity.stop_name || entity.area_name) : ''
27+
const codeOrId = entity && entity.stop_code ? entity.stop_code : entityId
28+
return `todo?! (${codeOrId})`
2729
}
2830

29-
const deleteHalt = (haltId) => {
31+
const deleteEntity = (entityId) => {
32+
console.log('deleting entity', entityId)
3033
if (typeof currentValue === 'string') return
3134

32-
processFieldChange(
33-
currentValue.filter(id => id !== haltId)
34-
)
35+
// Filter out the entityId and join remaining items with ';'
36+
const filtered = currentValue.filter(id => id !== entityId)
37+
const newValue = filtered.length > 1 ? filtered.join(';') : (filtered[0] || '')
38+
processFieldChange(newValue)
3539
}
3640

41+
console.log('currentValue:::::::', currentValue)
42+
3743
return (
3844
<>
3945
<div style={{
@@ -45,37 +51,37 @@ const StopAreasSelector = ({ currentValue, processFieldChange, stops }: Props) =
4551
{currentValue && typeof currentValue !== 'string' &&
4652
currentValue.map((l) => (
4753
<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)}>
54+
<span>{getStopOrAreaName(l)}</span>
55+
<Button bsSize='small' bsStyle='danger' style={{padding: '0 2px', margin: '0 1ch'}} onClick={() => deleteEntity(l)}>
5056
<Icon type='trash' />
5157
</Button>
5258
</React.Fragment>
5359
))}
5460
</div>
55-
{!dropdownShowing && !(stops.length === 0) && <Button
61+
{!dropdownShowing && !(areas.length === 0) && <Button
5662
block
5763
bsSize='small'
5864
onClick={() => setDropdownShowing(true)}
5965
>
60-
<Icon type='plus' /> Add stop or location by name
66+
<Icon type='plus' /> Add stop or area by name
6167
</Button>}
6268
{dropdownShowing && <VirtualizedEntitySelect
63-
component={'stop or location'}
64-
entityKey={'stop_or_location_id'}
69+
component={'stop or area'}
70+
entityKey={'stop_or_area_id'}
6571
entities={[
66-
...stops
72+
...areas
6773
// $FlowFixMe Flow struggles with union types
68-
].filter((stopOrLocation: GtfsStop) => {
74+
].filter((stopOrArea: GtfsStop | GtfsArea) => {
6975
return !currentValue || !currentValue.includes(
7076
// $FlowFixMe making this flow compatible would introduce a lot of unneeded code
71-
stopOrLocation.stop_id || stopOrLocation.location_id
77+
stopOrArea.stop_id || stopOrArea.area_id
7278
)
7379
})}
7480
onChange={(change) => {
75-
processFieldChange([
76-
...(currentValue || []),
77-
change.entity.stop_id || change.entity.location_id
78-
])
81+
const selectedId = change.entity.stop_id || change.entity.area_id
82+
const valuesArray = Array.isArray(currentValue) ? currentValue : (currentValue ? [currentValue] : [])
83+
const newValue = [...valuesArray, selectedId].filter(Boolean).join('§')
84+
processFieldChange(newValue)
7985
setDropdownShowing(false)
8086
}}
8187
/>}

lib/types/index.js

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -646,6 +646,15 @@ export type Pattern = {|
646646
useFrequency: boolean
647647
|}
648648

649+
export type FareRule = {
650+
contains_id: ?string,
651+
destination_id: ?string,
652+
fare_id: string,
653+
id: number,
654+
origin_id: ?string,
655+
route_id: ?string
656+
}
657+
649658
export type GtfsAgency = {|
650659
agency_branding_url: string,
651660
agency_email: string,
@@ -660,14 +669,10 @@ export type GtfsAgency = {|
660669
id: number
661670
|}
662671

663-
export type FareRule = {
664-
contains_id: ?string,
665-
destination_id: ?string,
666-
fare_id: string,
667-
id: number,
668-
origin_id: ?string,
669-
route_id: ?string
670-
}
672+
export type GtfsArea = {|
673+
area_id: string,
674+
area_name: ?string
675+
|}
671676

672677
export type GtfsFare = {|
673678
agency_id: ?string,
@@ -748,6 +753,7 @@ export type GtfsStop = {|
748753
parent_station?: ?string,
749754
pickupType?: ?number,
750755
stopId?: string,
756+
stop_area_ids?: ?string,
751757
stop_code?: ?string,
752758
stop_desc?: string,
753759
stop_id: string,

0 commit comments

Comments
 (0)