Skip to content

Commit

Permalink
fix(editor): add refetch option to create GTFS entity method
Browse files Browse the repository at this point in the history
  • Loading branch information
landonreed committed Feb 22, 2018
1 parent 87dc6ab commit 5366bf0
Showing 1 changed file with 33 additions and 27 deletions.
60 changes: 33 additions & 27 deletions lib/editor/actions/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ export function newGtfsEntities (feedSourceId, component, propsArray, save) {
}
}

export function newGtfsEntity (feedSourceId, component, props, save) {
export function newGtfsEntity (feedSourceId, component, props, save, refetch = true) {
return function (dispatch, getState) {
if (!props) {
props = generateProps(component, getState().editor)
Expand All @@ -208,7 +208,7 @@ export function newGtfsEntity (feedSourceId, component, props, save) {
...props
}
if (save) {
return dispatch(saveActiveGtfsEntity(component, props))
return dispatch(saveActiveGtfsEntity(component, props, refetch))
} else {
dispatch(createGtfsEntity(feedSourceId, component, props))
if (props && 'routeId' in props) {
Expand Down Expand Up @@ -300,30 +300,36 @@ export function fetchBaseGtfs ({namespace, component, newId, activeEntityId, fee
}
`
// TODO: fetch patterns / subcomponent in nested query?
return dispatch(lockEditorFeedSource(feedSourceId))
.then(lockSuccess => {
if (!lockSuccess) {
console.warn('No lock on editor. Canceling feed fetch')
dispatch(setEditorCheckIn({feedId: null, sessionId: null, timer: null, timestamp: null}))
browserHistory.push(`/feed/${feedSourceId}/edit`)
return
}
dispatch(fetchingBaseGtfs({namespace}))
if (!namespace) {
console.error('Cannot fetch GTFS for undefined or null namespace')
dispatch(showEditorModal())
return
}
return dispatch(fetchGraphQL({query, variables: {namespace}}))
.then(res => res.json())
.then(data => dispatch(receiveBaseGtfs({...data})))
// FIXME? Setting active entity is currently done after fetching base GTFS
// (in a separate action). Maybe we want to combine that step here.
// .then(() => {
// console.log('setting active after fetch', component, newId)
// dispatch(dispatch(setActiveGtfsEntity(feedSourceId, component, newId, subComponent, subEntityId, subSubComponent, activeSubSubEntity)))
// })
// .catch(err => console.log(err))
})
if (!getState().editor.data.lock.sessionId) {
return dispatch(lockEditorFeedSource(feedSourceId))
.then(lockSuccess => {
if (!lockSuccess) {
console.warn('No lock on editor. Canceling feed fetch')
dispatch(setEditorCheckIn({feedId: null, sessionId: null, timer: null, timestamp: null}))
browserHistory.push(`/feed/${feedSourceId}/edit`)
return
}
dispatch(fetchingBaseGtfs({namespace}))
if (!namespace) {
console.error('Cannot fetch GTFS for undefined or null namespace')
dispatch(showEditorModal())
return
}
return dispatch(fetchGraphQL({query, variables: {namespace}}))
.then(res => res.json())
.then(data => dispatch(receiveBaseGtfs({...data})))
})
} else {
// If there is already a session lock, skip trying to create another.
dispatch(fetchingBaseGtfs({namespace}))
if (!namespace) {
console.error('Cannot fetch GTFS for undefined or null namespace')
dispatch(showEditorModal())
return
}
return dispatch(fetchGraphQL({query, variables: {namespace}}))
.then(res => res.json())
.then(data => dispatch(receiveBaseGtfs({...data})))
}
}
}

0 comments on commit 5366bf0

Please sign in to comment.