Skip to content

Commit

Permalink
Update style
Browse files Browse the repository at this point in the history
  • Loading branch information
tspenov committed Oct 30, 2024
1 parent c217fb6 commit 59be914
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions lib/sanbase_web/generic_admin/version.ex
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,29 @@ defmodule SanbaseWeb.GenericAdmin.Version do
end

defp format_patch(%{patch: patch}) when is_map(patch) do
patch
|> Enum.map_join("\n", fn {field, change} ->
format_change(field, change)
end)
changes =
patch
|> Enum.map(fn {field, change} ->
"<li><strong>#{field}</strong>: #{format_change_value(change)}</li>"
end)
|> Enum.join("")

Phoenix.HTML.raw("<ul class=\"list-disc list-inside\">#{changes}</ul>")
end

defp format_patch(_), do: ""
defp format_patch(_), do: Phoenix.HTML.raw("")

defp format_change(field, {:changed, {:primitive_change, old_val, new_val}}) do
"#{field}: #{inspect(old_val)}#{inspect(new_val)}"
defp format_change_value({:changed, {:primitive_change, old_val, new_val}}) do
"#{inspect(old_val)}#{inspect(new_val)}"
end

defp format_change(field, {:changed, nested}) when is_map(nested) do
defp format_change_value({:changed, nested}) when is_map(nested) do
nested_changes =
nested
|> Enum.map_join(", ", fn {k, v} -> format_change(k, v) end)
|> Enum.map_join(", ", fn {k, v} -> "#{k}: #{format_change_value(v)}" end)

"#{field}: {#{nested_changes}}"
"{#{nested_changes}}"
end

defp format_change(field, other), do: "#{field}: #{inspect(other)}"
defp format_change_value(other), do: inspect(other)
end

0 comments on commit 59be914

Please sign in to comment.