Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
refactor: Add type field to pill items.
m-e-l-u-h-a-na2c7f35e5c97
diff --git a/frontend_tests/node_tests/input_pill.js b/frontend_tests/node_tests/input_pill.jsindex b71a3116edf..ab05fa68969 100644--- a/frontend_tests/node_tests/input_pill.js+++ b/frontend_tests/node_tests/input_pill.js@@ -75,9 +75,12 @@ run_test("basics", (override) => {config.get_text_from_item = noop;const widget = input_pill.create(config);+ // type for a pill can be any string but it needs to be+ // defined while creating any pill.const item = {display_value: "JavaScript",language: "js",+ type: "language",img_src: example_img_link,};@@ -100,16 +103,19 @@ function set_up() {blue: {display_value: "BLUE",description: "color of the sky",+ type: "color",img_src: example_img_link,},red: {display_value: "RED",+ type: "color",description: "color of stop signs",},yellow: {display_value: "YELLOW",+ type: "color",description: "color of bananas",},};@@ -551,6 +557,13 @@ run_test("misc things", () => {blueslip.expect("error", "no display_value returned");widget.appendValidatedData("this-has-no-item-attribute");+ blueslip.expect("error", "no type defined for the item");+ widget.appendValidatedData({+ display_value: "This item has no type.",+ language: "js",+ img_src: example_img_link,+ });+// click on containerconst container_click_handler = container.get_on_handler("click");@@ -575,7 +588,7 @@ run_test("appendValue/clear", () => {const config = {container,- create_item_from_text: (s) => ({display_value: s}),+ create_item_from_text: (s) => ({type: "color", display_value: s}),get_text_from_item: (s) => s.display_value,};diff --git a/frontend_tests/node_tests/stream_pill.js b/frontend_tests/node_tests/stream_pill.jsindex f9404b8bc91..2295e936e28 100644--- a/frontend_tests/node_tests/stream_pill.js+++ b/frontend_tests/node_tests/stream_pill.js@@ -26,11 +26,13 @@ peer_data.set_subscribers(sweden.stream_id, [1, 2, 3, 4, 5]);const denmark_pill = {stream_name: denmark.name,stream_id: denmark.stream_id,+ type: "stream",display_value: "#Denmark: 3 users",};const sweden_pill = {stream_name: sweden.name,stream_id: sweden.stream_id,+ type: "stream",display_value: "#Sweden: 5 users",};diff --git a/frontend_tests/node_tests/user_group_pill.js b/frontend_tests/node_tests/user_group_pill.jsindex 8fb94d561b1..ce742d47507 100644--- a/frontend_tests/node_tests/user_group_pill.js+++ b/frontend_tests/node_tests/user_group_pill.js@@ -24,11 +24,13 @@ const testers = {const admins_pill = {id: admins.id,group_name: admins.name,+ type: "user_group",display_value: admins.name + ": " + admins.members.length + " users",};const testers_pill = {id: testers.id,group_name: testers.name,+ type: "user_group",display_value: testers.name + ": " + testers.members.length + " users",};diff --git a/frontend_tests/node_tests/user_pill.js b/frontend_tests/node_tests/user_pill.jsindex 26878b68cde..9688f4db2cb 100644--- a/frontend_tests/node_tests/user_pill.js+++ b/frontend_tests/node_tests/user_pill.js@@ -23,12 +23,14 @@ const isaac = {const bogus_item = {email: "[email protected]",+ type: "user",display_value: "[email protected]",};const isaac_item = {email: "[email protected]",display_value: "Isaac Newton",+ type: "user",user_id: isaac.user_id,img_src: `/avatar/${isaac.user_id}&s=50`,};diff --git a/static/js/input_pill.js b/static/js/input_pill.jsindex 552ab42ec15..85f30ea00a4 100644--- a/static/js/input_pill.js+++ b/static/js/input_pill.js@@ -94,6 +94,11 @@ export function create(opts) {return;}+ if (!item.type) {+ blueslip.error("no type defined for the item");+ return;+ }+const payload = {id,item,diff --git a/static/js/stream_pill.js b/static/js/stream_pill.jsindex 2a07fdaa7e4..55036bb3e44 100644--- a/static/js/stream_pill.js+++ b/static/js/stream_pill.js@@ -24,6 +24,7 @@ export function create_item_from_stream_name(stream_name, current_items) {}const item = {+ type: "stream",display_value: display_pill(sub),stream_id: sub.stream_id,stream_name: sub.name,@@ -58,6 +59,7 @@ export function get_user_ids(pill_widget) {export function append_stream(stream, pill_widget) {pill_widget.appendValidatedData({+ type: "stream",display_value: display_pill(stream),stream_id: stream.stream_id,stream_name: stream.name,diff --git a/static/js/user_group_pill.js b/static/js/user_group_pill.jsindex 1ec2dcc4677..95f7bcdfab4 100644--- a/static/js/user_group_pill.js+++ b/static/js/user_group_pill.js@@ -17,6 +17,7 @@ export function create_item_from_group_name(group_name, current_items) {}const item = {+ type: "user_group",display_value: display_pill(group),id: group.id,group_name: group.name,@@ -51,6 +52,7 @@ export function get_user_ids(pill_widget) {export function append_user_group(group, pill_widget) {if (group !== undefined && group !== null) {pill_widget.appendValidatedData({+ type: "user_group",display_value: display_pill(group),id: group.id,});diff --git a/static/js/user_pill.js b/static/js/user_pill.jsindex f3980b71c55..5662b633ebc 100644--- a/static/js/user_pill.js+++ b/static/js/user_pill.js@@ -22,6 +22,7 @@ export function create_item_from_email(email, current_items) {// so we just create a pill where the display value// is the email itself.return {+ type: "user",display_value: email,email,};@@ -42,6 +43,7 @@ export function create_item_from_email(email, current_items) {// We must supply display_value for the widget to work. Everything// else is for our own use in callbacks.const item = {+ type: "user",display_value: user.full_name,user_id: user.user_id,email: user.email,@@ -61,6 +63,7 @@ export function append_person(opts) {const avatar_url = people.small_avatar_url_for_person(person);pill_widget.appendValidatedData({+ type: "user",display_value: person.full_name,user_id: person.user_id,email: person.email,