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

Subway status in alerts page display #2388

Open
wants to merge 20 commits into
base: main
Choose a base branch
from

Conversation

thecristen
Copy link
Collaborator

Summary of changes

Asana Ticket: Service Alerts page | Add "Current Status" section for subway

The component's got a few differences to its homepage counterpart! There's a lot of silly code things I'm working around so this implementation is on the slightly "dumb" side, but it works while building off the existing logic.

The preview page is modified to show both component versions side by side.

Note: this PR uses the existing alert component for now, will be modified to use the same alert format from the planned work widget in #2387

image

@thecristen thecristen requested a review from a team as a code owner February 18, 2025 18:30
Copy link
Contributor

@joshlarson joshlarson left a comment

Choose a reason for hiding this comment

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

This looks so good! I love how simple the solution is, and how clearly it exposes how the original version of this can be improved even more! 😅

I added some non-blocking thoughts. The two that are blocking are:

  • I'm pretty sure the type in Subway.subway_status should be a list, rather than a single alert (I guess Dialyzer will also block approval on that 😅).
  • The way the alerts are rendering doesn't look quite right.

EDIT: Just realized from looking in Slack that the alert rendering is already on your radar, and blocked by another PR 🤦‍♂️

defp status_to_alerts_rows(subway_status) do
@route_ids
|> Enum.map(&{&1, subway_status |> Map.get(&1)})
|> Enum.flat_map(&rows_for_route(&1, false))
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggestion (non-blocking): Use a keyword argument to make it clearer what the boolean value that's being passed in is there for.

Suggested change
|> Enum.flat_map(&rows_for_route(&1, false))
|> Enum.flat_map(&rows_for_route(&1, collapse: false))

Another option would be finding a different way of accomplishing the combining, for instance, pushing the combine-like-alerts step to a homepage-only post-processing step (kind of like the other collapsing bits), but honestly I don't think that's necessary for this PR.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oh, I like this!

@@ -87,27 +61,31 @@ defmodule DotcomWeb.Live.SystemStatus do
"""
end

defp alert(assigns) do
defp example_table(assigns) do
Copy link
Contributor

Choose a reason for hiding this comment

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

This is such a nice presentation for this!

</div>
</:heading>
<:content>
{Phoenix.View.render_one(row.alert, DotcomWeb.AlertView, "_item.html",
Copy link
Contributor

Choose a reason for hiding this comment

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

Annoyingly I think we'll need a component here that's slightly different from the regular alert, because this creates a kind of accordion-within-an-accordion situation, which is different from what's in the designs.

Figma

Screenshot 2025-02-18 at 2 46 08 PM

Current branch

Screenshot 2025-02-18 at 2 46 20 PM

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, the actual plan is to use the alert component from Anthony's branch in #2387

Copy link
Contributor

Choose a reason for hiding this comment

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

Ahaaa - gotcha!

@thecristen thecristen added the dev-green Deploy to dev-green label Feb 19, 2025
|> SystemStatus.Alerts.filter_relevant()
Dotcom.Alerts.Disruptions.Subway.todays_disruptions()
|> Map.get(:today, [])
|> SystemStatus.Alerts.for_day(@date_time_module.now())
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 removed the underlying defp @joshlarson had here... what's it for? I can't tell if I should've kept it?

Copy link
Contributor

@anthonyshull anthonyshull Feb 19, 2025

Choose a reason for hiding this comment

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

I don't think you'll need that extra call. Is there a difference between:

Dotcom.Alerts.Disruptions.Subway.todays_disruptions()
|> Map.get(:today, [])

and

Dotcom.Alerts.Disruptions.Subway.todays_disruptions()
|> Map.get(:today, [])
|> SystemStatus.Alerts.for_day(@date_time_module.now())

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe if it just filters out alerts that are today, but earlier today, that can just be a private function in this module.

@@ -36,7 +37,7 @@ defmodule Dotcom.Alerts.Disruptions.Subway do
# 4. Sorts the alerts within the group by start time.
defp disruption_groups() do
subway_route_ids()
|> @alerts_repo.by_route_ids(Utils.DateTime.now())
|> @alerts_repo.by_route_ids(@date_time_module.now())
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

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 was very amused we'd forgotten this!

Comment on lines 63 to 74
def active_now_or_later_on_day?(alert, datetime) do
Enum.any?(alert.active_period, fn {active_period_start, active_period_end} ->
starts_before_end_of_service?(active_period_start, datetime) &&
has_not_ended?(active_period_end, datetime)
end)
end

@doc """
Given a list of alerts, filters only the ones that are active today, as defined in `active_on_day?/2`.
Given a list of alerts, filters only the ones that are active at the, as defined in `active_now_or_later_on_day?/2`.
"""
def for_day(alerts, datetime) do
Enum.filter(alerts, &active_on_day?(&1, datetime))
Enum.filter(alerts, &active_now_or_later_on_day?(&1, datetime))
Copy link
Contributor

Choose a reason for hiding this comment

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

Unless these are used anywhere else, I think they can be moved to the system status module as a private function.

also fix it a bit since the struct's default "" are truthy
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.

3 participants