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: Change itinerary-panel-view state for TripPlannerResultsSection #2242

Merged
merged 3 commits into from
Dec 6, 2024

Conversation

joshlarson
Copy link
Contributor

It was bugging me that expanded_itinerary_index and selected_itinerary_detail_index were separate assigns in TripPlannerResultsSection (eventually will get bumped up to TripPlanner itself), since in reality, they're more like two parts of the same state. So I decided to try combining them into a single itinerary_panel_view assign instead.

Things I like:

  • It's clearer that those two bits of state are in fact related
  • It's impossible to accidentally change expanded_itinerary_index without also resetting selected_itinerary_detail_index (note how those two assigns basically always have to go together in the "before" side of the diff)

Things I'm not sure about:

  • With itinerary_panel_view, updating which specific itinerary is selected is more of a pain, because we need to keep :expanded and the rest of itinerary_panel_view the same.

@joshlarson joshlarson requested a review from a team as a code owner December 2, 2024 21:47
@joshlarson joshlarson requested review from anthonyshull and removed request for a team December 2, 2024 21:47
Base automatically changed from jdl/depart-at-buttons to main December 3, 2024 17:10
@joshlarson joshlarson force-pushed the jdl/change_state_in_trip_planner_results_section branch from 5231e49 to 3261bfb Compare December 3, 2024 19:22
@joshlarson joshlarson enabled auto-merge (squash) December 3, 2024 19:24
@joshlarson joshlarson requested a review from thecristen December 3, 2024 19:24
@@ -72,7 +74,7 @@ defmodule DotcomWeb.Components.LiveComponents.TripPlannerResultsSection do
"""
end

defp itinerary_panel(%{details_index: nil} = assigns) do
defp itinerary_panel(%{itinerary_panel_view: :collapsed} = assigns) do
Copy link
Collaborator

Choose a reason for hiding this comment

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

how about we make this the fallback clause in case the next clause isn't matched?

%{"trip-index" => index_str},
%{assigns: %{itinerary_panel_view: {:expanded, itinerary_panel_view}}} = socket
) do
{index, ""} = Integer.parse(index_str)
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit:technically you could use a case statement here too in case the integer doesn't parse out...

@joshlarson joshlarson merged commit 3dd2f69 into main Dec 6, 2024
17 checks passed
@joshlarson joshlarson deleted the jdl/change_state_in_trip_planner_results_section branch December 6, 2024 21:46
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