1
1
import { connect } from 'react-redux'
2
2
3
3
import GtfsEditor from '../components/GtfsEditor'
4
- import { ENTITY } from '../constants'
5
4
import { fetchFeedSourceAndProject } from '../../manager/actions/feeds'
6
5
import {
7
6
fetchTripPatternsForRoute ,
@@ -45,37 +44,32 @@ import {updateUserMetadata} from '../../manager/actions/user'
45
44
import { findProjectByFeedSource } from '../../manager/util'
46
45
import { setTutorialHidden } from '../../manager/actions/ui'
47
46
import { getControlPoints , getValidationErrors } from '../selectors'
48
- import { getTableById } from '../util/gtfs'
47
+ import { getTableById , getIdsFromParams } from '../util/gtfs'
49
48
50
49
const mapStateToProps = ( state , ownProps ) => {
51
50
const {
52
51
feedSourceId,
53
52
activeComponent,
54
53
subComponent,
55
54
subSubComponent,
56
- // activeEntityId,
57
- // subEntityId,
58
55
activeSubSubEntity
59
56
} = ownProps . routeParams
60
- // TODO: Figure out a better way to parse an integer from react-router route
61
- // params
62
57
// 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 )
65
59
const { data, editSettings : editSettingsState , mapState} = state . editor
66
60
const { present : editSettings } = editSettingsState
67
61
const { active, tables, tripPatterns, status} = data
68
62
// FIXME: entityId is now a non-string line number and somewhere the number is
69
63
// 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'
72
67
? active . entity
73
- : active . entity && activeComponent === 'feedinfo' ? active . entity : null
68
+ : null
74
69
const activePattern = active . subEntity
75
70
const entityEdited = active . edited
76
71
const patternEdited = Boolean ( active . patternEdited )
77
72
const { controlPoints, patternSegments : patternCoordinates } = getControlPoints ( state )
78
- // console.log('pattern segments', patternCoordinates)
79
73
const tableView = ownProps . location . query && ownProps . location . query . table === 'true'
80
74
// Active set of entities (e.g., stops, routes, agency)
81
75
const entities = activeComponent && getTableById ( tables , activeComponent )
@@ -86,6 +80,7 @@ const mapStateToProps = (state, ownProps) => {
86
80
// find the containing project
87
81
const project = findProjectByFeedSource ( state . projects . all , feedSourceId )
88
82
const feedSource = project && project . feedSources . find ( fs => fs . id === feedSourceId )
83
+ const namespace = feedSource && feedSource . editorNamespace
89
84
90
85
const feedInfo = getTableById ( tables , 'feedinfo' ) [ 0 ]
91
86
const patternStop = active . patternStop || { }
@@ -100,6 +95,7 @@ const mapStateToProps = (state, ownProps) => {
100
95
feedSource,
101
96
entities,
102
97
feedSourceId,
98
+ namespace,
103
99
feedInfo,
104
100
entityEdited,
105
101
tableView,
@@ -133,16 +129,10 @@ const mapDispatchToProps = (dispatch, ownProps) => {
133
129
activeComponent,
134
130
subComponent,
135
131
subSubComponent,
136
- // activeEntityId,
137
- // subEntityId,
138
132
activeSubSubEntity
139
133
} = 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 )
146
136
const props = {
147
137
component : activeComponent ,
148
138
newId : activeEntityId ,
@@ -171,18 +161,15 @@ const mapDispatchToProps = (dispatch, ownProps) => {
171
161
}
172
162
} ,
173
163
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 ||
177
167
prevProps . activeEntityId !== newProps . activeEntityId ||
178
168
prevProps . subComponent !== newProps . subComponent ||
179
169
prevProps . subEntityId !== newProps . subEntityId ||
180
170
prevProps . subSubComponent !== newProps . subSubComponent ||
181
- prevProps . activeSubSubEntity !== newProps . activeSubSubEntity )
171
+ prevProps . activeSubSubEntity !== newProps . activeSubSubEntity
182
172
) {
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.
186
173
dispatch ( setActiveGtfsEntity ( feedSourceId , activeComponent , activeEntityId , subComponent , subEntityId , subSubComponent , activeSubSubEntity ) )
187
174
}
188
175
} ,
0 commit comments