Skip to content

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

UX: fix combined AI search enter and reopen (#44909)

Kris6493b53e4199
diff --git a/plugins/discourse-ai/assets/javascripts/discourse/connectors/search-menu-results-top/ai-discobot-discoveries.gjs b/plugins/discourse-ai/assets/javascripts/discourse/connectors/search-menu-results-top/ai-discobot-discoveries.gjs
index 99c2eaaa9a5..2c950aabb5e 100644
--- a/plugins/discourse-ai/assets/javascripts/discourse/connectors/search-menu-results-top/ai-discobot-discoveries.gjs
+++ b/plugins/discourse-ai/assets/javascripts/discourse/connectors/search-menu-results-top/ai-discobot-discoveries.gjs
@@ -29,11 +29,16 @@ export default class AiDiscobotDiscoveries extends Component {
// A search can start from somewhere other than a key press, such as a recent
// search picked from the menu, so the session is given the menu's own way to
- // show topics.
+ // show topics. A reopened menu starts without them, so a search still active
+ // for its term switches it back.
connectMenu = modifier(() => {
- this.aiSearchSession.showTopicsInMenu = () =>
- this.args.outletArgs.updateTypeFilter(null);
- return () => (this.aiSearchSession.showTopicsInMenu = null);
+ const showTopics = () => this.args.outletArgs.updateTypeFilter(null);
+ this.aiSearchSession.showTopicsInMenu = showTopics;
+ const timer = this.searched ? next(showTopics) : null;
+ return () => {
+ cancel(timer);
+ this.aiSearchSession.showTopicsInMenu = null;
+ };
});
// These are deferred because what they set off updates state this render
diff --git a/plugins/discourse-ai/assets/javascripts/discourse/initializers/ai-search-discoveries.js b/plugins/discourse-ai/assets/javascripts/discourse/initializers/ai-search-discoveries.js
index 9d144a54ae5..98a6c24fe9a 100644
--- a/plugins/discourse-ai/assets/javascripts/discourse/initializers/ai-search-discoveries.js
+++ b/plugins/discourse-ai/assets/javascripts/discourse/initializers/ai-search-discoveries.js
@@ -302,14 +302,17 @@ export default apiInitializer((api) => {
if (combinedSearch) {
if (!event.shiftKey && query) {
- // a search already on screen for this term is not run again, unless
- // its answer broke down; returning false skips the menu's own enter
- // handling, which would otherwise treat a second enter as "open the
- // full page"
+ // A search already on screen for this term is not run again, unless
+ // its answer broke down. Enter on it opens the full page instead, as
+ // a second enter does in the menu, whose own handling is skipped
+ // because the menu never saw the first.
if (
- !aiSearchSession.isActiveFor(query) ||
- aiSearchSession.answerErrored
+ aiSearchSession.isActiveFor(query) &&
+ !aiSearchSession.answerErrored
) {
+ searchTerm.args.fullSearch();
+ searchTerm.args.closeSearchMenu();
+ } else {
startCombined(query, { trigger: "enter" });
}
return false;
diff --git a/plugins/discourse-ai/spec/system/ai_combined_search_spec.rb b/plugins/discourse-ai/spec/system/ai_combined_search_spec.rb
index 61c0d84b3dc..d4784a8e3bc 100644
--- a/plugins/discourse-ai/spec/system/ai_combined_search_spec.rb
+++ b/plugins/discourse-ai/spec/system/ai_combined_search_spec.rb
@@ -275,6 +275,33 @@ describe "AI combined search" do
after { SearchIndexer.disable }
+ it "opens the full search page on a second enter" do
+ visit "/"
+ wait_for_discoveries_channel
+ ask(query)
+
+ expect(page).to have_css(".search-menu .search-result-topic", text: topic_1.title)
+ find("#welcome-banner-search-input").send_keys(:enter)
+
+ expect(page).to have_current_path(%r{/search\?q=password\z})
+ expect(request_ids.size).to eq(1)
+ end
+
+ it "shows the search's topics again when the menu is reopened" do
+ visit "/about"
+ wait_for_discoveries_channel
+ find("#search-button").click
+ ask(query, input: "#icon-search-input")
+
+ expect(page).to have_css(".search-menu .search-result-topic", text: topic_1.title)
+ find("#icon-search-input").send_keys(:escape)
+ expect(page).to have_no_css("#icon-search-input")
+
+ find("#search-button").click
+ expect(page).to have_css(".search-menu .search-result-topic", text: topic_1.title)
+ expect(request_ids.size).to eq(1)
+ end
+
it "opens a lookup on its topics, with every tab fetched at once" do
visit "/"
wait_for_discoveries_channel