forked from mattermost/mattermost-webapp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
team_utils.jsx
28 lines (22 loc) · 930 Bytes
/
team_utils.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
import LocalizationStore from 'stores/localization_store.jsx';
// Use when sorting multiple teams by their `display_name` field
function sortTeamsByDisplayName(a, b) {
const locale = LocalizationStore.getLocale();
if (a.display_name !== b.display_name) {
return a.display_name.localeCompare(b.display_name, locale, {numeric: true});
}
return a.name.localeCompare(b.name, locale, {numeric: true});
}
// Use to filter out teams that are deleted and without display_name, then sort by their `display_name` field
export function filterAndSortTeamsByDisplayName(teams = []) {
if (!teams) {
return [];
}
return teams.
filter((team) => {
return team && !team.delete_at > 0 && team.display_name != null;
}).
sort(sortTeamsByDisplayName);
}