mirror of
https://github.com/zulip/zulip.git
synced 2025-11-02 04:53:36 +00:00
stream edit: Allow creating stream pills when typeahead is unused.
This completes the remaining work required to support addition of all members of another stream. This allows the creation of stream pills on pasting the #streamname and copying it from the stream pill. The user pills uses email ids instead. And also allows creating stream pills when the user hides the typeahead. Tested by commenting out the "set_up_typeahead_on_pills" line in `stream_edit.js`. A `node_tests/stream_pill.js` file has been created for the node tests and the other half of the coverage check takes place in `node_tests/stream_edit.js`.
This commit is contained in:
49
frontend_tests/node_tests/stream_pill.js
Normal file
49
frontend_tests/node_tests/stream_pill.js
Normal file
@@ -0,0 +1,49 @@
|
||||
"use strict";
|
||||
|
||||
zrequire("stream_data");
|
||||
zrequire("stream_pill");
|
||||
|
||||
const denmark = {
|
||||
stream_id: 1,
|
||||
name: "Denmark",
|
||||
subscribed: true,
|
||||
subscriber_count: 10,
|
||||
};
|
||||
const sweden = {
|
||||
stream_id: 2,
|
||||
name: "Sweden",
|
||||
subscribed: false,
|
||||
subscriber_count: 30,
|
||||
};
|
||||
|
||||
const denmark_pill = {
|
||||
stream_name: denmark.name,
|
||||
stream_id: denmark.stream_id,
|
||||
display_value: "#" + denmark.name + ": " + denmark.subscriber_count + " users",
|
||||
};
|
||||
const sweden_pill = {
|
||||
stream_name: sweden.name,
|
||||
stream_id: sweden.stream_id,
|
||||
display_value: "#" + sweden.name + ": " + sweden.subscriber_count + " users",
|
||||
};
|
||||
|
||||
const subs = [denmark, sweden];
|
||||
for (const sub of subs) {
|
||||
stream_data.add_sub(sub);
|
||||
}
|
||||
|
||||
run_test("create_item", () => {
|
||||
function test_create_item(stream_name, current_items, expected_item) {
|
||||
const item = stream_pill.create_item_from_stream_name(stream_name, current_items);
|
||||
assert.deepEqual(item, expected_item);
|
||||
}
|
||||
|
||||
test_create_item("sweden", [], undefined);
|
||||
test_create_item("#sweden", [sweden_pill], undefined);
|
||||
test_create_item(" #sweden", [], sweden_pill);
|
||||
test_create_item("#test", [], undefined);
|
||||
});
|
||||
|
||||
run_test("get_stream_id", () => {
|
||||
assert.equal(stream_pill.get_stream_name_from_item(denmark_pill), denmark.name);
|
||||
});
|
@@ -298,10 +298,26 @@ function show_subscription_settings(sub) {
|
||||
stream_id +
|
||||
"'] .pill-container",
|
||||
);
|
||||
|
||||
function create_item_from_text(text, current_items) {
|
||||
const item = stream_pill.create_item_from_stream_name(text, current_items);
|
||||
if (item) {
|
||||
return item;
|
||||
}
|
||||
return user_pill.create_item_from_email(text, current_items);
|
||||
}
|
||||
function get_text_from_item(item) {
|
||||
const text = stream_pill.get_stream_name_from_item(item);
|
||||
if (text) {
|
||||
return text;
|
||||
}
|
||||
return user_pill.get_email_from_item(item);
|
||||
}
|
||||
|
||||
exports.pill_widget = input_pill.create({
|
||||
container,
|
||||
create_item_from_text: user_pill.create_item_from_email,
|
||||
get_text_from_item: user_pill.get_email_from_item,
|
||||
create_item_from_text,
|
||||
get_text_from_item,
|
||||
});
|
||||
|
||||
if (!sub.render_subscribers) {
|
||||
|
@@ -1,5 +1,39 @@
|
||||
"use strict";
|
||||
|
||||
function display_pill(sub) {
|
||||
return "#" + sub.name + ": " + sub.subscriber_count + " users";
|
||||
}
|
||||
|
||||
exports.create_item_from_stream_name = function (stream_name, current_items) {
|
||||
stream_name = stream_name.trim();
|
||||
if (!stream_name.startsWith("#")) {
|
||||
return;
|
||||
}
|
||||
stream_name = stream_name.substring(1);
|
||||
|
||||
const sub = stream_data.get_sub(stream_name);
|
||||
if (!sub) {
|
||||
return;
|
||||
}
|
||||
|
||||
const existing_ids = current_items.map((item) => item.stream_id);
|
||||
if (existing_ids.includes(sub.stream_id)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const item = {
|
||||
display_value: display_pill(sub),
|
||||
stream_id: sub.stream_id,
|
||||
stream_name: sub.name,
|
||||
};
|
||||
|
||||
return item;
|
||||
};
|
||||
|
||||
exports.get_stream_name_from_item = function (item) {
|
||||
return item.stream_name;
|
||||
};
|
||||
|
||||
function get_user_ids_from_subs(items) {
|
||||
let user_ids = [];
|
||||
const stream_ids = items.map((item) => item.stream_id);
|
||||
@@ -24,8 +58,9 @@ exports.get_user_ids = function (pill_widget) {
|
||||
|
||||
exports.append_stream = function (stream, pill_widget) {
|
||||
pill_widget.appendValidatedData({
|
||||
display_value: "#" + stream.name + ": " + stream.subscriber_count + " users",
|
||||
display_value: display_pill(stream),
|
||||
stream_id: stream.stream_id,
|
||||
stream_name: stream.name,
|
||||
});
|
||||
pill_widget.clear_text();
|
||||
};
|
||||
|
Reference in New Issue
Block a user