Sha256: 201ca9e90a0c77c589f206f89adbabbf0e755a475094631f014cd4a2e25d39f2

Contents?: true

Size: 1.99 KB

Versions: 84

Compression:

Stored size: 1.99 KB

Contents

# frozen_string_literal: true

class Avo::Items::SwitcherComponent < Avo::BaseComponent
  include Turbo::FramesHelper

  attr_reader :resource
  attr_reader :reflection
  attr_reader :index
  attr_reader :item
  attr_reader :view

  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

  def form
    @form || nil
  end

  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

  def in_reflection?
    @reflection.present?
  end

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

  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

  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
end

Version data entries

84 entries across 84 versions & 1 rubygems

Version Path
avo-3.16.5 app/components/avo/items/switcher_component.rb
avo-3.16.4 app/components/avo/items/switcher_component.rb
avo-3.16.3 app/components/avo/items/switcher_component.rb
avo-3.16.2 app/components/avo/items/switcher_component.rb
avo-3.16.1 app/components/avo/items/switcher_component.rb
avo-3.16.0 app/components/avo/items/switcher_component.rb
avo-3.15.7 app/components/avo/items/switcher_component.rb
avo-3.15.6 app/components/avo/items/switcher_component.rb
avo-3.15.5 app/components/avo/items/switcher_component.rb
avo-3.15.4 app/components/avo/items/switcher_component.rb
avo-3.15.3 app/components/avo/items/switcher_component.rb
avo-3.15.2 app/components/avo/items/switcher_component.rb
avo-3.15.1 app/components/avo/items/switcher_component.rb
avo-3.15.0 app/components/avo/items/switcher_component.rb
avo-3.14.5 app/components/avo/items/switcher_component.rb
avo-3.14.4 app/components/avo/items/switcher_component.rb
avo-3.14.3 app/components/avo/items/switcher_component.rb
avo-3.14.2 app/components/avo/items/switcher_component.rb
avo-3.14.1 app/components/avo/items/switcher_component.rb
avo-3.14.0 app/components/avo/items/switcher_component.rb