Skip to content

A platform for community discussion. Free, open, simple.

FIX: AI suggestions fixes (#37463)

Keegan George82cd602a8a64
diff --git a/plugins/discourse-ai/assets/javascripts/discourse/components/suggestion-menus/ai-category-suggester.gjs b/plugins/discourse-ai/assets/javascripts/discourse/components/suggestion-menus/ai-category-suggester.gjs
index 3eca90b0c1e..7c157210a65 100644
--- a/plugins/discourse-ai/assets/javascripts/discourse/components/suggestion-menus/ai-category-suggester.gjs
+++ b/plugins/discourse-ai/assets/javascripts/discourse/components/suggestion-menus/ai-category-suggester.gjs
@@ -41,12 +41,7 @@ export default class AiCategorySuggester extends Component {
}
get showDropdown() {
- if (this.suggestions?.length === 0) {
- this.dMenu.close();
- return false;
- }
-
- return !this.loading;
+ return !this.loading && this.suggestions?.length > 0;
}
@action
@@ -75,6 +70,7 @@ export default class AiCategorySuggester extends Component {
this.suggestions = assistant;
if (this.suggestions?.length === 0) {
+ this.dMenu.close();
showSuggestionsError(this, this.loadSuggestions.bind(this));
return;
}
diff --git a/plugins/discourse-ai/assets/javascripts/discourse/components/suggestion-menus/ai-tag-suggester.gjs b/plugins/discourse-ai/assets/javascripts/discourse/components/suggestion-menus/ai-tag-suggester.gjs
index e716b3f0d5f..5b9aee52e45 100644
--- a/plugins/discourse-ai/assets/javascripts/discourse/components/suggestion-menus/ai-tag-suggester.gjs
+++ b/plugins/discourse-ai/assets/javascripts/discourse/components/suggestion-menus/ai-tag-suggester.gjs
@@ -184,7 +184,7 @@ export default class AiTagSuggester extends Component {
data-value={{index}}
title={{suggestion.name}}
@translatedLabel={{suggestion.name}}
- @disabled={{this.isDisabled suggestion}}
+ @disabled={{suggestion.disabled}}
@action={{fn this.applySuggestion suggestion}}
>
{{discourseTag
diff --git a/plugins/discourse-ai/spec/system/ai_helper/ai_composer_helper_spec.rb b/plugins/discourse-ai/spec/system/ai_helper/ai_composer_helper_spec.rb
index a829f35fc0b..9c549d2275e 100644
--- a/plugins/discourse-ai/spec/system/ai_helper/ai_composer_helper_spec.rb
+++ b/plugins/discourse-ai/spec/system/ai_helper/ai_composer_helper_spec.rb
@@ -333,6 +333,19 @@ RSpec.describe "AI Composer helper", type: :system do
expect(page).to have_css(".category-chooser summary[data-name='#{suggestion}']")
end
+
+ it "shows an error toast and closes the dropdown when no suggestions are returned" do
+ DiscourseAi::AiHelper::SemanticCategorizer.any_instance.stubs(:categories).returns([])
+ visit("/latest")
+ page.find("#create-topic").click
+ composer.fill_content(input)
+ ai_suggestion_dropdown.click_suggest_category_button
+
+ expect(ai_suggestion_dropdown).to have_no_dropdown
+ expect(toasts).to have_error(
+ I18n.t("js.discourse_ai.ai_helper.suggest_errors.no_suggestions"),
+ )
+ end
end
context "when suggesting the tags with AI tag suggester" do
@@ -380,6 +393,37 @@ RSpec.describe "AI Composer helper", type: :system do
expect(page).to have_no_css(tag1_css)
expect(page).to have_no_css(tag2_css)
end
+
+ it "removes applied tag suggestions from the dropdown" do
+ response = [cloud, feedback, review].map { |t| { id: t.id, name: t.name, score: 1.0 } }
+ DiscourseAi::AiHelper::SemanticCategorizer.any_instance.stubs(:tags).returns(response)
+
+ visit("/latest")
+ page.find("#create-topic").click
+ composer.fill_content(input)
+
+ ai_suggestion_dropdown.click_suggest_tags_button
+ wait_for { ai_suggestion_dropdown.has_dropdown? }
+
+ ai_suggestion_dropdown.select_suggestion_by_name(cloud.name)
+
+ expect(page).to have_css(".mini-tag-chooser summary[data-name='#{cloud.name}']")
+ expect(page).to have_no_css(".ai-suggestions-menu button[data-name='#{cloud.name}']")
+ end
+
+ it "shows an error toast when no suggestions are returned" do
+ DiscourseAi::AiHelper::SemanticCategorizer.any_instance.stubs(:tags).returns([])
+
+ visit("/latest")
+ page.find("#create-topic").click
+ composer.fill_content(input)
+
+ ai_suggestion_dropdown.click_suggest_tags_button
+
+ expect(toasts).to have_error(
+ I18n.t("js.discourse_ai.ai_helper.suggest_errors.no_suggestions"),
+ )
+ end
end
context "when AI helper is disabled" do