Skip to content

Commit

Permalink
fix: use core-utils v3 to sort routes by agency
Browse files Browse the repository at this point in the history
  • Loading branch information
evansiroky committed Nov 6, 2020
1 parent d0cfd7d commit 198e5e5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 21 deletions.
21 changes: 4 additions & 17 deletions lib/components/viewers/route-viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,6 @@ import Icon from '../narrative/icon'
import { setMainPanelContent, setViewedRoute } from '../../actions/ui'
import { findRoutes, findRoute } from '../../actions/api'

function routeOperatorComparatorValue (transitOperators, route) {
const routeOperator = coreUtils.route.getTransitOperatorFromOtpRoute(
route,
transitOperators
)
if (!routeOperator) return 0
return routeOperator.order
}

/**
* Determine the appropriate contrast color for text (white or black) based on
* the input hex string (e.g., '#ff00ff') value.
Expand Down Expand Up @@ -59,14 +50,10 @@ class RouteViewer extends Component {
viewedRoute
} = this.props
const sortedRoutes = routes
? Object.values(routes).sort(coreUtils.route.routeComparator)
? Object.values(routes).sort(
coreUtils.route.makeRouteComparator(transitOperators)
)
: []
const agencySortedRoutes = transitOperators.length > 0
? sortedRoutes.sort((a, b) => {
return routeOperatorComparatorValue(transitOperators, a) -
routeOperatorComparatorValue(transitOperators, b)
})
: sortedRoutes
return (
<div className='route-viewer'>
{/* Header Block */}
Expand All @@ -92,7 +79,7 @@ class RouteViewer extends Component {
</div>

<div className='route-viewer-body'>
{agencySortedRoutes
{sortedRoutes
.map(route => {
// Find operator based on agency_id (extracted from OTP route ID).
const operator = coreUtils.route.getTransitOperatorFromOtpRoute(
Expand Down
18 changes: 14 additions & 4 deletions lib/components/viewers/stop-viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,12 +250,21 @@ class StopViewer extends Component {
stopData,
stopViewerArriving,
stopViewerConfig,
timeFormat
timeFormat,
transitOperators
} = this.props
const { scheduleView, spin } = this.state
const hasStopTimesAndRoutes = !!(stopData && stopData.stopTimes && stopData.stopTimes.length > 0 && stopData.routes)
// construct a lookup table mapping pattern (e.g. 'ROUTE_ID-HEADSIGN') to an array of stoptimes
// construct a lookup table mapping pattern (e.g. 'ROUTE_ID-HEADSIGN') to
// an array of stoptimes
const stopTimesByPattern = getStopTimesByPattern(stopData)
const routeComparator = coreUtils.route.makeRouteComparator(
transitOperators
)
const patternComparator = (patternA, patternB) => routeComparator(
patternA.route,
patternB.route
)
return (
<div className='stop-viewer'>
{/* Header Block */}
Expand All @@ -268,7 +277,7 @@ class StopViewer extends Component {
? <>
<div style={{ marginTop: 20 }}>
{Object.values(stopTimesByPattern)
.sort((a, b) => coreUtils.route.routeComparator(a.route, b.route))
.sort(patternComparator)
.map(patternTimes => {
// Only add pattern row if route is found.
// FIXME: there is currently a bug with the alernative transit index
Expand Down Expand Up @@ -344,7 +353,8 @@ const mapStateToProps = (state, ownProps) => {
stopData: state.otp.transitIndex.stops[state.otp.ui.viewedStop.stopId],
stopViewerArriving: state.otp.config.language.stopViewerArriving,
stopViewerConfig,
timeFormat: getTimeFormat(state.otp.config)
timeFormat: getTimeFormat(state.otp.config),
transitOperators: state.otp.config.transitOperators
}
}

Expand Down

0 comments on commit 198e5e5

Please sign in to comment.