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.

compose_typeahead: Add new indicator to topic items in typeahead.

Joelutec7ef2555fda1
diff --git a/web/e2e-tests/mention.test.ts b/web/e2e-tests/mention.test.ts
index 1cc2df24d96..f395dfbb3f1 100644
--- a/web/e2e-tests/mention.test.ts
+++ b/web/e2e-tests/mention.test.ts
@@ -12,9 +12,12 @@ async function test_mention(page: Page): Promise<void> {
await page.waitForSelector("#compose", {visible: true});
await common.select_stream_in_compose_via_dropdown(page, "Verona");
- await common.fill_form(page, 'form[action^="/json/messages"]', {
- stream_message_recipient_topic: "Test mention all",
- });
+ await common.select_item_via_typeahead(
+ page,
+ "#stream_message_recipient_topic",
+ "Test mention all",
+ "Test mention all",
+ );
await common.select_item_via_typeahead(page, "#compose-textarea", "@**all", "all");
await common.ensure_enter_does_not_send(page);
diff --git a/web/src/composebox_typeahead.js b/web/src/composebox_typeahead.js
index c291d981e17..30e18f43554 100644
--- a/web/src/composebox_typeahead.js
+++ b/web/src/composebox_typeahead.js
@@ -1143,11 +1143,17 @@ export function initialize({on_enter_send}) {
},
sorter(items) {
const sorted = typeahead_helper.sorter(this.query, items, (x) => x);
- if (sorted.length > 0 && !sorted.includes(this.query)) {
+ if (!sorted.includes(this.query)) {
sorted.unshift(this.query);
}
return sorted;
},
+ option_label(matching_items, item) {
+ if (!matching_items.includes(item)) {
+ return `<em>${$t({defaultMessage: "New"})}</em>`;
+ }
+ return false;
+ },
header: render_topic_typeahead_hint,
});
diff --git a/web/styles/zulip.css b/web/styles/zulip.css
index 3023407d2bf..15d3a9f46c9 100644
--- a/web/styles/zulip.css
+++ b/web/styles/zulip.css
@@ -3383,3 +3383,12 @@ select.invite-as {
top: 2px;
}
}
+
+.typeahead-option-label {
+ display: flex !important;
+ justify-content: space-between;
+
+ > strong {
+ margin-right: 14px;
+ }
+}
diff --git a/web/tests/composebox_typeahead.test.js b/web/tests/composebox_typeahead.test.js
index 40cd827d1e2..84fc19dd981 100644
--- a/web/tests/composebox_typeahead.test.js
+++ b/web/tests/composebox_typeahead.test.js
@@ -790,11 +790,10 @@ test("initialize", ({override, override_rewire, mock_template}) => {
expected_value = ["e", "furniture", "ice"];
assert.deepEqual(actual_value, expected_value);
- // Don't make any suggestions if this query doesn't match any
- // existing topic.
+ // Suggest the query if this query doesn't match any existing topic.
options.query = "non-existing-topic";
actual_value = options.sorter([]);
- expected_value = [];
+ expected_value = ["non-existing-topic"];
assert.deepEqual(actual_value, expected_value);
topic_typeahead_called = true;
diff --git a/web/third/bootstrap-typeahead/typeahead.js b/web/third/bootstrap-typeahead/typeahead.js
index 50634c92cc6..086e1a0147c 100644
--- a/web/third/bootstrap-typeahead/typeahead.js
+++ b/web/third/bootstrap-typeahead/typeahead.js
@@ -171,6 +171,7 @@ import {get_string_diff} from "../../src/util";
this.on_move = this.options.on_move;
this.on_escape = this.options.on_escape;
this.header = this.options.header || this.header;
+ this.option_label = this.options.option_label || this.option_label;
if (this.fixed) {
this.$container.css('position', 'fixed');
@@ -233,6 +234,11 @@ import {get_string_diff} from "../../src/util";
return false;
}
+ , option_label: function (matching_items, item) {
+ // return a string to show in typeahead items or false.
+ return false
+ }
+
, show: function () {
var header_text = this.header();
if (header_text) {
@@ -312,20 +318,18 @@ import {get_string_diff} from "../../src/util";
, process: function (items) {
var that = this
- items = $.grep(items, function (item) {
- return that.matcher(item)
- })
+ const matching_items = $.grep(items, (item) => this.matcher(item));
- items = this.sorter(items)
+ const final_items = this.sorter(matching_items);
- if (!items.length) {
+ if (!final_items.length) {
return this.shown ? this.hide() : this
}
if (this.automated()) {
this.select();
return this;
}
- return this.render(items.slice(0, this.options.items)).show()
+ return this.render(final_items.slice(0, this.options.items), matching_items).show();
}
, matcher: function (item) {
@@ -354,12 +358,18 @@ import {get_string_diff} from "../../src/util";
})
}
- , render: function (items) {
+ , render: function (final_items, matching_items) {
var that = this
- items = $(items).map(function (i, item) {
- i = $(that.options.item).data('typeahead-value', item)
- i.find('a').html(that.highlighter(item))
+ const items = $(final_items).map((index, item) => {
+ const i = $(that.options.item).data('typeahead-value', item)
+ const item_html = i.find('a').html(that.highlighter(item))
+
+ const option_label_html = that.option_label(matching_items, item)
+
+ if (option_label_html) {
+ item_html.append(option_label_html).addClass("typeahead-option-label");
+ }
return i[0]
})