add contextual insights to device preseem tab

This commit is contained in:
Graham McIntire 2026-02-13 08:58:19 -06:00
parent 9a19b9b0a5
commit 62b8ec7afd
No known key found for this signature in database
2 changed files with 75 additions and 3 deletions

View file

@ -436,16 +436,20 @@ defmodule ToweropsWeb.DeviceLive.Show do
device = socket.assigns.device
preseem_ap = Towerops.Preseem.get_access_point_for_device(device.id)
metrics =
{metrics, insights} =
if preseem_ap do
Towerops.Preseem.list_subscriber_metrics(preseem_ap.id, limit: 50)
{
Towerops.Preseem.list_subscriber_metrics(preseem_ap.id, limit: 50),
Towerops.Preseem.list_device_insights(device.id)
}
else
[]
{[], []}
end
socket
|> assign(:preseem_access_point, preseem_ap)
|> assign(:preseem_metrics, metrics)
|> assign(:preseem_insights, insights)
end
defp get_available_firmware(nil), do: nil
@ -1222,6 +1226,17 @@ defmodule ToweropsWeb.DeviceLive.Show do
{:noreply, assign(socket, :selected_backup_ids, MapSet.new())}
end
@impl true
def handle_event("dismiss_insight", %{"id" => insight_id}, socket) do
case Towerops.Preseem.dismiss_insight(insight_id) do
{:ok, _} ->
{:noreply, assign_preseem_data(socket)}
{:error, _} ->
{:noreply, put_flash(socket, :error, "Failed to dismiss insight")}
end
end
@impl true
def handle_event("delete_backup", %{"id" => backup_id}, socket) do
import ToweropsWeb.Permissions

View file

@ -2206,6 +2206,63 @@
<% "preseem" -> %>
<%= if @preseem_access_point do %>
<div class="space-y-6">
<%!-- Insights section --%>
<%= if @preseem_insights != [] do %>
<div class="space-y-3">
<%= for insight <- @preseem_insights do %>
<div class={[
"rounded-lg border p-4 flex items-start justify-between",
case insight.urgency do
"critical" ->
"bg-red-50 border-red-200 dark:bg-red-900/20 dark:border-red-800"
"warning" ->
"bg-yellow-50 border-yellow-200 dark:bg-yellow-900/20 dark:border-yellow-800"
_ ->
"bg-blue-50 border-blue-200 dark:bg-blue-900/20 dark:border-blue-800"
end
]}>
<div class="flex items-start gap-3">
<div class={[
"mt-0.5",
case insight.urgency do
"critical" -> "text-red-500"
"warning" -> "text-yellow-500"
_ -> "text-blue-500"
end
]}>
<%= case insight.urgency do %>
<% "critical" -> %>
<.icon name="hero-exclamation-triangle" class="h-5 w-5" />
<% "warning" -> %>
<.icon name="hero-exclamation-circle" class="h-5 w-5" />
<% _ -> %>
<.icon name="hero-information-circle" class="h-5 w-5" />
<% end %>
</div>
<div>
<p class="text-sm font-medium text-gray-900 dark:text-white">
{insight.title}
</p>
<p class="mt-1 text-sm text-gray-600 dark:text-gray-300">
{insight.description}
</p>
</div>
</div>
<button
phx-click="dismiss_insight"
phx-value-id={insight.id}
class="ml-4 text-gray-400 hover:text-gray-600 dark:hover:text-gray-300 flex-shrink-0"
title="Dismiss"
>
<.icon name="hero-x-mark" class="h-4 w-4" />
</button>
</div>
<% end %>
</div>
<% end %>
<%!-- Score cards --%>
<div class="grid grid-cols-1 sm:grid-cols-3 gap-4">
<div class="bg-white dark:bg-gray-800/50 rounded-lg border border-gray-200 dark:border-white/10 p-4">