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

refactor: Convert itinerary legs to segments for easier rendering #2262

Merged
merged 10 commits into from
Dec 11, 2024

Conversation

joshlarson
Copy link
Contributor

@joshlarson joshlarson commented Dec 11, 2024

Pure refactor.

No ticket.

The point of this refactor is that the data returned from OpenTripPlanner is subtly different from what we want to render on the screen. Even in a simple case, when OTP returns [walking, transit, walking], what we actually want to draw on the screen is [location, walking, transit, walking, location]*, and there are some corner-cases that make this even more complicated.

*I'm making the assumption that drawing transit on the screen actually means drawing the transit leg's start location and end location, each with the right icon for that transit leg, on either side of the transit leg details itself. This works out, since all transit legs are bracketed by locations indicating their stops or stations.


This'll enable follow-ups to address two use cases:

  • When OTP returns [transit, walking, transit] or something like that, where the first or last leg of an itinerary is transit, then we want to draw [transit, walking, transit] - in other words, we don't want to show location right next to transit. Ticket for this, which includes a screenshot of what it looks like now.
  • When OTP returns something like [walking, transit, transit, walking], that is, when there's a transfer that involves no walking, then we want to add in a "waiting leg", so the end result should be [location, walking, transit, waiting, transit, walking, location]. Ticket for this (same deal - has a screenshot).

@joshlarson joshlarson requested a review from a team as a code owner December 11, 2024 17:18
@@ -0,0 +1,37 @@
defmodule DotcomWeb.Components.TripPlanner.LegToSegmentHelper do
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'm not sold on either this name or this location for this file, but I couldn't think of a better one off the top of my head.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Since it's not technically a rendered component, you can move this to the Dotcom.TripPlan. namespace. I don't mind the current name.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

💥 5caf9b7 💥

Copy link
Collaborator

@thecristen thecristen 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 so elegant 🤩

I think you should move the helper module. And as the linter says you can add a @moduledoc to it too. And don't forget the formatting!

Otherwise I think this looks great.

@joshlarson
Copy link
Contributor Author

@thecristen I think I addressed everything - want to take another look?

@@ -49,6 +49,7 @@ defmodule Dotcom.TripPlan.InputForm do
date: PlanParams.to_date_param(datetime),
time: PlanParams.to_time_param(datetime),
transportModes: __MODULE__.Modes.selected_mode_keys(modes) |> PlanParams.to_modes_param(),
numItineraries: 40,
Copy link
Collaborator

Choose a reason for hiding this comment

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

I kinda wanna let this slide, but 40 seems kinda excessive?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh oops - didn't mean to include this change. I've been using that to get more itineraries so that the one I'm looking for is more likely to actually show up.

@joshlarson joshlarson enabled auto-merge (squash) December 11, 2024 19:19
@joshlarson joshlarson merged commit de2d3dc into main Dec 11, 2024
17 checks passed
@joshlarson joshlarson deleted the jdl/refactor/convert-itinerary-legs-to-segments branch December 11, 2024 19:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants