From 39d0748a5b5a596f1f0486182ca9c7dcf3a12666 Mon Sep 17 00:00:00 2001 From: Nithin David Thomas <1277421+nithindavid@users.noreply.github.com> Date: Sat, 4 Nov 2023 15:27:25 +0530 Subject: [PATCH] feat: Lets users insert connected portal article into replies [CW-2282] (#8117) - Lets users insert connected portal articles into replies https://linear.app/chatwoot/issue/CW-2282/list-all-the-top-articles-from-the-connected-help-center https://linear.app/chatwoot/issue/CW-1453/container-view-for-showing-search-input-and-result-items --- .../widgets/WootWriter/ReplyBottomPanel.vue | 24 +++ .../widgets/conversation/ReplyBox.vue | 53 +++++- app/javascript/dashboard/featureFlags.js | 1 + .../i18n/locale/en/conversation.json | 1 + .../dashboard/i18n/locale/en/helpCenter.json | 18 ++ .../ArticleSearch/ArticleSearchResultItem.vue | 54 +++--- .../components/ArticleSearch/ArticleView.vue | 14 +- .../components/ArticleSearch/Header.vue | 30 +++- .../ArticleSearch/SearchPopover.vue | 169 ++++++++++++++++++ .../ArticleSearch/SearchResults.vue | 11 +- .../FluentIcon/dashboard-icons.json | 1 + .../shared/components/IframeLoader.vue | 2 +- app/javascript/shared/constants/busEvents.js | 1 + config/features.yml | 2 + 14 files changed, 327 insertions(+), 54 deletions(-) create mode 100644 app/javascript/dashboard/routes/dashboard/helpcenter/components/ArticleSearch/SearchPopover.vue diff --git a/app/javascript/dashboard/components/widgets/WootWriter/ReplyBottomPanel.vue b/app/javascript/dashboard/components/widgets/WootWriter/ReplyBottomPanel.vue index 8477accc2..77355977f 100644 --- a/app/javascript/dashboard/components/widgets/WootWriter/ReplyBottomPanel.vue +++ b/app/javascript/dashboard/components/widgets/WootWriter/ReplyBottomPanel.vue @@ -109,6 +109,16 @@ +
diff --git a/app/javascript/dashboard/components/widgets/conversation/ReplyBox.vue b/app/javascript/dashboard/components/widgets/conversation/ReplyBox.vue index d72c8dff6..da47bd556 100644 --- a/app/javascript/dashboard/components/widgets/conversation/ReplyBox.vue +++ b/app/javascript/dashboard/components/widgets/conversation/ReplyBox.vue @@ -18,6 +18,12 @@ :popout-reply-box="popoutReplyBox" @click="$emit('click')" /> +
line.trim() !== ''); + const filteredMarkdown = nonEmptyLines.join(' '); + bus.$emit( + BUS_EVENTS.INSERT_INTO_RICH_EDITOR, + `[${filteredMarkdown}](${url})` + ); + } else { + this.addIntoEditor( + `${this.$t('CONVERSATION.REPLYBOX.INSERT_READ_MORE')} ${url}` + ); + } + }, toggleRichContentEditor() { this.updateUISettings({ display_rich_content_editor: !this.showRichContentEditor, @@ -862,22 +895,22 @@ export default { clearEditorSelection() { this.updateEditorSelectionWith = ''; }, - insertEmoji(emoji, selectionStart, selectionEnd) { + insertIntoTextEditor(text, selectionStart, selectionEnd) { const { message } = this; const newMessage = message.slice(0, selectionStart) + - emoji + + text + message.slice(selectionEnd, message.length); this.message = newMessage; }, - emojiOnClick(emoji) { + addIntoEditor(content) { if (this.showRichContentEditor) { - this.updateEditorSelectionWith = emoji; + this.updateEditorSelectionWith = content; this.onFocus(); } if (!this.showRichContentEditor) { const { selectionStart, selectionEnd } = this.$refs.messageInput.$el; - this.insertEmoji(emoji, selectionStart, selectionEnd); + this.insertIntoTextEditor(content, selectionStart, selectionEnd); } }, clearMessage() { @@ -1136,6 +1169,12 @@ export default { // When new conversation modal is open this.newConversationModalActive = isActive; }, + onSearchPopoverClose() { + this.showArticleSearchPopover = false; + }, + toggleInsertArticle() { + this.showArticleSearchPopover = !this.showArticleSearchPopover; + }, }, }; @@ -1154,7 +1193,7 @@ export default { } .reply-box { - @apply border-t border-slate-50 dark:border-slate-700 bg-white dark:bg-slate-900; + @apply relative border-t border-slate-50 dark:border-slate-700 bg-white dark:bg-slate-900; &.is-private { @apply bg-yellow-50 dark:bg-yellow-200; diff --git a/app/javascript/dashboard/featureFlags.js b/app/javascript/dashboard/featureFlags.js index 0da932e30..143ee521d 100644 --- a/app/javascript/dashboard/featureFlags.js +++ b/app/javascript/dashboard/featureFlags.js @@ -17,4 +17,5 @@ export const FEATURE_FLAGS = { VOICE_RECORDER: 'voice_recorder', AUDIT_LOGS: 'audit_logs', MESSAGE_REPLY_TO: 'message_reply_to', + INSERT_ARTICLE_IN_REPLY: 'insert_article_in_reply', }; diff --git a/app/javascript/dashboard/i18n/locale/en/conversation.json b/app/javascript/dashboard/i18n/locale/en/conversation.json index 65b55b732..19012abed 100644 --- a/app/javascript/dashboard/i18n/locale/en/conversation.json +++ b/app/javascript/dashboard/i18n/locale/en/conversation.json @@ -139,6 +139,7 @@ "PRIVATE_NOTE": "Private Note", "SEND": "Send", "CREATE": "Add Note", + "INSERT_READ_MORE": "Read more", "DISMISS_REPLY": "Dismiss reply", "REPLYING_TO": "Replying to:", "TIP_FORMAT_ICON": "Show rich text editor", diff --git a/app/javascript/dashboard/i18n/locale/en/helpCenter.json b/app/javascript/dashboard/i18n/locale/en/helpCenter.json index af692a27e..43b419328 100644 --- a/app/javascript/dashboard/i18n/locale/en/helpCenter.json +++ b/app/javascript/dashboard/i18n/locale/en/helpCenter.json @@ -76,6 +76,9 @@ }, "ARTICLE_SEARCH_RESULT": { "UNCATEGORIZED": "Uncategorized", + "SEARCH_RESULTS": "Search results for %{query}", + "EMPTY_TEXT": "Search for articles to insert into replies.", + "SEARCH_LOADER": "Searching...", "INSERT_ARTICLE": "Insert", "NO_RESULT": "No articles found", "COPY_LINK": "Copy article link to clipboard", @@ -426,6 +429,21 @@ } } }, + "ARTICLE_SEARCH": { + "TITLE": "Search articles", + "PLACEHOLDER": "Search articles", + "NO_RESULT": "No articles found", + "SEARCHING": "Searching...", + "SEARCH_BUTTON": "Search", + "INSERT_ARTICLE": "Insert link", + "IFRAME_ERROR": "URL is empty or invalid. Unable to display content.", + "OPEN_ARTICLE_SEARCH": "Insert article from Help Center", + "SUCCESS_ARTICLE_INSERTED": "Article inserted successfully", + "PREVIEW_LINK": "Preview article", + "CANCEL": "Close", + "BACK": "Back", + "BACK_RESULTS": "Back to results" + }, "UPGRADE_PAGE": { "TITLE": "Help Center", "DESCRIPTION": "Create user-friendly self-service portals. Help your users to access the articles and get support 24/7. Upgrade your subscription to enable this feature.", diff --git a/app/javascript/dashboard/routes/dashboard/helpcenter/components/ArticleSearch/ArticleSearchResultItem.vue b/app/javascript/dashboard/routes/dashboard/helpcenter/components/ArticleSearch/ArticleSearchResultItem.vue index 728a2886d..e603ec917 100644 --- a/app/javascript/dashboard/routes/dashboard/helpcenter/components/ArticleSearch/ArticleSearchResultItem.vue +++ b/app/javascript/dashboard/routes/dashboard/helpcenter/components/ArticleSearch/ArticleSearchResultItem.vue @@ -1,17 +1,18 @@ diff --git a/app/javascript/dashboard/routes/dashboard/helpcenter/components/ArticleSearch/SearchPopover.vue b/app/javascript/dashboard/routes/dashboard/helpcenter/components/ArticleSearch/SearchPopover.vue new file mode 100644 index 000000000..1c221d3be --- /dev/null +++ b/app/javascript/dashboard/routes/dashboard/helpcenter/components/ArticleSearch/SearchPopover.vue @@ -0,0 +1,169 @@ + + + diff --git a/app/javascript/dashboard/routes/dashboard/helpcenter/components/ArticleSearch/SearchResults.vue b/app/javascript/dashboard/routes/dashboard/helpcenter/components/ArticleSearch/SearchResults.vue index 343d6108e..4a6eb5b8b 100644 --- a/app/javascript/dashboard/routes/dashboard/helpcenter/components/ArticleSearch/SearchResults.vue +++ b/app/javascript/dashboard/routes/dashboard/helpcenter/components/ArticleSearch/SearchResults.vue @@ -1,8 +1,9 @@