compose pill: Add has_unconverted_data() helper.

This commit is contained in:
Steve Howell
2018-09-17 23:40:27 +00:00
committed by Tim Abbott
parent 3225f81a92
commit 27ef6a9991
3 changed files with 48 additions and 0 deletions

View File

@@ -152,3 +152,32 @@ run_test('pills', () => {
assert(appendValue_called);
assert(text_cleared);
});
run_test('has_unconverted_data', () => {
compose_pm_pill.widget = {
is_pending: () => true,
};
// If the pill itself has pending data, we have unconverted
// data.
assert.equal(compose_pm_pill.has_unconverted_data(), true);
compose_pm_pill.widget = {
is_pending: () => false,
items: () => [{user_id: 99}],
};
// Our pill is complete and all items containt user_id, so
// we do NOT have unconverted data.
assert.equal(compose_pm_pill.has_unconverted_data(), false);
compose_pm_pill.widget = {
is_pending: () => false,
items: () => [{user_id: 99}, {email: 'random@mit.edu'}],
};
// One of our items only knows email (as in a bridge-with-zephyr
// scenario where we might not have registered the user yet), so
// we have some unconverted data.
assert.equal(compose_pm_pill.has_unconverted_data(), true);
});

View File

@@ -41,6 +41,10 @@ exports.get_user_ids = function () {
return user_pill.get_user_ids(exports.widget);
};
exports.has_unconverted_data = function () {
return user_pill.has_unconverted_data(exports.widget);
};
exports.get_user_ids_string = function () {
var user_ids = exports.get_user_ids();
var sorted_user_ids = util.sorted_ids(user_ids);

View File

@@ -76,6 +76,21 @@ exports.get_user_ids = function (pill_widget) {
return user_ids;
};
exports.has_unconverted_data = function (pill_widget) {
// This returns true if we either have text that hasn't been
// turned into pills or email-only pills (for Zephyr).
if (pill_widget.is_pending()) {
return true;
}
var items = pill_widget.items();
var has_unknown_items = _.any(items, function (item) {
return item.user_id === undefined;
});
return has_unknown_items;
};
exports.typeahead_source = function (pill_widget) {
var items = people.get_realm_persons();
var taken_user_ids = exports.get_user_ids(pill_widget);