Skip to content

Commit

Permalink
[8.x] [Obs AI Assistant] Remove the copy button if there is no conten…
Browse files Browse the repository at this point in the history
…t to copy (#199064) (#199874)

# Backport

This will backport the following commits from `main` to `8.x`:
- [[Obs AI Assistant] Remove the copy button if there is no content to
copy (#199064)](#199064)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Viduni
Wickramarachchi","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-11-12T19:41:47Z","message":"[Obs
AI Assistant] Remove the copy button if there is no content to copy
(#199064)\n\nCloses
https://github.com/elastic/kibana/issues/196986\r\n\r\n##
Summary\r\n\r\n### Problem\r\nThe copy button for a visualization does
nothing, as there's no content\r\nto copy. When clicked on this button,
a message is shown saying \"Copied\r\nMessage\", but nothing is
copied.\r\n\r\n### Solution\r\nRemove the copy button, when there's no
content to copy.\r\n\r\n### Checklist\r\n\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common
scenarios","sha":"a613277a549a1be8643446bdf65517313a0c1e00","branchLabelMapping":{"^v9.0.0$":"main","^v8.17.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix","v9.0.0","Team:Obs
AI Assistant","backport:version","v8.17.0"],"title":"[Obs AI Assistant]
Remove the copy button if there is no content to
copy","number":199064,"url":"https://github.com/elastic/kibana/pull/199064","mergeCommit":{"message":"[Obs
AI Assistant] Remove the copy button if there is no content to copy
(#199064)\n\nCloses
https://github.com/elastic/kibana/issues/196986\r\n\r\n##
Summary\r\n\r\n### Problem\r\nThe copy button for a visualization does
nothing, as there's no content\r\nto copy. When clicked on this button,
a message is shown saying \"Copied\r\nMessage\", but nothing is
copied.\r\n\r\n### Solution\r\nRemove the copy button, when there's no
content to copy.\r\n\r\n### Checklist\r\n\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common
scenarios","sha":"a613277a549a1be8643446bdf65517313a0c1e00"}},"sourceBranch":"main","suggestedTargetBranches":["8.x"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/199064","number":199064,"mergeCommit":{"message":"[Obs
AI Assistant] Remove the copy button if there is no content to copy
(#199064)\n\nCloses
https://github.com/elastic/kibana/issues/196986\r\n\r\n##
Summary\r\n\r\n### Problem\r\nThe copy button for a visualization does
nothing, as there's no content\r\nto copy. When clicked on this button,
a message is shown saying \"Copied\r\nMessage\", but nothing is
copied.\r\n\r\n### Solution\r\nRemove the copy button, when there's no
content to copy.\r\n\r\n### Checklist\r\n\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common
scenarios","sha":"a613277a549a1be8643446bdf65517313a0c1e00"}},{"branch":"8.x","label":"v8.17.0","branchLabelMappingKey":"^v8.17.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Viduni Wickramarachchi <[email protected]>
  • Loading branch information
kibanamachine and viduni94 authored Nov 12, 2024
1 parent 00a829c commit c938f31
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 c938f31

Please sign in to comment.