Skip to content

Commit

Permalink
Fix crash that can occur with schemas that only have a single field
Browse files Browse the repository at this point in the history
  • Loading branch information
nyxcharon committed Dec 14, 2023
1 parent ab3e9c5 commit 1887ca6
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions lib/kaffy/resource_schema.ex
Original file line number Diff line number Diff line change
Expand Up @@ -88,18 +88,21 @@ defmodule Kaffy.ResourceSchema do
end

defp reorder_fields(fields_list, schema) do
[_id, first_field | _fields] = schema.__schema__(:fields)

# this is a "nice" feature to re-order the default fields to put the specified fields at the top/bottom of the form
fields_list
|> reorder_field(first_field, :first)
|> reorder_field(:email, :first)
|> reorder_field(:name, :first)
|> reorder_field(:title, :first)
|> reorder_field(:id, :first)
|> reorder_field(:inserted_at, :last)
|> reorder_field(:updated_at, :last)
if length(schema.__schema__(:fields)) > 1 do
[_id, first_field | _fields] = schema.__schema__(:fields)

# this is a "nice" feature to re-order the default fields to put the specified fields at the top/bottom of the form
fields_list
|> reorder_field(first_field, :first)
|> reorder_field(:email, :first)
|> reorder_field(:name, :first)
|> reorder_field(:title, :first)
|> reorder_field(:id, :first)
|> reorder_field(:inserted_at, :last)
|> reorder_field(:updated_at, :last)
else
fields_list
end
# |> reorder_field(Kaffy.ResourceSchema.embeds(schema), :last)
end

Expand Down

0 comments on commit 1887ca6

Please sign in to comment.