fix: Binary data display (#25)

This commit is contained in:
Rebecca Le 2022-08-25 22:54:53 +08:00 committed by GitHub
parent b8858a933e
commit 4a502c2ced
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 2 deletions

View file

@ -553,6 +553,12 @@ defmodule AshAdmin.Components.Resource.Form do
"""
end
def render_attribute_input(assigns, %{type: Ash.Type.Binary}, _form, _value, _name) do
~F"""
<span class="italic">(binary fields cannot be edited)</span>
"""
end
def render_attribute_input(
assigns,
%{

View file

@ -315,6 +315,18 @@ defmodule AshAdmin.Components.Resource.Show do
end
end
defp render_attribute(assigns, _resource, record, %{name: name, type: Ash.Type.Binary}, _) do
if Map.get(record, name) do
~F"""
<span class="italic">(binary data)</span>
"""
else
~F"""
(empty)
"""
end
end
defp render_attribute(assigns, resource, record, attribute, nested?) do
if Ash.Type.embedded_type?(attribute.type) do
both_classes = "ml-1 pl-2 pr-2"

View file

@ -134,14 +134,22 @@ defmodule AshAdmin.Components.Resource.Table do
|> Map.get(attribute.name)
|> (&apply(mod, func, [&1] ++ args)).()
format_attribute_value(data)
format_attribute_value(data, attribute)
end
defp process_attribute(_api, _record, _attr, _formats) do
"..."
end
defp format_attribute_value(data) do
defp format_attribute_value(data, %{type: Ash.Type.Binary}) when data not in [[], nil, ""] do
assigns = %{}
~F"""
<span class='italic'>(binary)</span>
"""
end
defp format_attribute_value(data, _attribute) do
if is_binary(data) and !String.valid?(data) do
"..."
else