Current section
Files
Jump to
Current section
Files
lib/integrations/tcp/display.ex
defmodule Integrations.Tcp.Display do
@moduledoc """
Dashboard panel for `Integrations.Tcp` (same package).
Nested under the monitor's own namespace deliberately — the package's
top-level module name never changes, and this module's name is
guaranteed distinct from any separately-published standalone display
package. `Display.BundledDefault` auto-hooks this whenever
`Integrations.Tcp` starts, the same as if they were still one module.
"""
use CodeNameRaven.Display, category: :infrastructure, size_hint: :small
@impl true
def display_name, do: "TCP Port"
@impl true
def compatible_monitors, do: [Integrations.Tcp]
@impl true
def render(assigns) do
result = assigns[:result]
assigns = Map.merge(assigns, %{result: result})
~H"""
<div class="space-y-3">
<div class="flex items-start justify-between gap-2">
<div class="min-w-0">
<h2 class="text-sm font-semibold text-base-content truncate">
<%= @config.name || host_port(@config.params) %>
</h2>
<p class="text-xs font-mono text-base-content/40 truncate">
<%= host_port(@config.params) %>
</p>
</div>
<CodeNameRaven.MonitorComponents.status_chip status={@status} />
</div>
<div :if={@result} class="flex gap-2 flex-wrap">
<CodeNameRaven.MonitorComponents.stat
label="Latency"
value={"#{@result.latency_ms} ms"} />
</div>
<CodeNameRaven.MonitorComponents.error_message message={@last_error} />
<CodeNameRaven.MonitorComponents.check_time checked_at={@last_checked_at} />
</div>
"""
end
# ---------------------------------------------------------------------------
# Helpers
# ---------------------------------------------------------------------------
defp host_port(params) do
host = params[:host] || params["host"] || "?"
port = params[:port] || params["port"] || "?"
"#{host}:#{port}"
end
end