Skip to content

Commit

Permalink
Add selector to get map channels by name
Browse files Browse the repository at this point in the history
  • Loading branch information
jwilander committed May 22, 2017
1 parent 3d858c6 commit 90606aa
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/selectors/entities/channels.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,19 @@ export const getChannelsInCurrentTeam = createSelector(
}
);

export const getChannelsNameMapInCurrentTeam = createSelector(
getAllChannels,
getChannelSetInCurrentTeam,
(channels, currentTeamChannelSet) => {
const channelMap = {};
currentTeamChannelSet.forEach((id) => {
const channel = channels[id];
channelMap[channel.name] = channel;
});
return channelMap;
}
);

export const getDirectChannels = createSelector(
getAllChannels,
getDirectChannelsSet,
Expand Down
10 changes: 10 additions & 0 deletions test/selectors/channels.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,14 @@ describe('Selectors.Channels', () => {
it('get unreads for current team', () => {
assert.equal(Selectors.getUnreadsInCurrentTeam(testState).mentionCount, 1);
});

it('get channel map for current team', () => {
const channelMap = {
[channel1.name]: channel1,
[channel2.name]: channel2,
[channel5.name]: channel5,
[channel6.name]: channel6
};
assert.deepEqual(Selectors.getChannelsNameMapInCurrentTeam(testState), channelMap);
});
});

0 comments on commit 90606aa

Please sign in to comment.