mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
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:
@@ -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));
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -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', () => {
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user