Skip to content

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

UX: Show search history for more contexts (#25705)

Isaac Janzen5a67c8f0cad0
diff --git a/app/assets/javascripts/discourse/app/components/search-menu/results/initial-options.hbs b/app/assets/javascripts/discourse/app/components/search-menu/results/initial-options.hbs
index e149ab71931..b4e611b2e06 100644
--- a/app/assets/javascripts/discourse/app/components/search-menu/results/initial-options.hbs
+++ b/app/assets/javascripts/discourse/app/components/search-menu/results/initial-options.hbs
@@ -46,6 +46,19 @@
@closeSearchMenu={{@closeSearchMenu}}
@searchTermChanged={{@searchTermChanged}}
/>
+
+ {{#if
+ (and
+ this.currentUser
+ this.siteSettings.log_search_queries
+ this.displayInitialOptions
+ )
+ }}
+ <SearchMenu::Results::RecentSearches
+ @closeSearchMenu={{@closeSearchMenu}}
+ @searchTermChanged={{@searchTermChanged}}
+ />
+ {{/if}}
{{/if}}
{{else}}
<SearchMenu::Results::RandomQuickTip
diff --git a/app/assets/javascripts/discourse/app/components/search-menu/results/initial-options.js b/app/assets/javascripts/discourse/app/components/search-menu/results/initial-options.js
index caaf7aec63c..537d6401e4d 100644
--- a/app/assets/javascripts/discourse/app/components/search-menu/results/initial-options.js
+++ b/app/assets/javascripts/discourse/app/components/search-menu/results/initial-options.js
@@ -14,6 +14,14 @@ const SEARCH_CONTEXT_TYPE_COMPONENTS = {
user: AssistantItem,
};
+const DISPLAY_INITIAL_OPTIONS_FOR_CONTEXT_TYPES = [
+ "topic",
+ "category",
+ "tag",
+ "tagIntersection",
+ "user",
+];
+
export default class InitialOptions extends Component {
@service search;
@service siteSettings;
@@ -37,6 +45,15 @@ export default class InitialOptions extends Component {
return this.search.activeGlobalSearchTerm?.match(MODIFIER_REGEXP);
}
+ get displayInitialOptions() {
+ if (this.search.activeGlobalSearchTerm) {
+ return false;
+ }
+ return DISPLAY_INITIAL_OPTIONS_FOR_CONTEXT_TYPES.includes(
+ this.search.searchContext?.type
+ );
+ }
+
setAttributesForSearchContextType(type) {
switch (type) {
case "topic":
diff --git a/app/assets/javascripts/discourse/tests/acceptance/search-test.js b/app/assets/javascripts/discourse/tests/acceptance/search-test.js
index 307bad43d29..7589b9d874f 100644
--- a/app/assets/javascripts/discourse/tests/acceptance/search-test.js
+++ b/app/assets/javascripts/discourse/tests/acceptance/search-test.js
@@ -697,7 +697,7 @@ acceptance("Search - Authenticated", function (needs) {
);
});
- test("initial options - recent search results", async function (assert) {
+ test("initial options - search history - no context", async function (assert) {
await visit("/");
await click("#search-button");
@@ -745,6 +745,24 @@ acceptance("Search - Authenticated", function (needs) {
assert.strictEqual(query("#search-term").value, "hijacked!");
});
+
+ test("initial options - search history - category context", async function (assert) {
+ await visit("/c/bug");
+ await click("#search-button");
+
+ assert
+ .dom(".search-menu .search-menu-recent li:nth-of-type(1) .search-link")
+ .exists("shows search history");
+ });
+
+ test("initial options - search history - user context", async function (assert) {
+ await visit("/u/eviltrout");
+ await click("#search-button");
+
+ assert
+ .dom(".search-menu .search-menu-recent li:nth-of-type(1) .search-link")
+ .exists("shows search history");
+ });
});
acceptance("Search - with tagging enabled", function (needs) {
@@ -847,6 +865,15 @@ acceptance("Search - with tagging enabled", function (needs) {
assert.strictEqual(firstTag, "monkey");
});
+ test("initial options - search history - tag context", async function (assert) {
+ await visit("/tags/c/bug/dev");
+ await click("#search-button");
+
+ assert
+ .dom(".search-menu .search-menu-recent li:nth-of-type(1) .search-link")
+ .exists("shows search history");
+ });
+
test("initial options - tag search scope - shows category / tag combination shortcut when both are present", async function (assert) {
await visit("/tags/c/bug/dev");
await click("#search-button");
@@ -895,6 +922,15 @@ acceptance("Search - with tagging enabled", function (needs) {
);
});
+ test("initial options - search history - tag intersection context", async function (assert) {
+ await visit("/tags/intersection/dev/foo");
+ await click("#search-button");
+
+ assert
+ .dom(".search-menu .search-menu-recent li:nth-of-type(1) .search-link")
+ .exists("shows search history");
+ });
+
test("initial options - tag intersection search scope - shows tag combination shortcut when visiting tag intersection", async function (assert) {
await visit("/tags/intersection/dev/foo");
await click("#search-button");
@@ -1171,6 +1207,24 @@ acceptance("Search - assistant", function (needs) {
.doesNotExist("'in this topic' button is not shown");
});
+ test("initial options - search history - topic context", async function (assert) {
+ await visit("/t/internationalization-localization/280");
+ await click("#search-button");
+
+ assert
+ .dom(".search-menu .search-menu-recent li:nth-of-type(1) .search-link")
+ .exists("shows search history");
+ });
+
+ test("initial options - search history - private message context", async function (assert) {
+ await visit("/u/charlie/messages");
+ await click("#search-button");
+
+ assert
+ .dom(".search-menu .search-menu-recent")
+ .doesNotExist("does not show search history");
+ });
+
test("initial options - private message search scope - shows 'in messages' button when in an inbox", async function (assert) {
await visit("/u/charlie/messages");
await click("#search-button");