Sha256: b27f3c362548be86321a8e78b9112d4af45349cba674c077862db8d5306d61ca

Contents?: true

Size: 1.48 KB

Versions: 8

Compression:

Stored size: 1.48 KB

Contents

# frozen_string_literal: true

class Avo::TabSwitcherComponent < Avo::BaseComponent
  include Avo::UrlHelpers
  include Avo::ApplicationHelper

  attr_reader :active_tab_name
  attr_reader :group
  attr_reader :current_tab
  attr_reader :tabs
  attr_reader :view
  attr_reader :resource

  delegate :white_panel_classes, to: :helpers

  def initialize(resource:, group:, current_tab:, active_tab_name:, view:)
    @active_tab_name = active_tab_name
    @resource = resource
    @group = group
    @current_tab = current_tab
    @tabs = group.items
    @view = view
  end

  #TOD: helper to record:
  def tab_path(tab)
    if is_edit?
      helpers.edit_resource_path(resource: @resource, record: @resource.record, keep_query_params: true, active_tab_name: tab.name, tab_turbo_frame: group.turbo_frame_id)
    elsif is_new?
      helpers.new_resource_path(resource: @resource, keep_query_params: true, active_tab_name: tab.name, tab_turbo_frame: group.turbo_frame_id)
    else
      helpers.resource_path(resource: @resource, record: @resource.record, keep_query_params: true, active_tab_name: tab.name, tab_turbo_frame: group.turbo_frame_id)
    end
  end

  def is_edit?
    @view.in?(%w[edit update])
  end

  def is_new?
    @view.in?(%w[new create])
  end

  # We'll mark the tab as selected if it's the current one
  def current_one?(tab)
    tab.name == active_tab_name
  end

  private

  def group_param
    "tab-group_#{group.id}"
  end

  def tab_param_missing?
    params[group_param].blank?
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
avo-3.2.3 app/components/avo/tab_switcher_component.rb
avo-3.2.2 app/components/avo/tab_switcher_component.rb
avo-3.2.1 app/components/avo/tab_switcher_component.rb
avo-3.2.0 app/components/avo/tab_switcher_component.rb
avo-3.1.7 app/components/avo/tab_switcher_component.rb
avo-3.1.6 app/components/avo/tab_switcher_component.rb
avo-3.1.5 app/components/avo/tab_switcher_component.rb
avo-3.1.4 app/components/avo/tab_switcher_component.rb