diff --git a/webapp/channels/src/actions/websocket_actions.jsx b/webapp/channels/src/actions/websocket_actions.jsx index adb05f4215..0ee45e48a0 100644 --- a/webapp/channels/src/actions/websocket_actions.jsx +++ b/webapp/channels/src/actions/websocket_actions.jsx @@ -1474,7 +1474,8 @@ function handleSidebarCategoryUpdated(msg) { } // Fetch all categories in case any other categories had channels moved out of them. - doDispatch(fetchMyCategories(msg.broadcast.team_id)); + // True indicates it is called from WebSocket + doDispatch(fetchMyCategories(msg.broadcast.team_id, true)); }; } diff --git a/webapp/channels/src/packages/mattermost-redux/src/actions/channel_categories.test.js b/webapp/channels/src/packages/mattermost-redux/src/actions/channel_categories.test.js index 0cfcadbdf9..d0c1342510 100644 --- a/webapp/channels/src/packages/mattermost-redux/src/actions/channel_categories.test.js +++ b/webapp/channels/src/packages/mattermost-redux/src/actions/channel_categories.test.js @@ -327,6 +327,88 @@ describe('fetchMyCategories', () => { expect(state.entities.channelCategories.byId.category2).toEqual(categories[1]); expect(state.entities.channelCategories.orderByTeam[teamId]).toEqual(['category1', 'category2']); }); + test('should update collapse state if it\'s not from websocket', async () => { + const currentUserId = TestHelper.generateId(); + const teamId = TestHelper.generateId(); + const isWebSocket = false; + + const categories = [ + { + id: 'category1', + collapsed: false, + team_id: teamId, + }, + { + id: 'category2', + collapsed: true, + team_id: teamId, + }, + ]; + + const store = configureStore({ + entities: { + users: { + currentUserId, + }, + channelCategories: { + byId: { + category1: {id: 'category1', team_id: teamId, collapsed: true}, + category2: {id: 'category2', team_id: teamId, collapsed: false}, + + }, + }, + }}); + + nock(Client4.getBaseRoute()). + get(`/users/${currentUserId}/teams/${teamId}/channels/categories`). + reply(200, {categories, order: categories.map((category) => category.id)}); + await store.dispatch(Actions.fetchMyCategories(teamId, isWebSocket)); + const categoriesById = getAllCategoriesByIds(store.getState()); + + expect(categoriesById.category1.collapsed).toEqual(false); + expect(categoriesById.category2.collapsed).toEqual(true); + }); + test('should not update collapse state if it\'s from websocket', async () => { + const currentUserId = TestHelper.generateId(); + const teamId = TestHelper.generateId(); + const isWebSocket = true; + + const categories = [ + { + id: 'category1', + collapsed: false, + team_id: teamId, + }, + { + id: 'category2', + collapsed: true, + team_id: teamId, + }, + ]; + + const store = configureStore({ + entities: { + users: { + currentUserId, + }, + channelCategories: { + byId: { + category1: {id: 'category1', team_id: teamId, collapsed: true}, + category2: {id: 'category2', team_id: teamId, collapsed: false}, + + }, + }, + }}); + nock(Client4.getBaseRoute()). + get(`/users/${currentUserId}/teams/${teamId}/channels/categories`). + reply(200, {categories, order: categories.map((category) => category.id)}); + + await store.dispatch(Actions.fetchMyCategories(teamId, isWebSocket)); + const categoriesById = getAllCategoriesByIds(store.getState()); + + expect(categoriesById.category1.collapsed).toEqual(true); + expect(categoriesById.category2.collapsed).toEqual(false); + }); }); describe('addChannelToInitialCategory', () => { diff --git a/webapp/channels/src/packages/mattermost-redux/src/actions/channel_categories.ts b/webapp/channels/src/packages/mattermost-redux/src/actions/channel_categories.ts index 0dbddbd4d6..66230f2ae0 100644 --- a/webapp/channels/src/packages/mattermost-redux/src/actions/channel_categories.ts +++ b/webapp/channels/src/packages/mattermost-redux/src/actions/channel_categories.ts @@ -137,7 +137,7 @@ function updateCategory(category: ChannelCategory) { }; } -export function fetchMyCategories(teamId: string) { +export function fetchMyCategories(teamId: string, isWebSocket: boolean) { return async (dispatch: DispatchFunc, getState: GetStateFunc) => { const currentUserId = getCurrentUserId(getState()); @@ -154,6 +154,7 @@ export function fetchMyCategories(teamId: string) { { type: ChannelCategoryTypes.RECEIVED_CATEGORIES, data: data.categories, + isWebSocket, }, { type: ChannelCategoryTypes.RECEIVED_CATEGORY_ORDER, diff --git a/webapp/channels/src/packages/mattermost-redux/src/reducers/entities/channel_categories.ts b/webapp/channels/src/packages/mattermost-redux/src/reducers/entities/channel_categories.ts index 5afd2f4dae..08425c4d69 100644 --- a/webapp/channels/src/packages/mattermost-redux/src/reducers/entities/channel_categories.ts +++ b/webapp/channels/src/packages/mattermost-redux/src/reducers/entities/channel_categories.ts @@ -23,6 +23,7 @@ export function byId(state: IDMappedObjects = {}, action: Gener [category.id]: { ...nextState[category.id], ...category, + collapsed: action.isWebSocket ? state[category.id].collapsed : category.collapsed, }, }; }, state); diff --git a/webapp/playbooks/src/components/backstage/playbook_editor/playbook_editor.tsx b/webapp/playbooks/src/components/backstage/playbook_editor/playbook_editor.tsx index f486f115e4..4be848a6f0 100644 --- a/webapp/playbooks/src/components/backstage/playbook_editor/playbook_editor.tsx +++ b/webapp/playbooks/src/components/backstage/playbook_editor/playbook_editor.tsx @@ -66,7 +66,7 @@ const PlaybookEditor = () => { dispatch(selectTeam(teamId)); dispatch(fetchMyChannelsAndMembersREST(teamId)); - dispatch(fetchMyCategories(teamId)); + dispatch(fetchMyCategories(teamId, false)); }, [dispatch, playbook?.team_id, playbookId]); useDefaultRedirectOnTeamChange(playbook?.team_id);