From 1ab7034574de2229d3cfc49391e6579db37a3064 Mon Sep 17 00:00:00 2001 From: Antti Ahti Date: Wed, 14 Oct 2015 18:27:03 +0300 Subject: Use team display name in team switcher menu - /teams/find_teams returns team objects instead of just team names - use display_name in UI instead of name in the team switch menu --- web/react/components/navbar_dropdown.jsx | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'web/react/components') diff --git a/web/react/components/navbar_dropdown.jsx b/web/react/components/navbar_dropdown.jsx index 49d517419..b3f8e4418 100644 --- a/web/react/components/navbar_dropdown.jsx +++ b/web/react/components/navbar_dropdown.jsx @@ -145,7 +145,7 @@ export default class NavbarDropdown extends React.Component { var teams = []; - if (this.state.teams.length > 1) { + if (Object.keys(this.state.teams).length > 1) { teams.push(
  • ); - this.state.teams.forEach((teamName) => { - if (teamName !== this.props.teamName) { - teams.push(
  • {'Switch to ' + teamName}
  • ); + for (let teamId in this.state.teams) { + if (this.state.teams.hasOwnProperty(teamId)) { + let team = this.state.teams[teamId]; + if (team.name !== this.props.teamName) { + teams.push(
  • {'Switch to ' + team.display_name}
  • ); + } } - }); + } } if (global.window.config.EnableTeamCreation === 'true') { -- cgit v1.2.3-1-g7c22 From 059df3de0126f2a506b525f92911035eba02bbd3 Mon Sep 17 00:00:00 2001 From: Antti Ahti Date: Thu, 15 Oct 2015 08:41:52 +0300 Subject: Sort teams by display name First we need to convert the object to array, because objects cannot be sorted. --- web/react/components/navbar_dropdown.jsx | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'web/react/components') diff --git a/web/react/components/navbar_dropdown.jsx b/web/react/components/navbar_dropdown.jsx index b3f8e4418..d4308ad72 100644 --- a/web/react/components/navbar_dropdown.jsx +++ b/web/react/components/navbar_dropdown.jsx @@ -11,7 +11,25 @@ var AboutBuildModal = require('./about_build_modal.jsx'); var Constants = require('../utils/constants.jsx'); function getStateFromStores() { - return {teams: UserStore.getTeams()}; + let teams = []; + let teamsObject = UserStore.getTeams(); + for (let teamId in teamsObject) { + if (teamsObject.hasOwnProperty(teamId)) { + teams.push(teamsObject[teamId]) + } + } + teams.sort(function (teamA, teamB) { + let teamADisplayName = teamA.display_name.toLowerCase(); + let teamBDisplayName = teamB.display_name.toLowerCase(); + if (teamADisplayName < teamBDisplayName) { + return -1 + } else if (teamADisplayName > teamBDisplayName) { + return 1; + } else { + return 0; + } + }); + return {teams}; } export default class NavbarDropdown extends React.Component { -- cgit v1.2.3-1-g7c22 From c0809bbc3fc7a9630659872850c313eb6df701d9 Mon Sep 17 00:00:00 2001 From: Antti Ahti Date: Thu, 15 Oct 2015 08:54:20 +0300 Subject: Treat teams as an array instead of object --- web/react/components/navbar_dropdown.jsx | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'web/react/components') diff --git a/web/react/components/navbar_dropdown.jsx b/web/react/components/navbar_dropdown.jsx index d4308ad72..564a64f48 100644 --- a/web/react/components/navbar_dropdown.jsx +++ b/web/react/components/navbar_dropdown.jsx @@ -163,7 +163,7 @@ export default class NavbarDropdown extends React.Component { var teams = []; - if (Object.keys(this.state.teams).length > 1) { + if (this.state.teams.length > 1) { teams.push(
  • ); - for (let teamId in this.state.teams) { - if (this.state.teams.hasOwnProperty(teamId)) { - let team = this.state.teams[teamId]; - if (team.name !== this.props.teamName) { - teams.push(
  • {'Switch to ' + team.display_name}
  • ); - } + this.state.teams.forEach((team) => { + if (team.name !== this.props.teamName) { + teams.push(
  • {'Switch to ' + team.display_name}
  • ); } - } + }); } if (global.window.config.EnableTeamCreation === 'true') { -- cgit v1.2.3-1-g7c22 From 7abde676a1828714c71b25184fdd91a81c2d77a1 Mon Sep 17 00:00:00 2001 From: Antti Ahti Date: Thu, 15 Oct 2015 19:35:45 +0300 Subject: Fix lint --- web/react/components/navbar_dropdown.jsx | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'web/react/components') diff --git a/web/react/components/navbar_dropdown.jsx b/web/react/components/navbar_dropdown.jsx index 564a64f48..dc41775c7 100644 --- a/web/react/components/navbar_dropdown.jsx +++ b/web/react/components/navbar_dropdown.jsx @@ -15,19 +15,18 @@ function getStateFromStores() { let teamsObject = UserStore.getTeams(); for (let teamId in teamsObject) { if (teamsObject.hasOwnProperty(teamId)) { - teams.push(teamsObject[teamId]) + teams.push(teamsObject[teamId]); } } - teams.sort(function (teamA, teamB) { + teams.sort(function sortByDisplayName(teamA, teamB) { let teamADisplayName = teamA.display_name.toLowerCase(); let teamBDisplayName = teamB.display_name.toLowerCase(); if (teamADisplayName < teamBDisplayName) { - return -1 + return -1; } else if (teamADisplayName > teamBDisplayName) { return 1; - } else { - return 0; } + return 0; }); return {teams}; } -- cgit v1.2.3-1-g7c22