diff --git a/app/components/procedure/groupes_search_component.rb b/app/components/procedure/groupes_search_component.rb new file mode 100644 index 000000000..e1e12d7b0 --- /dev/null +++ b/app/components/procedure/groupes_search_component.rb @@ -0,0 +1,5 @@ +class Procedure::GroupesSearchComponent < ApplicationComponent + def initialize(procedure:, query:, to_configure_count:) + @procedure, @query, @to_configure_count = procedure, query, to_configure_count + end +end diff --git a/app/components/procedure/groupes_search_component/groupes_search_component.html.haml b/app/components/procedure/groupes_search_component/groupes_search_component.html.haml new file mode 100644 index 000000000..26bcd5f34 --- /dev/null +++ b/app/components/procedure/groupes_search_component/groupes_search_component.html.haml @@ -0,0 +1,9 @@ += form_for admin_procedure_groupe_instructeurs_path(@procedure), + method: :get do + #header-search.fr-search-bar.fr-mb-2w{ role: "search" } + = label_tag :q, 'Rechercher par nom', class: 'fr-label' + = text_field_tag :q, @query, class: 'fr-input', type: 'search', autocomplete: 'off', placeholder: 'Rechercher par nom' + %button.fr-btn{ title: "Rechercher" } Rechercher + +- if @to_configure_count > 0 + %span #{ @to_configure_count } à configurer diff --git a/app/controllers/administrateurs/groupe_instructeurs_controller.rb b/app/controllers/administrateurs/groupe_instructeurs_controller.rb index 036a3d105..af3196a7a 100644 --- a/app/controllers/administrateurs/groupe_instructeurs_controller.rb +++ b/app/controllers/administrateurs/groupe_instructeurs_controller.rb @@ -291,8 +291,17 @@ module Administrateurs end def paginated_groupe_instructeurs - procedure - .groupe_instructeurs + groupes = if params[:q].present? + query = ActiveRecord::Base.sanitize_sql_like(params[:q]) + + procedure + .groupe_instructeurs + .where('unaccent(label) ILIKE unaccent(?)', "%#{query}%") + else + procedure.groupe_instructeurs + end + + groupes .page(params[:page]) .per(ITEMS_PER_PAGE) end diff --git a/spec/controllers/administrateurs/groupe_instructeurs_controller_spec.rb b/spec/controllers/administrateurs/groupe_instructeurs_controller_spec.rb index 35760e5b3..eda4df189 100644 --- a/spec/controllers/administrateurs/groupe_instructeurs_controller_spec.rb +++ b/spec/controllers/administrateurs/groupe_instructeurs_controller_spec.rb @@ -13,13 +13,25 @@ describe Administrateurs::GroupeInstructeursController, type: :controller do describe '#index' do context 'of a procedure I own' do - before { get :index, params: { procedure_id: procedure.id } } + before { get :index, params: } context 'when a procedure has multiple groups' do - it { expect(response).to have_http_status(:ok) } - it { expect(response.body).to include(gi_1_1.label) } - it { expect(response.body).to include(gi_1_2.label) } - it { expect(response.body).not_to include(gi_2_2.label) } + let(:params) { { procedure_id: procedure.id } } + + it do + expect(response).to have_http_status(:ok) + expect(response.body).to include(gi_1_1.label) + expect(response.body).to include(gi_1_2.label) + expect(response.body).not_to include(gi_2_2.label) + end + + context 'when there is a search' do + let(:params) { { procedure_id: procedure.id, q: '2' } } + + it do + expect(assigns(:groupes_instructeurs)).to match_array([gi_1_2]) + end + end end end end