Skip to content

Commit b705a1a

Browse files
correct flow issues (non location group)
1 parent e5ec45b commit b705a1a

File tree

18 files changed

+48
-23
lines changed

18 files changed

+48
-23
lines changed

lib/editor/actions/location.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {getMapFromGtfsStrategy, entityIsNew} from '../util/objects'
44
import { getEditorNamespace } from '../util/gtfs'
55
import {fetchGTFSEntities} from '../../manager/actions/versions'
66
import type {dispatchFn, getStateFn} from '../../types/reducers'
7-
import type {GtfsLocationGroup} from '../../types'
7+
import type {GtfsLocation} from '../../types'
88

99
import { receivedNewEntity, savedGtfsEntity } from './active'
1010

lib/editor/actions/map/stopStrategies.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import lineSlice from 'turf-line-slice'
99
import lineString from 'turf-linestring'
1010
import point from 'turf-point'
1111
import turfPolygon from 'turf-polygon'
12+
// $FlowFixMe flow doesn't understand new packages
1213
import centerOfMass from '@turf/center-of-mass'
1314

1415
import {updateActiveGtfsEntity, saveActiveGtfsEntity} from '../active'
@@ -230,7 +231,7 @@ export function addStopAtInterval (latlng: LatLng, activePattern: Pattern, contr
230231
}
231232
}
232233

233-
export function addStopToPattern (pattern: Pattern, stop: GtfsStop | GtfsLocation, index?: ?number) {
234+
export function addStopToPattern (pattern: Pattern, origStop: GtfsStop | GtfsLocation, index?: ?number) {
234235
// eslint-disable-next-line complexity
235236
return async function (dispatch: dispatchFn, getState: getStateFn) {
236237
const {data, editSettings} = getState().editor
@@ -243,6 +244,9 @@ export function addStopToPattern (pattern: Pattern, stop: GtfsStop | GtfsLocatio
243244
const {controlPoints, patternSegments} = getControlPoints(getState())
244245
const hasShapePoints = shapePoints && shapePoints.length > 1
245246

247+
// $FlowFixMe this is a bit of a hack to get locations to work with methods built for stops. We do the work required to have all methods work.
248+
const stop: GtfsStop = clone(origStop)
249+
246250
if (stop.stop_id === undefined || stop.stop_id === null) {
247251
// convert stop to turf polygon
248252
const polygon = stop.location_shapes.map(ls => [ls.geometry_pt_lat, ls.geometry_pt_lon])
@@ -306,7 +310,7 @@ export function addStopToPattern (pattern: Pattern, stop: GtfsStop | GtfsLocatio
306310
const locationgroups = getTableById(data.tables, 'locationgroup')
307311
const previousStop = stops.find(s => s.stop_id === previousStopId) || locations.find(s => s.location_id === previousStopId) || locationgroups.find(s => s.location_group_id === previousStopId)
308312
if (!previousStop) {
309-
throw new Error(`Stop not found for stop_id ${previousStopId}.`)
313+
throw new Error(`Stop not found for stop_id ${previousStopId || '(no previous stop id)'}.`)
310314
}
311315
const points = [previousStop, stop]
312316
.map((stop, index) => ({lng: stop.stop_lon, lat: stop.stop_lat}))
@@ -551,6 +555,7 @@ export function removeStopFromPattern (pattern: Pattern, stop: GtfsLocation | Gt
551555
const clonedControlPoints = clone(controlPoints)
552556
const clonedPatternSegments = clone(patternSegments)
553557
const {shapePoints, patternStops} = pattern
558+
// $FlowFixMe Flow doesn't understand this property check
554559
const stopIsStop = stop.hasOwnProperty('stopId') && stop.stopId !== null
555560
// Use control points to determine control point index for removed stop.
556561
// This is distinct from the index arg supplied because there may be more

lib/editor/actions/trip.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export const updateCellValue = createAction(
6363
(payload: {
6464
key: string,
6565
rowIndex: number,
66-
value: ?(number | string | { stopId: string })
66+
value: ?(number | string | { stopId: ?string })
6767
}) => payload
6868
)
6969

lib/editor/actions/tripPattern.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {fetchGTFSEntities, receiveGTFSEntities} from '../../manager/actions/vers
1212
import {getEditorNamespace} from '../util/gtfs'
1313
import {resequenceShapePoints, resequenceStops} from '../util/map'
1414
import {entityIsNew} from '../util/objects'
15-
import type { ControlPoint, Pattern } from '../../types'
15+
import type { ControlPoint, Pattern, PatternStop } from '../../types'
1616
import type {dispatchFn, getStateFn} from '../../types/reducers'
1717

1818
import {fetchTripCounts} from './trip'

lib/editor/components/map/PatternStopsLayer.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ export default class PatternStopsLayer extends Component<Props> {
9494
}
9595
if (
9696
editSettings.hideInactiveSegments &&
97+
cpIndex &&
9798
(cpIndex > patternSegment + 1 || cpIndex < patternSegment - 1)
9899
) {
99100
// Do not render pattern stop if hiding inactive segments and
@@ -131,6 +132,7 @@ export default class PatternStopsLayer extends Component<Props> {
131132
location={location}
132133
setActiveStop={setActiveStop}
133134
// fallback to index if/when id changes
135+
// $FlowFixMe
134136
ref={`${patternStop.id || patternStop.locationId || patternStop.locationGroupId}`}
135137
removeStopFromPattern={removeStopFromPattern}
136138
stop={stop}

lib/editor/components/pattern/AddPatternStopDropdown.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import React, {Component} from 'react'
55
import { Button, Dropdown, MenuItem } from 'react-bootstrap'
66

77
import * as stopStrategiesActions from '../../actions/map/stopStrategies'
8-
import type {GtfsLocation, GtfsStop, Pattern, Style} from '../../../types'
8+
import type {GtfsLocation, GtfsStop, Pattern, Style, PatternStop} from '../../../types'
99

1010
type Props = {
1111
activePattern: Pattern,

lib/editor/components/pattern/EditShapePanel.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ export default class EditShapePanel extends Component<Props> {
100100
.map((s, index) => {
101101
const stop = stops.find(st => st.stop_id === s.stopId)
102102
if (!stop) {
103-
console.warn(`Could not locate stop with stop_id=${s.stopId}`)
103+
console.warn(`Could not locate stop with stop_id=${s.stopId || '(no stop id found)'}`)
104104
return {lng: 0, lat: 0}
105105
}
106106
return {lng: stop.stop_lon, lat: stop.stop_lat}

lib/editor/components/pattern/PatternStopCard.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ import * as tripPatternActions from '../../actions/tripPattern'
2222
import { getEntityName, getAbbreviatedStopName, getTableById } from '../../util/gtfs'
2323
import MinuteSecondInput from '../MinuteSecondInput'
2424
import { getComponentMessages, getGtfsSpecField } from '../../../common/util/config'
25-
import type { Feed, Pattern } from '../../../types'
26-
import type { AppState, RouterProps } from '../../../types/reducers'
25+
import type { Feed, Pattern, PatternStop } from '../../../types'
26+
import type { EditorTables, AppState, RouterProps } from '../../../types/reducers'
2727

2828
import NormalizeStopTimesTip from './NormalizeStopTimesTip'
2929
import PatternStopButtons from './PatternStopButtons'
@@ -199,6 +199,7 @@ class PatternStopCard extends Component<Props> {
199199
_formatTravelTime (cumulativeTravelTime, patternStop) {
200200
if (!patternStop.defaultTravelTime || !patternStop.defaultDwellTime) return
201201

202+
// $FlowFixMe Flow doesn't understand our type check above
202203
return `${Math.round(cumulativeTravelTime / 60)} (+${Math.round(patternStop.defaultTravelTime / 60)}${patternStop.defaultDwellTime > 0 ? ` +${Math.round(patternStop.defaultDwellTime / 60)}` : ''})`
203204
}
204205

@@ -241,6 +242,7 @@ class PatternStopCard extends Component<Props> {
241242
if (patternStop.locationId !== null || patternStop.locationGroupId !== null) {
242243
cardBackground = 'hsla(187, 84%, 87%, 0.5)'
243244
}
245+
// $FlowFixMe flexDefaultTravelTime doens't exist on a PatternStop, which is the point of this check
244246
if ((!patternStop.defaultTravelTime && !patternStop.flexDefaultTravelTime) && index !== 0) {
245247
cardBackground = 'hsla(35, 84%, 87%, 1)'
246248
}
@@ -300,15 +302,15 @@ class PatternStopContents extends Component<Props, State> {
300302

301303
if (patternStop.stopId !== null) {
302304
this.setState({
303-
initialDwellTime: patternStop.defaultDwellTime,
304-
initialTravelTime: patternStop.defaultTravelTime,
305+
initialDwellTime: patternStop.defaultDwellTime || undefined,
306+
initialTravelTime: patternStop.defaultTravelTime || undefined,
305307
update: false
306308
})
307309
} else {
308310
// If patternStop is not a fixed stop, it is a flex location/location group.
309311
this.setState({
310-
defaultDwellTime: patternStop.defaultDwellTime,
311-
defaultTravelTime: patternStop.defaultTravelTime,
312+
defaultDwellTime: patternStop.defaultDwellTime || undefined,
313+
defaultTravelTime: patternStop.defaultTravelTime || undefined,
312314
update: false
313315
})
314316
}

lib/editor/components/pattern/PatternStopContainer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import HTML5Backend from 'react-dnd-html5-backend'
99
import * as activeActions from '../../actions/active'
1010
import * as stopStrategiesActions from '../../actions/map/stopStrategies'
1111
import * as tripPatternActions from '../../actions/tripPattern'
12-
import type {GtfsLocation, GtfsStop, Feed, Pattern} from '../../../types'
12+
import type {GtfsLocation, GtfsStop, Feed, Pattern, PatternStop} from '../../../types'
1313

1414
import PatternStopCard from './PatternStopCard'
1515

lib/editor/components/timetable/TimetableGrid.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ import {
2828
WRAPPER_STYLE
2929
} from '../../util/timetable'
3030
import type {Pattern, TimetableColumn} from '../../../types'
31+
import type { TimetableState } from '../../../types/reducers'
32+
import type {TripValidationIssues} from '../../../editor/selectors/timetable'
3133

3234
import EditableCell from './EditableCell'
3335
import HeaderCell from './HeaderCell'

0 commit comments

Comments
 (0)