Skip to content

Commit

Permalink
fix: All fields should include subfields nested in a field
Browse files Browse the repository at this point in the history
  • Loading branch information
staylorwr committed Nov 10, 2021
1 parent 3566384 commit 75de0fc
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions lib/ex_teal/resource/fields.ex
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,10 @@ defmodule ExTeal.Resource.Fields do
end

def pivot_fields_for(related, rel, _queried) do
relationship_field = Enum.find(related.fields(), &(&1.field == rel))
relationship_field =
related
|> all_fields()
|> Enum.find(&(&1.field == rel))

case Map.get(relationship_field, :private_options) do
nil ->
Expand Down Expand Up @@ -201,7 +204,7 @@ defmodule ExTeal.Resource.Fields do

def all_fields(resource) do
resource.fields()
|> Enum.map(&panel_fields/1)
|> Enum.map(&subfields/1)
|> Enum.concat()
end

Expand All @@ -219,8 +222,9 @@ defmodule ExTeal.Resource.Fields do
end
end

defp panel_fields(%Field{} = field), do: [field]
defp panel_fields(%Panel{fields: fields}), do: fields
defp subfields(%Field{options: %{fields: fields}}), do: fields
defp subfields(%Field{} = field), do: [field]
defp subfields(%Panel{fields: fields}), do: fields

def apply_values(fields, model, resource, conn, type, panel \\ nil)

Expand Down

0 comments on commit 75de0fc

Please sign in to comment.