Skip to content

Commit

Permalink
fix(editor): fix schedule exceptions for sql editor
Browse files Browse the repository at this point in the history
  • Loading branch information
landonreed committed Feb 12, 2018
1 parent 1944357 commit cd01332
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 76 deletions.
12 changes: 9 additions & 3 deletions gtfs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -733,10 +733,16 @@
name: (none)
helpContent: Conveyal-specific table for classifying schedule exceptions.
fields:
- name: "name"
- name: name
required: true
- name: "dates"
- name: dates
required: true
inputType: EXCEPTION_DATE
- name: "exemplar"
- name: exemplar
required: true
- name: custom_schedule
required: false
- name: removed_service
required: false
- name: added_service
required: false
37 changes: 19 additions & 18 deletions lib/editor/components/ScheduleExceptionForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Select from 'react-select'

import toSentenceCase from '../../common/util/to-sentence-case'
import ExceptionDate from './ExceptionDate'
import {EXEMPLARS} from '../util'
import {EXCEPTION_EXEMPLARS} from '../util'
import {getTableById} from '../util/gtfs'

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

_onCustomScheduleChange = (input) => {
const {activeComponent, activeEntity, updateActiveEntity} = this.props
const val = input ? input.map(i => i.value) : null
updateActiveEntity(activeEntity, activeComponent, {customSchedule: val})
updateActiveEntity(activeEntity, activeComponent, {custom_schedule: val})
}

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

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

calendarToOption = calendar => ({
value: calendar.id,
label: calendar.description,
value: calendar.service_id,
label: calendar.description || calendar.id,
calendar
})

Expand Down Expand Up @@ -87,10 +87,10 @@ export default class ScheduleExceptionForm extends Component {
value={(activeEntity && activeEntity.exemplar) || ''}
onChange={this._onExemplarChange}>
<option value='' disabled>-- Select exception type --</option>
{EXEMPLARS.map(exemplar => {
{Object.keys(EXCEPTION_EXEMPLARS).map(exemplar => {
return (
<option value={exemplar} key={exemplar}>
{exemplar === 'SWAP'
<option value={EXCEPTION_EXEMPLARS[exemplar]} key={EXCEPTION_EXEMPLARS[exemplar]}>
{exemplar === EXCEPTION_EXEMPLARS.SWAP
? 'Swap, add, or remove'
: toSentenceCase(exemplar)
}
Expand All @@ -99,7 +99,8 @@ export default class ScheduleExceptionForm extends Component {
})}
</FormControl>
</FormGroup>
{activeEntity && activeEntity.exemplar === 'CUSTOM'
{/* FIXME: This should likely use service_id rather than id */}
{activeEntity && activeEntity.exemplar === EXCEPTION_EXEMPLARS.CUSTOM
? <FormGroup
controlId={`custom`}
className={`col-xs-12`}>
Expand All @@ -108,13 +109,13 @@ export default class ScheduleExceptionForm extends Component {
placeholder='Select calendar...'
clearable
multi
value={activeEntity && activeEntity.customSchedule}
value={activeEntity && activeEntity.custom_schedule}
onChange={this._onCustomScheduleChange}
options={calendars.map(this.calendarToOption)} />
</FormGroup>
: null
}
{activeEntity && activeEntity.exemplar === 'SWAP'
{activeEntity && activeEntity.exemplar === EXCEPTION_EXEMPLARS.SWAP
? <FormGroup
controlId={`custom`}
className={`col-xs-12`}>
Expand All @@ -123,21 +124,21 @@ export default class ScheduleExceptionForm extends Component {
placeholder='Select calendar...'
clearable
multi
value={activeEntity && activeEntity.addedService}
value={activeEntity && activeEntity.added_service}
onChange={this._onAddedServiceChange}
options={calendars
.filter(cal => !activeEntity.removedService || activeEntity.removedService.indexOf(cal.id) === -1)
.filter(cal => !activeEntity.removed_service || activeEntity.removed_service.indexOf(cal.id) === -1)
.map(this.calendarToOption)
} />
<ControlLabel><small>Select calendars to remove (optional):</small></ControlLabel>
<Select
placeholder='Select calendar...'
clearable
multi
value={activeEntity && activeEntity.removedService}
value={activeEntity && activeEntity.removed_service}
onChange={this._onRemovedServiceChange}
options={calendars
.filter(cal => !activeEntity.addedService || activeEntity.addedService.indexOf(cal.id) === -1)
.filter(cal => !activeEntity.added_service || activeEntity.added_service.indexOf(cal.id) === -1)
.map(this.calendarToOption)
} />
</FormGroup>
Expand All @@ -148,7 +149,7 @@ export default class ScheduleExceptionForm extends Component {
validationState={validationErrors.find(e => e.field === 'dates') ? 'error' : undefined}
className={`col-xs-12`}>
<ControlLabel><small>On these dates*</small></ControlLabel>
{activeEntity && activeEntity.dates.length
{activeEntity && activeEntity.dates && activeEntity.dates.length
? activeEntity.dates.map((date, index) => (
<ExceptionDate
index={index}
Expand Down
7 changes: 5 additions & 2 deletions lib/editor/util/gtfs.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export const COMPONENT_LIST = [
{id: 'feedinfo', tableName: 'feed_info'},
// FIXME: table name for calendar, fare, and schedule exception
{id: 'calendar', tableName: 'calendar'},
{id: 'scheduleexception', tableName: 'scheduleexception'},
{id: 'scheduleexception', tableName: 'schedule_exceptions'},
{id: 'agency', tableName: 'agency'}
]

Expand Down Expand Up @@ -134,7 +134,10 @@ export const generateProps = (component: string, editorState: any): any => {
}
case 'scheduleexception':
return {
dates: []
dates: [],
customSchedule: null,
addedService: null,
removedService: null
}
case 'trippattern':
return {
Expand Down
24 changes: 12 additions & 12 deletions lib/editor/util/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@ export const CLICK_OPTIONS: Array<string> = [
'ADD_STOPS_AT_INTERSECTIONS'
]
export const YEAR_FORMAT: string = 'YYYY-MM-DD'
export const EXEMPLARS: Array<string> = [
'MONDAY',
'TUESDAY',
'WEDNESDAY',
'THURSDAY',
'FRIDAY',
'SATURDAY',
'SUNDAY',
'NO_SERVICE',
'CUSTOM',
'SWAP'
]
export const EXCEPTION_EXEMPLARS: any = {
MONDAY: 0,
TUESDAY: 1,
WEDNESDAY: 2,
THURSDAY: 3,
FRIDAY: 4,
SATURDAY: 5,
SUNDAY: 6,
NO_SERVICE: 7,
CUSTOM: 8,
SWAP: 9,
}

export function getStopsForPattern (pattern: Pattern, stops: Array<GtfsStop>): Array<GtfsStop> {
return pattern && pattern.patternStops && stops
Expand Down
42 changes: 2 additions & 40 deletions lib/editor/util/objects.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import clone from 'lodash.clonedeep'

import {ENTITY} from '../constants'
import camelcaseKeys from 'camelcase-keys'
import snakeCaseKeys from 'snakecase-keys'

import type {
Agency,
Expand Down Expand Up @@ -51,33 +52,12 @@ export const getMapFromGtfsStrategy = (component: string) => {
return calendarFromGtfs
case 'fare': // no mapping exists for fares
default:
return (entity: any) => entity
return (entity: any) => snakeCaseKeys(entity)
}
}

export function stopToGtfs (s: any): any {
return s
// return {
// // datatools props
// id: s.id,
// feedId: s.feedId,
// pickupType: s.pickupType,
// dropOffType: s.dropOffType,
//
// // gtfs spec props
// stop_code: s.stopCode,
// stop_name: s.stopName,
// stop_desc: s.stopDesc,
// stop_lat: s.lat,
// stop_lon: s.lon,
// zone_id: s.zoneId,
// stop_url: s.stopUrl,
// location_type: s.locationType,
// parent_station: s.parentStation,
// stop_timezone: s.stopTimezone,
// wheelchair_boarding: s.wheelchairBoarding,
// stop_id: s.gtfsStopId
// }
}

export function stopFromGtfs (stop: any): any {
Expand All @@ -86,24 +66,6 @@ export function stopFromGtfs (stop: any): any {
delete data.isCreating
delete data.id
return data
// return {
// dropOffType: stop.dropOffType,
// feedId: stop.feedId,
// gtfsStopId: stop.stop_id,
// id: entityIsNew(stop) ? null : stop.id,
// lat: stop.stop_lat,
// locationType: stop.location_type,
// lon: stop.stop_lon,
// parentStation: stop.parent_station,
// pickupType: stop.pickupType,
// stopCode: stop.stop_code,
// stopDesc: stop.stop_desc,
// stopName: stop.stop_name,
// stopTimezone: stop.stop_timezone,
// stopUrl: stop.stop_url,
// wheelchairBoarding: stop.wheelchair_boarding,
// zoneId: stop.zone_id
// }
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/editor/util/validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ export function validate (
})
}
}
if (value.length === 0) {
if (!value || value.length === 0) {
return {field: `dates`, invalid: true, reason}
}
// check if date already exists in this or other exceptions
Expand Down
4 changes: 4 additions & 0 deletions lib/gtfs/util/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ export function getEntityGraphQLRoot (type: string): string {
return 'trips'
case 'stoptime':
return 'trips'
case 'scheduleexception':
return 'schedule_exceptions'
case 'service':
return 'services'
case 'pattern':
Expand Down Expand Up @@ -163,6 +165,8 @@ export function getEntityTableString (type: string): string {
return 'route'
case 'trip':
return 'trip'
case 'scheduleexception':
return 'scheduleexception'
case 'stoptime':
return 'stop_time'
case 'service':
Expand Down

0 comments on commit cd01332

Please sign in to comment.