Add command to filter by tag

This commit is contained in:
Jorge Manrubia
2025-05-07 16:07:21 +02:00
parent b8daaa193a
commit 50da28c0be
3 changed files with 40 additions and 0 deletions
+18
View File
@@ -0,0 +1,18 @@
class Command::FilterByTag < Command
store_accessor :data, :tag_id, :params
validates_presence_of :tag_id
def title
"Filter by tag ##{tag&.title || tag_id} "
end
def execute
redirect_to cards_path(**params.merge(tag_ids: [ tag_id ]))
end
private
def tag
Tag.find_by_id(tag_id)
end
end
+7
View File
@@ -23,6 +23,8 @@ class Command::Parser
Command::Assign.new(assignee_ids: assignees_from(command_arguments).collect(&:id), card_ids: cards.ids)
when "/close"
Command::Close.new(card_ids: cards.ids, reason: command_arguments.join(" "))
when /^#/
Command::FilterByTag.new(tag_id: tag_from(string).id, params: filter.as_params)
when /^@/
Command::GoToUser.new(user_id: assignee_from(command_name)&.id)
else
@@ -44,6 +46,11 @@ class Command::Parser
User.all.find { |user| user.mentionable_handles.include?(string_without_at) }
end
def tag_from(string)
title = string.gsub(/^#/, "")
Tag.find_or_create_by!(title: title)
end
def parse_free_string(string)
if cards = multiple_cards_from(string)
Command::FilterCards.new(card_ids: cards.ids, params: filter.as_params)
+15
View File
@@ -0,0 +1,15 @@
require "test_helper"
class Command::FilterByCardTest < ActionDispatch::IntegrationTest
include CommandTestHelper
setup do
@tag = tags(:web)
end
test "redirects to the cards index filtering by cards" do
result = execute_command "##{@tag.title}"
assert_equal cards_path(indexed_by: "newest", tag_ids: [ @tag.id ]), result.url
end
end