From 5758f234e579120bd2cf36158c97dfda7727f01e Mon Sep 17 00:00:00 2001 From: Christopher Speller Date: Wed, 14 Feb 2024 07:46:12 -0800 Subject: [PATCH] Allow plugins to specify all props for create comment. (#26152) * Allow plugins to specificy all props for create comment. * Types --- .../advanced_create_comment.tsx | 1 + .../advanced_create_comment/index.ts | 25 +++++++++++-------- .../src/plugins/exported_create_post.tsx | 15 ++++------- 3 files changed, 20 insertions(+), 21 deletions(-) diff --git a/webapp/channels/src/components/advanced_create_comment/advanced_create_comment.tsx b/webapp/channels/src/components/advanced_create_comment/advanced_create_comment.tsx index 6bd5a5e3c6..4c5b529176 100644 --- a/webapp/channels/src/components/advanced_create_comment/advanced_create_comment.tsx +++ b/webapp/channels/src/components/advanced_create_comment/advanced_create_comment.tsx @@ -182,6 +182,7 @@ export type Props = { searchAssociatedGroupsForReference: (prefix: string, teamId: string, channelId: string | undefined) => Promise; postEditorActions: PluginComponent[]; placeholder?: string; + isPlugin?: boolean; } type State = { diff --git a/webapp/channels/src/components/advanced_create_comment/index.ts b/webapp/channels/src/components/advanced_create_comment/index.ts index c511268260..5ad6e47ddf 100644 --- a/webapp/channels/src/components/advanced_create_comment/index.ts +++ b/webapp/channels/src/components/advanced_create_comment/index.ts @@ -45,6 +45,7 @@ type OwnProps = { rootId: string; channelId: string; latestPostId: string; + isPlugin?: boolean; }; function makeMapStateToProps() { @@ -134,20 +135,22 @@ function makeMapDispatchToProps() { let latestPostId: string; return (dispatch: Dispatch, ownProps: OwnProps) => { - if (rootId !== ownProps.rootId) { - onUpdateCommentDraft = makeOnUpdateCommentDraft(ownProps.rootId, ownProps.channelId); - } + if (!ownProps.isPlugin) { + if (rootId !== ownProps.rootId) { + onUpdateCommentDraft = makeOnUpdateCommentDraft(ownProps.rootId, ownProps.channelId); + } - if (channelId !== ownProps.channelId) { - updateCommentDraftWithRootId = makeUpdateCommentDraftWithRootId(ownProps.channelId); - } + if (channelId !== ownProps.channelId) { + updateCommentDraftWithRootId = makeUpdateCommentDraftWithRootId(ownProps.channelId); + } - if (rootId !== ownProps.rootId) { - onEditLatestPost = makeOnEditLatestPost(ownProps.rootId); - } + if (rootId !== ownProps.rootId) { + onEditLatestPost = makeOnEditLatestPost(ownProps.rootId); + } - if (rootId !== ownProps.rootId || channelId !== ownProps.channelId || latestPostId !== ownProps.latestPostId) { - onSubmit = makeOnSubmit(ownProps.channelId, ownProps.rootId, ownProps.latestPostId); + if (rootId !== ownProps.rootId || channelId !== ownProps.channelId || latestPostId !== ownProps.latestPostId) { + onSubmit = makeOnSubmit(ownProps.channelId, ownProps.rootId, ownProps.latestPostId); + } } rootId = ownProps.rootId; diff --git a/webapp/channels/src/plugins/exported_create_post.tsx b/webapp/channels/src/plugins/exported_create_post.tsx index 4f6a619f90..f16ad2821a 100644 --- a/webapp/channels/src/plugins/exported_create_post.tsx +++ b/webapp/channels/src/plugins/exported_create_post.tsx @@ -4,30 +4,25 @@ import React from 'react'; import AdvancedCreateComment from 'components/advanced_create_comment'; +import type {Props} from 'components/advanced_create_comment/advanced_create_comment'; -import type {PostDraft} from 'types/store/draft'; - -type Props = { - placeholder?: string; - onSubmit: (draft: PostDraft) => void; -} - -const ExportedCreatePost = ({placeholder, onSubmit}: Props) => { +const ExportedCreatePost = (props: Partial) => { const Component = AdvancedCreateComment as any; return ( null} updateCommentDraftWithRootId={() => null} onMoveHistoryIndexBack={() => null} onMoveHistoryIndexForward={() => null} onEditLatestPost={() => ({data: true})} + isPlugin={true} + {...props} /> ); };