Skip to content
This repository has been archived by the owner on Mar 13, 2024. It is now read-only.

Commit

Permalink
MM-21584 Add initial state for channel categories (#1052)
Browse files Browse the repository at this point in the history
* MM-21584 Add initial reducers and actions for channel categories

* MM-21584 Add initial selectors for channel categories

* Add channelCategories to the base reducer

* Remove collapsedById

* Fix typo in test name
  • Loading branch information
hmhealey committed Mar 5, 2020
1 parent 7e9e04f commit 2463432
Show file tree
Hide file tree
Showing 16 changed files with 1,199 additions and 5 deletions.
15 changes: 15 additions & 0 deletions src/action_types/channel_categories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.

import keyMirror from 'utils/key_mirror';

export default keyMirror({
RECEIVED_CATEGORY: null,
RECEIVED_CATEGORIES: null,
RECEIVED_CATEGORY_ORDER: null,

CATEGORY_COLLAPSED: null,
CATEGORY_EXPANDED: null,

CATEGORY_DELETED: null,
});
3 changes: 3 additions & 0 deletions src/action_types/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.

import ChannelTypes from './channels';
import ErrorTypes from './errors';
import GeneralTypes from './general';
Expand All @@ -20,6 +21,7 @@ import SchemeTypes from './schemes';
import GroupTypes from './groups';
import BotTypes from './bots';
import PluginTypes from './plugins';
import ChannelCategoryTypes from './channel_categories';

export {
ErrorTypes,
Expand All @@ -42,4 +44,5 @@ export {
GroupTypes,
BotTypes,
PluginTypes,
ChannelCategoryTypes,
};
18 changes: 18 additions & 0 deletions src/actions/channel_categories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.

import {ChannelCategoryTypes} from 'action_types';

export function expandCategory(categoryId: string) {
return {
type: ChannelCategoryTypes.CATEGORY_EXPANDED,
data: categoryId,
};
}

export function collapseCategory(categoryId: string) {
return {
type: ChannelCategoryTypes.CATEGORY_COLLAPSED,
data: categoryId,
};
}
12 changes: 12 additions & 0 deletions src/constants/channel_categories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.

import {ChannelCategoryType} from 'types/channel_categories';

export const CategoryTypes: {[name: string]: ChannelCategoryType} = {
FAVORITES: 'favorites',
PUBLIC: 'public',
PRIVATE: 'private',
DIRECT_MESSAGES: 'direct_messages',
CUSTOM: 'custom',
};
4 changes: 3 additions & 1 deletion src/constants/preferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ const Preferences: Dictionary<any> = {
USE_MILITARY_TIME: 'use_military_time',
CATEGORY_SIDEBAR_SETTINGS: 'sidebar_settings',
CHANNEL_SIDEBAR_ORGANIZATION: 'channel_sidebar_organization',
CHANNEL_SIDEBAR_AUTOCLOSE_DMS: 'close_unused_direct_messages',
AUTOCLOSE_DMS_ENABLED: 'after_seven_days',
CATEGORY_ADVANCED_SETTINGS: 'advanced_settings',
ADVANCED_FILTER_JOIN_LEAVE: 'join_leave',
ADVANCED_CODE_BLOCK_ON_CTRL_ENTER: 'code_block_ctrl_enter',
Expand Down Expand Up @@ -152,4 +154,4 @@ const Preferences: Dictionary<any> = {
},
};

export default Preferences;
export default Preferences;
156 changes: 156 additions & 0 deletions src/reducers/entities/channel_categories.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.

import {CategoryTypes} from '../../constants/channel_categories';

import {ChannelCategoryTypes, TeamTypes} from 'action_types';

import * as Reducers from './channel_categories';

describe('byId', () => {
test('default categories should be added when a member is received', () => {
const initialState = {};

const state = Reducers.byId(
initialState,
{
type: TeamTypes.RECEIVED_MY_TEAM_MEMBER,
data: {
team_id: 'team1',
},
}
);

expect(state['team1-favorites']).toBeDefined();
expect(state['team1-public']).toBeDefined();
expect(state['team1-private']).toBeDefined();
expect(state['team1-direct_messages']).toBeDefined();
});

test('default categories should be added when multiple members are received', () => {
const initialState = {};

const state = Reducers.byId(
initialState,
{
type: TeamTypes.RECEIVED_MY_TEAM_MEMBERS,
data: [
{team_id: 'team1'},
{team_id: 'team2'},
],
}
);

expect(state['team1-favorites']).toBeDefined();
expect(state['team1-public']).toBeDefined();
expect(state['team1-private']).toBeDefined();
expect(state['team1-direct_messages']).toBeDefined();
expect(state['team2-favorites']).toBeDefined();
expect(state['team2-public']).toBeDefined();
expect(state['team2-private']).toBeDefined();
expect(state['team2-direct_messages']).toBeDefined();
});

test('should remove corresponding categories when leaving a team', () => {
const initialState = {
category1: {id: 'category1', team_id: 'team1', type: CategoryTypes.CUSTOM},
category2: {id: 'category2', team_id: 'team1', type: CategoryTypes.CUSTOM},
dmCategory1: {id: 'dmCategory1', team_id: 'team1', type: CategoryTypes.DIRECT_MESSAGES},
category3: {id: 'category3', team_id: 'team2', type: CategoryTypes.CUSTOM},
category4: {id: 'category4', team_id: 'team2', type: CategoryTypes.CUSTOM},
dmCategory2: {id: 'dmCategory1', team_id: 'team2', type: CategoryTypes.DIRECT_MESSAGES},
};

const state = Reducers.byId(
initialState,
{
type: TeamTypes.LEAVE_TEAM,
data: {
id: 'team1',
},
}
);

expect(state).toEqual({
category3: state.category3,
category4: state.category4,
dmCategory2: state.dmCategory2,
});
});
});

describe('orderByTeam', () => {
test('default category order should be added when a member is received', () => {
const initialState = {};

const state = Reducers.orderByTeam(
initialState,
{
type: TeamTypes.RECEIVED_MY_TEAM_MEMBER,
data: {
team_id: 'team1',
},
}
);

expect(state).toEqual({
team1: [
'team1-favorites',
'team1-public',
'team1-private',
'team1-direct_messages',
],
});
});

test('default category order should be added when multiple members are received', () => {
const initialState = {};

const state = Reducers.orderByTeam(
initialState,
{
type: TeamTypes.RECEIVED_MY_TEAM_MEMBERS,
data: [
{team_id: 'team1'},
{team_id: 'team2'},
],
}
);

expect(state).toEqual({
team1: [
'team1-favorites',
'team1-public',
'team1-private',
'team1-direct_messages',
],
team2: [
'team2-favorites',
'team2-public',
'team2-private',
'team2-direct_messages',
],
});
});

test('should remove correspoding order when leaving a team', () => {
const initialState = {
team1: ['category1', 'category2', 'dmCategory1'],
team2: ['category3', 'category4', 'dmCategory2'],
};

const state = Reducers.orderByTeam(
initialState,
{
type: TeamTypes.LEAVE_TEAM,
data: {
id: 'team1',
},
}
);

expect(state).toEqual({
team2: initialState.team2,
});
});
});
Loading

0 comments on commit 2463432

Please sign in to comment.