Skip to content

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

FIX: Keep topic context when redirecting to full search (#14846)

Penar Musaraje90f506bf847
diff --git a/app/assets/javascripts/discourse/app/widgets/search-menu.js b/app/assets/javascripts/discourse/app/widgets/search-menu.js
index 82f7855f35a..ad03c11b4a6 100644
--- a/app/assets/javascripts/discourse/app/widgets/search-menu.js
+++ b/app/assets/javascripts/discourse/app/widgets/search-menu.js
@@ -204,6 +204,12 @@ export default createWidget("search-menu", {
query += `q=${encodeURIComponent(searchData.term)}`;
+ const searchContext = this.searchContext();
+
+ if (searchContext?.type === "topic") {
+ query += encodeURIComponent(` topic:${searchContext.id}`);
+ }
+
if (query) {
params.push(query);
}
diff --git a/app/assets/javascripts/discourse/tests/acceptance/search-test.js b/app/assets/javascripts/discourse/tests/acceptance/search-test.js
index 2f205413bf3..d3f39aeff8d 100644
--- a/app/assets/javascripts/discourse/tests/acceptance/search-test.js
+++ b/app/assets/javascripts/discourse/tests/acceptance/search-test.js
@@ -243,6 +243,44 @@ acceptance("Search - Anonymous", function (needs) {
);
});
+ test("topic search scope - keep 'in this topic' filter in full page search", async function (assert) {
+ await visit("/t/internationalization-localization/280/1");
+
+ await click("#search-button");
+
+ const firstResult =
+ ".search-menu .results .search-menu-assistant-item:first-child";
+
+ assert.strictEqual(
+ query(firstResult).textContent.trim(),
+ I18n.t("search.in_this_topic"),
+ "contenxtual topic search is first available option"
+ );
+
+ await fillIn("#search-term", "proper");
+ await focus("input#search-term");
+ await triggerKeyEvent(".search-menu", "keydown", 40);
+ await click(document.activeElement);
+
+ assert.ok(
+ exists(".search-menu .search-context"),
+ "search context indicator is visible"
+ );
+
+ await click(".show-advanced-search");
+
+ assert.strictEqual(
+ query(".full-page-search").value,
+ "proper topic:280",
+ "it goes to full search page and preserves search term + context"
+ );
+
+ assert.ok(
+ exists(".search-advanced-options"),
+ "advanced search is expanded"
+ );
+ });
+
test("topic search scope - special case when matching a single user", async function (assert) {
await visit("/t/internationalization-localization/280/1");