Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
composebox_typeahead: Add "New" label to non existant topics.
Aman Agrawal68dc868658c2
diff --git a/web/src/composebox_typeahead.ts b/web/src/composebox_typeahead.tsindex 08150029381..0096fe9f9a2 100644--- a/web/src/composebox_typeahead.ts+++ b/web/src/composebox_typeahead.ts@@ -93,6 +93,7 @@ export type TopicSuggestion = {is_channel_link: boolean;used_syntax_prefix: string;stream_data: StreamPillData;+ is_new_topic: boolean;};type TimeJumpSuggestion = {@@ -998,7 +999,9 @@ export function get_candidates(// or adding a topic.const topic_list = topics_seen_for(sub.stream_id);- if (should_show_custom_query(token, topic_list)) {+ // Topic name doesn't match any of the existing topics.+ const is_new_topic = should_show_custom_query(token, topic_list);+ if (is_new_topic) {topic_list.push(token);}const matcher = get_topic_matcher(token);@@ -1017,6 +1020,7 @@ export function get_candidates(// itself, not topic rows, so we leave this blank.rendered_description: "",},+ is_new_topic: topic === token && is_new_topic,}));const topic_suggestion_candidates = typeahead_helper.sorter(token,@@ -1038,6 +1042,7 @@ export function get_candidates(type: "stream",rendered_description: "",},+ is_new_topic: false,});}return topic_suggestion_candidates;@@ -1452,8 +1457,14 @@ export function initialize_compose_typeahead($element: JQuery<HTMLTextAreaElemenselect_on_escape_condition: () => completing === "topic_list",automated: compose_automated_selection,option_label(_matching_items, item): string | false {- if (item.type === "topic_list" && item.is_channel_link) {- return `<em>${$t({defaultMessage: "(link to channel)"})}</em>`;+ if (item.type === "topic_list") {+ if (item.is_channel_link) {+ return `<em>${$t({defaultMessage: "(link to channel)"})}</em>`;+ }++ if (item.is_new_topic) {+ return `<em>${$t({defaultMessage: "New"})}</em>`;+ }}return false;},diff --git a/web/tests/composebox_typeahead.test.cjs b/web/tests/composebox_typeahead.test.cjsindex 7b53d7b1939..4ddbf67773d 100644--- a/web/tests/composebox_typeahead.test.cjs+++ b/web/tests/composebox_typeahead.test.cjs@@ -2153,7 +2153,7 @@ test("begins_typeahead", ({override, override_rewire}) => {// topic_list// includes "more ice"- function typed_topics(stream, topics) {+ function typed_topics(stream, topics, is_new_topic = false) {const matches_list = topics.map((topic, index) => ({is_channel_link: topic === stream && index === 0,stream_data: {@@ -2165,6 +2165,7 @@ test("begins_typeahead", ({override, override_rewire}) => {topic_display_name: get_final_topic_display_name(topic),type: "topic_list",used_syntax_prefix: "#**",+ is_new_topic,}));return matches_list;}@@ -2176,9 +2177,10 @@ test("begins_typeahead", ({override, override_rewire}) => {"#**Sweden>",typed_topics("Sweden", ["Sweden", ...sweden_topics_to_show]),);+ const is_new_topic = true;assert_typeahead_equals("#**Sweden>totally new topic",- typed_topics("Sweden", ["totally new topic"]),+ typed_topics("Sweden", ["totally new topic"], is_new_topic),);assert_typeahead_equals("#**Sweden>\n\nmore ice", typed_topics("Sweden", []));