fix: treat URL with only custom fields as valid in ?fields= mode
Some checks reported errors
continuous-integration/drone/push Build was killed
continuous-integration/drone/promote/production Build is passing

Consider visible custom fields in compute_final_field_selection so that
a link with only custom_field_X is not wrongly treated as invalid and
reverted to session/global. Add test for URL containing only custom field.
This commit is contained in:
Moritz 2026-02-24 09:42:10 +01:00
parent d5df2338a7
commit 10ad32eb6f
Signed by: moritz
GPG key ID: 1020A035E5DD0824
2 changed files with 15 additions and 2 deletions

View file

@ -821,9 +821,10 @@ defmodule MvWeb.MemberLive.Index do
only_url = only_url =
FieldVisibility.selection_from_url_only(url_selection, socket.assigns.all_custom_fields) FieldVisibility.selection_from_url_only(url_selection, socket.assigns.all_custom_fields)
visible = FieldVisibility.get_visible_member_fields(only_url) visible_members = FieldVisibility.get_visible_member_fields(only_url)
visible_custom = FieldVisibility.get_visible_custom_fields(only_url)
if visible == [] do if visible_members == [] and visible_custom == [] do
# URL had only invalid field names; fall back to session + global. # URL had only invalid field names; fall back to session + global.
compute_final_field_selection(false, url_selection, socket) compute_final_field_selection(false, url_selection, socket)
else else

View file

@ -361,6 +361,18 @@ defmodule MvWeb.MemberLive.IndexFieldVisibilityTest do
assert html =~ "Alice" assert html =~ "Alice"
end end
test "URL with only custom field keeps custom field visible (no invalid fallback)", %{
conn: conn,
custom_field: custom_field
} do
conn = conn_with_oidc_user(conn)
id = custom_field.id
{:ok, _view, html} = live(conn, "/members?fields=custom_field_#{id}")
# Selection must not be treated as invalid; custom field column stays visible
assert html =~ "M001" or html =~ custom_field.name
end
test "handles rapid toggling", %{conn: conn} do test "handles rapid toggling", %{conn: conn} do
conn = conn_with_oidc_user(conn) conn = conn_with_oidc_user(conn)
{:ok, view, _html} = live(conn, "/members") {:ok, view, _html} = live(conn, "/members")