Skip to content

Commit

Permalink
[MM-11282] Add selector to get channel by name (mattermost#628)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan Wang authored and enahum committed Sep 14, 2018
1 parent e81cc19 commit b94c4bd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/selectors/entities/channels.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {
completeDirectChannelInfo,
completeDirectChannelDisplayName,
getUserIdFromChannelName,
getChannelByName as getChannelByNameHelper,
isChannelMuted,
getDirectChannelName,
isAutoClosed,
Expand Down Expand Up @@ -150,6 +151,10 @@ export function shouldHideDefaultChannel(state, channel) {
!isCurrentUserSystemAdmin(state) && getConfig(state).ExperimentalHideTownSquareinLHS === 'true';
}

export function getChannelByName(state, channelName) {
return getChannelByNameHelper(getAllChannels(state), channelName);
}

export const getChannelSetInCurrentTeam = createSelector(
getCurrentTeamId,
getChannelsInTeam,
Expand Down
5 changes: 5 additions & 0 deletions test/selectors/channels.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ describe('Selectors.Channels', () => {

const channel1 = TestHelper.fakeChannelWithId(team1.id);
channel1.display_name = 'Channel Name';
channel1.name = 'Name';

const channel2 = TestHelper.fakeChannelWithId(team1.id);
channel2.total_msg_count = 2;
Expand Down Expand Up @@ -203,6 +204,10 @@ describe('Selectors.Channels', () => {
assert.deepEqual(Selectors.getChannel(testState, channel1.id), channel1);
});

it('get first channel that matches by name', () => {
assert.deepEqual(Selectors.getChannelByName(testState, channel1.name), channel1);
});

it('get unreads for current team', () => {
assert.equal(Selectors.getUnreadsInCurrentTeam(testState).mentionCount, 3);
});
Expand Down

0 comments on commit b94c4bd

Please sign in to comment.