fix(members): restore column visibility from URL on reload
All checks were successful
continuous-integration/drone/push Build is passing

Read 'fields' from URI when conn.params has no query (e.g. full page load).
When ?fields=... is present use URL-only selection so columns are not
merged with global settings. Fall back to session+global when URL has
only invalid field names.
This commit is contained in:
Moritz 2026-02-24 01:06:41 +01:00
parent e86c78a0dc
commit d41d13d122
Signed by: moritz
GPG key ID: 1020A035E5DD0824
2 changed files with 86 additions and 15 deletions

View file

@ -64,6 +64,25 @@ defmodule MvWeb.MemberLive.Index.FieldVisibility do
member_fields ++ custom_field_names
end
@doc """
Builds field selection from URL only: fields in `url_selection` are visible, all others false.
Use when `?fields=...` is in the URL so column visibility is not merged with global settings.
"""
@spec selection_from_url_only(%{String.t() => boolean()}, [struct()]) :: %{
String.t() => boolean()
}
def selection_from_url_only(url_selection, custom_fields) when is_map(url_selection) do
all_fields = get_all_available_fields(custom_fields)
Enum.reduce(all_fields, %{}, fn field, acc ->
field_string = field_to_string(field)
visible = Map.get(url_selection, field_string, false)
Map.put(acc, field_string, visible)
end)
end
def selection_from_url_only(_, _), do: %{}
@doc """
Merges user field selection with global settings.