From f7af0f0879c037fec4b2f824283d1008e1ad0b0d Mon Sep 17 00:00:00 2001 From: Evy Kassirer Date: Thu, 5 Jun 2025 00:08:03 -0700 Subject: [PATCH] search: Update description string for channel terms. --- web/src/filter.ts | 9 +++++++-- web/src/search_suggestion.ts | 5 ++--- web/templates/search_description.hbs | 8 ++++++-- web/tests/filter.test.cjs | 21 +++++++++++---------- web/tests/search_suggestion.test.cjs | 4 ++-- 5 files changed, 28 insertions(+), 19 deletions(-) diff --git a/web/src/filter.ts b/web/src/filter.ts index 88f16c3d7c..3ee08cbb3e 100644 --- a/web/src/filter.ts +++ b/web/src/filter.ts @@ -45,6 +45,11 @@ type Part = topic_display_name: string; is_empty_string_topic: boolean; } + | { + type: "channel"; + prefix_for_operator: string; + operand: string; + } | { type: "is_operator"; verb: string; @@ -694,7 +699,7 @@ export class Filter { switch (operator) { case "channel": - return verb + "channel"; + return verb + "messages in #"; case "channels": return verb + "channels"; case "near": @@ -839,7 +844,7 @@ export class Filter { const stream = stream_data.get_sub_by_id_string(operand); if (stream) { return { - type: "prefix_for_operator", + type: "channel", prefix_for_operator, operand: stream.name, }; diff --git a/web/src/search_suggestion.ts b/web/src/search_suggestion.ts index d34f105bc2..1ab762fdb3 100644 --- a/web/src/search_suggestion.ts +++ b/web/src/search_suggestion.ts @@ -157,10 +157,9 @@ function get_channel_suggestions(last: NarrowTerm, terms: NarrowTerm[]): Suggest channels = typeahead_helper.sorter(query, channels, (x) => x); return channels.map((channel_name) => { - const prefix = "channel"; + const prefix = "messages in #"; const verb = last.negated ? "exclude " : ""; - const description_html = - verb + prefix + " " + Handlebars.Utils.escapeExpression(channel_name); + const description_html = verb + prefix + Handlebars.Utils.escapeExpression(channel_name); const channel = stream_data.get_sub_by_name(channel_name); assert(channel !== undefined); const term = { diff --git a/web/templates/search_description.hbs b/web/templates/search_description.hbs index 84cbb0b24b..87f4b88d2b 100644 --- a/web/templates/search_description.hbs +++ b/web/templates/search_description.hbs @@ -4,10 +4,14 @@ {{~this.content~}} {{else if (eq this.type "channel_topic")}} {{~#if is_empty_string_topic~}} - channel {{this.channel}} > {{this.topic_display_name}} + messages in #{{this.channel}} > {{this.topic_display_name}} {{~else~}} - channel {{this.channel}} > {{this.topic_display_name}} + messages in #{{this.channel}} > {{this.topic_display_name}} {{~/if~}} + {{else if (eq this.type "channel")}} + {{~!-- squash whitespace --~}} + {{this.prefix_for_operator}}{{this.operand}} + {{~!-- squash whitespace --~}} {{else if (eq this.type "invalid_has")}} {{~!-- squash whitespace --~}} invalid {{this.operand}} operand for has operator diff --git a/web/tests/filter.test.cjs b/web/tests/filter.test.cjs index 886ef9cbe6..c8aa038aa1 100644 --- a/web/tests/filter.test.cjs +++ b/web/tests/filter.test.cjs @@ -1682,7 +1682,7 @@ test("describe", ({mock_template, override}) => { {operator: "channel", operand: devel_id.toString()}, {operator: "is", operand: "starred"}, ]; - string = "channel devel, starred messages"; + string = "messages in #devel, starred messages"; assert.equal(Filter.search_description_as_html(narrow, false), string); const river_id = new_stream_id(); @@ -1691,14 +1691,14 @@ test("describe", ({mock_template, override}) => { {operator: "channel", operand: river_id.toString()}, {operator: "is", operand: "unread"}, ]; - string = "channel river, unread messages"; + string = "messages in #river, unread messages"; assert.equal(Filter.search_description_as_html(narrow, false), string); narrow = [ {operator: "channel", operand: devel_id.toString()}, {operator: "topic", operand: "JS"}, ]; - string = "channel devel > JS"; + string = "messages in #devel > JS"; assert.equal(Filter.search_description_as_html(narrow, false), string); narrow = [ @@ -1754,7 +1754,7 @@ test("describe", ({mock_template, override}) => { {operator: "channel", operand: devel_id.toString()}, {operator: "topic", operand: "JS", negated: true}, ]; - string = "channel devel, exclude topic JS"; + string = "messages in #devel, exclude topic JS"; assert.equal(Filter.search_description_as_html(narrow, false), string); narrow = [ @@ -1768,28 +1768,28 @@ test("describe", ({mock_template, override}) => { {operator: "channel", operand: devel_id.toString()}, {operator: "is", operand: "starred", negated: true}, ]; - string = "channel devel, exclude starred messages"; + string = "messages in #devel, exclude starred messages"; assert.equal(Filter.search_description_as_html(narrow, false), string); narrow = [ {operator: "channel", operand: devel_id.toString()}, {operator: "has", operand: "image", negated: true}, ]; - string = "channel devel, exclude messages with images"; + string = "messages in #devel, exclude messages with images"; assert.equal(Filter.search_description_as_html(narrow, false), string); narrow = [ {operator: "has", operand: "abc", negated: true}, {operator: "channel", operand: devel_id.toString()}, ]; - string = "invalid abc operand for has operator, channel devel"; + string = "invalid abc operand for has operator, messages in #devel"; assert.equal(Filter.search_description_as_html(narrow, false), string); narrow = [ {operator: "has", operand: "image", negated: true}, {operator: "channel", operand: devel_id.toString()}, ]; - string = "exclude messages with images, channel devel"; + string = "exclude messages with images, messages in #devel"; assert.equal(Filter.search_description_as_html(narrow, false), string); narrow = []; @@ -1801,7 +1801,7 @@ test("describe", ({mock_template, override}) => { {operator: "stream", operand: devel_id.toString()}, {operator: "subject", operand: "JS", negated: true}, ]; - string = "channel devel, exclude topic JS"; + string = "messages in #devel, exclude topic JS"; assert.equal(Filter.search_description_as_html(narrow, false), string); // Empty string topic involved. @@ -1810,7 +1810,8 @@ test("describe", ({mock_template, override}) => { {operator: "channel", operand: devel_id.toString()}, {operator: "topic", operand: ""}, ]; - string = 'channel devel > translated: general chat'; + string = + 'messages in #devel > translated: general chat'; assert.equal(Filter.search_description_as_html(narrow, false), string); narrow = [ diff --git a/web/tests/search_suggestion.test.cjs b/web/tests/search_suggestion.test.cjs index ded9e7d4d6..6a2d6f1e0f 100644 --- a/web/tests/search_suggestion.test.cjs +++ b/web/tests/search_suggestion.test.cjs @@ -706,7 +706,7 @@ test("topic_suggestions", ({override, mock_template}) => { return suggestions.lookup_table.get(q).description_html; } assert.equal(describe("te"), "Search for te"); - assert.equal(describe(`channel:${office_id} topic:team`), "Channel office > team"); + assert.equal(describe(`channel:${office_id} topic:team`), "Messages in #office > team"); suggestions = get_suggestions(`topic:staplers channel:${office_id}`); expected = [`topic:staplers channel:${office_id}`, "topic:staplers"]; @@ -826,7 +826,7 @@ test("xss_channel_name", () => { const suggestions = get_suggestions(query); assert.deepEqual( suggestions.lookup_table.get(`channel:${stream_id}`).description_html, - "Channel <em> Italics </em>", + "Messages in #<em> Italics </em>", ); });