@@ -197,7 +197,7 @@ export function newGtfsEntities (feedSourceId, component, propsArray, save) {
197
197
}
198
198
}
199
199
200
- export function newGtfsEntity ( feedSourceId , component , props , save ) {
200
+ export function newGtfsEntity ( feedSourceId , component , props , save , refetch = true ) {
201
201
return function ( dispatch , getState ) {
202
202
if ( ! props ) {
203
203
props = generateProps ( component , getState ( ) . editor )
@@ -208,7 +208,7 @@ export function newGtfsEntity (feedSourceId, component, props, save) {
208
208
...props
209
209
}
210
210
if ( save ) {
211
- return dispatch ( saveActiveGtfsEntity ( component , props ) )
211
+ return dispatch ( saveActiveGtfsEntity ( component , props , refetch ) )
212
212
} else {
213
213
dispatch ( createGtfsEntity ( feedSourceId , component , props ) )
214
214
if ( props && 'routeId' in props ) {
@@ -300,30 +300,36 @@ export function fetchBaseGtfs ({namespace, component, newId, activeEntityId, fee
300
300
}
301
301
`
302
302
// 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
+ }
328
334
}
329
335
}
0 commit comments