Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: wrong label on belongs_tofield #2758

Merged
merged 1 commit into from
May 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/components/avo/field_wrapper_component.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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 %>
Expand Down
4 changes: 2 additions & 2 deletions lib/avo/concerns/breadcrumbs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lib/avo/concerns/can_replace_items.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lib/avo/concerns/checks_assoc_authorization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down
18 changes: 8 additions & 10 deletions lib/avo/concerns/has_items.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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?
Expand Down Expand Up @@ -308,8 +308,6 @@ def extract_fields(structure)
item
elsif extractable_structure?(item)
extract_fields(item)
else
nil
end
end.compact
end
Expand Down
6 changes: 3 additions & 3 deletions lib/avo/concerns/visible_in_different_views.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions lib/avo/fields/base_field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,10 @@ def assign_value(record:, value:)
end
end

def form_field_label
id
end

private

def model_or_class(model)
Expand Down
4 changes: 4 additions & 0 deletions lib/avo/fields/belongs_to_field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,10 @@ def can_create?
@can_create
end

def form_field_label
id
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should have been "#{id}_id" probably?

end

private

def get_model_class(record)
Expand Down
1 change: 0 additions & 1 deletion lib/avo/fields/concerns/frame_loading.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,3 @@ def turbo_frame_loading
end
end
end

Loading