Class: Avo::Items::SwitcherComponent

Inherits:
ResourceComponent
  • Object
show all
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.



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'app/components/avo/items/switcher_component.rb', line 18

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.



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

def index
  @index
end

#itemObject (readonly)

Returns the value of attribute item.



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

def item
  @item
end

#reflectionObject (readonly)

Returns the value of attribute reflection.



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

def reflection
  @reflection
end

#resourceObject (readonly)

Returns the value of attribute resource.



4
5
6
# File 'app/components/avo/items/switcher_component.rb', line 4

def resource
  @resource
end

#viewObject (readonly)

Returns the value of attribute view.



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

def view
  @view
end

Instance Method Details

#field_componentObject



72
73
74
75
# File 'app/components/avo/items/switcher_component.rb', line 72

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

#formObject



44
45
46
# File 'app/components/avo/items/switcher_component.rb', line 44

def form
  @form || nil
end

#in_reflection?Boolean

Returns:

  • (Boolean)


57
58
59
# File 'app/components/avo/items/switcher_component.rb', line 57

def in_reflection?
  @reflection.present?
end

#panel_componentObject



77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'app/components/avo/items/switcher_component.rb', line 77

def panel_component
  Avo::Items::PanelComponent.new(
    actions: @actions,
    form: form,
    index: index,
    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)


48
49
50
51
52
53
54
55
# File 'app/components/avo/items/switcher_component.rb', line 48

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?(@reflection)
  end

  true
end

#tab_group_componentObject



61
62
63
64
65
66
67
68
69
70
# File 'app/components/avo/items/switcher_component.rb', line 61

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