Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions lib/editor/actions/active.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@ import {createAction, type ActionType} from 'redux-actions'

import {createVoidPayloadAction, secureFetch} from '../../common/actions'
import {ENTITY} from '../constants'
import {newGtfsEntity, fetchBaseGtfs} from './editor'
import {fetchFeedSourceAndProject} from '../../manager/actions/feeds'
import {fetchGTFSEntities} from '../../manager/actions/versions'
import {saveTripPattern} from './tripPattern'
import {
getEditorNamespace,
getTableById,
Expand All @@ -18,10 +16,12 @@ import {
subSubComponentList
} from '../util/gtfs'
import {getMapFromGtfsStrategy, entityIsNew} from '../util/objects'

import type {Entity, Feed} from '../../types'
import type {dispatchFn, getStateFn, AppState} from '../../types/reducers'

import {saveTripPattern} from './tripPattern'
import {newGtfsEntity, fetchBaseGtfs} from './editor'

Comment on lines +22 to +24
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can these imports be before the import type or is this something prettier automatically format?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was an automatic format

export const clearGtfsContent = createVoidPayloadAction('CLEAR_GTFSEDITOR_CONTENT')
const receivedNewEntity = createAction(
'RECEIVE_NEW_ENTITY',
Expand Down Expand Up @@ -331,14 +331,25 @@ export function saveEntity (
return
}
dispatch(savingActiveGtfsEntity())
const notNew = !entityIsNew(entity)
// Add default vals for component
const defaults = {}
if (component === 'route') {
defaults.continuous_pickup = 1 // Default value for no continuous pickup
defaults.continuous_drop_off = 1 // Default value for no continuous drop off
} else if (component === 'feedinfo') {
defaults.default_lang = ''
defaults.feed_contact_url = ''
defaults.feed_contact_email = ''
Comment on lines +341 to +342
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These fields make it to the database, but on page reload are not populated in the UI. Can you fix this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a problem with the fetchBaseGTFS method, which did not fetch the new fields. Fixed in c48bb18

}
const entityWithDefaults = {...defaults, ...(entity: any)} // add defaults, if any.
const notNew = !entityIsNew(entityWithDefaults)
const method = notNew ? 'put' : 'post'
const idParam = notNew ? `/${entity.id || ''}` : ''
const idParam = notNew ? `/${entityWithDefaults.id || ''}` : ''
const {sessionId} = getState().editor.data.lock
const route = component === 'fare' ? 'fareattribute' : component
const url = `/api/editor/secure/${route}${idParam}?feedId=${feedId}&sessionId=${sessionId || ''}`
const mappingStrategy = getMapFromGtfsStrategy(component)
const data = mappingStrategy(entity)
const data = mappingStrategy(entityWithDefaults)
return dispatch(secureFetch(url, method, data))
.then(res => res.json())
.then(savedEntity => {
Expand Down
7 changes: 5 additions & 2 deletions lib/editor/actions/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {createAction, type ActionType} from 'redux-actions'

import {createVoidPayloadAction, fetchGraphQL, secureFetch} from '../../common/actions'
import {generateUID} from '../../common/util/util'
import {clearGtfsContent, saveActiveGtfsEntity, setActiveGtfsEntity} from './active'
import {ENTITY} from '../constants'
import {
generateNullProps,
Expand All @@ -17,7 +16,6 @@ import {
getTableById
} from '../util/gtfs'
import {fetchGTFSEntities} from '../../manager/actions/versions'

import type {
dispatchFn,
getStateFn,
Expand All @@ -26,6 +24,8 @@ import type {
LockState
} from '../../types/reducers'

import {clearGtfsContent, saveActiveGtfsEntity, setActiveGtfsEntity} from './active'

export const updateEntitySort = createAction('UPDATE_ENTITY_SORT')

const createGtfsEntity = createAction(
Expand Down Expand Up @@ -384,6 +384,9 @@ export function fetchBaseGtfs ({
feed_version
default_route_color
default_route_type
default_lang
feed_contact_url
feed_contact_email
}
agency (limit: -1) {
id
Expand Down
15 changes: 12 additions & 3 deletions lib/editor/actions/trip.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
// @flow

import clone from 'lodash/cloneDeep'
import {createAction, type ActionType} from 'redux-actions'

import {snakeCaseKeys} from '../../common/util/map-keys'
import {createVoidPayloadAction, fetchGraphQL, secureFetch} from '../../common/actions'
import {setErrorMessage} from '../../manager/actions/status'
import {entityIsNew} from '../util/objects'
import {getEditorNamespace} from '../util/gtfs'

import type {Pattern, TimetableColumn, Trip} from '../../types'
import type {dispatchFn, getStateFn, TripCounts} from '../../types/reducers'

Expand Down Expand Up @@ -159,11 +158,21 @@ export function saveTripsForCalendar (
trips = trips.map(snakeCaseKeys)
return Promise.all(trips.filter(t => t).map((trip, index) => {
const tripExists = !entityIsNew(trip) && trip.id !== null
const tripCopy: any = clone((trip: any))
// Add default value to continuous pickup if not provided
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add comment saying editing continuous pickup/drop off is not currently supported in the schedule editor.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added in c48bb18

// Editing continuous pickup/drop off is not currently supported in the schedule editor
const defaults = {
continuous_pickup: 1,
continuous_drop_off: 1
}
tripCopy.stop_times = tripCopy.stop_times.map((stopTime, index) => {
return {...defaults, ...(stopTime: any)}
})
const method = tripExists ? 'put' : 'post'
const url = tripExists && trip.id
? `/api/editor/secure/trip/${trip.id}?feedId=${feedId}&sessionId=${sessionId}`
: `/api/editor/secure/trip?feedId=${feedId}&sessionId=${sessionId}`
return dispatch(secureFetch(url, method, trip))
return dispatch(secureFetch(url, method, tripCopy))
.then(res => res.json())
.catch(err => {
console.warn(err)
Expand Down