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

feat: add interactive stop to map for create shuttle stop and edit shuttle stop #999

Merged
merged 19 commits into from
Aug 19, 2024

Conversation

meagharty
Copy link
Collaborator

@meagharty meagharty commented Aug 5, 2024

Summary of changes

Asana Ticket: Implement "Create Shuttle Stop" and "Edit Shuttle Stop" map view - display draft stop on map

  • Fixes live view setup
  • Add phoenix package and javascript dep for LiveView and React integration (simliar to existing non-LiveView integration)
  • Moves create/edit/update to live view page (stop_live.ex)
  • On stop form changes, phx-change triggers a socket.assigns update, which re-renders the React map with the new props
    • This doesn't currently validate the changeset on change (only on submit), I could add that
    • I thought about keeping the form submit as a HTTP call (using the existing controller definitions, not phx-submit) but it was an awkward experience especially on create

Reviewer Checklist

  • Meets ticket's acceptance criteria
  • Any new or changed functions have typespecs
  • Tests were added for any new functionality (don't just rely on Codecov)
  • This branch was deployed to the staging environment and is currently running with no unexpected increase in warnings, and no errors or crashes.

Copy link

github-actions bot commented Aug 5, 2024

Coverage of commit f0528f6

Summary coverage rate:
  lines......: 81.9% (899 of 1098 lines)
  functions..: 61.8% (620 of 1003 functions)
  branches...: no data found

Files changed coverage rate:
                                                                     |Lines       |Functions  |Branches    
  Filename                                                           |Rate     Num|Rate    Num|Rate     Num
  =========================================================================================================
  lib/arrow/shuttle/stop.ex                                          | 100%      2| 100%     6|    -      0
  lib/arrow_web.ex                                                   | 100%      2|30.0%    10|    -      0
  lib/arrow_web/components/core_components.ex                        |46.7%    169|52.5%    40|    -      0
  lib/arrow_web/controllers/stop_controller.ex                       | 100%      4|85.7%     7|    -      0
  lib/arrow_web/controllers/stop_html.ex                             |50.0%      2|20.0%     5|    -      0
  lib/arrow_web/endpoint.ex                                          | 100%      2|44.4%    18|    -      0
  lib/arrow_web/live/stop_live/stop_live.ex                          |96.3%     27|55.6%     9|    -      0
  lib/arrow_web/router.ex                                            |96.2%     26|36.3%    91|    -      0

Download coverage report

Copy link

github-actions bot commented Aug 5, 2024

Coverage of commit bff73b5

Summary coverage rate:
  lines......: 81.9% (899 of 1098 lines)
  functions..: 61.8% (620 of 1003 functions)
  branches...: no data found

Files changed coverage rate:
                                                                     |Lines       |Functions  |Branches    
  Filename                                                           |Rate     Num|Rate    Num|Rate     Num
  =========================================================================================================
  lib/arrow/shuttle/stop.ex                                          | 100%      2| 100%     6|    -      0
  lib/arrow_web.ex                                                   | 100%      2|30.0%    10|    -      0
  lib/arrow_web/components/core_components.ex                        |46.7%    169|52.5%    40|    -      0
  lib/arrow_web/controllers/stop_controller.ex                       | 100%      4|85.7%     7|    -      0
  lib/arrow_web/controllers/stop_html.ex                             |50.0%      2|20.0%     5|    -      0
  lib/arrow_web/endpoint.ex                                          | 100%      2|44.4%    18|    -      0
  lib/arrow_web/live/stop_live/stop_live.ex                          |96.3%     27|55.6%     9|    -      0
  lib/arrow_web/router.ex                                            |96.2%     26|36.3%    91|    -      0

Download coverage report

Copy link

github-actions bot commented Aug 6, 2024

Coverage of commit 6b4a1b4

Summary coverage rate:
  lines......: 81.9% (899 of 1098 lines)
  functions..: 61.8% (620 of 1003 functions)
  branches...: no data found

Files changed coverage rate:
                                                                     |Lines       |Functions  |Branches    
  Filename                                                           |Rate     Num|Rate    Num|Rate     Num
  =========================================================================================================
  lib/arrow/shuttle/stop.ex                                          | 100%      2| 100%     6|    -      0
  lib/arrow_web.ex                                                   | 100%      2|30.0%    10|    -      0
  lib/arrow_web/components/core_components.ex                        |46.7%    169|52.5%    40|    -      0
  lib/arrow_web/controllers/stop_controller.ex                       | 100%      4|85.7%     7|    -      0
  lib/arrow_web/controllers/stop_html.ex                             |50.0%      2|20.0%     5|    -      0
  lib/arrow_web/endpoint.ex                                          | 100%      2|44.4%    18|    -      0
  lib/arrow_web/live/stop_live/stop_live.ex                          |96.3%     27|55.6%     9|    -      0
  lib/arrow_web/router.ex                                            |96.2%     26|36.3%    91|    -      0

Download coverage report

Copy link

github-actions bot commented Aug 6, 2024

Coverage of commit c007680

Summary coverage rate:
  lines......: 81.9% (899 of 1098 lines)
  functions..: 61.8% (620 of 1003 functions)
  branches...: no data found

Files changed coverage rate:
                                                                     |Lines       |Functions  |Branches    
  Filename                                                           |Rate     Num|Rate    Num|Rate     Num
  =========================================================================================================
  lib/arrow/shuttle/stop.ex                                          | 100%      2| 100%     6|    -      0
  lib/arrow_web.ex                                                   | 100%      2|30.0%    10|    -      0
  lib/arrow_web/components/core_components.ex                        |46.7%    169|52.5%    40|    -      0
  lib/arrow_web/controllers/stop_controller.ex                       | 100%      4|85.7%     7|    -      0
  lib/arrow_web/controllers/stop_html.ex                             |50.0%      2|20.0%     5|    -      0
  lib/arrow_web/endpoint.ex                                          | 100%      2|44.4%    18|    -      0
  lib/arrow_web/live/stop_live/stop_live.ex                          |96.3%     27|55.6%     9|    -      0
  lib/arrow_web/router.ex                                            |96.2%     26|36.3%    91|    -      0

Download coverage report

Copy link

github-actions bot commented Aug 6, 2024

Coverage of commit 2593fa6

Summary coverage rate:
  lines......: 81.9% (899 of 1098 lines)
  functions..: 61.8% (620 of 1003 functions)
  branches...: no data found

Files changed coverage rate:
                                                                     |Lines       |Functions  |Branches    
  Filename                                                           |Rate     Num|Rate    Num|Rate     Num
  =========================================================================================================
  lib/arrow/shuttle/stop.ex                                          | 100%      2| 100%     6|    -      0
  lib/arrow_web.ex                                                   | 100%      2|30.0%    10|    -      0
  lib/arrow_web/components/core_components.ex                        |46.7%    169|52.5%    40|    -      0
  lib/arrow_web/controllers/stop_controller.ex                       | 100%      4|85.7%     7|    -      0
  lib/arrow_web/controllers/stop_html.ex                             |50.0%      2|20.0%     5|    -      0
  lib/arrow_web/endpoint.ex                                          | 100%      2|44.4%    18|    -      0
  lib/arrow_web/live/stop_live/stop_live.ex                          |96.3%     27|55.6%     9|    -      0
  lib/arrow_web/router.ex                                            |96.2%     26|36.3%    91|    -      0

Download coverage report

Copy link

github-actions bot commented Aug 6, 2024

Coverage of commit a668457

Summary coverage rate:
  lines......: 81.9% (899 of 1098 lines)
  functions..: 61.8% (620 of 1003 functions)
  branches...: no data found

Files changed coverage rate:
                                                                     |Lines       |Functions  |Branches    
  Filename                                                           |Rate     Num|Rate    Num|Rate     Num
  =========================================================================================================
  lib/arrow/shuttle/stop.ex                                          | 100%      2| 100%     6|    -      0
  lib/arrow_web.ex                                                   | 100%      2|30.0%    10|    -      0
  lib/arrow_web/components/core_components.ex                        |46.7%    169|52.5%    40|    -      0
  lib/arrow_web/controllers/stop_controller.ex                       | 100%      4|85.7%     7|    -      0
  lib/arrow_web/controllers/stop_html.ex                             |50.0%      2|20.0%     5|    -      0
  lib/arrow_web/endpoint.ex                                          | 100%      2|44.4%    18|    -      0
  lib/arrow_web/live/stop_live/stop_live.ex                          |96.3%     27|55.6%     9|    -      0
  lib/arrow_web/router.ex                                            |96.2%     26|36.3%    91|    -      0

Download coverage report

@meagharty meagharty requested review from a team and jzimbel-mbta and removed request for a team August 6, 2024 19:19
@@ -7,7 +7,7 @@
</:actions>
</.header>

<.table id="stops" rows={@stops} row_click={&JS.navigate(~p"/stops/#{&1}")}>
Copy link
Collaborator Author

@meagharty meagharty Aug 6, 2024

Choose a reason for hiding this comment

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

This row_click attribute wasn't working previously

@@ -24,9 +24,6 @@
<:col :let={stop} label="At street"><%= stop.at_street %></:col>
<:col :let={stop} label="Last updated"><%= format_timestamp(stop.updated_at) %></:col>
<:action :let={stop}>
<div class="sr-only">
<.link navigate={~p"/stops/#{stop}"}>Show</.link>
Copy link
Collaborator Author

@meagharty meagharty Aug 6, 2024

Choose a reason for hiding this comment

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

This page didn't exist before anyway. The screenreader-only tag hid the visible broken link.

@@ -16,6 +16,8 @@
"leaflet": "^1.9.4",
"phoenix": "file:../deps/phoenix",
"phoenix_html": "file:../deps/phoenix_html",
"phoenix_live_react": "file:../deps/phoenix_live_react",
"phoenix_live_view": "file:../deps/phoenix_live_view",
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@@ -0,0 +1,22 @@
<!DOCTYPE html>
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Copy link
Member

@jzimbel-mbta jzimbel-mbta left a comment

Choose a reason for hiding this comment

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

LGTM! No hard blockers, just some questions and minor, optional suggestions.

Copy link
Member

Choose a reason for hiding this comment

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

Nit: Could you nest this in a stop_live directory so its path mirrors that of the source file in lib that it's testing?

(Or move stop_live.ex up a level)

lib/arrow_web/router.ex Outdated Show resolved Hide resolved
<meta charset="utf-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<meta name="csrf-token" content={Plug.CSRFProtection.get_csrf_token()} />
Copy link
Member

Choose a reason for hiding this comment

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

Should app.js be referenced in a <script> tag somewhere after this?

(Looks like it's added via content_tag(:script ...) in each of the layout templates, but maybe it would make more sense to do that in this root-level file if it's always used?)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm going to keep this script tag as-is inside the body tag (as it was before this PR). I don't want to make further changes to the setup with React and LiveView in this PR.

.getAttribute("content")
const liveSocket = new LiveSocket("/live", Socket, {
hooks,
// longPollFallbackMs: 2500,
Copy link
Member

Choose a reason for hiding this comment

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

Should this be removed? Or is it good to keep around?

(I couldn't find documentation on this option in a quick skim of the phoenix_live_view docs / the live_socket.js source.)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This option was configured in the generated app.js in a new phoenix project with live_view (template source code in phoenix here).

I uncommented this with an update for local development.

This issue describes trade-offs of falling back to long polling if the websocket fails to connect (including local development): phoenixframework/phoenix#5741, a helpful comment in particular: phoenixframework/phoenix#5741 (comment)

env: %{
"NODE_PATH" =>
Enum.join(
[Path.expand("../deps", __DIR__), Path.expand("../assets/node_modules", __DIR__)],
Copy link
Member

Choose a reason for hiding this comment

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

Any reason why /assets/node_modules needed to be added to NODE_PATH?

Copy link
Collaborator Author

@meagharty meagharty Aug 19, 2024

Choose a reason for hiding this comment

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

I can't recall why so I can only assume this was from debugging the liveview setup. I removed this addition and I didn't see any differences testing the application locally.

Copy link
Member

Choose a reason for hiding this comment

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

Looks like a good deal of markup is shared between this template and app.html.heex, would it make sense / would it be possible to consolidate it in another template?

Comment on lines +5 to +10
type Stop = {
stop_name: string
stop_desc: string
stop_lat: number
stop_lon: number
}
Copy link
Member

Choose a reason for hiding this comment

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

Any reason for type Stop = {...} instead of interface Stop {...}? They're equivalent if I remember correctly, but I'm used to a soft standard of people using interface.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'll change this. To your point the Typescript community when setting a standard prefers interface for better error messages.

This is a personal preference for type that I have trouble kicking from a time when I was writing both Typescript and types in F#. I like that types can't be re-declared, can be used for objects, functions, and other types (primitives, unions, tuples), and are extended with & (over extends which feels OOPish).

Copy link

Coverage of commit 2722442

Summary coverage rate:
  lines......: 79.8% (918 of 1150 lines)
  functions..: 61.9% (641 of 1036 functions)
  branches...: no data found

Files changed coverage rate:
                                                                     |Lines       |Functions  |Branches    
  Filename                                                           |Rate     Num|Rate    Num|Rate     Num
  =========================================================================================================
  lib/arrow/shuttle/stop.ex                                          | 100%      2| 100%     6|    -      0
  lib/arrow_web.ex                                                   | 100%      2|30.0%    10|    -      0
  lib/arrow_web/components/core_components.ex                        |47.1%    172|52.5%    40|    -      0
  lib/arrow_web/controllers/stop_controller.ex                       | 100%      4|85.7%     7|    -      0
  lib/arrow_web/controllers/stop_html.ex                             |33.3%      6|33.3%     6|    -      0
  lib/arrow_web/endpoint.ex                                          | 100%      2|44.4%    18|    -      0
  lib/arrow_web/live/stop_live/stop_live.ex                          |96.3%     27|55.6%     9|    -      0
  lib/arrow_web/router.ex                                            |96.2%     26|34.7%    95|    -      0

Download coverage report

@meagharty meagharty merged commit 270e17f into master Aug 19, 2024
11 checks passed
@meagharty meagharty deleted the meag/stop-map-view branch August 19, 2024 20: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