Skip to content

Commit cd01332

Browse files
committed
fix(editor): fix schedule exceptions for sql editor
1 parent 1944357 commit cd01332

File tree

7 files changed

+52
-76
lines changed

7 files changed

+52
-76
lines changed

gtfs.yml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -733,10 +733,16 @@
733733
name: (none)
734734
helpContent: Conveyal-specific table for classifying schedule exceptions.
735735
fields:
736-
- name: "name"
736+
- name: name
737737
required: true
738-
- name: "dates"
738+
- name: dates
739739
required: true
740740
inputType: EXCEPTION_DATE
741-
- name: "exemplar"
741+
- name: exemplar
742742
required: true
743+
- name: custom_schedule
744+
required: false
745+
- name: removed_service
746+
required: false
747+
- name: added_service
748+
required: false

lib/editor/components/ScheduleExceptionForm.js

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import Select from 'react-select'
55

66
import toSentenceCase from '../../common/util/to-sentence-case'
77
import ExceptionDate from './ExceptionDate'
8-
import {EXEMPLARS} from '../util'
8+
import {EXCEPTION_EXEMPLARS} from '../util'
99
import {getTableById} from '../util/gtfs'
1010

1111
export default class ScheduleExceptionForm extends Component {
@@ -27,18 +27,18 @@ export default class ScheduleExceptionForm extends Component {
2727
_onAddedServiceChange = (input) => {
2828
const {activeComponent, activeEntity, updateActiveEntity} = this.props
2929
const val = input ? input.map(i => i.value) : null
30-
updateActiveEntity(activeEntity, activeComponent, {addedService: val})
30+
updateActiveEntity(activeEntity, activeComponent, {added_service: val})
3131
}
3232

3333
_onCustomScheduleChange = (input) => {
3434
const {activeComponent, activeEntity, updateActiveEntity} = this.props
3535
const val = input ? input.map(i => i.value) : null
36-
updateActiveEntity(activeEntity, activeComponent, {customSchedule: val})
36+
updateActiveEntity(activeEntity, activeComponent, {custom_schedule: val})
3737
}
3838

3939
_onExemplarChange = (evt) => {
4040
const {activeComponent, activeEntity, updateActiveEntity} = this.props
41-
updateActiveEntity(activeEntity, activeComponent, {exemplar: evt.target.value, customSchedule: null})
41+
updateActiveEntity(activeEntity, activeComponent, {exemplar: +evt.target.value, custom_schedule: null})
4242
}
4343

4444
_onNameChange = (evt) => {
@@ -49,12 +49,12 @@ export default class ScheduleExceptionForm extends Component {
4949
_onRemovedServiceChange = (input) => {
5050
const {activeComponent, activeEntity, updateActiveEntity} = this.props
5151
const val = input ? input.map(i => i.value) : null
52-
updateActiveEntity(activeEntity, activeComponent, {removedService: val})
52+
updateActiveEntity(activeEntity, activeComponent, {removed_service: val})
5353
}
5454

5555
calendarToOption = calendar => ({
56-
value: calendar.id,
57-
label: calendar.description,
56+
value: calendar.service_id,
57+
label: calendar.description || calendar.id,
5858
calendar
5959
})
6060

@@ -87,10 +87,10 @@ export default class ScheduleExceptionForm extends Component {
8787
value={(activeEntity && activeEntity.exemplar) || ''}
8888
onChange={this._onExemplarChange}>
8989
<option value='' disabled>-- Select exception type --</option>
90-
{EXEMPLARS.map(exemplar => {
90+
{Object.keys(EXCEPTION_EXEMPLARS).map(exemplar => {
9191
return (
92-
<option value={exemplar} key={exemplar}>
93-
{exemplar === 'SWAP'
92+
<option value={EXCEPTION_EXEMPLARS[exemplar]} key={EXCEPTION_EXEMPLARS[exemplar]}>
93+
{exemplar === EXCEPTION_EXEMPLARS.SWAP
9494
? 'Swap, add, or remove'
9595
: toSentenceCase(exemplar)
9696
}
@@ -99,7 +99,8 @@ export default class ScheduleExceptionForm extends Component {
9999
})}
100100
</FormControl>
101101
</FormGroup>
102-
{activeEntity && activeEntity.exemplar === 'CUSTOM'
102+
{/* FIXME: This should likely use service_id rather than id */}
103+
{activeEntity && activeEntity.exemplar === EXCEPTION_EXEMPLARS.CUSTOM
103104
? <FormGroup
104105
controlId={`custom`}
105106
className={`col-xs-12`}>
@@ -108,13 +109,13 @@ export default class ScheduleExceptionForm extends Component {
108109
placeholder='Select calendar...'
109110
clearable
110111
multi
111-
value={activeEntity && activeEntity.customSchedule}
112+
value={activeEntity && activeEntity.custom_schedule}
112113
onChange={this._onCustomScheduleChange}
113114
options={calendars.map(this.calendarToOption)} />
114115
</FormGroup>
115116
: null
116117
}
117-
{activeEntity && activeEntity.exemplar === 'SWAP'
118+
{activeEntity && activeEntity.exemplar === EXCEPTION_EXEMPLARS.SWAP
118119
? <FormGroup
119120
controlId={`custom`}
120121
className={`col-xs-12`}>
@@ -123,21 +124,21 @@ export default class ScheduleExceptionForm extends Component {
123124
placeholder='Select calendar...'
124125
clearable
125126
multi
126-
value={activeEntity && activeEntity.addedService}
127+
value={activeEntity && activeEntity.added_service}
127128
onChange={this._onAddedServiceChange}
128129
options={calendars
129-
.filter(cal => !activeEntity.removedService || activeEntity.removedService.indexOf(cal.id) === -1)
130+
.filter(cal => !activeEntity.removed_service || activeEntity.removed_service.indexOf(cal.id) === -1)
130131
.map(this.calendarToOption)
131132
} />
132133
<ControlLabel><small>Select calendars to remove (optional):</small></ControlLabel>
133134
<Select
134135
placeholder='Select calendar...'
135136
clearable
136137
multi
137-
value={activeEntity && activeEntity.removedService}
138+
value={activeEntity && activeEntity.removed_service}
138139
onChange={this._onRemovedServiceChange}
139140
options={calendars
140-
.filter(cal => !activeEntity.addedService || activeEntity.addedService.indexOf(cal.id) === -1)
141+
.filter(cal => !activeEntity.added_service || activeEntity.added_service.indexOf(cal.id) === -1)
141142
.map(this.calendarToOption)
142143
} />
143144
</FormGroup>
@@ -148,7 +149,7 @@ export default class ScheduleExceptionForm extends Component {
148149
validationState={validationErrors.find(e => e.field === 'dates') ? 'error' : undefined}
149150
className={`col-xs-12`}>
150151
<ControlLabel><small>On these dates*</small></ControlLabel>
151-
{activeEntity && activeEntity.dates.length
152+
{activeEntity && activeEntity.dates && activeEntity.dates.length
152153
? activeEntity.dates.map((date, index) => (
153154
<ExceptionDate
154155
index={index}

lib/editor/util/gtfs.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export const COMPONENT_LIST = [
4444
{id: 'feedinfo', tableName: 'feed_info'},
4545
// FIXME: table name for calendar, fare, and schedule exception
4646
{id: 'calendar', tableName: 'calendar'},
47-
{id: 'scheduleexception', tableName: 'scheduleexception'},
47+
{id: 'scheduleexception', tableName: 'schedule_exceptions'},
4848
{id: 'agency', tableName: 'agency'}
4949
]
5050

@@ -134,7 +134,10 @@ export const generateProps = (component: string, editorState: any): any => {
134134
}
135135
case 'scheduleexception':
136136
return {
137-
dates: []
137+
dates: [],
138+
customSchedule: null,
139+
addedService: null,
140+
removedService: null
138141
}
139142
case 'trippattern':
140143
return {

lib/editor/util/index.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,18 @@ export const CLICK_OPTIONS: Array<string> = [
1919
'ADD_STOPS_AT_INTERSECTIONS'
2020
]
2121
export const YEAR_FORMAT: string = 'YYYY-MM-DD'
22-
export const EXEMPLARS: Array<string> = [
23-
'MONDAY',
24-
'TUESDAY',
25-
'WEDNESDAY',
26-
'THURSDAY',
27-
'FRIDAY',
28-
'SATURDAY',
29-
'SUNDAY',
30-
'NO_SERVICE',
31-
'CUSTOM',
32-
'SWAP'
33-
]
22+
export const EXCEPTION_EXEMPLARS: any = {
23+
MONDAY: 0,
24+
TUESDAY: 1,
25+
WEDNESDAY: 2,
26+
THURSDAY: 3,
27+
FRIDAY: 4,
28+
SATURDAY: 5,
29+
SUNDAY: 6,
30+
NO_SERVICE: 7,
31+
CUSTOM: 8,
32+
SWAP: 9,
33+
}
3434

3535
export function getStopsForPattern (pattern: Pattern, stops: Array<GtfsStop>): Array<GtfsStop> {
3636
return pattern && pattern.patternStops && stops

lib/editor/util/objects.js

Lines changed: 2 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import clone from 'lodash.clonedeep'
33

44
import {ENTITY} from '../constants'
55
import camelcaseKeys from 'camelcase-keys'
6+
import snakeCaseKeys from 'snakecase-keys'
67

78
import type {
89
Agency,
@@ -51,33 +52,12 @@ export const getMapFromGtfsStrategy = (component: string) => {
5152
return calendarFromGtfs
5253
case 'fare': // no mapping exists for fares
5354
default:
54-
return (entity: any) => entity
55+
return (entity: any) => snakeCaseKeys(entity)
5556
}
5657
}
5758

5859
export function stopToGtfs (s: any): any {
5960
return s
60-
// return {
61-
// // datatools props
62-
// id: s.id,
63-
// feedId: s.feedId,
64-
// pickupType: s.pickupType,
65-
// dropOffType: s.dropOffType,
66-
//
67-
// // gtfs spec props
68-
// stop_code: s.stopCode,
69-
// stop_name: s.stopName,
70-
// stop_desc: s.stopDesc,
71-
// stop_lat: s.lat,
72-
// stop_lon: s.lon,
73-
// zone_id: s.zoneId,
74-
// stop_url: s.stopUrl,
75-
// location_type: s.locationType,
76-
// parent_station: s.parentStation,
77-
// stop_timezone: s.stopTimezone,
78-
// wheelchair_boarding: s.wheelchairBoarding,
79-
// stop_id: s.gtfsStopId
80-
// }
8161
}
8262

8363
export function stopFromGtfs (stop: any): any {
@@ -86,24 +66,6 @@ export function stopFromGtfs (stop: any): any {
8666
delete data.isCreating
8767
delete data.id
8868
return data
89-
// return {
90-
// dropOffType: stop.dropOffType,
91-
// feedId: stop.feedId,
92-
// gtfsStopId: stop.stop_id,
93-
// id: entityIsNew(stop) ? null : stop.id,
94-
// lat: stop.stop_lat,
95-
// locationType: stop.location_type,
96-
// lon: stop.stop_lon,
97-
// parentStation: stop.parent_station,
98-
// pickupType: stop.pickupType,
99-
// stopCode: stop.stop_code,
100-
// stopDesc: stop.stop_desc,
101-
// stopName: stop.stop_name,
102-
// stopTimezone: stop.stop_timezone,
103-
// stopUrl: stop.stop_url,
104-
// wheelchairBoarding: stop.wheelchair_boarding,
105-
// zoneId: stop.zone_id
106-
// }
10769
}
10870

10971
/**

lib/editor/util/validation.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ export function validate (
211211
})
212212
}
213213
}
214-
if (value.length === 0) {
214+
if (!value || value.length === 0) {
215215
return {field: `dates`, invalid: true, reason}
216216
}
217217
// check if date already exists in this or other exceptions

lib/gtfs/util/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,8 @@ export function getEntityGraphQLRoot (type: string): string {
132132
return 'trips'
133133
case 'stoptime':
134134
return 'trips'
135+
case 'scheduleexception':
136+
return 'schedule_exceptions'
135137
case 'service':
136138
return 'services'
137139
case 'pattern':
@@ -163,6 +165,8 @@ export function getEntityTableString (type: string): string {
163165
return 'route'
164166
case 'trip':
165167
return 'trip'
168+
case 'scheduleexception':
169+
return 'scheduleexception'
166170
case 'stoptime':
167171
return 'stop_time'
168172
case 'service':

0 commit comments

Comments
 (0)