Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

search_suggestion: Show `channel:` operator suggestion on empty query.

Pratik Chanda76e0acd0278e
diff --git a/web/src/search_suggestion.ts b/web/src/search_suggestion.ts
index bb3c7847703..0213ad4a0d1 100644
--- a/web/src/search_suggestion.ts
+++ b/web/src/search_suggestion.ts
@@ -790,7 +790,7 @@ function get_sent_by_me_suggestions(last: NarrowTerm, terms: NarrowTerm[]): Sugg
}
function get_operator_suggestions(last: NarrowTerm): Suggestion[] {
- if (!(last.operator === "search")) {
+ if (!(last.operator === "search" || last.operator === "")) {
return [];
}
let last_operand = last.operand;
@@ -801,17 +801,24 @@ function get_operator_suggestions(last: NarrowTerm): Suggestion[] {
last_operand = last_operand.slice(1);
}
- let choices = [
- "channel",
- "topic",
- "dm",
- "dm-including",
- "sender",
- "near",
- "from",
- "pm-with",
- "stream",
- ];
+ let choices;
+
+ if (last.operator === "") {
+ choices = ["channel", "stream"];
+ } else {
+ choices = [
+ "channel",
+ "topic",
+ "dm",
+ "dm-including",
+ "sender",
+ "near",
+ "from",
+ "pm-with",
+ "stream",
+ ];
+ }
+
choices = choices.filter((choice) => common.phrase_match(last_operand, choice));
return choices.map((choice) => {
diff --git a/web/tests/search_suggestion.test.cjs b/web/tests/search_suggestion.test.cjs
index 5d27ff8edbd..15424ba776f 100644
--- a/web/tests/search_suggestion.test.cjs
+++ b/web/tests/search_suggestion.test.cjs
@@ -107,6 +107,7 @@ test("basic_get_suggestions_for_spectator", () => {
const query = "";
const suggestions = get_suggestions(query);
assert.deepEqual(suggestions.strings, [
+ "channel:",
"is:resolved",
"-is:resolved",
"has:link",
@@ -390,6 +391,7 @@ test("empty_query_suggestions", () => {
const expected = [
"channels:public",
+ "channel:",
"is:dm",
"is:starred",
"is:mentioned",