From 37f7a7dbd58a654a913dee191348ed6afaa9f26b Mon Sep 17 00:00:00 2001 From: Viduni Wickramarachchi Date: Tue, 5 Nov 2024 17:16:46 -0500 Subject: [PATCH] [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 ? (