Sha256: d67d203a977cfa37680d19f31620281e5b2b361cd955bc86b8514dbb3abfaa42

Contents?: true

Size: 1.46 KB

Versions: 52

Compression:

Stored size: 1.46 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
  delegate :group_param, to: :@group

  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 tab_param_missing?
    params[group_param].blank?
  end
end

Version data entries

52 entries across 52 versions & 1 rubygems

Version Path
avo-3.11.7 app/components/avo/tab_switcher_component.rb
avo-3.11.6 app/components/avo/tab_switcher_component.rb
avo-3.11.5 app/components/avo/tab_switcher_component.rb
avo-3.11.4 app/components/avo/tab_switcher_component.rb
avo-3.11.3 app/components/avo/tab_switcher_component.rb
avo-3.11.2 app/components/avo/tab_switcher_component.rb
avo-3.11.1 app/components/avo/tab_switcher_component.rb
avo-3.11.0 app/components/avo/tab_switcher_component.rb
avo-3.10.10 app/components/avo/tab_switcher_component.rb
avo-3.10.9 app/components/avo/tab_switcher_component.rb
avo-3.10.8 app/components/avo/tab_switcher_component.rb
avo-3.10.7 app/components/avo/tab_switcher_component.rb
avo-3.10.6 app/components/avo/tab_switcher_component.rb
avo-3.10.5 app/components/avo/tab_switcher_component.rb
avo-3.10.4 app/components/avo/tab_switcher_component.rb
avo-3.10.3 app/components/avo/tab_switcher_component.rb
avo-3.10.2 app/components/avo/tab_switcher_component.rb
avo-3.10.1 app/components/avo/tab_switcher_component.rb
avo-3.10.0 app/components/avo/tab_switcher_component.rb
avo-3.9.2 app/components/avo/tab_switcher_component.rb