Add a clear command to clear filters
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
class Command::ClearFilters < Command
|
||||
store_accessor :data, :params
|
||||
|
||||
def title
|
||||
"Clear filters"
|
||||
end
|
||||
|
||||
def execute
|
||||
redirect_to cards_path(**params.to_h.with_indifferent_access.without(*filters_to_clear))
|
||||
end
|
||||
|
||||
private
|
||||
FILTERS_TO_KEEP = [ :collection_ids, :indexed_by ]
|
||||
|
||||
def filters_to_clear
|
||||
Filter::Params::PERMITTED_PARAMS
|
||||
.flat_map { |param| param.is_a?(Hash) ? param.keys : param }
|
||||
.without(*FILTERS_TO_KEEP)
|
||||
end
|
||||
end
|
||||
@@ -25,6 +25,8 @@ class Command::Parser
|
||||
Command::GoToUser.new(user_id: assignee_from(command_name)&.id)
|
||||
when "/assign", "/assignto"
|
||||
Command::Assign.new(assignee_ids: assignees_from(command_arguments).collect(&:id), card_ids: cards.ids)
|
||||
when "/clear"
|
||||
Command::ClearFilters.new(params: filter.as_params)
|
||||
when "/close"
|
||||
Command::Close.new(card_ids: cards.ids, reason: command_arguments.join(" "))
|
||||
when "/tag"
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
<dd>Filter multiple cards by their IDs</dd>
|
||||
<dt><code>search_term</code></dt>
|
||||
<dd>Search for cards containing the term</dd>
|
||||
<dt><code>/clear</code></dt>
|
||||
<dd>Clear all the filters</dd>
|
||||
|
||||
<h3>Cards</h3>
|
||||
<dt><code>/assign [username 1] [username 2]...</code></dt>
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
require "test_helper"
|
||||
|
||||
class Command::FilterTest < ActionDispatch::IntegrationTest
|
||||
include CommandTestHelper
|
||||
|
||||
setup do
|
||||
Current.session = sessions(:david)
|
||||
end
|
||||
|
||||
test "clear the filters keeping the selected collections" do
|
||||
result = execute_command "/clear", context_url: "?card_ids%5B%5D=1&card_ids%5B%5D=2&collection_ids%5B%5D=#{collections(:writebook).id}&indexed_by=newest&terms%5B%5D=jorge"
|
||||
|
||||
assert_equal cards_path(indexed_by: "newest", collection_ids: [ collections(:writebook).id ]), result.url
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user