Skip to content

Commit

Permalink
fix: heading can't be the first item in your resource (#1124)
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianthedev committed Aug 5, 2022
1 parent fed8189 commit be5194a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
21 changes: 11 additions & 10 deletions lib/avo/concerns/has_fields.rb
Expand Up @@ -17,19 +17,19 @@ module HasFields
def field(name, **args, &block)
ensure_items_holder_initialized

self.items_holder.field name, **args, &block
items_holder.field name, **args, &block
end

def panel(name = nil, **args, &block)
ensure_items_holder_initialized

self.items_holder.panel name, **args, &block
items_holder.panel name, **args, &block
end

def tabs(&block)
ensure_items_holder_initialized

self.items_holder.tabs Avo::TabGroupBuilder.parse_block(&block)
items_holder.tabs Avo::TabGroupBuilder.parse_block(&block)
end

def tool(klass, **args)
Expand All @@ -39,27 +39,29 @@ def tool(klass, **args)
end

def heading(body, **args)
self.items_holder.heading body, **args
ensure_items_holder_initialized

items_holder.heading body, **args
end
# END DSL methods

def items
if self.items_holder.present?
self.items_holder.items
if items_holder.present?
items_holder.items
else
[]
end
end

def tools
self.tools_holder
tools_holder
end

# Dives deep into panels and tabs to fetch all the fields for a resource.
def fields(only_root: false)
fields = []

self.items.each do |item|
items.each do |item|
next if item.nil?

unless only_root
Expand All @@ -76,7 +78,6 @@ def fields(only_root: false)
end
end


if item.is_field?
fields << item
end
Expand All @@ -86,7 +87,7 @@ def fields(only_root: false)
end

def tab_groups
self.items.select do |item|
items.select do |item|
item.instance_of? Avo::TabGroup
end
end
Expand Down
3 changes: 2 additions & 1 deletion lib/avo/hosts/base_host.rb
@@ -1,6 +1,6 @@
require "dry-initializer"

# This object holds some data tha is usually needed to compute blocks around the app.
# This object holds some data that is usually needed to compute blocks around the app.
module Avo
module Hosts
class BaseHost
Expand All @@ -10,6 +10,7 @@ class BaseHost
option :params, default: proc { Avo::App.params }
option :view_context, default: proc { Avo::App.view_context }
option :current_user, default: proc { Avo::App.current_user }
# This is optional because we might instantiate the `Host` first and later hydrate it with a block.
option :block, optional: true

delegate :authorize, to: Avo::Services::AuthorizationService
Expand Down

0 comments on commit be5194a

Please sign in to comment.