A platform for community discussion. Free, open, simple.
UX: Show category badges in AI edit descriptions (#44293)
Jordan Vidrinea164ac774122
diff --git a/plugins/discourse-ai/config/locales/server.en.yml b/plugins/discourse-ai/config/locales/server.en.ymlindex e6ed4e5d154..647f6f87b2f 100644--- a/plugins/discourse-ai/config/locales/server.en.yml+++ b/plugins/discourse-ai/config/locales/server.en.yml@@ -930,7 +930,7 @@ en:create_tag: "Creating tag '%{name}'"edit_tag: "Editing tag '%{name}' (%{fields})"create_category: "Creating category '%{name}'"- edit_category: "Editing category %{category_id} (%{fields})"+ edit_category: "Editing %{fields} for %{category_name}"change_topic_category: "Moving topic %{topic_id} to category %{category_id}"set_topic_timer: "Setting %{timer_type} timer on topic %{topic_id} (%{duration_hours}h)"set_slow_mode: "Setting slow mode on topic %{topic_id} (%{slow_mode_seconds}s)"diff --git a/plugins/discourse-ai/lib/agents/tools/edit_category.rb b/plugins/discourse-ai/lib/agents/tools/edit_category.rbindex 4eb98ae1f22..d507e116cb2 100644--- a/plugins/discourse-ai/lib/agents/tools/edit_category.rb+++ b/plugins/discourse-ai/lib/agents/tools/edit_category.rb@@ -91,7 +91,11 @@ module DiscourseAienddef description_args- { category_id: parameters[:category_id], fields: changes.keys.join(", ") }+ {+ category_id: parameters[:category_id],+ category_name: category ? "##{category.slug_ref}::category" : parameters[:category_id],+ fields: changes.keys.map { |field| "`#{field}`" }.join(", "),+ }endprivatediff --git a/plugins/discourse-ai/spec/lib/agents/tools/edit_category_spec.rb b/plugins/discourse-ai/spec/lib/agents/tools/edit_category_spec.rbindex e9c4efdc2c1..79e178e109b 100644--- a/plugins/discourse-ai/spec/lib/agents/tools/edit_category_spec.rb+++ b/plugins/discourse-ai/spec/lib/agents/tools/edit_category_spec.rb@@ -19,6 +19,27 @@ RSpec.describe DiscourseAi::Agents::Tools::EditCategory dodescribed_class.new(params, bot_user: bot_user, llm: llm, context: context)end+ describe "#details" do+ it "renders the edited fields and a category badge in chat for a subcategory" do+ subcategory = Fabricate(:category, parent_category: category)+ details =+ tool(+ category_id: subcategory.id,+ name: "New name",+ color: "FF0000",+ reason: "Rebranding",+ ).details++ cooked = Nokogiri::HTML5.fragment(Chat::Message.cook(details, user_id: admin.id))++ expect(cooked.css("code").map(&:text)).to eq(%w[name color])+ badge = cooked.at_css("a.hashtag-cooked[data-type='category']")+ expect(badge["data-id"]).to eq(subcategory.id.to_s)+ expect(badge["href"]).to eq(subcategory.url)+ expect(badge.text).to include(subcategory.name)+ end+ end+it "updates the category's name and colors" doresult =tool(