-
Notifications
You must be signed in to change notification settings - Fork 53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Correctly sort routes in route viewer by agency #201
Conversation
@@ -93,14 +99,13 @@ class RouteViewer extends Component { | |||
{agencySortedRoutes | |||
.map(route => { | |||
// Find operator based on agency_id (extracted from OTP route ID). | |||
// TODO: re-implement multi-agency logos for route viewer. | |||
// const operator = operatorForRoute(transitOperators, route) || {} | |||
const operator = operatorForRoute(transitOperators, route) || {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the operator is missing, the <img>
tag is shown below, but it is a broken image. I think this default to empty object should be removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a great idea, although the condition for showing the image should be tweaked a little.
// routes endpoint and causing this to only display transitOperators for | ||
// the selected route. | ||
// operator && <img src={operator.logo} style={{marginRight: '5px'}} height={25} /> | ||
{operator && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On the configs that don't define a logo, this results in a "broken image link" placeholder to be shown, so the condition for showing <img>
should rather be operator && operator.logo
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If no logo is found, should some other indicator for agency be used (e.g., name)?
@@ -62,7 +67,8 @@ class RouteViewer extends Component { | |||
: [] | |||
const agencySortedRoutes = transitOperators.length > 0 | |||
? sortedRoutes.sort((a, b) => { | |||
return operatorIndexForRoute(transitOperators, a) - operatorIndexForRoute(transitOperators, b) | |||
return routeOperatorComparatorValue(transitOperators, a) - | |||
routeOperatorComparatorValue(transitOperators, b) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we should just be placing this agency-sorting logic within otp-ui? Perhaps not, but I think the question is worth asking.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems specific to the route-viewer, so I'd say if the route-viewer becomes an otp-ui component, then it'd make sense to put this in otp-ui core-utils.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a few changes. But also, should this be moved to otp-ui?
E.g, the method getTransitOperatorFromConfig
already exists:
And it's invoked with agencyId (whereas you have changed it to route ID).
This PR is now dependent on opentripplanner/otp-ui#188. |
This PR is now dependent on opentripplanner/otp-ui#189. |
This PR is ready to go, except for being dependent on opentripplanner/otp-ui#221. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. There are some code and layout items that could be refined further, but I'm in favor to pass this as is.
color | ||
}}> | ||
</RouteRowElement> | ||
<ModeIconElement> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was to ensure that rotues with a background color on their label had sufficient space. I went ahead and changed the styling to reduce that spacing for labels with a white background color in 6cacf91.
* Route model returns the mode as an integer type whereas the RouteShort model | ||
* returns the mode string. | ||
*/ | ||
export function getModeFromRoute (route) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel this function should be in OTP-UI core-utils instead...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought that too, but nothing else in otp-ui needs this at the moment, so I just put it here to not create even more otp-ui PRs.
Ready for review! |
mobile, | ||
showUserSettings | ||
} = this.props | ||
const actionText = mobile ? 'tap' : 'click' | ||
return ( | ||
<ViewerContainer> | ||
<ViewerContainer ModeIcon={ModeIcon}> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe out of scope for this PR, but is there a better way for us to pass around Leg/ModeIcon? Would it be useful to place them in the store on app startup (passed along with the OTP config object perhaps). I just find it a bit cumbersome to pass them to these connected components in this way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See #274 which proposes to address this comment.
const patternComparator = (patternA, patternB) => routeComparator( | ||
patternA.route, | ||
patternB.route | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't seem to have a fallback sort if the routes are the same. Should we have it fall back on pattern headsign or something along those lines?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can do that. I'd like to reuse a sorting helper that isn't exported from otp-ui. Can you please approve opentripplanner/otp-ui#226 to make this possible?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approved.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
||
const OperatorImg = styled.img` | ||
height: 25px; | ||
margin-right: 8px; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 576730f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a few minor comments. Oh, and it might be nice to update the example-config.yml
to contain a valid operators
config.
Ready for review again. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Just a final question on how feeds with no agency id are handled.
🎉 This PR is included in version 2.0.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
This PR looks at the route id and parses out the agency ID and then attempts to match to a transit operator id in order to properly sort routes by multiple agencies. Also, the operator image is now shown in the route viewer from this fix.To try this out, look at the route list with a deployment with multiple agencies.This PR will now correctly sort routes in both the route viewer and stop viewer using the core-utils v3 logic and config if provided. As such, this updates all otp-ui packages to the latest version. Part of that update is correcting how the stops-overlay works so that it works with the zoom-based-overlay. One more thing that this PR does is now show a mode icon for each route in the route viewer and also an agency icon (if one is properly defined in the transit operators config).