Skip to content

Commit e204e04

Browse files
committed
fix(editor): fix entity type checks using field typeof
1 parent 23acc18 commit e204e04

File tree

1 file changed

+10
-75
lines changed

1 file changed

+10
-75
lines changed

lib/editor/util/gtfs.js

Lines changed: 10 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -255,25 +255,26 @@ export function getEntityName (entity: ?Entity): string {
255255
return '[Unnamed]'
256256
}
257257

258-
let nameKey: string = '[Unnamed]'
258+
let nameKey: string = 'name'
259259

260-
if (entity.route_id) {
260+
// FIXME: Checking for undefined fields to assert entity type doesn't work so
261+
// well with GraphQL.
262+
if (typeof entity.route_id !== 'undefined') {
261263
nameKey = 'route_short_name'
262-
} else if (entity.patternStops) {
264+
} else if (typeof entity.patternStops !== 'undefined') {
263265
nameKey = 'name'
264-
} else if (entity.agency_name) {
266+
} else if (typeof entity.agency_name !== 'undefined') {
265267
nameKey = 'agency_name'
266-
} else if (entity.stop_id) {
268+
} else if (typeof entity.stop_id !== 'undefined') {
267269
nameKey = 'stop_name'
268-
} else if (entity.service_id) {
270+
} else if (typeof entity.service_id !== 'undefined') {
269271
nameKey = 'description'
270-
} else if (entity.fare_id) {
272+
} else if (typeof entity.fare_id !== 'undefined') {
271273
nameKey = 'fare_id'
272-
} else if (entity.exemplar) {
274+
} else if (typeof entity.exemplar !== 'undefined') {
273275
nameKey = 'name'
274276
}
275277

276-
// if (nameKey !== 'stop_name') console.log(nameKey)
277278
switch (nameKey) {
278279
case 'stop_name':
279280
const stop: GtfsStop = ((entity: any): GtfsStop)
@@ -319,72 +320,6 @@ export function getAbbreviatedStopName (stop: GtfsStop, maxCharactersPerWord: nu
319320
: stop.stop_name
320321
}
321322

322-
// export function getControlPoints (
323-
// pattern: ?any,
324-
// stops: any,
325-
// snapToStops: boolean
326-
// ): Array<ControlPoint> {
327-
// if (pattern || !pattern || !pattern.shape || !pattern.patternStops) {
328-
// return []
329-
// }
330-
//
331-
// const controlPoints = []
332-
// const {patternStops, shape, shapePoints} = pattern
333-
// const hasShapePoints = shapePoints.length > 0
334-
// patternStops.map(ps => {
335-
// const stop = stops && stops.find(st => st.stop_id === ps.stopId)
336-
// if (!stop) console.warn(`No stop found for pattern stop ID: ${ps.stopId}`, stops)
337-
// return [stop.stop_lon, stop.stop_lat]//, ShapePoint.STOP]
338-
// })
339-
// if (hasShapePoints) {
340-
// if (patternStops[0] && patternStops[0].shapeDistTraveled === null) {
341-
// // if distance values are null, calculate distance values.
342-
// // FIXME
343-
// // calculateShapeDistTraveled(pattern, stops)
344-
// naiveShapeDistTraveled(pattern, stops)
345-
// } else {
346-
// // FIXME: this should be moved out of the else clause
347-
// // Add projected stops at shape dist traveled for pattern stops
348-
// for (var i = 0; i < patternStops.length; i++) {
349-
// const patternStop = patternStops[i]
350-
// // const next = patternStops[i + 1]
351-
// // set distance to average of patternStop and next patternStop, if last stop set to end of segment
352-
// const distance = patternStop.shapeDistTraveled
353-
// const point = along(lineString, distance, {units: 'meters'})
354-
// }
355-
// }
356-
// }
357-
// try {
358-
// patternStops.map((patternStop: PatternStop, index) => {
359-
// // set distance to average of patternStop and next patternStop, if last stop set to end of segment
360-
// const distance = patternStops[index + 1]
361-
// ? (patternStops[index + 1].shapeDistTraveled +
362-
// patternStop.shapeDistTraveled) /
363-
// 2
364-
// : lineDistance(shape, 'meters')
365-
// const point = along(shape, distance, {units: 'meters'})
366-
// const controlPoint = newControlPoint(distance, point, true)
367-
// const stopPoint = along(shape, patternStop.shapeDistTraveled, {units: 'meters'})
368-
// const stopControl = newControlPoint(
369-
// patternStop.shapeDistTraveled,
370-
// stopPoint,
371-
// true,
372-
// patternStop
373-
// )
374-
// if (snapToStops) {
375-
// stopControl.hidden = true
376-
// }
377-
// controlPoints.push(stopControl)
378-
// controlPoints.push(controlPoint)
379-
// })
380-
//
381-
// return controlPoints
382-
// } catch (e) {
383-
// console.error('Error constructing control points', e)
384-
// return []
385-
// }
386-
// }
387-
388323
export function getRouteNameAlerts (route: GtfsRoute): string | null {
389324
const routeName =
390325
route.route_short_name && route.route_long_name

0 commit comments

Comments
 (0)