11import { connect } from 'react-redux'
22
33import GtfsEditor from '../components/GtfsEditor'
4- import { ENTITY } from '../constants'
54import { fetchFeedSourceAndProject } from '../../manager/actions/feeds'
65import {
76 fetchTripPatternsForRoute ,
@@ -45,37 +44,32 @@ import {updateUserMetadata} from '../../manager/actions/user'
4544import { findProjectByFeedSource } from '../../manager/util'
4645import { setTutorialHidden } from '../../manager/actions/ui'
4746import { getControlPoints , getValidationErrors } from '../selectors'
48- import { getTableById } from '../util/gtfs'
47+ import { getTableById , getIdsFromParams } from '../util/gtfs'
4948
5049const mapStateToProps = ( state , ownProps ) => {
5150 const {
5251 feedSourceId,
5352 activeComponent,
5453 subComponent,
5554 subSubComponent,
56- // activeEntityId,
57- // subEntityId,
5855 activeSubSubEntity
5956 } = ownProps . routeParams
60- // TODO: Figure out a better way to parse an integer from react-router route
61- // params
6257 // Cast IDs to integers to match data type of fields returned by the SQL database
63- const activeEntityId = typeof ownProps . routeParams . activeEntityId !== 'undefined' ? + ownProps . routeParams . activeEntityId : undefined
64- const subEntityId = typeof ownProps . routeParams . subEntityId !== 'undefined' ? + ownProps . routeParams . subEntityId : undefined
58+ const { activeEntityId, subEntityId} = getIdsFromParams ( ownProps . routeParams )
6559 const { data, editSettings : editSettingsState , mapState} = state . editor
6660 const { present : editSettings } = editSettingsState
6761 const { active, tables, tripPatterns, status} = data
6862 // FIXME: entityId is now a non-string line number and somewhere the number is
6963 // being cast to a string.
70- const activeEntity =
71- active . entity && active . entity . id === activeEntityId
64+ const activeEntity = active . entity && active . entity . id === activeEntityId
65+ ? active . entity
66+ : active . entity && activeComponent === 'feedinfo'
7267 ? active . entity
73- : active . entity && activeComponent === 'feedinfo' ? active . entity : null
68+ : null
7469 const activePattern = active . subEntity
7570 const entityEdited = active . edited
7671 const patternEdited = Boolean ( active . patternEdited )
7772 const { controlPoints, patternSegments : patternCoordinates } = getControlPoints ( state )
78- // console.log('pattern segments', patternCoordinates)
7973 const tableView = ownProps . location . query && ownProps . location . query . table === 'true'
8074 // Active set of entities (e.g., stops, routes, agency)
8175 const entities = activeComponent && getTableById ( tables , activeComponent )
@@ -86,6 +80,7 @@ const mapStateToProps = (state, ownProps) => {
8680 // find the containing project
8781 const project = findProjectByFeedSource ( state . projects . all , feedSourceId )
8882 const feedSource = project && project . feedSources . find ( fs => fs . id === feedSourceId )
83+ const namespace = feedSource && feedSource . editorNamespace
8984
9085 const feedInfo = getTableById ( tables , 'feedinfo' ) [ 0 ]
9186 const patternStop = active . patternStop || { }
@@ -100,6 +95,7 @@ const mapStateToProps = (state, ownProps) => {
10095 feedSource,
10196 entities,
10297 feedSourceId,
98+ namespace,
10399 feedInfo,
104100 entityEdited,
105101 tableView,
@@ -133,16 +129,10 @@ const mapDispatchToProps = (dispatch, ownProps) => {
133129 activeComponent,
134130 subComponent,
135131 subSubComponent,
136- // activeEntityId,
137- // subEntityId,
138132 activeSubSubEntity
139133 } = ownProps . routeParams
140- // console.log(ownProps.routeParams)
141- // TODO: Figure out a better way to parse an integer from react-router route
142- // params
143- // FIXME: handle "new" entityId route
144- const activeEntityId = typeof ownProps . routeParams . activeEntityId !== 'undefined' ? + ownProps . routeParams . activeEntityId : undefined
145- const subEntityId = typeof ownProps . routeParams . subEntityId !== 'undefined' ? + ownProps . routeParams . subEntityId : undefined
134+ // Parse IDs from route params
135+ const { activeEntityId, subEntityId} = getIdsFromParams ( ownProps . routeParams )
146136 const props = {
147137 component : activeComponent ,
148138 newId : activeEntityId ,
@@ -171,18 +161,15 @@ const mapDispatchToProps = (dispatch, ownProps) => {
171161 }
172162 } ,
173163 onComponentUpdate : ( prevProps , newProps ) => {
174- // handle back button presses by re-setting active gtfs entity
175- if ( prevProps . activeEntityId !== ENTITY . NEW_ID &&
176- ( prevProps . activeComponent !== newProps . activeComponent ||
164+ // Detect push changes to URL (e.g., back button or direct link) and update
165+ // active table/entity accordingly.
166+ if ( prevProps . activeComponent !== newProps . activeComponent ||
177167 prevProps . activeEntityId !== newProps . activeEntityId ||
178168 prevProps . subComponent !== newProps . subComponent ||
179169 prevProps . subEntityId !== newProps . subEntityId ||
180170 prevProps . subSubComponent !== newProps . subSubComponent ||
181- prevProps . activeSubSubEntity !== newProps . activeSubSubEntity )
171+ prevProps . activeSubSubEntity !== newProps . activeSubSubEntity
182172 ) {
183- console . log ( 'handling back button' , activeEntityId , subEntityId )
184- // FIXME: handle infinite loop case when, for example, entity ID is bad
185- // or is not found.
186173 dispatch ( setActiveGtfsEntity ( feedSourceId , activeComponent , activeEntityId , subComponent , subEntityId , subSubComponent , activeSubSubEntity ) )
187174 }
188175 } ,
0 commit comments