Skip to content

Commit 50fe3d5

Browse files
authored
Device filter inflight (#2261)
This should allow watching updates as they happen. It'll be a lot better if we land the changes to live updating. But this adds the filter and a link on the summary page whenever devices are actively updating.
1 parent d9ff65f commit 50fe3d5

File tree

5 files changed

+57
-4
lines changed

5 files changed

+57
-4
lines changed

lib/nerves_hub/devices/device_filtering.ex

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ defmodule NervesHub.Devices.DeviceFiltering do
77

88
alias NervesHub.Devices.Alarms
99
alias NervesHub.Devices.DeviceMetric
10+
alias NervesHub.Devices.InflightUpdate
1011
alias NervesHub.Types.Tag
1112

1213
@spec build_filters(Ecto.Query.t(), %{optional(atom) => String.t()}) :: Ecto.Query.t()
@@ -124,6 +125,16 @@ defmodule NervesHub.Devices.DeviceFiltering do
124125
def filter(query, _filters, :display_deleted, "only"),
125126
do: where(query, [d], not is_nil(d.deleted_at))
126127

128+
def filter(query, _filters, :only_updating, false),
129+
do: query
130+
131+
def filter(query, _filters, :only_updating, true),
132+
do:
133+
join(query, :inner, [d], iu in InflightUpdate,
134+
on: d.id == iu.device_id,
135+
as: :inflight_update
136+
)
137+
127138
def filter(query, _filters, :search, value) when is_binary(value) and value != "" do
128139
search_term = "%#{value}%"
129140

lib/nerves_hub_web/components/deployment_group_page/summary.ex

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,16 @@ defmodule NervesHubWeb.Components.DeploymentGroupPage.Summary do
110110
</div>
111111
<div class="flex flex-col gap-3">
112112
<div :if={@inflight_updates == []} class="flex gap-4 items-center">
113-
<span class="text-sm text-nerves-gray-500">No devices are currently updating</span>
113+
<span class="text-sm text-nerves-gray-500">No devices are currently updating.</span>
114114
</div>
115115
<div :if={@inflight_updates != []} class="flex gap-4 items-center">
116-
<span class="text-sm text-nerves-gray-500"><span class="font-semibold">{Enum.count(@inflight_updates)}</span> device(s) are currently updating</span>
116+
<span class="text-sm text-nerves-gray-500">
117+
<span class="font-semibold">{Enum.count(@inflight_updates)}</span>
118+
device(s) are currently updating.
119+
<.link class="text-base-300 underline" navigate={~p"/org/#{@org}/#{@product}/devices?#{[only_updating: true, sort: "connection_established_at", sort_direction: "desc"]}"}>
120+
View details
121+
</.link>
122+
</span>
117123
</div>
118124
<div :for={inflight_update <- @inflight_updates} :if={@inflight_updates != []} class="flex gap-4 items-center">
119125
<span class="flex h-7 py-1 px-2 items-center rounded bg-zinc-800 text-base-300">

lib/nerves_hub_web/live/devices/index-new.html.heex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,7 @@
408408
{"Only deleted devices", "only"}
409409
]}
410410
/>
411+
<:filter attr="only_updating" label="Update status" type={:select} values={[{"All", "false"}, {"Updating", "true"}]} />
411412
</FilterSidebar.render>
412413

413414
<div class="pointer-events-none fixed inset-y-0 right-0 flex max-w-full pl-10 mb-[119px] sm:pl-16 z-40">

lib/nerves_hub_web/live/devices/index.ex

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ defmodule NervesHubWeb.Live.Devices.Index do
4747
deployment_id: "",
4848
is_pinned: false,
4949
search: "",
50-
display_deleted: "exclude"
50+
display_deleted: "exclude",
51+
only_updating: false
5152
}
5253

5354
@filter_types %{
@@ -69,7 +70,8 @@ defmodule NervesHubWeb.Live.Devices.Index do
6970
deployment_id: :string,
7071
is_pinned: :boolean,
7172
search: :string,
72-
display_deleted: :string
73+
display_deleted: :string,
74+
only_updating: :boolean
7375
}
7476

7577
@default_page 1

test/nerves_hub_web/live/new_ui/devices/index_test.exs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,39 @@ defmodule NervesHubWeb.Live.NewUI.Devices.IndexTest do
256256
|> assert_has("a", text: deleted_device.identifier, timeout: 1000, exact: false)
257257
|> refute_has("a", text: device.identifier, exact: false)
258258
end
259+
260+
test "filter only updating devices", %{
261+
conn: conn,
262+
fixture: %{
263+
device: device,
264+
org: org,
265+
product: product,
266+
deployment_group: deployment_group
267+
}
268+
} do
269+
conn
270+
|> visit("/org/#{org.name}/#{product.name}/devices")
271+
|> assert_has("a", text: device.identifier, timeout: 1000)
272+
273+
conn
274+
|> visit("/org/#{org.name}/#{product.name}/devices")
275+
|> select("Update status", option: "Updating")
276+
|> refute_has("a", text: device.identifier, timeout: 1000)
277+
278+
{:ok, _inflight_update} = Devices.told_to_update(device, deployment_group)
279+
280+
conn
281+
|> visit("/org/#{org.name}/#{product.name}/devices")
282+
|> select("Update status", option: "Updating")
283+
|> assert_has("a", text: device.identifier, timeout: 1000)
284+
285+
{:ok, _device} = Devices.firmware_update_successful(device)
286+
287+
conn
288+
|> visit("/org/#{org.name}/#{product.name}/devices")
289+
|> select("Update status", option: "Updating")
290+
|> refute_has("a", text: device.identifier, timeout: 1000)
291+
end
259292
end
260293

261294
describe "pagination" do

0 commit comments

Comments
 (0)