diff options
author | Saturnino Abril <saturnino.abril@gmail.com> | 2017-02-01 08:57:16 +0900 |
---|---|---|
committer | enahum <nahumhbl@gmail.com> | 2017-01-31 20:57:16 -0300 |
commit | 9ba968ce3354b1a8ab307ecc4cc785bdee16f914 (patch) | |
tree | 1180a7913c326ed66191555d5a21d0643e932b8a /webapp/components | |
parent | 9369cab56c82629d505d44d572f273df1d396972 (diff) | |
download | chat-9ba968ce3354b1a8ab307ecc4cc785bdee16f914.tar.gz chat-9ba968ce3354b1a8ab307ecc4cc785bdee16f914.tar.bz2 chat-9ba968ce3354b1a8ab307ecc4cc785bdee16f914.zip |
Use consistent Display Name sorting code throughout the webapp #5159 (#5213)
* Use consistent Display Name sorting code throughout the webapp #5159
* fixed broken sorting of teams and channels
Diffstat (limited to 'webapp/components')
7 files changed, 35 insertions, 67 deletions
diff --git a/webapp/components/admin_console/admin_navbar_dropdown.jsx b/webapp/components/admin_console/admin_navbar_dropdown.jsx index d4e144c4f..a1ec2885b 100644 --- a/webapp/components/admin_console/admin_navbar_dropdown.jsx +++ b/webapp/components/admin_console/admin_navbar_dropdown.jsx @@ -6,6 +6,7 @@ import ReactDOM from 'react-dom'; import TeamStore from 'stores/team_store.jsx'; import Constants from 'utils/constants.jsx'; +import {sortTeamsByDisplayName} from 'utils/utils.jsx'; import * as GlobalActions from 'actions/global_actions.jsx'; import {FormattedMessage} from 'react-intl'; @@ -64,9 +65,7 @@ export default class AdminNavbarDropdown extends React.Component { } // Sort teams alphabetically with display_name - teamsArray.sort((teamA, teamB) => - teamA.display_name.localeCompare(teamB.display_name) - ); + teamsArray = teamsArray.sort(sortTeamsByDisplayName); for (const team of teamsArray) { teams.push( diff --git a/webapp/components/admin_console/admin_sidebar.jsx b/webapp/components/admin_console/admin_sidebar.jsx index e8303ea0c..952fe9ff4 100644 --- a/webapp/components/admin_console/admin_sidebar.jsx +++ b/webapp/components/admin_console/admin_sidebar.jsx @@ -114,19 +114,6 @@ export default class AdminSidebar extends React.Component { document.title = Utils.localizeMessage('sidebar_right_menu.console', 'System Console') + ' - ' + currentSiteName; } - sortTeams(a, b) { - const teamA = a.display_name.toLowerCase(); - const teamB = b.display_name.toLowerCase(); - - if (teamA < teamB) { - return -1; - } - if (teamA > teamB) { - return 1; - } - return 0; - } - renderAddTeamButton() { const addTeamTooltip = ( <Tooltip id='add-team-tooltip'> @@ -159,7 +146,7 @@ export default class AdminSidebar extends React.Component { renderTeams() { const teams = []; - const teamsArray = []; + let teamsArray = []; Reflect.ownKeys(this.state.selectedTeams).forEach((key) => { if (this.state.teams[key]) { @@ -167,7 +154,7 @@ export default class AdminSidebar extends React.Component { } }); - teamsArray.sort(this.sortTeams); + teamsArray = teamsArray.sort(Utils.sortTeamsByDisplayName); for (let i = 0; i < teamsArray.length; i++) { const team = teamsArray[i]; diff --git a/webapp/components/admin_console/select_team_modal.jsx b/webapp/components/admin_console/select_team_modal.jsx index 14448d753..68e20f852 100644 --- a/webapp/components/admin_console/select_team_modal.jsx +++ b/webapp/components/admin_console/select_team_modal.jsx @@ -3,18 +3,17 @@ import ReactDOM from 'react-dom'; import {FormattedMessage} from 'react-intl'; - import {Modal} from 'react-bootstrap'; - import React from 'react'; +import {sortTeamsByDisplayName} from 'utils/utils.jsx'; + export default class SelectTeamModal extends React.Component { constructor(props) { super(props); this.doSubmit = this.doSubmit.bind(this); this.doCancel = this.doCancel.bind(this); - this.compare = this.compare.bind(this); } doSubmit(e) { @@ -25,24 +24,19 @@ export default class SelectTeamModal extends React.Component { this.props.onModalDismissed(); } - compare(a, b) { - return a.display_name.localeCompare(b.display_name); - } - render() { if (this.props.teams == null) { return <div/>; } const options = []; - const teamsArray = []; + let teamsArray = []; Reflect.ownKeys(this.props.teams).forEach((key) => { teamsArray.push(this.props.teams[key]); }); - teamsArray.sort(this.compare); - + teamsArray = teamsArray.sort(sortTeamsByDisplayName); for (let i = 0; i < teamsArray.length; i++) { const team = teamsArray[i]; options.push( diff --git a/webapp/components/channel_select.jsx b/webapp/components/channel_select.jsx index 194de3874..ad0abd501 100644 --- a/webapp/components/channel_select.jsx +++ b/webapp/components/channel_select.jsx @@ -6,6 +6,7 @@ import React from 'react'; import Constants from 'utils/constants.jsx'; import ChannelStore from 'stores/channel_store.jsx'; import * as Utils from 'utils/utils.jsx'; +import {sortChannelsByDisplayName} from 'utils/channel_utils.jsx'; import * as AsyncClient from 'utils/async_client.jsx'; export default class ChannelSelect extends React.Component { @@ -32,12 +33,11 @@ export default class ChannelSelect extends React.Component { this.handleChannelChange = this.handleChannelChange.bind(this); this.filterChannels = this.filterChannels.bind(this); - this.compareByDisplayName = this.compareByDisplayName.bind(this); AsyncClient.getMoreChannels(true); this.state = { - channels: ChannelStore.getAll().filter(this.filterChannels).sort(this.compareByDisplayName) + channels: ChannelStore.getAll().filter(this.filterChannels).sort(sortChannelsByDisplayName) }; } @@ -52,7 +52,7 @@ export default class ChannelSelect extends React.Component { handleChannelChange() { this.setState({ channels: ChannelStore.getAll().concat(ChannelStore.getMoreAll()). - filter(this.filterChannels).sort(this.compareByDisplayName) + filter(this.filterChannels).sort(sortChannelsByDisplayName) }); } @@ -64,10 +64,6 @@ export default class ChannelSelect extends React.Component { return false; } - compareByDisplayName(channelA, channelB) { - return channelA.display_name.localeCompare(channelB.display_name); - } - render() { const options = [ <option diff --git a/webapp/components/suggestion/search_channel_provider.jsx b/webapp/components/suggestion/search_channel_provider.jsx index 8965e7a76..c0ec06181 100644 --- a/webapp/components/suggestion/search_channel_provider.jsx +++ b/webapp/components/suggestion/search_channel_provider.jsx @@ -10,6 +10,7 @@ import ChannelStore from 'stores/channel_store.jsx'; import AppDispatcher from 'dispatcher/app_dispatcher.jsx'; import {Constants, ActionTypes} from 'utils/constants.jsx'; +import {sortChannelsByDisplayName} from 'utils/channel_utils.jsx'; import React from 'react'; @@ -51,7 +52,7 @@ export default class SearchChannelProvider extends Provider { const publicChannels = data; const localChannels = ChannelStore.getAll(); - const privateChannels = []; + let privateChannels = []; for (const id of Object.keys(localChannels)) { const channel = localChannels[id]; @@ -60,15 +61,15 @@ export default class SearchChannelProvider extends Provider { } } - const filteredPublicChannels = []; + let filteredPublicChannels = []; publicChannels.forEach((item) => { if (item.name.startsWith(channelPrefix)) { filteredPublicChannels.push(item); } }); - privateChannels.sort((a, b) => a.name.localeCompare(b.name)); - filteredPublicChannels.sort((a, b) => a.name.localeCompare(b.name)); + privateChannels = privateChannels.sort(sortChannelsByDisplayName); + filteredPublicChannels = filteredPublicChannels.sort(sortChannelsByDisplayName); const channels = filteredPublicChannels.concat(privateChannels); const channelNames = channels.map((channel) => channel.name); diff --git a/webapp/components/suggestion/switch_channel_provider.jsx b/webapp/components/suggestion/switch_channel_provider.jsx index 0bc30a79f..3b7bec319 100644 --- a/webapp/components/suggestion/switch_channel_provider.jsx +++ b/webapp/components/suggestion/switch_channel_provider.jsx @@ -12,6 +12,7 @@ import Client from 'client/web_client.jsx'; import AppDispatcher from 'dispatcher/app_dispatcher.jsx'; import {Constants, ActionTypes} from 'utils/constants.jsx'; import * as Utils from 'utils/utils.jsx'; +import {sortChannelsByDisplayName} from 'utils/channel_utils.jsx'; import React from 'react'; @@ -105,19 +106,9 @@ export default class SwitchChannelProvider extends Provider { userMap[user.id] = user; } - channels.sort((a, b) => { - if (a.display_name === b.display_name) { - if (a.type !== Constants.DM_CHANNEL && b.type === Constants.DM_CHANNEL) { - return -1; - } else if (a.type === Constants.DM_CHANNEL && b.type !== Constants.DM_CHANNEL) { - return 1; - } - return a.name.localeCompare(b.name); - } - return a.display_name.localeCompare(b.display_name); - }); - - const channelNames = channels.map((channel) => channel.name); + const channelNames = channels. + sort(sortChannelsByDisplayName). + map((channel) => channel.name); AppDispatcher.handleServerAction({ type: ActionTypes.SUGGESTION_RECEIVED_SUGGESTIONS, diff --git a/webapp/components/team_sidebar/team_sidebar_controller.jsx b/webapp/components/team_sidebar/team_sidebar_controller.jsx index ac3a9f894..49635455f 100644 --- a/webapp/components/team_sidebar/team_sidebar_controller.jsx +++ b/webapp/components/team_sidebar/team_sidebar_controller.jsx @@ -118,21 +118,21 @@ export default class TeamSidebar extends React.Component { } const teams = myTeams. - sort((a, b) => a.display_name.localeCompare(b.display_name)). - map((team) => { - return ( - <TeamButton - key={'switch_team_' + team.name} - url={`/${team.name}`} - tip={team.display_name} - active={team.id === this.state.currentTeamId} - isMobile={this.state.isMobile} - displayName={team.display_name} - unread={team.unread} - mentions={team.mentions} - /> - ); - }); + sort(Utils.sortTeamsByDisplayName). + map((team) => { + return ( + <TeamButton + key={'switch_team_' + team.name} + url={`/${team.name}`} + tip={team.display_name} + active={team.id === this.state.currentTeamId} + isMobile={this.state.isMobile} + displayName={team.display_name} + unread={team.unread} + mentions={team.mentions} + /> + ); + }); if (moreTeams) { teams.push( |