Merge pull request #10983 from demarches-simplifiees/fix_empty_filter

Instructeur: corrige les pb d'affichage des listes de dossiers dans le cas de fitre vide
This commit is contained in:
LeSim 2024-10-24 10:28:17 +00:00 committed by GitHub
commit 69e1b1be41
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 66 additions and 16 deletions

View file

@ -6,13 +6,30 @@
%react-fragment %react-fragment
= render ReactComponent.new "ComboBox/SingleComboBox", **filter_react_props = render ReactComponent.new "ComboBox/SingleComboBox", **filter_react_props
%input.hidden{ type: 'submit', formaction: update_filter_instructeur_procedure_path(procedure), data: { autosubmit_target: 'submitter' } } %input.hidden{
type: 'submit',
formaction: update_filter_instructeur_procedure_path(procedure),
formnovalidate: 'true',
data: { autosubmit_target: 'submitter' }
}
= label_tag :value, t('.value'), for: 'value', class: 'fr-label' = label_tag :value, t('.value'), for: 'value', class: 'fr-label'
- if column_type == :enum || column_type == :enums - if column_type == :enum || column_type == :enums
= select_tag :filter, options_for_select(options_for_select_of_column), id: 'value', name: "#{prefix}[filter]", class: 'fr-select', data: { no_autosubmit: true } = select_tag :filter,
options_for_select(options_for_select_of_column),
id: 'value',
name: "#{prefix}[filter]",
class: 'fr-select',
data: { no_autosubmit: true }
- else - else
%input#value.fr-input{ type: column_type, name: "#{prefix}[filter]", maxlength: FilteredColumn::FILTERS_VALUE_MAX_LENGTH, disabled: column.nil? ? true : false, data: { no_autosubmit: true } } %input#value.fr-input{
type: column_type,
name: "#{prefix}[filter]",
maxlength: FilteredColumn::FILTERS_VALUE_MAX_LENGTH,
disabled: column.nil? ? true : false,
data: { no_autosubmit: true },
required: true
}
= hidden_field_tag :statut, statut = hidden_field_tag :statut, statut
= submit_tag t('.add_filter'), class: 'fr-btn fr-btn--secondary fr-mt-2w' = submit_tag t('.add_filter'), class: 'fr-btn fr-btn--secondary fr-mt-2w'

View file

@ -13,6 +13,9 @@ class FilteredColumn
validate :check_filter_max_length validate :check_filter_max_length
validate :check_filter_max_integer validate :check_filter_max_integer
validates :filter, presence: {
message: -> (object, _data) { "Le filtre « #{object.label} » ne peut pas être vide" }
}
def initialize(column:, filter:) def initialize(column:, filter:)
@column = column @column = column
@ -33,14 +36,14 @@ class FilteredColumn
if @filter.present? && @filter.length.to_i > FILTERS_VALUE_MAX_LENGTH if @filter.present? && @filter.length.to_i > FILTERS_VALUE_MAX_LENGTH
errors.add( errors.add(
:base, :base,
"Le filtre #{label} est trop long (maximum: #{FILTERS_VALUE_MAX_LENGTH} caractères)" "Le filtre « #{label} » est trop long (maximum: #{FILTERS_VALUE_MAX_LENGTH} caractères)"
) )
end end
end end
def check_filter_max_integer def check_filter_max_integer
if @column.column == 'id' && @filter.to_i > PG_INTEGER_MAX_VALUE if @column.column == 'id' && @filter.to_i > PG_INTEGER_MAX_VALUE
errors.add(:base, "Le filtre #{label} n'est pas un numéro de dossier possible") errors.add(:base, "Le filtre « #{label} » n'est pas un numéro de dossier possible")
end end
end end
end end

View file

@ -103,6 +103,7 @@ ignore_unused:
- 'activerecord.attributes.*' - 'activerecord.attributes.*'
- 'activemodel.attributes.map_filter.*' - 'activemodel.attributes.map_filter.*'
- 'activemodel.attributes.helpscout/form.*' - 'activemodel.attributes.helpscout/form.*'
- 'activemodel.errors.models.*'
- 'activerecord.errors.*' - 'activerecord.errors.*'
- 'errors.messages.blank' - 'errors.messages.blank'
- 'errors.messages.content_type_invalid' - 'errors.messages.content_type_invalid'

View file

@ -0,0 +1,7 @@
en:
activemodel:
errors:
models:
filtered_column:
format: "%{message}"

View file

@ -0,0 +1,7 @@
fr:
activemodel:
errors:
models:
filtered_column:
format: "%{message}"

View file

@ -911,7 +911,7 @@ describe Instructeurs::ProceduresController, type: :controller do
it 'should render the error' do it 'should render the error' do
subject subject
expect(flash.alert[0]).to include("Le filtre Nom est trop long (maximum: 4048 caractères)") expect(flash.alert[0]).to include("Le filtre « Nom » est trop long (maximum: 4048 caractères)")
end end
end end
end end

View file

@ -11,7 +11,7 @@ describe FilteredColumn do
let(:filter) { 'a' * (FilteredColumn::FILTERS_VALUE_MAX_LENGTH + 1) } let(:filter) { 'a' * (FilteredColumn::FILTERS_VALUE_MAX_LENGTH + 1) }
it 'adds an error' do it 'adds an error' do
expect(filtered_column.errors.map(&:message)).to include(/Le filtre label est trop long/) expect(filtered_column.errors.map(&:message)).to include(/Le filtre « label » est trop long/)
end end
end end
@ -22,14 +22,6 @@ describe FilteredColumn do
expect(filtered_column.errors).to be_empty expect(filtered_column.errors).to be_empty
end end
end end
context 'when the filter is empty' do
let(:filter) { nil }
it 'does not add an error' do
expect(filtered_column.errors).to be_empty
end
end
end end
describe '#check_filters_max_integer' do describe '#check_filters_max_integer' do
@ -43,7 +35,7 @@ describe FilteredColumn do
let(:filter) { (FilteredColumn::PG_INTEGER_MAX_VALUE + 1).to_s } let(:filter) { (FilteredColumn::PG_INTEGER_MAX_VALUE + 1).to_s }
it 'adds an error' do it 'adds an error' do
expect(filtered_column.errors.map(&:message)).to include(/Le filtre label n'est pas un numéro de dossier possible/) expect(filtered_column.errors.map(&:message)).to include(/Le filtre « label » n'est pas un numéro de dossier possible/)
end end
end end
@ -56,4 +48,27 @@ describe FilteredColumn do
end end
end end
end end
describe '#check_filter_is_not_blank' do
let(:column) { Column.new(procedure_id: 1, table: 'table', column: 'column', label: 'label') }
let(:filtered_column) { described_class.new(column:, filter:) }
before { filtered_column.valid? }
context 'when the filter is blank' do
let(:filter) { '' }
it 'adds an error' do
expect(filtered_column.errors.map(&:message)).to include(/Le filtre « label » ne peut pas être vide/)
end
end
context 'when the filter is not blank' do
let(:filter) { 'a' }
it 'does not add an error' do
expect(filtered_column.errors).to be_empty
end
end
end
end end