From ce7fdb6c227b151b7ae4ac2eb10cde39da95210e Mon Sep 17 00:00:00 2001 From: Harrison Healey Date: Mon, 7 Oct 2024 16:04:06 -0400 Subject: [PATCH] Removed unused code from actions/views/create_comment.tsx (#28479) * Removed unused code from actions/views/create_comment.tsx * i18n-extract --- .../src/actions/views/create_comment.test.jsx | 70 --------------- .../src/actions/views/create_comment.tsx | 90 ------------------- webapp/channels/src/i18n/en.json | 1 - 3 files changed, 161 deletions(-) diff --git a/webapp/channels/src/actions/views/create_comment.test.jsx b/webapp/channels/src/actions/views/create_comment.test.jsx index 86e2111c6e..c52c1808c6 100644 --- a/webapp/channels/src/actions/views/create_comment.test.jsx +++ b/webapp/channels/src/actions/views/create_comment.test.jsx @@ -9,16 +9,11 @@ import {Posts} from 'mattermost-redux/constants'; import {executeCommand} from 'actions/command'; import * as HookActions from 'actions/hooks'; import * as PostActions from 'actions/post_actions'; -import {setGlobalItem, actionOnGlobalItemsWithPrefix} from 'actions/storage'; import { - clearCommentDraftUploads, - updateCommentDraft, onSubmit, submitPost, submitCommand, - makeOnEditLatestPost, } from 'actions/views/create_comment'; -import {setGlobalDraftSource} from 'actions/views/drafts'; import mockStore from 'tests/test_store'; import {StoragePrefixes} from 'utils/constants'; @@ -183,54 +178,6 @@ describe('rhs view actions', () => { store = mockStore(initialState); }); - describe('clearCommentDraftUploads', () => { - test('it calls actionOnGlobalItemsWithPrefix action correctly', () => { - store.dispatch(clearCommentDraftUploads()); - - const actions = store.getActions(); - - expect(actions.length).toBe(1); - - const callback = actions[0].args[1]; - - // make sure callback is a function which clears uploadsInProgress - expect(typeof callback).toBe('function'); - - const draft = {message: 'test msg', channelId, rootId, uploadsInProgress: [3, 4], fileInfos: [{id: 1}, {id: 2}]}; - - expect(callback(null, draft)).toEqual({...draft, uploadsInProgress: []}); - - const testStore = mockStore(initialState); - - testStore.dispatch(actionOnGlobalItemsWithPrefix(StoragePrefixes.COMMENT_DRAFT, callback)); - - expect(store.getActions()).toEqual(testStore.getActions()); - }); - }); - - describe('updateCommentDraft', () => { - const draft = {message: 'test msg', fileInfos: [{id: 1}], uploadsInProgress: [2, 3]}; - - test('it calls setGlobalItem action correctly', () => { - jest.useFakeTimers(); - jest.setSystemTime(42); - store.dispatch(updateCommentDraft(rootId, draft)); - - const testStore = mockStore(initialState); - - const expectedKey = `${StoragePrefixes.COMMENT_DRAFT}${rootId}`; - testStore.dispatch(setGlobalItem(expectedKey, { - ...draft, - createAt: 42, - updateAt: 42, - })); - testStore.dispatch(setGlobalDraftSource(expectedKey, false)); - - expect(store.getActions()).toEqual(testStore.getActions()); - jest.useRealTimers(); - }); - }); - describe('submitPost', () => { const draft = {message: '', channelId, rootId, fileInfos: []}; @@ -381,21 +328,4 @@ describe('rhs view actions', () => { ); }); }); - - describe('makeOnEditLatestPost', () => { - const onEditLatestPost = makeOnEditLatestPost(rootId); - - test('it dispatches the correct actions', () => { - store.dispatch(onEditLatestPost()); - - expect(store.getActions()).toEqual([ - PostActions.setEditingPost( - latestPostId, - 'reply_textbox', - 'Comment', - true, - ), - ]); - }); - }); }); diff --git a/webapp/channels/src/actions/views/create_comment.tsx b/webapp/channels/src/actions/views/create_comment.tsx index 58cdd557d3..787c4d5bbb 100644 --- a/webapp/channels/src/actions/views/create_comment.tsx +++ b/webapp/channels/src/actions/views/create_comment.tsx @@ -6,7 +6,6 @@ import type {Post} from '@mattermost/types/posts'; import type {CreatePostReturnType, SubmitReactionReturnType} from 'mattermost-redux/actions/posts'; import {addMessageIntoHistory} from 'mattermost-redux/actions/posts'; import {Permissions} from 'mattermost-redux/constants'; -import {createSelector} from 'mattermost-redux/selectors/create_selector'; import {getChannel} from 'mattermost-redux/selectors/entities/channels'; import {getCustomEmojisByName} from 'mattermost-redux/selectors/entities/emojis'; import {getLicense} from 'mattermost-redux/selectors/entities/general'; @@ -14,24 +13,18 @@ import {getAssociatedGroupsForReferenceByMention} from 'mattermost-redux/selecto import { getLatestInteractablePostId, getLatestPostToEdit, - getPost, - makeGetPostIdsForThread, } from 'mattermost-redux/selectors/entities/posts'; import {isCustomGroupsEnabled} from 'mattermost-redux/selectors/entities/preferences'; import {haveIChannelPermission} from 'mattermost-redux/selectors/entities/roles'; import {getCurrentTeamId} from 'mattermost-redux/selectors/entities/teams'; import {getCurrentUserId} from 'mattermost-redux/selectors/entities/users'; import type {ActionFunc, ActionFuncAsync} from 'mattermost-redux/types/actions'; -import {isPostPendingOrFailed} from 'mattermost-redux/utils/post_utils'; import type {ExecuteCommandReturnType} from 'actions/command'; import {executeCommand} from 'actions/command'; import {runMessageWillBePostedHooks, runSlashCommandWillBePostedHooks} from 'actions/hooks'; import * as PostActions from 'actions/post_actions'; -import {actionOnGlobalItemsWithPrefix} from 'actions/storage'; -import {updateDraft} from 'actions/views/drafts'; -import {Constants, StoragePrefixes} from 'utils/constants'; import EmojiMap from 'utils/emoji_map'; import {containsAtChannel, groupsMentionedInText} from 'utils/post_utils'; import * as Utils from 'utils/utils'; @@ -39,23 +32,6 @@ import * as Utils from 'utils/utils'; import type {GlobalState} from 'types/store'; import type {PostDraft} from 'types/store/draft'; -export function clearCommentDraftUploads() { - return actionOnGlobalItemsWithPrefix(StoragePrefixes.COMMENT_DRAFT, (_key: string, draft: PostDraft) => { - if (!draft || !draft.uploadsInProgress || draft.uploadsInProgress.length === 0) { - return draft; - } - - return {...draft, uploadsInProgress: []}; - }); -} - -// Temporarily store draft manually in localStorage since the current version of redux-persist -// we're on will not save the draft quickly enough on page unload. -export function updateCommentDraft(rootId: string, draft?: PostDraft, save = false) { - const key = `${StoragePrefixes.COMMENT_DRAFT}${rootId}`; - return updateDraft(key, draft ?? null, rootId, save); -} - export function submitPost( channelId: string, rootId: string, @@ -192,72 +168,6 @@ export function onSubmit( }; } -function makeGetCurrentUsersLatestReply() { - const getPostIdsInThread = makeGetPostIdsForThread(); - return createSelector( - 'makeGetCurrentUsersLatestReply', - getCurrentUserId, - getPostIdsInThread, - (state) => (id: string) => getPost(state, id), - (_state, rootId) => rootId, - (userId, postIds, getPostById, rootId) => { - let lastPost = null; - - if (!postIds) { - return lastPost; - } - - for (const id of postIds) { - const post = getPostById(id) || {}; - - // don't edit webhook posts, deleted posts, or system messages - if ( - post.user_id !== userId || - (post.props && post.props.from_webhook) || - post.state === Constants.POST_DELETED || - (post.type && post.type.startsWith(Constants.SYSTEM_MESSAGE_PREFIX)) || - isPostPendingOrFailed(post) - ) { - continue; - } - - if (rootId) { - if (post.root_id === rootId || post.id === rootId) { - lastPost = post; - break; - } - } else { - lastPost = post; - break; - } - } - - return lastPost; - }, - ); -} - -export function makeOnEditLatestPost(rootId: string): () => ActionFunc { - const getCurrentUsersLatestPost = makeGetCurrentUsersLatestReply(); - - return () => (dispatch, getState) => { - const state = getState(); - - const lastPost = getCurrentUsersLatestPost(state, rootId); - - if (!lastPost) { - return {data: false}; - } - - return dispatch(PostActions.setEditingPost( - lastPost.id, - 'reply_textbox', - Utils.localizeMessage({id: 'create_comment.commentTitle', defaultMessage: 'Comment'}), - true, - )); - }; -} - export function editLatestPost(channelId: string, rootId = ''): ActionFunc { return (dispatch, getState) => { const state = getState(); diff --git a/webapp/channels/src/i18n/en.json b/webapp/channels/src/i18n/en.json index 0cb42ea4c5..4deab3715f 100644 --- a/webapp/channels/src/i18n/en.json +++ b/webapp/channels/src/i18n/en.json @@ -3350,7 +3350,6 @@ "create_category_modal.create": "Create", "create_category_modal.createCategory": "Create New Category", "create_comment.addComment": "Reply to this thread...", - "create_comment.commentTitle": "Comment", "create_group_memberships_modal.cancel": "No", "create_group_memberships_modal.create": "Yes", "create_group_memberships_modal.desc": "You're about to add or re-add {username} to teams and channels based on their LDAP group membership. You can revert this change at any time.",