Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
composebox_typeahead: Add support for empty string topic in textarea.
apoorvapendseea3e89cdd930
diff --git a/web/src/composebox_typeahead.ts b/web/src/composebox_typeahead.tsindex a88583ffd79..035ca8c3fa7 100644--- a/web/src/composebox_typeahead.ts+++ b/web/src/composebox_typeahead.ts@@ -85,7 +85,9 @@ export type LanguageSuggestion = {export type TopicSuggestion = {topic: string;+ topic_display_name: string;type: "topic_list";+ is_empty_string_topic: boolean;// is_channel_link will be used when we want to only render the stream as an// option in the topic typeahead while having #**stream_name> as the token.is_channel_link: boolean;@@ -223,7 +225,8 @@ function get_topic_matcher(query: string): (topic: string) => boolean {query = typeahead.clean_query_lowercase(query);return function (topic: string): boolean {- return typeahead.query_matches_string_in_order(query, topic, " ");+ const topic_display_name = util.get_final_topic_display_name(topic);+ return typeahead.query_matches_string_in_order(query, topic_display_name, " ");};}@@ -980,6 +983,8 @@ export function get_candidates(const matches = topic_list.filter((item) => matcher(item));const matches_list: TopicSuggestion[] = matches.map((topic) => ({topic,+ topic_display_name: util.get_final_topic_display_name(topic),+ is_empty_string_topic: topic === "",type: "topic_list",is_channel_link: false,is_shortcut_syntax_used,@@ -994,13 +999,15 @@ export function get_candidates(const topic_suggestion_candidates = typeahead_helper.sorter(token,matches_list,- (x) => x.topic,+ (x) => x.topic_display_name,);// Add link to channel if and only if nothing is typed after '>'if (token.length === 0) {topic_suggestion_candidates.unshift({topic: sub.name,+ topic_display_name: sub.name,+ is_empty_string_topic: false,type: "topic_list",is_channel_link: true,is_shortcut_syntax_used,diff --git a/web/src/typeahead_helper.ts b/web/src/typeahead_helper.tsindex a7d21ffa12f..2161b05378c 100644--- a/web/src/typeahead_helper.ts+++ b/web/src/typeahead_helper.ts@@ -109,7 +109,6 @@ export let render_typeahead_item = (args: {is_user_group?: boolean;stream?: StreamData;emoji_code?: string | undefined;- is_empty_string_topic?: boolean;topic_object?: TopicSuggestion;is_stream_topic?: boolean;}): string => {diff --git a/web/templates/typeahead_list_item.hbs b/web/templates/typeahead_list_item.hbsindex 5473b5fd07e..80204612ef2 100644--- a/web/templates/typeahead_list_item.hbs+++ b/web/templates/typeahead_list_item.hbs@@ -24,14 +24,14 @@<span role="button" class="conversation-arrow zulip-icon zulip-icon-chevron-right stream-to-topic-arrow"></span></div><div class="typeahead-text-container">- <strong class="typeahead-strong-section">- {{~ topic ~}}+ <strong class="typeahead-strong-section{{#if is_empty_string_topic}} empty-topic-display{{/if}}">+ {{~ topic_display_name ~}}</strong></div>{{else}}{{!-- Separate container to ensure overflowing text remains in this container. --}}<div class="typeahead-text-container{{#if has_secondary_html}} has_secondary_html{{/if}}">- <strong class="typeahead-strong-section{{#if is_empty_string_topic}} empty-topic-display{{/if}}">+ <strong class="typeahead-strong-section">{{~#if stream~}}{{~> inline_decorated_stream_name stream=stream ~}}{{~else~}}diff --git a/web/tests/composebox_typeahead.test.cjs b/web/tests/composebox_typeahead.test.cjsindex e01e863d049..6d68c80c819 100644--- a/web/tests/composebox_typeahead.test.cjs+++ b/web/tests/composebox_typeahead.test.cjs@@ -2,6 +2,8 @@const assert = require("node:assert/strict");+const {get_final_topic_display_name} = require("../src/util.ts");+const {mock_banners} = require("./lib/compose_banner.cjs");const example_settings = require("./lib/example_settings.cjs");const {mock_esm, set_global, with_overrides, zrequire} = require("./lib/namespace.cjs");@@ -9,6 +11,7 @@ const {run_test, noop} = require("./lib/test.cjs");const $ = require("./lib/zjquery.cjs");let autosize_called;+const REALM_EMPTY_TOPIC_DISPLAY_NAME = "general chat";const bootstrap_typeahead = mock_esm("../src/bootstrap_typeahead");const compose_ui = mock_esm("../src/compose_ui", {@@ -59,7 +62,7 @@ const {initialize_user_settings} = zrequire("user_settings");const current_user = {};set_current_user(current_user);-const realm = {};+const realm = {realm_empty_topic_display_name: REALM_EMPTY_TOPIC_DISPLAY_NAME};set_realm(realm);const user_settings = {};initialize_user_settings({user_settings});@@ -882,6 +885,7 @@ test("content_typeahead_selected", ({override}) => {actual_value = ct.content_typeahead_selected({topic: "testing",+ topic_display_name: "testing",type: "topic_list",stream_data: {name: "Sweden",@@ -898,6 +902,7 @@ test("content_typeahead_selected", ({override}) => {actual_value = ct.content_typeahead_selected({topic: "testing",+ topic_display_name: "testing",type: "topic_list",stream_data: {name: "Sweden",@@ -933,6 +938,7 @@ test("content_typeahead_selected", ({override}) => {actual_value = ct.content_typeahead_selected({topic: "Sweden",+ topic_display_name: "Sweden",type: "topic_list",is_channel_link: false,stream_data: {@@ -945,10 +951,29 @@ test("content_typeahead_selected", ({override}) => {expected_value = "Hello #**Sweden>Sweden** ";assert.equal(actual_value, expected_value);+ query = "Hello #**Sweden>general";ct.get_or_set_token_for_testing("");actual_value = ct.content_typeahead_selected({topic: "",+ topic_display_name: get_final_topic_display_name(""),+ type: "topic_list",+ is_channel_link: false,+ stream_data: {+ name: "Sweden",+ },+ },+ query,+ input_element,+ );+ expected_value = `Hello #**Sweden>** `;+ assert.equal(actual_value, expected_value);++ ct.get_or_set_token_for_testing("");+ actual_value = ct.content_typeahead_selected(+ {+ topic: "Sweden",+ topic_display_name: "Sweden",type: "topic_list",is_channel_link: true,stream_data: {@@ -1034,7 +1059,15 @@ function sorted_names_from(subs) {return subs.map((sub) => sub.name).sort();}-const sweden_topics_to_show = ["<&>", "even more ice", "furniture", "ice", "kronor", "more ice"];+const sweden_topics_to_show = [+ "<&>",+ "even more ice",+ "furniture",+ "ice",+ "kronor",+ "more ice",+ "",+];test("initialize", ({override, override_rewire, mock_template}) => {mock_banners();@@ -2003,22 +2036,34 @@ test("begins_typeahead", ({override, override_rewire}) => {// topic_list// includes "more ice"- function typed_topics(topics) {- const matches_list = topics.map((topic) => ({- is_channel_link: false,+ function typed_topics(stream, topics) {+ const matches_list = topics.map((topic, index) => ({+ is_channel_link: topic === stream && index === 0,is_shortcut_syntax_used: false,stream_data: {...stream_data.get_sub_by_name("Sweden"),rendered_description: "",},topic,+ is_empty_string_topic: topic === "",+ topic_display_name: get_final_topic_display_name(topic),type: "topic_list",}));return matches_list;}- assert_typeahead_equals("#**Sweden>more ice", typed_topics(["more ice", "even more ice"]));- assert_typeahead_equals("#**Sweden>totally new topic", typed_topics(["totally new topic"]));- assert_typeahead_equals("#**Sweden>\n\nmore ice", typed_topics([]));+ assert_typeahead_equals(+ "#**Sweden>more ice",+ typed_topics("Sweden", ["more ice", "even more ice"]),+ );+ assert_typeahead_equals(+ "#**Sweden>",+ typed_topics("Sweden", ["Sweden", ...sweden_topics_to_show]),+ );+ assert_typeahead_equals(+ "#**Sweden>totally new topic",+ typed_topics("Sweden", ["totally new topic"]),+ );+ assert_typeahead_equals("#**Sweden>\n\nmore ice", typed_topics("Sweden", []));// time_jumpconst time_jump = [