refactor: DRY - use Mv.Constants.custom_field_prefix() instead of string literals
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Moritz 2025-12-03 18:47:27 +01:00
parent fabfe64468
commit cf6a108049
4 changed files with 28 additions and 8 deletions

View file

@ -155,9 +155,11 @@ defmodule MvWeb.MemberLive.Index.FieldVisibility do
"""
@spec get_visible_custom_fields(%{String.t() => boolean()}) :: [String.t()]
def get_visible_custom_fields(field_selection) when is_map(field_selection) do
prefix = Mv.Constants.custom_field_prefix()
field_selection
|> Enum.filter(fn {field_string, visible} ->
visible && String.starts_with?(field_string, "custom_field_")
visible && String.starts_with?(field_string, prefix)
end)
|> Enum.map(fn {field_string, _visible} -> field_string end)
end
@ -188,8 +190,10 @@ defmodule MvWeb.MemberLive.Index.FieldVisibility do
# Gets custom field visibility (all custom fields with show_in_overview=true are visible)
defp get_custom_field_visibility(custom_fields) do
prefix = Mv.Constants.custom_field_prefix()
Enum.reduce(custom_fields, %{}, fn custom_field, acc ->
field_string = "custom_field_#{custom_field.id}"
field_string = "#{prefix}#{custom_field.id}"
visible = Map.get(custom_field, :show_in_overview, true)
Map.put(acc, field_string, visible)
end)
@ -218,7 +222,7 @@ defmodule MvWeb.MemberLive.Index.FieldVisibility do
# Converts field string to atom (for member fields) or keeps as string (for custom fields)
defp to_field_identifier(field_string) when is_binary(field_string) do
if String.starts_with?(field_string, "custom_field_") do
if String.starts_with?(field_string, Mv.Constants.custom_field_prefix()) do
field_string
else
try do