From 55c6ab22587b8135fab03fb40f6ff8f5bbb7cf37 Mon Sep 17 00:00:00 2001 From: Kayla Firestack Date: Thu, 12 Dec 2024 10:45:24 -0500 Subject: [PATCH] feat: add estimated-duration column to frontend detours list --- assets/src/components/detoursTable.tsx | 8 +++++ assets/src/models/detoursList.ts | 3 ++ .../detourListPage.test.tsx.snap | 30 ++++++++++++++++++ .../detoursListPage.openDetour.test.tsx.snap | 30 ++++++++++++++++++ .../detours/detourListPage.test.tsx | 4 +++ assets/tests/factories/detourListFactory.ts | 1 + lib/skate/detours/detour.ex | 2 ++ lib/skate/detours/detours.ex | 6 +++- test/support/factories/detour_factory.ex | 31 ++++++++++++++----- 9 files changed, 106 insertions(+), 9 deletions(-) diff --git a/assets/src/components/detoursTable.tsx b/assets/src/components/detoursTable.tsx index 3da8896d3..b95cb47f9 100644 --- a/assets/src/components/detoursTable.tsx +++ b/assets/src/components/detoursTable.tsx @@ -51,6 +51,9 @@ export const DetoursTable = ({ {timestampLabelFromStatus(status)} + {status === DetourStatus.Active && ( + Est. Duration + )} @@ -102,6 +105,11 @@ const PopulatedDetourRows = ({ ? timeAgoLabelFromDate(detour.activatedAt, epochNow) : timeAgoLabel(epochNowInSeconds, detour.updatedAt)} + {detour.estimatedDuration && ( + + {detour.estimatedDuration} + + )} ))} diff --git a/assets/src/models/detoursList.ts b/assets/src/models/detoursList.ts index c709c0bbe..4f2895408 100644 --- a/assets/src/models/detoursList.ts +++ b/assets/src/models/detoursList.ts @@ -18,6 +18,7 @@ export interface SimpleDetour { intersection: string updatedAt: number activatedAt?: Date + estimatedDuration?: string } export const detourId = number() @@ -32,6 +33,7 @@ export const SimpleDetourData = type({ export const ActivatedDetourData = type({ activated_at: coerce(date(), string(), (dateStr) => new Date(dateStr)), + estimated_duration: string(), details: SimpleDetourData, }) @@ -68,6 +70,7 @@ export const groupedDetoursFromData = ( active: groupedDetours.active?.map((detour) => ({ ...simpleDetourFromData(detour.details), activatedAt: detour.activated_at, + estimatedDuration: detour.estimated_duration, })), draft: groupedDetours.draft?.map((detour) => simpleDetourFromData(detour)), past: groupedDetours.past?.map((detour) => simpleDetourFromData(detour)), diff --git a/assets/tests/components/detours/__snapshots__/detourListPage.test.tsx.snap b/assets/tests/components/detours/__snapshots__/detourListPage.test.tsx.snap index 1610141e0..395ca1c98 100644 --- a/assets/tests/components/detours/__snapshots__/detourListPage.test.tsx.snap +++ b/assets/tests/components/detours/__snapshots__/detourListPage.test.tsx.snap @@ -82,6 +82,11 @@ exports[`DetourListPage renders detour list page for dispatchers 1`] = ` > On detour since + + Est. Duration + @@ -123,6 +128,11 @@ exports[`DetourListPage renders detour list page for dispatchers 1`] = ` > 26 hours ago + + 2 hours + 29 hours ago + + 3 hours + @@ -453,6 +468,11 @@ exports[`DetourListPage renders limited detour list page for non-dispatchers 1`] > On detour since + + Est. Duration + @@ -494,6 +514,11 @@ exports[`DetourListPage renders limited detour list page for non-dispatchers 1`] > 26 hours ago + + 4 hours + 29 hours ago + + Until end of service + diff --git a/assets/tests/components/detours/__snapshots__/detoursListPage.openDetour.test.tsx.snap b/assets/tests/components/detours/__snapshots__/detoursListPage.openDetour.test.tsx.snap index aff965085..1ffc76dc8 100644 --- a/assets/tests/components/detours/__snapshots__/detoursListPage.openDetour.test.tsx.snap +++ b/assets/tests/components/detours/__snapshots__/detoursListPage.openDetour.test.tsx.snap @@ -85,6 +85,11 @@ exports[`Detours Page: Open a Detour renders detour details in an open drawer on > On detour since + + Est. Duration + @@ -126,6 +131,11 @@ exports[`Detours Page: Open a Detour renders detour details in an open drawer on > Just now + + 2 hours + Just now + + 2 hours + @@ -932,6 +947,11 @@ exports[`Detours Page: Open a Detour renders detour details modal to match mocke > On detour since + + Est. Duration + @@ -973,6 +993,11 @@ exports[`Detours Page: Open a Detour renders detour details modal to match mocke > Just now + + 2 hours + Just now + + 2 hours + diff --git a/assets/tests/components/detours/detourListPage.test.tsx b/assets/tests/components/detours/detourListPage.test.tsx index aa30e8374..99727a35f 100644 --- a/assets/tests/components/detours/detourListPage.test.tsx +++ b/assets/tests/components/detours/detourListPage.test.tsx @@ -42,6 +42,7 @@ describe("DetourListPage", () => { intersection: "Street A & Avenue B", updatedAt: 1724866392, activatedAt: new Date(1724866392000), + estimatedDuration: "2 hours", }, { id: 8, @@ -51,6 +52,7 @@ describe("DetourListPage", () => { intersection: "Street C & Avenue D", updatedAt: 1724856392, activatedAt: new Date(1724856392000), + estimatedDuration: "3 hours", }, ], draft: undefined, @@ -102,6 +104,7 @@ describe("DetourListPage", () => { intersection: "Street A & Avenue B", updatedAt: 1724866392, activatedAt: new Date(1724866392000), + estimatedDuration: "4 hours", }, { id: 8, @@ -111,6 +114,7 @@ describe("DetourListPage", () => { intersection: "Street C & Avenue D", updatedAt: 1724856392, activatedAt: new Date(1724856392000), + estimatedDuration: "Until end of service", }, ], draft: undefined, diff --git a/assets/tests/factories/detourListFactory.ts b/assets/tests/factories/detourListFactory.ts index 3d1efb2c1..ca524575a 100644 --- a/assets/tests/factories/detourListFactory.ts +++ b/assets/tests/factories/detourListFactory.ts @@ -26,4 +26,5 @@ const simpleDetourFactory = Factory.define(({ sequence }) => ({ const activeDetourFactory = simpleDetourFactory.params({ activatedAt: new Date(), + estimatedDuration: "2 hours", }) diff --git a/lib/skate/detours/detour.ex b/lib/skate/detours/detour.ex index d7758dce5..d51fce817 100644 --- a/lib/skate/detours/detour.ex +++ b/lib/skate/detours/detour.ex @@ -74,6 +74,7 @@ defmodule Skate.Detours.Detour do @type t :: %__MODULE__{ activated_at: DateTime.t(), + estimated_duration: String.t(), details: Detailed.t() } @@ -81,6 +82,7 @@ defmodule Skate.Detours.Detour do defstruct [ :activated_at, + :estimated_duration, :details ] end diff --git a/lib/skate/detours/detours.ex b/lib/skate/detours/detours.ex index a62e935bf..d093e015a 100644 --- a/lib/skate/detours/detours.ex +++ b/lib/skate/detours/detours.ex @@ -72,13 +72,17 @@ defmodule Skate.Detours.Detours do def db_detour_to_detour( :active, - %Detour{activated_at: activated_at} = db_detour + %Detour{ + activated_at: activated_at, + state: %{"context" => %{"selectedDuration" => estimated_duration}} + } = db_detour ) do details = DetailedDetour.from(:active, db_detour) details && %ActivatedDetourDetails{ activated_at: activated_at, + estimated_duration: estimated_duration, details: details } end diff --git a/test/support/factories/detour_factory.ex b/test/support/factories/detour_factory.ex index 723f3f261..f483280d4 100644 --- a/test/support/factories/detour_factory.ex +++ b/test/support/factories/detour_factory.ex @@ -61,22 +61,37 @@ defmodule Skate.DetourFactory do with_id(detour, id) end - def activated(update_arg, activated_at \\ DateTime.utc_now()) + def activated( + update_arg, + activated_at \\ DateTime.utc_now(), + estimated_duration \\ "1 hour" + ) - def activated(%Skate.Detours.Db.Detour{} = detour, activated_at) do + def activated(%Skate.Detours.Db.Detour{} = detour, activated_at, estimated_duration) do activated_at = Skate.DetourFactory.browser_date(activated_at) - %{detour | state: activated(detour.state, activated_at), activated_at: activated_at} + + %{ + detour + | state: activated(detour.state, activated_at, estimated_duration), + activated_at: activated_at + } end - def activated(%{"value" => %{}, "context" => %{}} = state, activated_at) do + def activated(%{"value" => %{}, "context" => %{}} = state, activated_at, estimated_duration) do state = put_in(state["value"], %{"Detour Drawing" => %{"Active" => "Reviewing"}}) + state = + put_in( + state["context"]["activatedAt"], + activated_at + |> Skate.DetourFactory.browser_date() + |> DateTime.to_iso8601() + ) + put_in( - state["context"]["activatedAt"], - activated_at - |> Skate.DetourFactory.browser_date() - |> DateTime.to_iso8601() + state["context"]["selectedDuration"], + estimated_duration ) end