-
Notifications
You must be signed in to change notification settings - Fork 88
fix(saveEntity, saveTripsForCalendar): Resolve missing defaults with GTFS spec changes #720
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
548fb24
c48bb18
cda4f65
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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, | ||
|
|
@@ -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' | ||
|
|
||
| export const clearGtfsContent = createVoidPayloadAction('CLEAR_GTFSEDITOR_CONTENT') | ||
| const receivedNewEntity = createAction( | ||
| 'RECEIVE_NEW_ENTITY', | ||
|
|
@@ -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
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 => { | ||
|
|
||
| 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' | ||
|
|
||
|
|
@@ -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 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
|
|
||
There was a problem hiding this comment.
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 typeor is this something prettier automatically format?There was a problem hiding this comment.
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