Use composite commands even for single commands since they can carry custom titles, which is what we want with AI
This commit is contained in:
@@ -37,6 +37,9 @@ class CommandsController < ApplicationController
|
||||
end
|
||||
|
||||
def respond_with_execution_result(result)
|
||||
# This saves unnecessary back and forth between server and client (e.g: to redirect)-
|
||||
result = result.is_a?(Array) && result.one? ? result.first : result
|
||||
|
||||
case result
|
||||
when Array
|
||||
respond_with_composite_response(result)
|
||||
|
||||
@@ -30,11 +30,7 @@ class Command::Ai::Parser
|
||||
commands.unshift Command::VisitUrl.new(user: user, url: query_context.url, context: resolved_context)
|
||||
end
|
||||
|
||||
if commands.many?
|
||||
Command::Composite.new(title: query, commands: commands, user: user, line: query, context: resolved_context)
|
||||
else
|
||||
build_standalone_command(commands, query)
|
||||
end
|
||||
Command::Composite.new(title: query, commands: commands, user: user, line: query, context: resolved_context)
|
||||
end
|
||||
|
||||
def commands_from_query(normalized_query, context)
|
||||
@@ -44,13 +40,6 @@ class Command::Ai::Parser
|
||||
end
|
||||
end
|
||||
|
||||
# This saves unnecessary interchanges with browser for redirect responses
|
||||
def build_standalone_command(commands, query)
|
||||
commands.first.tap do |command|
|
||||
command.line = query
|
||||
end
|
||||
end
|
||||
|
||||
def resolve_named_params_to_ids(normalized_query)
|
||||
normalized_query.tap do |query_json|
|
||||
if query_context = query_json[:context].presence
|
||||
|
||||
@@ -16,7 +16,7 @@ class Command::Ai::ParserTest < ActionDispatch::IntegrationTest
|
||||
test "resolve filter string params as ids" do
|
||||
command = parse_command "cards assigned to kevin, tagged with #web, in the collection writebook"
|
||||
|
||||
url = command.url
|
||||
url = command.commands.first.url
|
||||
query_string = URI.parse(url).query
|
||||
params = Rack::Utils.parse_nested_query(query_string).with_indifferent_access
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ class Command::GoToCardTest < ActionDispatch::IntegrationTest
|
||||
assert command.valid?
|
||||
|
||||
result = command.execute
|
||||
assert_equal cards_path(terms: [ "123" ]), result.url
|
||||
assert_equal 1, result.size
|
||||
assert_equal cards_path(terms: [ "123" ]), result.first.url
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user