Skip to content
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

Merged
merged 17 commits into from
Nov 20, 2020

Conversation

evansiroky
Copy link
Contributor

@evansiroky evansiroky commented Jul 17, 2020

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).

@@ -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) || {}
Copy link
Member

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.

Copy link
Collaborator

@binh-dam-ibigroup binh-dam-ibigroup left a 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 &&
Copy link
Collaborator

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.

Copy link
Member

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)
Copy link
Member

@landonreed landonreed Jul 17, 2020

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.

Copy link
Contributor Author

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.

@landonreed landonreed removed their assignment Jul 17, 2020
Copy link
Member

@landonreed landonreed left a 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:

https://github.com/opentripplanner/otp-ui/blob/382a189857bb6f1a94d37c66589d89193b07ec59/packages/itinerary-body/src/place-row.js#L15-L17

And it's invoked with agencyId (whereas you have changed it to route ID).

@evansiroky evansiroky added the BLOCKED Blocked (waiting on another PR to be merged) label Jul 21, 2020
@evansiroky
Copy link
Contributor Author

This PR is now dependent on opentripplanner/otp-ui#188.

@evansiroky
Copy link
Contributor Author

This PR is now dependent on opentripplanner/otp-ui#189.

@evansiroky evansiroky added WIP Work in progress and removed BLOCKED Blocked (waiting on another PR to be merged) labels Nov 6, 2020
@evansiroky evansiroky added BLOCKED Blocked (waiting on another PR to be merged) and removed WIP Work in progress labels Nov 6, 2020
@evansiroky
Copy link
Contributor Author

This PR is ready to go, except for being dependent on opentripplanner/otp-ui#221.

Copy link
Collaborator

@binh-dam-ibigroup binh-dam-ibigroup left a 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>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On configs that don't have operator logos, the current layout wastes a good bit of white space to the left of the mode icon, IMO.
image

Copy link
Contributor Author

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) {
Copy link
Collaborator

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...

Copy link
Contributor Author

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.

@evansiroky
Copy link
Contributor Author

Ready for review!

@evansiroky evansiroky removed the BLOCKED Blocked (waiting on another PR to be merged) label Nov 11, 2020
@evansiroky evansiroky assigned landonreed and unassigned evansiroky Nov 11, 2020
mobile,
showUserSettings
} = this.props
const actionText = mobile ? 'tap' : 'click'
return (
<ViewerContainer>
<ViewerContainer ModeIcon={ModeIcon}>
Copy link
Member

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.

Copy link
Contributor Author

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
)
Copy link
Member

@landonreed landonreed Nov 16, 2020

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?

Copy link
Contributor Author

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?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in d9410f9 and e110f9a


const OperatorImg = styled.img`
height: 25px;
margin-right: 8px;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The operator image appears to be offset vertically slightly from the other row elements:

image

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 576730f

Copy link
Member

@landonreed landonreed left a 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.

@evansiroky
Copy link
Contributor Author

Ready for review again.

@evansiroky evansiroky assigned landonreed and unassigned evansiroky Nov 18, 2020
Copy link
Member

@landonreed landonreed left a 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.

@landonreed landonreed assigned evansiroky and unassigned landonreed Nov 20, 2020
@evansiroky evansiroky merged commit da85709 into dev Nov 20, 2020
@evansiroky evansiroky mentioned this pull request Nov 20, 2020
evansiroky added a commit that referenced this pull request Jan 5, 2021
BREAKING CHANGE:

- Refactor various components and example.js file to more heavily use React's context API (see #274)
- Update to use latest config schema compatible with opentripplanner/core-utils v3 (see #201)
@github-actions
Copy link
Contributor

github-actions bot commented Jan 8, 2021

🎉 This PR is included in version 2.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants