refactor: fix Credo warnings in field visibility modules
Use Enum.map_join and reduce nesting in format_custom_field_label
This commit is contained in:
parent
4bbba65038
commit
690083bdf0
2 changed files with 11 additions and 12 deletions
|
|
@ -153,20 +153,20 @@ defmodule MvWeb.Components.FieldVisibilityDropdownComponent do
|
|||
|> field_to_string()
|
||||
|> String.replace("_", " ")
|
||||
|> String.split()
|
||||
|> Enum.map(&String.capitalize/1)
|
||||
|> Enum.join(" ")
|
||||
|> Enum.map_join(" ", &String.capitalize/1)
|
||||
end
|
||||
|
||||
defp format_custom_field_label(field_string, custom_fields) do
|
||||
case String.trim_leading(field_string, "custom_field_") do
|
||||
"" ->
|
||||
field_string
|
||||
id = String.trim_leading(field_string, "custom_field_")
|
||||
find_custom_field_name(id, field_string, custom_fields)
|
||||
end
|
||||
|
||||
id ->
|
||||
case Enum.find(custom_fields, fn cf -> to_string(cf.id) == id end) do
|
||||
nil -> gettext("Custom Field %{id}", id: id)
|
||||
custom_field -> custom_field.name
|
||||
end
|
||||
defp find_custom_field_name("", field_string, _custom_fields), do: field_string
|
||||
|
||||
defp find_custom_field_name(id, _field_string, custom_fields) do
|
||||
case Enum.find(custom_fields, fn cf -> to_string(cf.id) == id end) do
|
||||
nil -> gettext("Custom Field %{id}", id: id)
|
||||
custom_field -> custom_field.name
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -198,8 +198,7 @@ defmodule MvWeb.MemberLive.Index.FieldSelection do
|
|||
def to_url_param(selection) when is_map(selection) do
|
||||
selection
|
||||
|> Enum.filter(fn {_field, visible} -> visible end)
|
||||
|> Enum.map(fn {field, _visible} -> field end)
|
||||
|> Enum.join(",")
|
||||
|> Enum.map_join(",", fn {field, _visible} -> field end)
|
||||
end
|
||||
|
||||
def to_url_param(_), do: ""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue