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 Jan 9, 2025
1 parent 700b887 commit a5bfb3c
Show file tree
Hide file tree
Showing 9 changed files with 102 additions and 9 deletions.
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
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ exports[`Detours Page: Open a Detour renders detour details in an open drawer on
>
On detour since
</th>
<th
class="px-3 py-4 u-hide-for-mobile"
>
Est. Duration
</th>
</tr>
</thead>
<tbody>
Expand Down Expand Up @@ -126,6 +131,11 @@ exports[`Detours Page: Open a Detour renders detour details in an open drawer on
>
Just now
</td>
<td
class="align-middle p-3 u-hide-for-mobile"
>
2 hours
</td>
</tr>
<tr>
<td
Expand Down Expand Up @@ -165,6 +175,11 @@ exports[`Detours Page: Open a Detour renders detour details in an open drawer on
>
Just now
</td>
<td
class="align-middle p-3 u-hide-for-mobile"
>
2 hours
</td>
</tr>
</tbody>
</table>
Expand Down Expand Up @@ -932,6 +947,11 @@ exports[`Detours Page: Open a Detour renders detour details modal to match mocke
>
On detour since
</th>
<th
class="px-3 py-4 u-hide-for-mobile"
>
Est. Duration
</th>
</tr>
</thead>
<tbody>
Expand Down Expand Up @@ -973,6 +993,11 @@ exports[`Detours Page: Open a Detour renders detour details modal to match mocke
>
Just now
</td>
<td
class="align-middle p-3 u-hide-for-mobile"
>
2 hours
</td>
</tr>
<tr>
<td
Expand Down Expand Up @@ -1012,6 +1037,11 @@ exports[`Detours Page: Open a Detour renders detour details modal to match mocke
>
Just now
</td>
<td
class="align-middle p-3 u-hide-for-mobile"
>
2 hours
</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
31 changes: 23 additions & 8 deletions test/support/factories/detour_factory.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit a5bfb3c

Please sign in to comment.