From f8e8eca9854671b2990665d314506131e426bacd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Espino?= Date: Tue, 24 Oct 2023 10:35:20 +0200 Subject: [PATCH] Expose components needed for the ai plugin new interface (#24972) * Export thread components * Exporting AdvancedCreateComment * Expose components needed for the ai plugin new interface * Exporting the placeholder for the plugin CreatePost component, and simplify the export * Fixing linter errors * Fixing type errors * Reverting typescript related changes * Cheating typescript to keep the changes as minimal as possible * Fix linter errors --- .../advanced_create_comment.tsx | 2 ++ .../advanced_text_editor.tsx | 6 +++- .../threading/thread_viewer/thread_viewer.tsx | 2 ++ .../create_comment.tsx | 3 ++ .../virtualized_thread_viewer.tsx | 2 ++ webapp/channels/src/plugins/export.js | 4 +++ .../src/plugins/exported_create_post.tsx | 35 +++++++++++++++++++ 7 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 webapp/channels/src/plugins/exported_create_post.tsx 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 c8cc8bf8f2..bdf16ef47f 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 @@ -198,6 +198,7 @@ export type Props = { isFormattingBarHidden: boolean; searchAssociatedGroupsForReference: (prefix: string, teamId: string, channelId: string | undefined) => Promise<{ data: any }>; postEditorActions: PluginComponent[]; + placeholder?: string; } type State = { @@ -1311,6 +1312,7 @@ class AdvancedCreateComment extends React.PureComponent { fileUploadRef={this.fileUploadRef} isThreadView={this.props.isThreadView} additionalControls={pluginItems.filter(Boolean)} + placeholder={this.props.placeholder} /> ); diff --git a/webapp/channels/src/components/advanced_text_editor/advanced_text_editor.tsx b/webapp/channels/src/components/advanced_text_editor/advanced_text_editor.tsx index 439fb2e4e4..34d226038b 100644 --- a/webapp/channels/src/components/advanced_text_editor/advanced_text_editor.tsx +++ b/webapp/channels/src/components/advanced_text_editor/advanced_text_editor.tsx @@ -101,6 +101,7 @@ type Props = { additionalControls?: React.ReactNodeArray; labels?: React.ReactNode; disableSend?: boolean; + placeholder?: string; } const AdvanceTextEditor = ({ @@ -156,6 +157,7 @@ const AdvanceTextEditor = ({ additionalControls, labels, disableSend = false, + placeholder, }: Props) => { const readOnlyChannel = !canPost; const {formatMessage} = useIntl(); @@ -295,7 +297,9 @@ const AdvanceTextEditor = ({ ); let createMessage; - if (currentChannel && !readOnlyChannel) { + if (placeholder) { + createMessage = placeholder; + } else if (currentChannel && !readOnlyChannel) { createMessage = formatMessage( { id: 'create_post.write', diff --git a/webapp/channels/src/components/threading/thread_viewer/thread_viewer.tsx b/webapp/channels/src/components/threading/thread_viewer/thread_viewer.tsx index 53b16ed20d..bca19f239a 100644 --- a/webapp/channels/src/components/threading/thread_viewer/thread_viewer.tsx +++ b/webapp/channels/src/components/threading/thread_viewer/thread_viewer.tsx @@ -48,6 +48,7 @@ export type Props = Attrs & { highlightedPostId?: Post['id']; selectedPostFocusedAt?: number; isThreadView?: boolean; + inputPlaceholder?: string; }; type State = { @@ -212,6 +213,7 @@ export default class ThreadViewer extends React.PureComponent { {this.props.selected && ( (({ @@ -34,6 +35,7 @@ const CreateComment = forwardRef(({ threadId, latestPostId, isThreadView, + placeholder, }: Props, ref) => { const getChannel = useMemo(makeGetChannel, []); const rootPost = useSelector((state: GlobalState) => getPost(state, threadId)); @@ -95,6 +97,7 @@ const CreateComment = forwardRef(({ data-testid='comment-create' > { if (isCreateComment(itemId)) { return ( void; +} + +const ExportedCreatePost = ({placeholder, onSubmit}: Props) => { + const Component = AdvancedCreateComment as any; + + return ( + null} + updateCommentDraftWithRootId={() => null} + onMoveHistoryIndexBack={() => null} + onMoveHistoryIndexForward={() => null} + onEditLatestPost={() => ({data: true})} + /> + ); +}; + +export default ExportedCreatePost;