Skip to content

Commit 548fb24

Browse files
committed
fix(saveEntity, saveTripsForCalendar): Resolve missing defaults with GTFS spec change
fix #716, #717
1 parent 59d429a commit 548fb24

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

lib/editor/actions/active.js

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@ import {createAction, type ActionType} from 'redux-actions'
66

77
import {createVoidPayloadAction, secureFetch} from '../../common/actions'
88
import {ENTITY} from '../constants'
9-
import {newGtfsEntity, fetchBaseGtfs} from './editor'
109
import {fetchFeedSourceAndProject} from '../../manager/actions/feeds'
1110
import {fetchGTFSEntities} from '../../manager/actions/versions'
12-
import {saveTripPattern} from './tripPattern'
1311
import {
1412
getEditorNamespace,
1513
getTableById,
@@ -18,10 +16,12 @@ import {
1816
subSubComponentList
1917
} from '../util/gtfs'
2018
import {getMapFromGtfsStrategy, entityIsNew} from '../util/objects'
21-
2219
import type {Entity, Feed} from '../../types'
2320
import type {dispatchFn, getStateFn, AppState} from '../../types/reducers'
2421

22+
import {saveTripPattern} from './tripPattern'
23+
import {newGtfsEntity, fetchBaseGtfs} from './editor'
24+
2525
export const clearGtfsContent = createVoidPayloadAction('CLEAR_GTFSEDITOR_CONTENT')
2626
const receivedNewEntity = createAction(
2727
'RECEIVE_NEW_ENTITY',
@@ -331,14 +331,25 @@ export function saveEntity (
331331
return
332332
}
333333
dispatch(savingActiveGtfsEntity())
334-
const notNew = !entityIsNew(entity)
334+
// Add default vals for component
335+
const defaults = {}
336+
if (component === 'route') {
337+
defaults.continuous_pickup = 1 // Default value for no continuous pickup
338+
defaults.continuous_drop_off = 1 // Default value for no continuous drop off
339+
} else if (component === 'feedinfo') {
340+
defaults.default_lang = ''
341+
defaults.feed_contact_url = ''
342+
defaults.feed_contact_email = ''
343+
}
344+
const entityWithDefaults = {...defaults, ...(entity: any)} // add defaults, if any.
345+
const notNew = !entityIsNew(entityWithDefaults)
335346
const method = notNew ? 'put' : 'post'
336-
const idParam = notNew ? `/${entity.id || ''}` : ''
347+
const idParam = notNew ? `/${entityWithDefaults.id || ''}` : ''
337348
const {sessionId} = getState().editor.data.lock
338349
const route = component === 'fare' ? 'fareattribute' : component
339350
const url = `/api/editor/secure/${route}${idParam}?feedId=${feedId}&sessionId=${sessionId || ''}`
340351
const mappingStrategy = getMapFromGtfsStrategy(component)
341-
const data = mappingStrategy(entity)
352+
const data = mappingStrategy(entityWithDefaults)
342353
return dispatch(secureFetch(url, method, data))
343354
.then(res => res.json())
344355
.then(savedEntity => {

lib/editor/actions/trip.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import {createVoidPayloadAction, fetchGraphQL, secureFetch} from '../../common/a
77
import {setErrorMessage} from '../../manager/actions/status'
88
import {entityIsNew} from '../util/objects'
99
import {getEditorNamespace} from '../util/gtfs'
10-
1110
import type {Pattern, TimetableColumn, Trip} from '../../types'
1211
import type {dispatchFn, getStateFn, TripCounts} from '../../types/reducers'
1312

@@ -159,6 +158,15 @@ export function saveTripsForCalendar (
159158
trips = trips.map(snakeCaseKeys)
160159
return Promise.all(trips.filter(t => t).map((trip, index) => {
161160
const tripExists = !entityIsNew(trip) && trip.id !== null
161+
const tripCopy: any = (trip: any)
162+
// Add default value to continuous pickup if not provided
163+
const defaults = {
164+
continuous_pickup: 1,
165+
continuous_drop_off: 1
166+
}
167+
tripCopy.stop_times = tripCopy.stop_times.map((stopTime, index) => {
168+
return {...defaults, ...(stopTime: any)}
169+
})
162170
const method = tripExists ? 'put' : 'post'
163171
const url = tripExists && trip.id
164172
? `/api/editor/secure/trip/${trip.id}?feedId=${feedId}&sessionId=${sessionId}`

0 commit comments

Comments
 (0)