fix(rover-planning): index 'Band' column shows all mission bands

The /rover-planning index was rendering only band_mhz (the legacy
primary single-band column), so multi-band missions with bands_mhz
populated showed just the first band. Switched the renderer to
arity-2 and now pulls the full bands list via Mission.bands/1, so
multi-band missions render '10 GHz · 24 GHz · 47 GHz' etc. Sort
still keys on band_mhz so the column stays sortable on a single
scalar value.
This commit is contained in:
Graham McIntire 2026-05-03 16:06:07 -05:00
parent 833897e2f5
commit 893a02e1e2
No known key found for this signature in database
GPG key ID: F4ABF488E6029E59

View file

@ -8,6 +8,7 @@ defmodule MicrowavepropWeb.RoverPlanningLive do
alias Microwaveprop.Accounts.User
alias Microwaveprop.RoverPlanning
alias Microwaveprop.RoverPlanning.Mission
def table_options do
%{sorting: %{default_sort: [inserted_at: :desc]}}
@ -18,7 +19,7 @@ defmodule MicrowavepropWeb.RoverPlanningLive do
id: %{label: "ID", hidden: true},
user_id: %{label: "Owner", hidden: true},
name: %{label: "Mission", sortable: true, searchable: true, renderer: &name_cell/2},
band_mhz: %{label: "Band", sortable: true, renderer: &band_cell/1},
band_mhz: %{label: "Bands", sortable: true, renderer: &bands_cell/2},
only_known_good: %{label: "Scope", sortable: true, renderer: &scope_cell/1},
inserted_at: %{label: "Created", sortable: true, renderer: &format_ts/1}
]
@ -136,18 +137,26 @@ defmodule MicrowavepropWeb.RoverPlanningLive do
"""
end
defp band_cell(nil), do: ""
# Renders the full bands list (multi-band missions can have several;
# the bound column is `band_mhz` so the table can still sort by the
# primary band, but the cell shows every band the matrix scores).
defp bands_cell(_value, record) do
case Mission.bands(struct(Mission, Map.take(record, [:band_mhz, :bands_mhz]))) do
[] -> ""
[single] -> band_label(single)
list -> Enum.map_join(list, " · ", &band_label/1)
end
end
defp band_cell(mhz) when is_integer(mhz) do
if mhz >= 1000 do
defp band_label(mhz) when is_integer(mhz) and mhz >= 1000 do
ghz = mhz / 1000
label = if ghz == trunc(ghz), do: "#{trunc(ghz)}", else: Float.to_string(Float.round(ghz, 1))
"#{label} GHz"
else
"#{mhz} MHz"
end
end
defp band_label(mhz) when is_integer(mhz), do: "#{mhz} MHz"
defp band_label(_), do: ""
defp scope_cell(true) do
assigns = %{}
~H|<span class="badge badge-success badge-sm">Known good only</span>|