diff --git a/app/components/avo/field_wrapper_component.html.erb b/app/components/avo/field_wrapper_component.html.erb index e044301b9d..aad1147ffa 100644 --- a/app/components/avo/field_wrapper_component.html.erb +++ b/app/components/avo/field_wrapper_component.html.erb @@ -11,7 +11,7 @@ "md:w-64": !compact?, }), data: {slot: "label"} do %> <% if form.present? %> - <%= form.label field.id, label %> + <%= form.label field.form_field_label, label %> <% else %> <%= field.name %> <% end %> diff --git a/lib/avo/concerns/breadcrumbs.rb b/lib/avo/concerns/breadcrumbs.rb index b60c7f65a6..abd12c19d5 100644 --- a/lib/avo/concerns/breadcrumbs.rb +++ b/lib/avo/concerns/breadcrumbs.rb @@ -85,10 +85,10 @@ def avo_breadcrumbs end module HelperMethods - def render_avo_breadcrumbs(options = {}, &block) + def render_avo_breadcrumbs(options = {}, &) builder = Builder.new(self, options) content = builder.render.html_safe - block_given? ? capture(content, &block) : content + block_given? ? capture(content, &) : content end end end diff --git a/lib/avo/concerns/can_replace_items.rb b/lib/avo/concerns/can_replace_items.rb index c050638abe..2265cfe642 100644 --- a/lib/avo/concerns/can_replace_items.rb +++ b/lib/avo/concerns/can_replace_items.rb @@ -24,8 +24,8 @@ def with_new_items(&block) end end - def with_new_items(&block) - self.class.with_new_items(&block) + def with_new_items(&) + self.class.with_new_items(&) end end end diff --git a/lib/avo/concerns/checks_assoc_authorization.rb b/lib/avo/concerns/checks_assoc_authorization.rb index dd0600d2bd..e45c0260d3 100644 --- a/lib/avo/concerns/checks_assoc_authorization.rb +++ b/lib/avo/concerns/checks_assoc_authorization.rb @@ -8,7 +8,7 @@ def authorize_association_for(policy_method) policy_result = true if @reflection.present? - # Fetch the appropiate resource + # Fetch the appropriate resource reflection_resource = field.resource # Fetch the record # Hydrate the resource with the record if we have one @@ -23,7 +23,7 @@ def authorize_association_for(policy_method) service = reflection_resource.authorization if service.has_method?(method_name, raise_exception: false) - # Some policy methods should get the parent record in order to have the necessarry information to do the authorization + # Some policy methods should get the parent record in order to have the necessary information to do the authorization # Example: Post->has_many->Comments # # When you want to authorize the creation/attaching of a Comment, you don't have the Comment instance. diff --git a/lib/avo/concerns/has_items.rb b/lib/avo/concerns/has_items.rb index 83f61b55f2..9381b73cd6 100644 --- a/lib/avo/concerns/has_items.rb +++ b/lib/avo/concerns/has_items.rb @@ -84,7 +84,14 @@ def only_fields(only_root: false) items.each do |item| next if item.nil? - unless only_root + if only_root + # When `item.is_main_panel? == true` then also `item.is_panel? == true` + # But when only_root == true we want to extract main_panel items + # In all other circumstances items will get extracted when checking for `item.is_panel?` + if item.is_main_panel? + fields << extract_fields(item) + end + else # Dive into panels to fetch their fields if item.is_panel? fields << extract_fields(item) @@ -101,13 +108,6 @@ def only_fields(only_root: false) if item.is_sidebar? fields << extract_fields(item) end - else - # When `item.is_main_panel? == true` then also `item.is_panel? == true` - # But when only_root == true we want to extract main_panel items - # In all other circumstances items will get extracted when checking for `item.is_panel?` - if item.is_main_panel? - fields << extract_fields(item) - end end if item.is_field? @@ -308,8 +308,6 @@ def extract_fields(structure) item elsif extractable_structure?(item) extract_fields(item) - else - nil end end.compact end diff --git a/lib/avo/concerns/visible_in_different_views.rb b/lib/avo/concerns/visible_in_different_views.rb index 1e783119cb..fd5bf00cf7 100644 --- a/lib/avo/concerns/visible_in_different_views.rb +++ b/lib/avo/concerns/visible_in_different_views.rb @@ -32,7 +32,7 @@ def initialize_views def visible_in_view?(view:) raise "No view specified on visibility check." if view.blank? - send "show_on_#{view}" + send :"show_on_#{view}" end def show_on(*where) @@ -78,11 +78,11 @@ def show_on_update private def show_on_view(view) - send("show_on_#{view}=", true) + send(:"show_on_#{view}=", true) end def hide_on_view(view) - send("show_on_#{view}=", false) + send(:"show_on_#{view}=", false) end def only_on_view(view) diff --git a/lib/avo/fields/base_field.rb b/lib/avo/fields/base_field.rb index 8d45ef8fe1..39d6f150f7 100644 --- a/lib/avo/fields/base_field.rb +++ b/lib/avo/fields/base_field.rb @@ -277,6 +277,10 @@ def assign_value(record:, value:) end end + def form_field_label + id + end + private def model_or_class(model) diff --git a/lib/avo/fields/belongs_to_field.rb b/lib/avo/fields/belongs_to_field.rb index c459cf590b..65cf69606f 100644 --- a/lib/avo/fields/belongs_to_field.rb +++ b/lib/avo/fields/belongs_to_field.rb @@ -265,6 +265,10 @@ def can_create? @can_create end + def form_field_label + id + end + private def get_model_class(record) diff --git a/lib/avo/fields/concerns/frame_loading.rb b/lib/avo/fields/concerns/frame_loading.rb index dcbbc1242c..be83eff6e5 100644 --- a/lib/avo/fields/concerns/frame_loading.rb +++ b/lib/avo/fields/concerns/frame_loading.rb @@ -11,4 +11,3 @@ def turbo_frame_loading end end end -