From c8cd3d22ad8f6c184ed2c5f4b285bf939b593572 Mon Sep 17 00:00:00 2001
From: Debanshu Kundu <debanshu.kundu@joshtechnologygroup.com>
Date: Tue, 20 Dec 2016 03:16:13 +0530
Subject: PLT-4977 Sorting teams by display name on team list at system
 console's menue and select team modal. (#4797)

---
 .../admin_console/admin_navbar_dropdown.jsx        | 38 ++++++++++++++--------
 1 file changed, 24 insertions(+), 14 deletions(-)

(limited to 'webapp/components/admin_console/admin_navbar_dropdown.jsx')

diff --git a/webapp/components/admin_console/admin_navbar_dropdown.jsx b/webapp/components/admin_console/admin_navbar_dropdown.jsx
index 5b65868e9..07e32e658 100644
--- a/webapp/components/admin_console/admin_navbar_dropdown.jsx
+++ b/webapp/components/admin_console/admin_navbar_dropdown.jsx
@@ -50,7 +50,8 @@ export default class AdminNavbarDropdown extends React.Component {
     }
 
     render() {
-        const teams = [];
+        var teamsArray = [];  // Array of team objects
+        var teams = [];  // Array of team components
         let switchTeams;
 
         if (this.state.teamMembers && this.state.teamMembers.length > 0) {
@@ -58,22 +59,31 @@ export default class AdminNavbarDropdown extends React.Component {
                 if (this.state.teamMembers.hasOwnProperty(index)) {
                     const teamMember = this.state.teamMembers[index];
                     const team = this.state.teams[teamMember.team_id];
-                    teams.push(
-                        <li key={'team_' + team.name}>
-                            <Link
-                                to={'/' + team.name + '/channels/town-square'}
-                            >
-                                <FormattedMessage
-                                    id='navbar_dropdown.switchTo'
-                                    defaultMessage='Switch to '
-                                />
-                                {team.display_name}
-                            </Link>
-                        </li>
-                    );
+                    teamsArray.push(team);
                 }
             }
 
+            // Sort teams alphabetically with display_name
+            teamsArray.sort((teamA, teamB) =>
+                teamA.display_name.localeCompare(teamB.display_name)
+            );
+
+            for (const team of teamsArray) {
+                teams.push(
+                    <li key={'team_' + team.name}>
+                        <Link
+                            to={'/' + team.name + '/channels/town-square'}
+                        >
+                            <FormattedMessage
+                                id='navbar_dropdown.switchTo'
+                                defaultMessage='Switch to '
+                            />
+                            {team.display_name}
+                        </Link>
+                    </li>
+                );
+            }
+
             teams.push(
                 <li
                     key='teamDiv'
-- 
cgit v1.2.3-1-g7c22

