Skip to content

Commit

Permalink
feat: add estimated-duration column to frontend detours list
Browse files Browse the repository at this point in the history
  • Loading branch information
firestack committed Dec 21, 2024
1 parent 69c0258 commit 6556454
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 1 deletion.
4 changes: 4 additions & 0 deletions assets/src/components/detourListPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ export const DetourListPage = () => {
<th className="px-3 py-4 u-hide-for-mobile">
{timestampLabelFromStatus(DetourStatus.Active)}
</th>
<th className="px-3 py-4 u-hide-for-mobile">Est. Duration</th>
</tr>
</thead>
<tbody>
Expand Down Expand Up @@ -126,6 +127,9 @@ export const DetourListPage = () => {
<td className="align-middle p-3 u-hide-for-mobile">
{timeAgoLabelForDates(detour.activatedAt, epochNow)}
</td>
<td className="align-middle p-3 u-hide-for-mobile">
{detour.estimatedDuration}
</td>
</tr>
))
: null}
Expand Down
3 changes: 3 additions & 0 deletions assets/src/models/detoursList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export interface SimpleDetour {

export interface ActivatedDetour {
activatedAt: Date
estimatedDuration: string
details: SimpleDetour
}

Expand All @@ -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,
})

Expand Down Expand Up @@ -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)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ exports[`DetourListPage renders detour list page for dispatchers 1`] = `
>
On detour since
</th>
<th
class="px-3 py-4 u-hide-for-mobile"
>
Est. Duration
</th>
</tr>
</thead>
<tbody>
Expand Down Expand Up @@ -123,6 +128,11 @@ exports[`DetourListPage renders detour list page for dispatchers 1`] = `
>
26 hours ago
</td>
<td
class="align-middle p-3 u-hide-for-mobile"
>
2 hours
</td>
</tr>
<tr>
<td
Expand Down Expand Up @@ -162,6 +172,11 @@ exports[`DetourListPage renders detour list page for dispatchers 1`] = `
>
29 hours ago
</td>
<td
class="align-middle p-3 u-hide-for-mobile"
>
3 hours
</td>
</tr>
</tbody>
</table>
Expand Down Expand Up @@ -453,6 +468,11 @@ exports[`DetourListPage renders limited detour list page for non-dispatchers 1`]
>
On detour since
</th>
<th
class="px-3 py-4 u-hide-for-mobile"
>
Est. Duration
</th>
</tr>
</thead>
<tbody>
Expand Down Expand Up @@ -494,6 +514,11 @@ exports[`DetourListPage renders limited detour list page for non-dispatchers 1`]
>
26 hours ago
</td>
<td
class="align-middle p-3 u-hide-for-mobile"
>
4 hours
</td>
</tr>
<tr>
<td
Expand Down Expand Up @@ -533,6 +558,11 @@ exports[`DetourListPage renders limited detour list page for non-dispatchers 1`]
>
29 hours ago
</td>
<td
class="align-middle p-3 u-hide-for-mobile"
>
Until end of service
</td>
</tr>
</tbody>
</table>
Expand Down
4 changes: 4 additions & 0 deletions assets/tests/components/detours/detourListPage.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ describe("DetourListPage", () => {
updatedAt: 1724866392,
},
activatedAt: new Date(1724866392000),
estimatedDuration: "2 hours",
},
{
details: {
Expand All @@ -55,6 +56,7 @@ describe("DetourListPage", () => {
updatedAt: 1724856392,
},
activatedAt: new Date(1724856392000),
estimatedDuration: "3 hours",
},
],
draft: undefined,
Expand Down Expand Up @@ -108,6 +110,7 @@ describe("DetourListPage", () => {
updatedAt: 1724866392,
},
activatedAt: new Date(1724866392000),
estimatedDuration: "4 hours",
},
{
details: {
Expand All @@ -119,6 +122,7 @@ describe("DetourListPage", () => {
updatedAt: 1724856392,
},
activatedAt: new Date(1724856392000),
estimatedDuration: "Until end of service",
},
],
draft: undefined,
Expand Down
1 change: 1 addition & 0 deletions assets/tests/factories/detourListFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@ const simpleDetourFactory = Factory.define<SimpleDetour>(({ sequence }) => ({

const activeDetourFactory = Factory.define<ActivatedDetour>(() => ({
activatedAt: new Date(),
estimatedDuration: "2 hours",
details: simpleDetourFactory.build(),
}))
2 changes: 2 additions & 0 deletions lib/skate/detours/detour.ex
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,15 @@ defmodule Skate.Detours.Detour do

@type t :: %__MODULE__{
activated_at: DateTime.t(),
estimated_duration: String.t(),
details: Detailed.t()
}

@derive Jason.Encoder

defstruct [
:activated_at,
:estimated_duration,
:details
]
end
Expand Down
6 changes: 5 additions & 1 deletion lib/skate/detours/detours.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6556454

Please sign in to comment.