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:
commit
69e1b1be41
7 changed files with 66 additions and 16 deletions
|
@ -6,13 +6,30 @@
|
|||
%react-fragment
|
||||
= 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'
|
||||
- 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
|
||||
%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
|
||||
= submit_tag t('.add_filter'), class: 'fr-btn fr-btn--secondary fr-mt-2w'
|
||||
|
|
|
@ -13,6 +13,9 @@ class FilteredColumn
|
|||
|
||||
validate :check_filter_max_length
|
||||
validate :check_filter_max_integer
|
||||
validates :filter, presence: {
|
||||
message: -> (object, _data) { "Le filtre « #{object.label} » ne peut pas être vide" }
|
||||
}
|
||||
|
||||
def initialize(column:, filter:)
|
||||
@column = column
|
||||
|
@ -33,14 +36,14 @@ class FilteredColumn
|
|||
if @filter.present? && @filter.length.to_i > FILTERS_VALUE_MAX_LENGTH
|
||||
errors.add(
|
||||
: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
|
||||
|
||||
def check_filter_max_integer
|
||||
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
|
||||
|
|
|
@ -103,6 +103,7 @@ ignore_unused:
|
|||
- 'activerecord.attributes.*'
|
||||
- 'activemodel.attributes.map_filter.*'
|
||||
- 'activemodel.attributes.helpscout/form.*'
|
||||
- 'activemodel.errors.models.*'
|
||||
- 'activerecord.errors.*'
|
||||
- 'errors.messages.blank'
|
||||
- 'errors.messages.content_type_invalid'
|
||||
|
|
7
config/locales/models/filtered_column/en.yml
Normal file
7
config/locales/models/filtered_column/en.yml
Normal file
|
@ -0,0 +1,7 @@
|
|||
en:
|
||||
activemodel:
|
||||
errors:
|
||||
models:
|
||||
filtered_column:
|
||||
format: "%{message}"
|
||||
|
7
config/locales/models/filtered_column/fr.yml
Normal file
7
config/locales/models/filtered_column/fr.yml
Normal file
|
@ -0,0 +1,7 @@
|
|||
fr:
|
||||
activemodel:
|
||||
errors:
|
||||
models:
|
||||
filtered_column:
|
||||
format: "%{message}"
|
||||
|
|
@ -911,7 +911,7 @@ describe Instructeurs::ProceduresController, type: :controller do
|
|||
|
||||
it 'should render the error' do
|
||||
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
|
||||
|
|
|
@ -11,7 +11,7 @@ describe FilteredColumn do
|
|||
let(:filter) { 'a' * (FilteredColumn::FILTERS_VALUE_MAX_LENGTH + 1) }
|
||||
|
||||
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
|
||||
|
||||
|
@ -22,14 +22,6 @@ describe FilteredColumn do
|
|||
expect(filtered_column.errors).to be_empty
|
||||
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
|
||||
|
||||
describe '#check_filters_max_integer' do
|
||||
|
@ -43,7 +35,7 @@ describe FilteredColumn do
|
|||
let(:filter) { (FilteredColumn::PG_INTEGER_MAX_VALUE + 1).to_s }
|
||||
|
||||
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
|
||||
|
||||
|
@ -56,4 +48,27 @@ describe FilteredColumn do
|
|||
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
|
||||
|
|
Loading…
Reference in a new issue