From aa5ffcbd2e1fa45abe8dd5602bf81da2e70e6790 Mon Sep 17 00:00:00 2001 From: Steve Howell Date: Wed, 15 Apr 2020 13:35:14 +0000 Subject: [PATCH] admin user: Sort bot owners by name. The original commit here was sorting bot owners by id, which is of course meaningless to users: 444ce74a8e4a2dc75a6cf1f1dce14bdce496f446 It was also returning 1/-1 in cases where the bot owner on both sides of a comparison were missing, which is a big no-no for sorting algorithms. --- static/js/settings_users.js | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/static/js/settings_users.js b/static/js/settings_users.js index 20ab798a48..1230160a35 100644 --- a/static/js/settings_users.js +++ b/static/js/settings_users.js @@ -39,10 +39,24 @@ function sort_role(a, b) { } function sort_bot_owner(a, b) { - if (!a.bot_owner_id) { return 1; } - if (!b.bot_owner_id) { return -1; } + function owner_name(item) { + const owner = people.get_bot_owner_user(item); - return compare_a_b(a.bot_owner_id, b.bot_owner_id); + if (!owner) { + return ''; + } + + if (!owner.full_name) { + return ''; + } + + return owner.full_name.toLowerCase(); + } + + return compare_a_b( + owner_name(a), + owner_name(b) + ); } function sort_last_active(a, b) {