Skip to content

Commit

Permalink
fix: fix cases where data may not match expected patterns
Browse files Browse the repository at this point in the history
this was causing an empty page on update forms
  • Loading branch information
zachdaniel committed Nov 30, 2023
1 parent 339f933 commit d19d808
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 16 deletions.
5 changes: 4 additions & 1 deletion lib/ash_admin/components/resource/resource.ex
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ defmodule AshAdmin.Components.Resource do
prefix={@prefix}
/>
<div class="mx-24 relative grid grid-cols-1 justify-items-center"></div>
<div :if={@record && match?({:ok, record} when not is_nil(record), @record) && @tab == "update"}>
<div :if={
@record && match?({:ok, record} when not is_nil(record), @record) &&
@tab == "update"
}>
<% {:ok, record} = @record %>
<.live_component
module={Form}
Expand Down
34 changes: 19 additions & 15 deletions lib/ash_admin/pages/page_live.ex
Original file line number Diff line number Diff line change
Expand Up @@ -240,21 +240,25 @@ defmodule AshAdmin.PageLive do
record =
socket.assigns.resource
|> to_one_relationships(socket.assigns.api)
|> Enum.reduce(record, fn rel, record ->
case socket.assigns.api.load(record, rel,
actor: actor,
authorize?: socket.assigns.authorizing
) do
{:ok, record} ->
record

{:error, error} ->
Logger.warning(
"Error while loading relationship #{inspect(rel)} on admin dashboard\n: #{Exception.format(:error, error)}"
)

record
end
|> Enum.reduce(record, fn
rel, {:ok, record} ->
case socket.assigns.api.load(record, rel,
actor: actor,
authorize?: socket.assigns.authorizing
) do
{:ok, record} ->
{:ok, record}

{:error, error} ->
Logger.warning(
"Error while loading relationship #{inspect(rel)} on admin dashboard\n: #{Exception.format(:error, error)}"
)

record
end

_rel, other ->
other
end)

socket
Expand Down

0 comments on commit d19d808

Please sign in to comment.