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
…opy (elastic#199064)

Closes elastic#196986

## Summary

### Problem
The copy button for a visualization does nothing, as there's no content
to copy. When clicked on this button, a message is shown saying "Copied
Message", but nothing is copied.

### Solution
Remove the copy button, when there's no content to copy.

### Checklist

- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
  • Loading branch information
viduni94 authored and CAWilson94 committed Nov 18, 2024
1 parent 6ff42d7 commit 24dcdc0
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
4 changes: 2 additions & 2 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 @@ -182,7 +182,7 @@ export function ChatItem({
/>
}
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 @@ -247,7 +247,7 @@ describe('getTimelineItemsFromConversation', () => {

expect(pick(items[3], 'actions', 'display')).toEqual({
actions: {
canCopy: true,
canCopy: false,
canEdit: false,
canGiveFeedback: false,
canRegenerate: false,
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 24dcdc0

Please sign in to comment.