demarches-normaliennes/app/components/instructeurs/column_table_header_component.rb
Colin Darie e7768bbf4b
refactor(dossiers): table in new dsfr design
- remove obsolete css
- handle check / check all dsfr UI
- min height hack does not work anymore (pending a new solution)
2024-11-22 10:45:41 +01:00

44 lines
1.2 KiB
Ruby

# frozen_string_literal: true
class Instructeurs::ColumnTableHeaderComponent < ApplicationComponent
def initialize(procedure_presentation:)
@procedure_presentation = procedure_presentation
@columns = procedure_presentation.displayed_fields_for_headers
@sorted_column = procedure_presentation.sorted_column
end
private
def classname(column)
return 'number-col' if column.dossier_id?
return 'sva-col' if column.column == 'sva_svr_decision_on'
end
def column_header(column)
id = column.id
order = opposite_order_for(column)
button_to(
label_and_arrow(column),
[:instructeur, @procedure_presentation],
params: { sorted_column: { id: id, order: order } },
class: 'fr-text--bold'
)
end
def opposite_order_for(column)
@sorted_column.column == column ? @sorted_column.opposite_order : 'asc'
end
def label_and_arrow(column)
return column.label if @sorted_column.column != column
@sorted_column.ascending? ? "#{column.label} ↑" : "#{column.label} ↓"
end
def aria_sort(column)
return {} if @sorted_column.column != column
@sorted_column.ascending? ? { "aria-sort": "ascending" } : { "aria-sort": "descending" }
end
end