Module: SolidQueueMonitor::SortHelper

Defined in:
app/helpers/solid_queue_monitor/sort_helper.rb

Instance Method Summary collapse

Instance Method Details

#sortable_header(column, label, sort:, filters: {}) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'app/helpers/solid_queue_monitor/sort_helper.rb', line 5

def sortable_header(column, label, sort:, filters: {})
  return tag.th(label) unless sort

  column_str = column.to_s
  active = sort[:sort_by] == column_str
  next_dir = active && sort[:sort_direction] == 'asc' ? 'desc' : 'asc'
  query = filters.compact.merge(sort_by: column_str, sort_direction: next_dir)

  tag.th(
    link_to(
      safe_join([label, sort_arrow(active, sort[:sort_direction])]),
      "?#{query.to_query}",
      class: class_names('sortable-header', active: active)
    )
  )
end