Skip to content

Commit

Permalink
Add UI filtering for team if config setting set
Browse files Browse the repository at this point in the history
  • Loading branch information
jwilander committed Feb 27, 2017
1 parent 18bc17a commit 11ccb9b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
28 changes: 23 additions & 5 deletions webapp/components/more_direct_channels.jsx
Expand Up @@ -36,6 +36,7 @@ export default class MoreDirectChannels extends React.Component {
this.addValue = this.addValue.bind(this);

this.searchTimeoutId = 0;
this.listType = global.window.mm_config.RestrictDirectMessage;

const values = [];
if (props.startingUsers) {
Expand All @@ -58,16 +59,20 @@ export default class MoreDirectChannels extends React.Component {

componentDidMount() {
UserStore.addChangeListener(this.onChange);
UserStore.addInTeamChangeListener(this.onChange);
UserStore.addStatusesChangeListener(this.onChange);
TeamStore.addChangeListener(this.onChange);

AsyncClient.getProfiles(0, USERS_PER_PAGE * 2);
if (this.listType === 'any') {
AsyncClient.getProfiles(0, USERS_PER_PAGE * 2);
} else {
AsyncClient.getProfilesInTeam(TeamStore.getCurrentId(), 0, USERS_PER_PAGE * 2);
}
}

componentWillUnmount() {
UserStore.removeChangeListener(this.onChange);
UserStore.removeInTeamChangeListener(this.onChange);
UserStore.removeStatusesChangeListener(this.onChange);
TeamStore.removeChangeListener(this.onChange);
}

handleHide() {
Expand Down Expand Up @@ -134,7 +139,13 @@ export default class MoreDirectChannels extends React.Component {
return;
}

const users = Object.assign([], UserStore.getProfileList(true));
let users;
if (this.listType === 'any') {
users = Object.assign([], UserStore.getProfileList(true));
} else {
users = Object.assign([], UserStore.getProfileListInTeam(TeamStore.getCurrentId(), true));
}

for (let i = 0; i < users.length; i++) {
const user = Object.assign({}, users[i]);
user.value = user.id;
Expand Down Expand Up @@ -163,11 +174,18 @@ export default class MoreDirectChannels extends React.Component {
return;
}

let teamId;
if (this.listType === 'any') {
teamId = '';
} else {
teamId = TeamStore.getCurrentId();
}

const searchTimeoutId = setTimeout(
() => {
searchUsers(
term,
'',
teamId,
{},
(users) => {
if (searchTimeoutId !== this.searchTimeoutId) {
Expand Down
2 changes: 1 addition & 1 deletion webapp/components/multiselect/multiselect_list.jsx
Expand Up @@ -115,7 +115,7 @@ export default class MultiSelectList extends React.Component {
render() {
const options = this.props.options;

if (options == null) {
if (options == null || options.length === 0) {
return (
<div
key='no-users-found'
Expand Down

0 comments on commit 11ccb9b

Please sign in to comment.