Class: Avo::Items::SwitcherComponent

Inherits:
BaseComponent
  • Object
show all
Includes:
Turbo::FramesHelper
Defined in:
app/components/avo/items/switcher_component.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resource: nil, reflection: nil, item: nil, index: nil, view: nil, form: nil, parent_resource: nil, parent_record: nil, parent_component: nil, actions: nil, field_component_extra_args: {}) ⇒ SwitcherComponent

Returns a new instance of SwitcherComponent.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/components/avo/items/switcher_component.rb', line 12

def initialize(
  resource: nil,
  reflection: nil,
  item: nil,
  index: nil,
  view: nil,
  form: nil,
  parent_resource: nil,
  parent_record: nil,
  parent_component: nil,
  actions: nil,
  field_component_extra_args: {}
)
  @resource = resource
  @reflection = reflection
  @form = form
  @index = index
  @item = item
  @view = view
  @parent_resource = parent_resource
  @parent_record = parent_record
  @parent_component = parent_component
  @actions = actions
  @field_component_extra_args = field_component_extra_args
end

Instance Attribute Details

#indexObject (readonly)

Returns the value of attribute index.



8
9
10
# File 'app/components/avo/items/switcher_component.rb', line 8

def index
  @index
end

#itemObject (readonly)

Returns the value of attribute item.



9
10
11
# File 'app/components/avo/items/switcher_component.rb', line 9

def item
  @item
end

#reflectionObject (readonly)

Returns the value of attribute reflection.



7
8
9
# File 'app/components/avo/items/switcher_component.rb', line 7

def reflection
  @reflection
end

#resourceObject (readonly)

Returns the value of attribute resource.



6
7
8
# File 'app/components/avo/items/switcher_component.rb', line 6

def resource
  @resource
end

#viewObject (readonly)

Returns the value of attribute view.



10
11
12
# File 'app/components/avo/items/switcher_component.rb', line 10

def view
  @view
end

Instance Method Details

#field_componentObject



66
67
68
69
# File 'app/components/avo/items/switcher_component.rb', line 66

def field_component
  final_item = item.dup.hydrate(resource: @resource, record: @resource.record, user: resource.user, view: view)
  final_item.component_for_view(@view).new(field: final_item, resource: @resource, index: index, form: form, turbo_frame_loading: :lazy, **@field_component_extra_args)
end

#formObject



38
39
40
# File 'app/components/avo/items/switcher_component.rb', line 38

def form
  @form || nil
end

#in_reflection?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'app/components/avo/items/switcher_component.rb', line 51

def in_reflection?
  @reflection.present?
end

#panel_componentObject



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'app/components/avo/items/switcher_component.rb', line 71

def panel_component
  Avo::Items::PanelComponent.new(
    actions: @actions,
    form: form,
    index: index,
    is_main_panel: item.is_main_panel?,
    item: item.hydrate(view: view),
    parent_component: @parent_component,
    parent_record: @parent_record,
    parent_resource: @parent_resource,
    reflection: @reflection,
    resource: @resource,
    view: view
  )
end

#render?Boolean

Returns:

  • (Boolean)


42
43
44
45
46
47
48
49
# File 'app/components/avo/items/switcher_component.rb', line 42

def render?
  # Stops rendering if the field should be hidden in reflections
  if item.is_field?
    return false if in_reflection? && item.hidden_in_reflection?
  end

  true
end

#tab_group_componentObject



55
56
57
58
59
60
61
62
63
64
# File 'app/components/avo/items/switcher_component.rb', line 55

def tab_group_component
  Avo::TabGroupComponent.new(
    resource: @resource,
    group: item.hydrate(view: view),
    index: index,
    params: params,
    form: form,
    view: view
  )
end