MM-40566 Remove collapse from websocket sync (#22607)

* Web App -> Monorepo

* Fix Lint issues

* Fix Type issue

* Update webapp/playbooks/src/components/backstage/playbook_editor/playbook_editor.tsx

Co-authored-by: Harrison Healey <harrisonmhealey@gmail.com>

---------

Co-authored-by: Mattermost Build <build@mattermost.com>
Co-authored-by: Harrison Healey <harrisonmhealey@gmail.com>
This commit is contained in:
Safouen Turki
2023-05-10 15:00:34 +01:00
committed by GitHub
parent a3e4ea2e7a
commit 070ee26081
5 changed files with 88 additions and 3 deletions

View File

@@ -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));
};
}

View File

@@ -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', () => {

View File

@@ -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,

View File

@@ -23,6 +23,7 @@ export function byId(state: IDMappedObjects<ChannelCategory> = {}, action: Gener
[category.id]: {
...nextState[category.id],
...category,
collapsed: action.isWebSocket ? state[category.id].collapsed : category.collapsed,
},
};
}, state);

View File

@@ -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);