-
Notifications
You must be signed in to change notification settings - Fork 11
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
feat: Toggle between summary and details view in itinerary panel #2232
Merged
+226
−32
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
feb0141
feat: Toggle between summary and details view in itinerary panel
joshlarson c62bc3c
cleanup: Remove extraneous `dbg`'s
joshlarson 7227668
cleanup: Remove useless formatting change
joshlarson 8505bc5
fix: Add :index attr to <.itinerary_group /> definition
joshlarson 47fc2ed
cleanup: Refactor arguments to <.itinerary_panel_with_specific_result />
joshlarson 340ac26
refactor: Pull itinerary results section out as a LiveComponent
joshlarson 68e225b
refactor: Move itinerary_details_index into TripPlannerResultsSection
joshlarson bf1fae7
refactor: Make details_click_event on <.itinerary_group /> configurable
joshlarson 38a1b26
cleanup: Remove unnecessary @group_id assign
joshlarson 2608adf
Merge remote-tracking branch 'origin/main' into jdl/list-details-toggle
joshlarson 925af40
wip: stub out some tests!
thecristen e573834
tests: Clean up tests and assert on details view toggling
joshlarson 8acb0d2
refactor: Remove unnecessary intermediate itinerary panel components
joshlarson 9a3bad6
refactor: Replace show_itinerary_details/summary with set_expanded_it…
joshlarson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
89 changes: 89 additions & 0 deletions
89
lib/dotcom_web/components/live_components/trip_planner_results_section.ex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
defmodule DotcomWeb.Components.LiveComponents.TripPlannerResultsSection do | ||
@moduledoc """ | ||
The section of the trip planner page that shows the map and | ||
the summary or details panel | ||
""" | ||
|
||
use DotcomWeb, :live_component | ||
|
||
import DotcomWeb.Components.TripPlanner.ItineraryDetail | ||
import DotcomWeb.Components.TripPlanner.ItineraryGroup, only: [itinerary_group: 1] | ||
|
||
@impl true | ||
def mount(socket) do | ||
{:ok, socket |> assign(:expanded_itinerary_index, nil)} | ||
end | ||
|
||
@impl true | ||
def render(assigns) do | ||
~H""" | ||
<section class="flex w-full border border-solid border-slate-400"> | ||
<div :if={@error} class="w-full p-4 text-rose-400"> | ||
<%= inspect(@error) %> | ||
</div> | ||
<.async_result :let={results} assign={@results}> | ||
<div :if={results} class="w-full p-4"> | ||
<.itinerary_panel | ||
results={results} | ||
details_index={@expanded_itinerary_index} | ||
target={@myself} | ||
/> | ||
</div> | ||
</.async_result> | ||
<.live_component | ||
module={MbtaMetro.Live.Map} | ||
id="trip-planner-map" | ||
class="h-96 w-full relative overflow-none" | ||
config={@map_config} | ||
pins={[@from, @to]} | ||
/> | ||
</section> | ||
""" | ||
end | ||
|
||
defp itinerary_panel(%{details_index: nil} = assigns) do | ||
~H""" | ||
<.itinerary_group | ||
:for={{result, index} <- Enum.with_index(@results)} | ||
index={index} | ||
details_click_event="set_expanded_itinerary_index" | ||
target={@target} | ||
{result} | ||
/> | ||
""" | ||
end | ||
|
||
defp itinerary_panel(%{results: results, details_index: details_index} = assigns) do | ||
assigns = | ||
assign(assigns, :itineraries, results |> Enum.at(details_index) |> Map.get(:itineraries)) | ||
|
||
~H""" | ||
<div class="mt-30"> | ||
<button | ||
type="button" | ||
phx-click="set_expanded_itinerary_index" | ||
phx-value-index="nil" | ||
phx-target={@target} | ||
class="btn-link" | ||
> | ||
<p class="flex flex-row items-center"> | ||
<.icon class="fill-brand-primary h-4 mr-2" name="chevron-left" /> | ||
<span class="font-medium">View All Options</span> | ||
</p> | ||
</button> | ||
<.itinerary_detail :for={itinerary <- @itineraries} itinerary={itinerary} /> | ||
</div> | ||
""" | ||
end | ||
|
||
@impl true | ||
def handle_event("set_expanded_itinerary_index", %{"index" => index_str}, socket) do | ||
index = | ||
case Integer.parse(index_str) do | ||
{index, ""} -> index | ||
_ -> nil | ||
end | ||
|
||
{:noreply, socket |> assign(:expanded_itinerary_index, index)} | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
It took me a while to understand what this was for... ultimately I'd favor a more descriptive attribute name, maybe
:group_index
?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.
Thinking for a moment... the only reason an itinerary group cares about its
index
is because it does the right thing in response to clicking onDetails
. So maybe the thing to do is have settingindex
correctly be handled in a callback instead of implicitly through this param.I think that would require converting
itinerary_group
to a live component though, so if we think that's a good idea, my vote would be to do that as a follow-up PR.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 think that would work fine (and agree that might need a live component), but it might be overkill?
An alternate thought: the summary and itineraries here are populated by the output of
Dotcom.TripPlan.ItineraryGroups.from_itineraries/1
, which outputs a list of%{itineraries: itineraries, summary: summary}
maps. Why not have this function compute the indexes and have the map include thatindex
as well?A more meta thought - we're using index to really mean "unique identifier". The past iteration made up a unique ID (
assign(assigns, :group_id, "group-#{:erlang.phash2(assigns.itineraries)}")
). We might want to reconsider using the index value for that purpose (what if we want to let end users re-sort the list later, for example).