Skip to content

Commit

Permalink
[Obs AI Assistant] Remove the copy button if there is no content to c…
Browse files Browse the repository at this point in the history
  • Loading branch information
viduni94 committed Nov 5, 2024
1 parent 7818ed2 commit 37f7a7d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
5 changes: 2 additions & 3 deletions x-pack/packages/kbn-ai-assistant/src/chat/chat_item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export function ChatItem({
const [editing, setEditing] = useState<boolean>(false);
const [expanded, setExpanded] = useState<boolean>(Boolean(element));

const actions = [canCopy, collapsed, canCopy].filter(Boolean);
const actions = [canCopy, collapsed].filter(Boolean);

const noBodyMessageClassName = css`
${moreCompactHeaderClassName}
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -19,7 +18,6 @@ export function ChatItemActions({
onToggleEdit,
onToggleExpand,
onCopyToClipboard,
content,
}: {
canCopy: boolean;
canEdit: boolean;
Expand All @@ -29,7 +27,6 @@ export function ChatItemActions({
onToggleEdit: () => void;
onToggleExpand: () => void;
onCopyToClipboard: () => void;
content: Message['message']['content'];
}) {
const [isPopoverOpen, setIsPopoverOpen] = useState<string | undefined>();

Expand Down Expand Up @@ -73,7 +70,7 @@ export function ChatItemActions({
/>
) : null}

{canCopy && content ? (
{canCopy ? (
<EuiPopover
button={
<EuiButtonIcon
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ export function getTimelineItemsfromConversation({

switch (role) {
case MessageRole.User:
actions.canCopy = true;
actions.canGiveFeedback = false;
actions.canRegenerate = false;

Expand Down Expand Up @@ -210,11 +209,16 @@ export function getTimelineItemsfromConversation({
display.collapsed = false;
}

if (!content) {
actions.canCopy = false;
} else {
actions.canCopy = true;
}

break;

case MessageRole.Assistant:
actions.canRegenerate = hasConnector;
actions.canCopy = true;
actions.canGiveFeedback = true;
display.hide = false;

Expand Down Expand Up @@ -250,6 +254,13 @@ export function getTimelineItemsfromConversation({
display.collapsed = false;
actions.canEdit = false;
}

if (!content) {
actions.canCopy = false;
} else {
actions.canCopy = true;
}

break;
}

Expand Down

0 comments on commit 37f7a7d

Please sign in to comment.