Skip to content

Commit

Permalink
fix(editor): fix entity type checks using field typeof
Browse files Browse the repository at this point in the history
  • Loading branch information
landonreed committed Mar 6, 2018
1 parent 23acc18 commit e204e04
Showing 1 changed file with 10 additions and 75 deletions.
85 changes: 10 additions & 75 deletions lib/editor/util/gtfs.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,25 +255,26 @@ export function getEntityName (entity: ?Entity): string {
return '[Unnamed]'
}

let nameKey: string = '[Unnamed]'
let nameKey: string = 'name'

if (entity.route_id) {
// FIXME: Checking for undefined fields to assert entity type doesn't work so
// well with GraphQL.
if (typeof entity.route_id !== 'undefined') {
nameKey = 'route_short_name'
} else if (entity.patternStops) {
} else if (typeof entity.patternStops !== 'undefined') {
nameKey = 'name'
} else if (entity.agency_name) {
} else if (typeof entity.agency_name !== 'undefined') {
nameKey = 'agency_name'
} else if (entity.stop_id) {
} else if (typeof entity.stop_id !== 'undefined') {
nameKey = 'stop_name'
} else if (entity.service_id) {
} else if (typeof entity.service_id !== 'undefined') {
nameKey = 'description'
} else if (entity.fare_id) {
} else if (typeof entity.fare_id !== 'undefined') {
nameKey = 'fare_id'
} else if (entity.exemplar) {
} else if (typeof entity.exemplar !== 'undefined') {
nameKey = 'name'
}

// if (nameKey !== 'stop_name') console.log(nameKey)
switch (nameKey) {
case 'stop_name':
const stop: GtfsStop = ((entity: any): GtfsStop)
Expand Down Expand Up @@ -319,72 +320,6 @@ export function getAbbreviatedStopName (stop: GtfsStop, maxCharactersPerWord: nu
: stop.stop_name
}

// export function getControlPoints (
// pattern: ?any,
// stops: any,
// snapToStops: boolean
// ): Array<ControlPoint> {
// if (pattern || !pattern || !pattern.shape || !pattern.patternStops) {
// return []
// }
//
// const controlPoints = []
// const {patternStops, shape, shapePoints} = pattern
// const hasShapePoints = shapePoints.length > 0
// patternStops.map(ps => {
// const stop = stops && stops.find(st => st.stop_id === ps.stopId)
// if (!stop) console.warn(`No stop found for pattern stop ID: ${ps.stopId}`, stops)
// return [stop.stop_lon, stop.stop_lat]//, ShapePoint.STOP]
// })
// if (hasShapePoints) {
// if (patternStops[0] && patternStops[0].shapeDistTraveled === null) {
// // if distance values are null, calculate distance values.
// // FIXME
// // calculateShapeDistTraveled(pattern, stops)
// naiveShapeDistTraveled(pattern, stops)
// } else {
// // FIXME: this should be moved out of the else clause
// // Add projected stops at shape dist traveled for pattern stops
// for (var i = 0; i < patternStops.length; i++) {
// const patternStop = patternStops[i]
// // const next = patternStops[i + 1]
// // set distance to average of patternStop and next patternStop, if last stop set to end of segment
// const distance = patternStop.shapeDistTraveled
// const point = along(lineString, distance, {units: 'meters'})
// }
// }
// }
// try {
// patternStops.map((patternStop: PatternStop, index) => {
// // set distance to average of patternStop and next patternStop, if last stop set to end of segment
// const distance = patternStops[index + 1]
// ? (patternStops[index + 1].shapeDistTraveled +
// patternStop.shapeDistTraveled) /
// 2
// : lineDistance(shape, 'meters')
// const point = along(shape, distance, {units: 'meters'})
// const controlPoint = newControlPoint(distance, point, true)
// const stopPoint = along(shape, patternStop.shapeDistTraveled, {units: 'meters'})
// const stopControl = newControlPoint(
// patternStop.shapeDistTraveled,
// stopPoint,
// true,
// patternStop
// )
// if (snapToStops) {
// stopControl.hidden = true
// }
// controlPoints.push(stopControl)
// controlPoints.push(controlPoint)
// })
//
// return controlPoints
// } catch (e) {
// console.error('Error constructing control points', e)
// return []
// }
// }

export function getRouteNameAlerts (route: GtfsRoute): string | null {
const routeName =
route.route_short_name && route.route_long_name
Expand Down

0 comments on commit e204e04

Please sign in to comment.