Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
10 changes: 9 additions & 1 deletion lib/editor/actions/trip.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {createVoidPayloadAction, fetchGraphQL, secureFetch} from '../../common/a
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,6 +158,15 @@ 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 = (trip: any)
Copy link
Contributor

Choose a reason for hiding this comment

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

I would clone it (otherwise you are improperly overwrite data).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Cloned in c48bb18

// 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

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}`
Expand Down