diff --git a/app/assets/stylesheets/admin/poll/questions/filter.scss b/app/assets/stylesheets/admin/poll/questions/filter.scss new file mode 100644 index 000000000..78cb4fb4f --- /dev/null +++ b/app/assets/stylesheets/admin/poll/questions/filter.scss @@ -0,0 +1,16 @@ +.admin .poll-questions-filter { + $gap: 0.5em; + align-items: flex-end; + display: flex; + flex-wrap: wrap; + margin-left: -$gap; + + > * { + margin-left: $gap; + } + + [type="submit"] { + @include regular-button; + margin-left: $gap; + } +} diff --git a/app/components/admin/poll/questions/filter_component.html.erb b/app/components/admin/poll/questions/filter_component.html.erb index b1e988d8d..ee1f443ff 100644 --- a/app/components/admin/poll/questions/filter_component.html.erb +++ b/app/components/admin/poll/questions/filter_component.html.erb @@ -1,7 +1,7 @@ -<%= form_tag "", method: :get do %> - <%= label_tag :poll_id, t("admin.questions.index.filter_poll") %> - <%= select_tag "poll_id", - poll_select_options, - prompt: t("polls.all"), - class: "js-location-changer" %> +<%= form_tag "", method: :get, class: "poll-questions-filter" do %> +
+ <%= label_tag :poll_id, t("admin.questions.index.filter_poll") %> + <%= select_tag "poll_id", poll_select_options, prompt: t("polls.all") %> +
+ <%= submit_tag t("shared.filter") %> <% end %> diff --git a/app/components/admin/poll/questions/filter_component.rb b/app/components/admin/poll/questions/filter_component.rb index 881a8383b..b8b7d7412 100644 --- a/app/components/admin/poll/questions/filter_component.rb +++ b/app/components/admin/poll/questions/filter_component.rb @@ -9,9 +9,6 @@ class Admin::Poll::Questions::FilterComponent < ApplicationComponent private def poll_select_options - options = polls.map do |poll| - [poll.name, current_path_with_query_params(poll_id: poll.id)] - end - options_for_select(options, request.fullpath) + options_from_collection_for_select(polls, :id, :name, params[:poll_id]) end end diff --git a/app/views/admin/poll/questions/_questions.html.erb b/app/views/admin/poll/questions/_questions.html.erb index 4550796d5..e8ce0402e 100644 --- a/app/views/admin/poll/questions/_questions.html.erb +++ b/app/views/admin/poll/questions/_questions.html.erb @@ -1,6 +1,4 @@ -
- <%= render Admin::Poll::Questions::FilterComponent.new(@polls) %> -
+<%= render Admin::Poll::Questions::FilterComponent.new(@polls) %> <% if @questions.count == 0 %>
diff --git a/spec/components/admin/poll/questions/filter_component_spec.rb b/spec/components/admin/poll/questions/filter_component_spec.rb new file mode 100644 index 000000000..8861ad354 --- /dev/null +++ b/spec/components/admin/poll/questions/filter_component_spec.rb @@ -0,0 +1,9 @@ +require "rails_helper" + +describe Admin::Poll::Questions::FilterComponent, type: :component do + it "renders a button to submit the form" do + render_inline Admin::Poll::Questions::FilterComponent.new([]) + + expect(page).to have_button "Filter" + end +end