Skip to content

Commit 5366bf0

Browse files
committed
fix(editor): add refetch option to create GTFS entity method
1 parent 87dc6ab commit 5366bf0

File tree

1 file changed

+33
-27
lines changed

1 file changed

+33
-27
lines changed

lib/editor/actions/editor.js

Lines changed: 33 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ export function newGtfsEntities (feedSourceId, component, propsArray, save) {
197197
}
198198
}
199199

200-
export function newGtfsEntity (feedSourceId, component, props, save) {
200+
export function newGtfsEntity (feedSourceId, component, props, save, refetch = true) {
201201
return function (dispatch, getState) {
202202
if (!props) {
203203
props = generateProps(component, getState().editor)
@@ -208,7 +208,7 @@ export function newGtfsEntity (feedSourceId, component, props, save) {
208208
...props
209209
}
210210
if (save) {
211-
return dispatch(saveActiveGtfsEntity(component, props))
211+
return dispatch(saveActiveGtfsEntity(component, props, refetch))
212212
} else {
213213
dispatch(createGtfsEntity(feedSourceId, component, props))
214214
if (props && 'routeId' in props) {
@@ -300,30 +300,36 @@ export function fetchBaseGtfs ({namespace, component, newId, activeEntityId, fee
300300
}
301301
`
302302
// TODO: fetch patterns / subcomponent in nested query?
303-
return dispatch(lockEditorFeedSource(feedSourceId))
304-
.then(lockSuccess => {
305-
if (!lockSuccess) {
306-
console.warn('No lock on editor. Canceling feed fetch')
307-
dispatch(setEditorCheckIn({feedId: null, sessionId: null, timer: null, timestamp: null}))
308-
browserHistory.push(`/feed/${feedSourceId}/edit`)
309-
return
310-
}
311-
dispatch(fetchingBaseGtfs({namespace}))
312-
if (!namespace) {
313-
console.error('Cannot fetch GTFS for undefined or null namespace')
314-
dispatch(showEditorModal())
315-
return
316-
}
317-
return dispatch(fetchGraphQL({query, variables: {namespace}}))
318-
.then(res => res.json())
319-
.then(data => dispatch(receiveBaseGtfs({...data})))
320-
// FIXME? Setting active entity is currently done after fetching base GTFS
321-
// (in a separate action). Maybe we want to combine that step here.
322-
// .then(() => {
323-
// console.log('setting active after fetch', component, newId)
324-
// dispatch(dispatch(setActiveGtfsEntity(feedSourceId, component, newId, subComponent, subEntityId, subSubComponent, activeSubSubEntity)))
325-
// })
326-
// .catch(err => console.log(err))
327-
})
303+
if (!getState().editor.data.lock.sessionId) {
304+
return dispatch(lockEditorFeedSource(feedSourceId))
305+
.then(lockSuccess => {
306+
if (!lockSuccess) {
307+
console.warn('No lock on editor. Canceling feed fetch')
308+
dispatch(setEditorCheckIn({feedId: null, sessionId: null, timer: null, timestamp: null}))
309+
browserHistory.push(`/feed/${feedSourceId}/edit`)
310+
return
311+
}
312+
dispatch(fetchingBaseGtfs({namespace}))
313+
if (!namespace) {
314+
console.error('Cannot fetch GTFS for undefined or null namespace')
315+
dispatch(showEditorModal())
316+
return
317+
}
318+
return dispatch(fetchGraphQL({query, variables: {namespace}}))
319+
.then(res => res.json())
320+
.then(data => dispatch(receiveBaseGtfs({...data})))
321+
})
322+
} else {
323+
// If there is already a session lock, skip trying to create another.
324+
dispatch(fetchingBaseGtfs({namespace}))
325+
if (!namespace) {
326+
console.error('Cannot fetch GTFS for undefined or null namespace')
327+
dispatch(showEditorModal())
328+
return
329+
}
330+
return dispatch(fetchGraphQL({query, variables: {namespace}}))
331+
.then(res => res.json())
332+
.then(data => dispatch(receiveBaseGtfs({...data})))
333+
}
328334
}
329335
}

0 commit comments

Comments
 (0)