-
Notifications
You must be signed in to change notification settings - Fork 13
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: hide CR timetable in the presence of special alerts #2301
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
21de397
refactor: switch if -> cond to prep for adding CR alert state
paulswartz b640fc6
feat: add @blocking_alert if an alert should hide the timetable
paulswartz 015886a
feat: render blank schedule page if we have a blocking alert
paulswartz 2df3adc
feat(AlertView): special-case the CR timetable blocking text (when th…
paulswartz 4c0430b
refactor: pull timetable blocking logic into a module
paulswartz f8fcfcc
feat: show blocking alerts on the timetable even if they're low priority
paulswartz 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
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,43 @@ | ||
defmodule Dotcom.TimetableBlocking do | ||
@moduledoc """ | ||
Support for blocking the timetable in the presence of special alert text. | ||
""" | ||
alias Alerts.Alert | ||
alias Routes.Route | ||
|
||
def pdf_available_text, do: "View PDF Timetable on the MBTA website." | ||
def no_pdf_text, do: "Schedule will be available soon on the MBTA website." | ||
|
||
@doc """ | ||
Strips the timetable blocking text from an alert header (if present) | ||
""" | ||
@spec strip(String.t()) :: String.t() | ||
def strip(header) when is_binary(header) do | ||
String.replace_trailing(header, pdf_available_text(), "") | ||
end | ||
|
||
@doc """ | ||
Returns the alert blocking the timetable for a given route/date, or nil if there is no such alert. | ||
""" | ||
@spec blocking_alert([Alert.t()], Route.t(), Date.t()) :: Alert.t() | nil | ||
def blocking_alert(alerts, %Route{} = route, %Date{} = date) when is_list(alerts) do | ||
# we do the filtering in this order to do the cheap string comparison before | ||
# the more complicated informed entity/time matching | ||
alerts | ||
|> Enum.filter(fn alert -> | ||
String.ends_with?(alert.header, pdf_available_text()) or | ||
String.ends_with?(alert.header, no_pdf_text()) | ||
end) | ||
|> Alerts.Match.match( | ||
%Alerts.InformedEntity{route: route.id}, | ||
date | ||
) | ||
|> List.first() | ||
end | ||
|
||
@doc "Returns true if the given alert is blocking and has a PDF." | ||
@spec pdf?(Alert.t()) :: boolean | ||
def pdf?(%Alert{} = alert) do | ||
String.ends_with?(alert.header, pdf_available_text()) and is_binary(alert.url) | ||
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
10 changes: 10 additions & 0 deletions
10
lib/dotcom_web/templates/schedule/_timetable_blocked.html.eex
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,10 @@ | ||
<div class="callout schedule-empty"> | ||
The interactive timetable for <%= @formatted_date %> is temporarily unavailable due to a service change. | ||
<div> | ||
<%= if @alert.url do %> | ||
<%= link "View PDF Timetable", to: @alert.url %> | ||
<% else %> | ||
PDF Upcoming | ||
<% end %> | ||
</div> | ||
</div> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
defmodule Dotcom.TimetableBlockingTest do | ||
@moduledoc false | ||
use ExUnit.Case, async: true | ||
alias Dotcom.TimetableBlocking | ||
|
||
@date ~D[2025-01-01] | ||
@route %Routes.Route{id: "CR-route"} | ||
|
||
describe "blocking_alert/3" do | ||
test "returns an alert if there's a specially tagged alert without a PDF" do | ||
alert = | ||
Alerts.Alert.new( | ||
header: "No timetable. #{TimetableBlocking.no_pdf_text()}", | ||
informed_entity: [%Alerts.InformedEntity{route: @route.id}], | ||
active_period: [{~U[2025-01-01T00:00:00Z], nil}] | ||
) | ||
|
||
assert TimetableBlocking.blocking_alert([alert], @route, @date) == alert | ||
end | ||
|
||
test "returns an alert if there's a specially tagged alert with a PDF" do | ||
alert = | ||
Alerts.Alert.new( | ||
header: "No timetable. #{TimetableBlocking.pdf_available_text()}", | ||
informed_entity: [%Alerts.InformedEntity{route: @route.id}], | ||
active_period: [{~U[2025-01-01T00:00:00Z], nil}], | ||
url: "https://www.mbta.com/pdf-link" | ||
) | ||
|
||
assert TimetableBlocking.blocking_alert([alert], @route, @date) == alert | ||
end | ||
|
||
test "returns nil if there's no special alert" do | ||
ie = %Alerts.InformedEntity{route: "CR-route"} | ||
active_period = {~U[2025-01-01T00:00:00Z], ~U[2025-01-01T23:59:59Z]} | ||
|
||
alerts = [ | ||
Alerts.Alert.new( | ||
header: "Regular alert.", | ||
informed_entity: [ie], | ||
active_period: [active_period] | ||
), | ||
Alerts.Alert.new( | ||
header: "Not active. #{TimetableBlocking.no_pdf_text()}", | ||
informed_entity: [ie], | ||
active_period: [{~U[2025-06-06T00:00:00Z], nil}] | ||
), | ||
Alerts.Alert.new( | ||
header: "Different route. #{TimetableBlocking.no_pdf_text()}", | ||
informed_entity: [%Alerts.InformedEntity{route: "bus"}], | ||
active_period: [active_period] | ||
) | ||
] | ||
|
||
assert TimetableBlocking.blocking_alert(alerts, @route, @date) == nil | ||
end | ||
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
Oops, something went wrong.
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.
Thanks!!