Class: RubyCms::Admin::BulkActionTable::BulkActionTable

Inherits:
RubyCms::Admin::BaseComponent show all
Defined in:
app/components/ruby_cms/admin/bulk_action_table/bulk_action_table.rb

Overview

Root component for bulk action table Wraps entire table with Turbo Frame support, pagination, and bulk actions bar

Instance Method Summary collapse

Methods inherited from RubyCms::Admin::BaseComponent

#build_classes, #conditional_attributes, #controller, #form_authenticity_token, #helpers, #merge_data_attributes, #token_from_controller, #token_from_controller?, #token_from_helpers?

Constructor Details

#initialize(**options) ⇒ BulkActionTable

Returns a new instance of BulkActionTable.



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/components/ruby_cms/admin/bulk_action_table/bulk_action_table.rb', line 18

def initialize(**options)
  super()
  @turbo_frame = options[:turbo_frame]
  @pagination = options[:pagination]
  @pagination_path = options[:pagination_path]
  @bulk_actions_url = options[:bulk_actions_url]
  @bulk_actions_buttons = options[:bulk_actions_buttons] || []
  @item_name = options.fetch(:item_name, "item")
  @controller_name = options.fetch(:controller_name, "ruby-cms--bulk-action-table")
  @csrf_token = options[:csrf_token]
  @header = options[:header]
  @header_title = options[:header_title]
  @header_filter = options[:header_filter]
  @header_action_icons = options[:header_action_icons] || []
  @header_search_url = options[:header_search_url] || "#"
  @header_search_param = options[:header_search_param] || "q"
  @user_attrs = extract_user_attrs(options)
  @has_bulk_actions = @bulk_actions_url.present? || @bulk_actions_buttons.any?
end

Instance Method Details

#extract_user_attrs(options) ⇒ Object



38
39
40
41
42
43
44
45
# File 'app/components/ruby_cms/admin/bulk_action_table/bulk_action_table.rb', line 38

def extract_user_attrs(options)
  excluded_keys = %i[
    turbo_frame pagination pagination_path bulk_actions_url
    bulk_actions_buttons item_name controller_name csrf_token header
    header_title header_filter header_action_icons header_search_url header_search_param
  ]
  options.except(*excluded_keys)
end

#render_bulk_actionsObject



105
106
107
108
109
110
111
112
113
# File 'app/components/ruby_cms/admin/bulk_action_table/bulk_action_table.rb', line 105

def render_bulk_actions
  render BulkActions.new(
    controller_name: @controller_name,
    item_name: @item_name,
    bulk_actions_url: @bulk_actions_url,
    bulk_action_buttons: @bulk_actions_buttons
  )
  render BulkActionTableDeleteModal.new(controller_name: @controller_name)
end

#render_headerObject



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'app/components/ruby_cms/admin/bulk_action_table/bulk_action_table.rb', line 76

def render_header
  if @header_title.present? || @header_action_icons.any? || @header_search_url.present?
    render BulkActionTableHeaderBar.new(
      title: @header_title,
      header_filter: @header_filter,
      action_icons: @header_action_icons,
      search_url: @header_search_url,
      search_param: @header_search_param,
      turbo_frame: @turbo_frame
    )
  elsif @header
    div(class: "px-6 py-4 border-b border-border/60 bg-white") do
      if @header.respond_to?(:call)
        raw(@header.call) # rubocop:disable Rails/OutputSafety -- legacy capture support
      elsif @header.kind_of?(String)
        raw(sanitize(@header)) # rubocop:disable Rails/OutputSafety -- legacy capture support
      end
    end
  end
end

#render_paginationObject



115
116
117
118
119
120
121
# File 'app/components/ruby_cms/admin/bulk_action_table/bulk_action_table.rb', line 115

def render_pagination
  render BulkActionTablePagination.new(
    pagination: @pagination,
    pagination_path: @pagination_path,
    turbo_frame: @turbo_frame
  )
end

#render_table_content(&block) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'app/components/ruby_cms/admin/bulk_action_table/bulk_action_table.rb', line 58

def render_table_content(&block)
  div(
    class: build_classes(
      "rounded-xl border border-border/60 bg-white shadow-sm ring-1 ring-black/[0.03] overflow-hidden " \
      "flex flex-col",
      @user_attrs[:class]
    ),
    **table_data_attributes.except(:class)
  ) do
    render_header
    render_table_wrapper(&block)
    div(class: "border-t border-border/60 bg-white") do
      render_bulk_actions if @has_bulk_actions
      render_pagination if @pagination && @pagination_path
    end
  end
end

#render_table_wrapperObject



97
98
99
100
101
102
103
# File 'app/components/ruby_cms/admin/bulk_action_table/bulk_action_table.rb', line 97

def render_table_wrapper(&)
  div(class: "w-full overflow-x-auto") do
    table(class: "min-w-full text-sm caption-bottom") do
      yield if block_given?
    end
  end
end

#view_template(&block) ⇒ Object



47
48
49
50
51
52
53
54
55
56
# File 'app/components/ruby_cms/admin/bulk_action_table/bulk_action_table.rb', line 47

def view_template(&block)
  if @turbo_frame
    # Use turbo_frame_tag for proper Turbo Frame navigation (pagination, search)
    turbo_frame_tag(@turbo_frame, **turbo_frame_options) do
      render_table_content(&block)
    end
  else
    render_table_content(&block)
  end
end