From 5532a8a48f6864c6548f36ba6f5d09965012b1e5 Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Wed, 6 Nov 2024 17:45:06 +0100 Subject: [PATCH] small cleaning in filter_value_component --- .../column_filter_value_component.rb | 18 ++++++++---------- .../column_filter_value_component_spec.rb | 6 ++++++ 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/app/components/instructeurs/column_filter_value_component.rb b/app/components/instructeurs/column_filter_value_component.rb index 89713b985..61bd4df4b 100644 --- a/app/components/instructeurs/column_filter_value_component.rb +++ b/app/components/instructeurs/column_filter_value_component.rb @@ -7,25 +7,23 @@ class Instructeurs::ColumnFilterValueComponent < ApplicationComponent @column = column end - def column_type = column.present? ? column.type : :text - def call - if column_type.in?([:enum, :enums, :boolean]) - select_tag :filter, + if column.nil? + tag.input(id: 'value', class: 'fr-input', disabled: true) + elsif column.type.in?([:enum, :enums, :boolean]) + select_tag 'filters[][filter]', options_for_select(column.options_for_select), id: 'value', - name: "filters[][filter]", class: 'fr-select', data: { no_autosubmit: true }, required: true else tag.input( - class: 'fr-input', - id: 'value', - type:, name: "filters[][filter]", + id: 'value', + class: 'fr-input', + type:, maxlength: FilteredColumn::FILTERS_VALUE_MAX_LENGTH, - disabled: column.nil? ? true : false, data: { no_autosubmit: true }, required: true ) @@ -35,7 +33,7 @@ class Instructeurs::ColumnFilterValueComponent < ApplicationComponent private def type - case column_type + case column.type when :datetime, :date 'date' when :integer, :decimal diff --git a/spec/components/instructeurs/column_filter_value_component_spec.rb b/spec/components/instructeurs/column_filter_value_component_spec.rb index 22df5dddc..b4147c3b6 100644 --- a/spec/components/instructeurs/column_filter_value_component_spec.rb +++ b/spec/components/instructeurs/column_filter_value_component_spec.rb @@ -17,4 +17,10 @@ describe Instructeurs::ColumnFilterValueComponent, type: :component do it { expect(page).to have_selector('input[name="filters[][filter]"][type="date"]') } end + + describe 'the column empty case' do + let(:column) { nil } + + it { expect(page).to have_selector('input[disabled]') } + end end