Merge pull request #4569 from consul/poll_questions_filter
Use a submit button in admin poll question filters
This commit is contained in:
16
app/assets/stylesheets/admin/poll/questions/filter.scss
Normal file
16
app/assets/stylesheets/admin/poll/questions/filter.scss
Normal file
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
<%= form_tag "", method: :get, class: "poll-questions-filter" do %>
|
||||
<div class="filter">
|
||||
<%= label_tag :poll_id, t("admin.questions.index.filter_poll") %>
|
||||
<%= select_tag "poll_id", poll_select_options, prompt: t("polls.all") %>
|
||||
</div>
|
||||
<%= submit_tag t("shared.filter") %>
|
||||
<% end %>
|
||||
14
app/components/admin/poll/questions/filter_component.rb
Normal file
14
app/components/admin/poll/questions/filter_component.rb
Normal file
@@ -0,0 +1,14 @@
|
||||
class Admin::Poll::Questions::FilterComponent < ApplicationComponent
|
||||
attr_reader :polls
|
||||
delegate :current_path_with_query_params, to: :helpers
|
||||
|
||||
def initialize(polls)
|
||||
@polls = polls
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def poll_select_options
|
||||
options_from_collection_for_select(polls, :id, :name, params[:poll_id])
|
||||
end
|
||||
end
|
||||
@@ -1,16 +1,4 @@
|
||||
module PollsHelper
|
||||
def poll_select_options(include_all = nil)
|
||||
options = @polls.map do |poll|
|
||||
[poll.name, current_path_with_query_params(poll_id: poll.id)]
|
||||
end
|
||||
options << all_polls if include_all
|
||||
options_for_select(options, request.fullpath)
|
||||
end
|
||||
|
||||
def all_polls
|
||||
[I18n.t("polls.all"), admin_questions_path]
|
||||
end
|
||||
|
||||
def poll_dates(poll)
|
||||
if poll.starts_at.blank? || poll.ends_at.blank?
|
||||
I18n.t("polls.no_dates")
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
<%= form_tag "", method: :get do %>
|
||||
<%= label_tag :poll_id, t("admin.questions.index.filter_poll") %>
|
||||
<%= select_tag "poll_id",
|
||||
poll_select_options(true),
|
||||
prompt: t("admin.questions.index.select_poll"),
|
||||
class: "js-location-changer" %>
|
||||
<% end %>
|
||||
@@ -1,6 +1,4 @@
|
||||
<div class="small-12 medium-4 large-3">
|
||||
<%= render "filter" %>
|
||||
</div>
|
||||
<%= render Admin::Poll::Questions::FilterComponent.new(@polls) %>
|
||||
|
||||
<% if @questions.count == 0 %>
|
||||
<div class="callout primary margin-top">
|
||||
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user