From 1be9dbe5fed409eb1f3dc3e45c1f84b981c9aa9c Mon Sep 17 00:00:00 2001 From: Viduni Wickramarachchi Date: Tue, 5 Nov 2024 16:38:31 -0500 Subject: [PATCH 1/3] [Obs AI Assistant] Remove the copy button if there is no content to copy (#196986) --- x-pack/packages/kbn-ai-assistant/src/chat/chat_item.tsx | 1 + .../packages/kbn-ai-assistant/src/chat/chat_item_actions.tsx | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/x-pack/packages/kbn-ai-assistant/src/chat/chat_item.tsx b/x-pack/packages/kbn-ai-assistant/src/chat/chat_item.tsx index 23bdbdaea3593..009d4ee15db95 100644 --- a/x-pack/packages/kbn-ai-assistant/src/chat/chat_item.tsx +++ b/x-pack/packages/kbn-ai-assistant/src/chat/chat_item.tsx @@ -179,6 +179,7 @@ export function ChatItem({ onCopyToClipboard={handleCopyToClipboard} onToggleEdit={handleToggleEdit} onToggleExpand={handleToggleExpand} + content={content} /> } className={ diff --git a/x-pack/packages/kbn-ai-assistant/src/chat/chat_item_actions.tsx b/x-pack/packages/kbn-ai-assistant/src/chat/chat_item_actions.tsx index cb1196baa6bc1..958c2faacee22 100644 --- a/x-pack/packages/kbn-ai-assistant/src/chat/chat_item_actions.tsx +++ b/x-pack/packages/kbn-ai-assistant/src/chat/chat_item_actions.tsx @@ -8,6 +8,7 @@ import React, { useEffect, useState } from 'react'; import { i18n } from '@kbn/i18n'; import { EuiButtonIcon, EuiPopover, EuiText } from '@elastic/eui'; +import type { Message } from '@kbn/observability-ai-assistant-plugin/common'; export function ChatItemActions({ canCopy, @@ -18,6 +19,7 @@ export function ChatItemActions({ onToggleEdit, onToggleExpand, onCopyToClipboard, + content, }: { canCopy: boolean; canEdit: boolean; @@ -27,6 +29,7 @@ export function ChatItemActions({ onToggleEdit: () => void; onToggleExpand: () => void; onCopyToClipboard: () => void; + content: Message['message']['content']; }) { const [isPopoverOpen, setIsPopoverOpen] = useState(); @@ -70,7 +73,7 @@ export function ChatItemActions({ /> ) : null} - {canCopy ? ( + {canCopy && content ? ( Date: Tue, 5 Nov 2024 17:16:46 -0500 Subject: [PATCH 2/3] [Obs AI Assistant] Remove the copy button if there is no content to copy (#196986) --- .../kbn-ai-assistant/src/chat/chat_item.tsx | 5 ++--- .../src/chat/chat_item_actions.tsx | 5 +---- .../get_timeline_items_from_conversation.tsx | 15 +++++++++++++-- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/x-pack/packages/kbn-ai-assistant/src/chat/chat_item.tsx b/x-pack/packages/kbn-ai-assistant/src/chat/chat_item.tsx index 009d4ee15db95..fac7c77570673 100644 --- a/x-pack/packages/kbn-ai-assistant/src/chat/chat_item.tsx +++ b/x-pack/packages/kbn-ai-assistant/src/chat/chat_item.tsx @@ -99,7 +99,7 @@ export function ChatItem({ const [editing, setEditing] = useState(false); const [expanded, setExpanded] = useState(Boolean(element)); - const actions = [canCopy, collapsed, canCopy].filter(Boolean); + const actions = [canCopy, collapsed].filter(Boolean); const noBodyMessageClassName = css` ${moreCompactHeaderClassName} @@ -179,11 +179,10 @@ export function ChatItem({ onCopyToClipboard={handleCopyToClipboard} onToggleEdit={handleToggleEdit} onToggleExpand={handleToggleExpand} - content={content} /> } className={ - actions.length === 0 && !content + actions.length === 0 && !content && !element ? noPanelMessageClassName : collapsed ? noBodyMessageClassName diff --git a/x-pack/packages/kbn-ai-assistant/src/chat/chat_item_actions.tsx b/x-pack/packages/kbn-ai-assistant/src/chat/chat_item_actions.tsx index 958c2faacee22..cb1196baa6bc1 100644 --- a/x-pack/packages/kbn-ai-assistant/src/chat/chat_item_actions.tsx +++ b/x-pack/packages/kbn-ai-assistant/src/chat/chat_item_actions.tsx @@ -8,7 +8,6 @@ import React, { useEffect, useState } from 'react'; import { i18n } from '@kbn/i18n'; import { EuiButtonIcon, EuiPopover, EuiText } from '@elastic/eui'; -import type { Message } from '@kbn/observability-ai-assistant-plugin/common'; export function ChatItemActions({ canCopy, @@ -19,7 +18,6 @@ export function ChatItemActions({ onToggleEdit, onToggleExpand, onCopyToClipboard, - content, }: { canCopy: boolean; canEdit: boolean; @@ -29,7 +27,6 @@ export function ChatItemActions({ onToggleEdit: () => void; onToggleExpand: () => void; onCopyToClipboard: () => void; - content: Message['message']['content']; }) { const [isPopoverOpen, setIsPopoverOpen] = useState(); @@ -73,7 +70,7 @@ export function ChatItemActions({ /> ) : null} - {canCopy && content ? ( + {canCopy ? ( Date: Tue, 5 Nov 2024 17:18:33 -0500 Subject: [PATCH 3/3] [Obs AI Assistant] Update test (#196986) --- .../src/utils/get_timeline_items_from_conversation.test.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/packages/kbn-ai-assistant/src/utils/get_timeline_items_from_conversation.test.tsx b/x-pack/packages/kbn-ai-assistant/src/utils/get_timeline_items_from_conversation.test.tsx index 6a304430103ab..7dcf9cadb6bbf 100644 --- a/x-pack/packages/kbn-ai-assistant/src/utils/get_timeline_items_from_conversation.test.tsx +++ b/x-pack/packages/kbn-ai-assistant/src/utils/get_timeline_items_from_conversation.test.tsx @@ -247,7 +247,7 @@ describe('getTimelineItemsFromConversation', () => { expect(pick(items[3], 'actions', 'display')).toEqual({ actions: { - canCopy: true, + canCopy: false, canEdit: false, canGiveFeedback: false, canRegenerate: false,