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

enhancement: add divider to custom list (custom controls) #3407

Merged
merged 3 commits into from
Nov 18, 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
7 changes: 1 addition & 6 deletions app/components/avo/actions_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def icon(icon)
def render_item(action)
case action
when Avo::Divider
render_divider(action)
render Avo::DividerComponent.new(action.label)
when Avo::BaseAction
render_action_link(action)
when defined?(Avo::Advanced::Resources::Controls::Action) && Avo::Advanced::Resources::Controls::Action
Expand All @@ -84,11 +84,6 @@ def render_item(action)

private

def render_divider(action)
label = action.label.is_a?(Hash) ? action.label[:label] : nil
render Avo::DividerComponent.new(label)
end

def render_action_link(action, icon: nil)
link_to action.link_arguments(resource: @resource, arguments: action.arguments).first,
data: action_data_attributes(action),
Expand Down
8 changes: 4 additions & 4 deletions lib/avo/divider.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
class Avo::Divider < Avo::BaseAction
attr_reader :label, :view
attr_reader :label

def initialize(label: nil, view: nil, **kwargs)
@label = label
@view = view
def initialize(**kwargs)
@label = kwargs[:label]
@view = kwargs[:view]
end
end
4 changes: 2 additions & 2 deletions lib/avo/resources/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -322,8 +322,8 @@ def fetch_cards
cards
end

def divider(label = nil)
entity_loader(:action).use({class: Divider, label: label}.compact)
def divider(**kwargs)
entity_loader(:action).use({class: Divider, **kwargs}.compact)
end

# def fields / def cards
Expand Down
Loading