Skip to content

Commit

Permalink
Change active to current internally
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulJKim committed Oct 28, 2024
1 parent f31c437 commit 3291297
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 18 deletions.
14 changes: 8 additions & 6 deletions assets/js/components/Dashboard/PaMessagesPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { updateExistingPaMessage } from "Utils/api";
import { UpdatePaMessageBody } from "Models/pa_message";
import Toast from "Components/Toast";

type StateFilter = "active" | "future" | "past";
type StateFilter = "current" | "future" | "past";

type ServiceType =
| "Green"
Expand Down Expand Up @@ -98,7 +98,7 @@ const useDelayedLoadingState = (value: boolean, delay = 250) => {
const PaMessagesPage: ComponentType = () => {
const [params, setParams] = useSearchParams();
const [stateFilter, setStateFilter] = useState<StateFilter>(
() => (params.get("state") as StateFilter) ?? "active",
() => (params.get("state") as StateFilter) ?? "current",
);
const [serviceTypes, setServiceTypes] = useState<Array<ServiceType>>(
() => (params.getAll("serviceTypes[]") as Array<ServiceType>) ?? [],
Expand Down Expand Up @@ -156,8 +156,10 @@ const PaMessagesPage: ComponentType = () => {
<header>Filter by message state</header>
<ButtonGroup className="button-group" vertical>
<Button
className={cx("button", { active: stateFilter === "active" })}
onClick={() => setStateFilter("active")}
className={cx("button", {
active: stateFilter === "current",
})}
onClick={() => setStateFilter("current")}
>
Now
</Button>
Expand Down Expand Up @@ -250,7 +252,7 @@ const PaMessageTable: ComponentType<PaMessageTableProps> = ({
<th>Message</th>
<th>Interval</th>
<th className="pa-message-table__start-end">Start-End</th>
{stateFilter == "active" && <th>Actions</th>}
{stateFilter == "current" && <th>Actions</th>}
</tr>
</thead>
<tbody>
Expand Down Expand Up @@ -324,7 +326,7 @@ const PaMessageRow: ComponentType<PaMessageRowProps> = ({
<br />
{end && end.toLocaleString().replace(",", "")}
</td>
{stateFilter == "active" && (
{stateFilter == "current" && (
<td>
<div className="pause-active-switch-container" onClick={togglePaused}>
<FormCheck
Expand Down
8 changes: 4 additions & 4 deletions lib/screenplay/pa_messages.ex
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ defmodule Screenplay.PaMessages do
import Ecto.Changeset

@type t :: %{
optional(:state) => :all | :active | :future | :past,
optional(:state) => :all | :current | :future | :past,
optional(:now) => DateTime.t(),
optional(:signs) => [String.t(), ...],
optional(:routes) => [String.t(), ...]
Expand All @@ -27,7 +27,7 @@ defmodule Screenplay.PaMessages do
@primary_key false

embedded_schema do
field :state, Ecto.Enum, values: [:all, :active, :future, :past], default: :all
field :state, Ecto.Enum, values: [:all, :current, :future, :past], default: :all
field :now, :utc_datetime, autogenerate: {DateTime, :utc_now, []}
field :signs, {:array, :string}
field :routes, {:array, :string}
Expand Down Expand Up @@ -83,13 +83,13 @@ defmodule Screenplay.PaMessages do
end

@doc """
Returns a list of the currently active PA Messages, excluding ones that are paused
Returns a list of the currently active PA Messages
"""
@spec get_active_messages() :: [PaMessage.t()]
@spec get_active_messages(now :: DateTime.t()) :: [PaMessage.t()]
def get_active_messages(now \\ DateTime.utc_now()) do
AlertsCache.alert_ids()
|> PaMessage.Queries.active_exclude_paused(now)
|> PaMessage.Queries.active(now)
|> Repo.all()
end

Expand Down
16 changes: 8 additions & 8 deletions lib/screenplay/pa_messages/pa_message/queries.ex
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,24 @@ defmodule Screenplay.PaMessages.PaMessage.Queries do

def state(q \\ PaMessage, state, alert_ids, now)
def state(q, :past, alert_ids, now), do: past(q, alert_ids, now)
def state(q, :active, alert_ids, now), do: active(q, alert_ids, now)
def state(q, :current, alert_ids, now), do: current(q, alert_ids, now)
def state(q, :future, _alert_ids, now), do: future(q, now)
def state(q, :all, _, _), do: q

@doc """
Limit the query to only PaMessages that are currently active, excluding messages that are paused.
Limit the query to only PaMessages that are currently active.
A PaMessage is considered "active" if its start time is in the past and
either its end time is in the future or it has no end time and its associated
alert is in passed list of alert IDs.
alert is in passed list of alert IDs and is also not paused.
"""
@spec active_exclude_paused(
@spec active(
queryable :: Ecto.Queryable.t(),
alert_ids :: [String.t()],
now :: DateTime.t()
) ::
Ecto.Query.t()
def active_exclude_paused(q \\ PaMessage, alert_ids, now) do
def active(q \\ PaMessage, alert_ids, now) do
current_service_day_of_week = Util.get_current_service_day(now)

from m in q,
Expand All @@ -41,15 +41,15 @@ defmodule Screenplay.PaMessages.PaMessage.Queries do
end

@doc """
Limit the query to only PaMessages that are currently active.
Limit the query to only PaMessages that are current.
A PaMessage is considered "active" if its start time is in the past and
A PaMessage is considered "current" if its start time is in the past and
either its end time is in the future or it has no end time and its associated
alert is in passed list of alert IDs.
"""
@spec active(queryable :: Ecto.Queryable.t(), alert_ids :: [String.t()], now :: DateTime.t()) ::
Ecto.Query.t()
def active(q \\ PaMessage, alert_ids, now) do
def current(q \\ PaMessage, alert_ids, now) do
current_service_day_of_week = Util.get_current_service_day(now)

from m in q,
Expand Down

0 comments on commit 3291297

Please sign in to comment.