Class: Avo::ActionsComponent

Inherits:
ViewComponent::Base
  • Object
show all
Includes:
ApplicationHelper
Defined in:
app/components/avo/actions_component.rb

Instance Method Summary collapse

Methods included from ApplicationHelper

#a_button, #a_link, #button_classes, #empty_state, #get_model_class, #input_classes, #render_license_warning, #render_license_warnings, #root_path_without_url, #svg

Constructor Details

#initialize(actions: [], resource: nil, view: nil, exclude: [], style: :outline, color: :blue) ⇒ ActionsComponent

Returns a new instance of ActionsComponent.



6
7
8
9
10
11
12
13
# File 'app/components/avo/actions_component.rb', line 6

def initialize(actions: [], resource: nil, view: nil, exclude: [], style: :outline, color: :blue)
  @actions = actions || []
  @resource = resource
  @view = view
  @exclude = exclude
  @color = color
  @style = style
end

Instance Method Details

#action_path(id) ⇒ Object

When running an action for one record we should do it on a special path. We do that so we get the `model` param inside the action so we can prefill fields.



27
28
29
30
31
32
33
34
35
# File 'app/components/avo/actions_component.rb', line 27

def action_path(id)
  return many_records_path(id) unless @resource.has_model_id?

  if on_record_page?
    single_record_path id
  else
    many_records_path id
  end
end

#actionsObject



19
20
21
22
23
# File 'app/components/avo/actions_component.rb', line 19

def actions
  @actions.select do |action|
    !action.class.in?(@exclude)
  end
end

#is_disabled?(action) ⇒ Boolean

How should the action be displayed by default

Returns:

  • (Boolean)


38
39
40
41
42
# File 'app/components/avo/actions_component.rb', line 38

def is_disabled?(action)
  return false if action.standalone

  on_index_page?
end

#render?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'app/components/avo/actions_component.rb', line 15

def render?
  actions.present?
end