diff --git a/assets/src/components/detourListPage.tsx b/assets/src/components/detourListPage.tsx index 3dab1214a..c430e7a54 100644 --- a/assets/src/components/detourListPage.tsx +++ b/assets/src/components/detourListPage.tsx @@ -98,6 +98,7 @@ export const DetourListPage = () => { {timestampLabelFromStatus(DetourStatus.Active)} + Est. Duration @@ -126,6 +127,9 @@ export const DetourListPage = () => { {timeAgoLabelForDates(detour.activatedAt, epochNow)} + + {detour.estimatedDuration} + )) : null} diff --git a/assets/src/models/detoursList.ts b/assets/src/models/detoursList.ts index 1d004ea7a..50776f2ef 100644 --- a/assets/src/models/detoursList.ts +++ b/assets/src/models/detoursList.ts @@ -21,6 +21,7 @@ export interface SimpleDetour { export interface ActivatedDetour { activatedAt: Date + estimatedDuration: string details: SimpleDetour } @@ -36,6 +37,7 @@ export const SimpleDetourData = type({ export const ActivatedDetourData = type({ activated_at: coerce(date(), string(), (dateStr) => new Date(dateStr)), + estimated_duration: string(), details: SimpleDetourData, }) @@ -72,6 +74,7 @@ export const groupedDetoursFromData = ( active: groupedDetours.active?.map((detour) => ({ details: 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/detourListPage.test.tsx b/assets/tests/components/detours/detourListPage.test.tsx index 3f1a37785..da791e73f 100644 --- a/assets/tests/components/detours/detourListPage.test.tsx +++ b/assets/tests/components/detours/detourListPage.test.tsx @@ -44,6 +44,7 @@ describe("DetourListPage", () => { updatedAt: 1724866392, }, activatedAt: new Date(1724866392000), + estimatedDuration: "2 hours", }, { details: { @@ -55,6 +56,7 @@ describe("DetourListPage", () => { updatedAt: 1724856392, }, activatedAt: new Date(1724856392000), + estimatedDuration: "3 hours", }, ], draft: undefined, @@ -108,6 +110,7 @@ describe("DetourListPage", () => { updatedAt: 1724866392, }, activatedAt: new Date(1724866392000), + estimatedDuration: "4 hours", }, { details: { @@ -119,6 +122,7 @@ describe("DetourListPage", () => { 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 08dbaedd0..89961d63f 100644 --- a/assets/tests/factories/detourListFactory.ts +++ b/assets/tests/factories/detourListFactory.ts @@ -27,5 +27,6 @@ const simpleDetourFactory = Factory.define(({ sequence }) => ({ const activeDetourFactory = Factory.define(() => ({ activatedAt: new Date(), + estimatedDuration: "2 hours", details: simpleDetourFactory.build(), })) diff --git a/lib/skate/detours/detour.ex b/lib/skate/detours/detour.ex index e2e76699f..87743dac6 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 6d12bb2d1..5b11846ec 100644 --- a/lib/skate/detours/detours.ex +++ b/lib/skate/detours/detours.ex @@ -80,13 +80,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