-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tweaks to prompt editor #174030
Tweaks to prompt editor #174030
Conversation
🤖 GitHub commentsExpand to view the GitHub comments
Just comment with:
|
e4dff55
to
e963efa
Compare
@@ -141,6 +141,8 @@ export function ChatBody({ | |||
: '100%'}; | |||
`; | |||
|
|||
const [isEditing, setIsEditing] = useState(false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what does this signify? I guess it means "editing a single message"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this is a dumb question, but if focus can only be on a single input, why don't we use that to constrain submits?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dgieselaar This allows this behavior (disabling the main editor when editing an existing message):
Screen.Recording.2024-01-02.at.16.48.59.mov
We could not do that. Wdyt?
…when done editing
…to avoid sharing of model between multiple editors
…ana; branch 'main' of github.com:elastic/kibana into bug/inline-prompt-editing
x-pack/plugins/observability_ai_assistant/public/hooks/use_json_editor_model.ts
Outdated
Show resolved
Hide resolved
return () => { | ||
onBlur(); | ||
}; | ||
}, [onBlur]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm this looks a little dangerous in terms of consumers passing a new callback every render?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Its in the return of the useEffect though, so it should only run on unmount, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh right, it just re-creates the unmount hook. I think it's better to use a ref here though, that way we don't call this hook on every render. I'm not too worried about performance, but more so about bugs creeping in and testability.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That was my first thought as well, unfortunately Monaco (or at least Kibana's implementation of it) does not have an onBlur
.
FWIW it also does not have an onFocus
. It only has an editorDidMount
prop, which can be used as an alternative for onFocus
. There is no corresponding editorWillUnmount
though 🤷🏻♂️
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry, I meant onBlurRef = useRef(props.onBlur); onBlurRef.current = props.onBlur;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Turns out the monaco editor instance has a onDidBlurEditorWidget
event.
Implemented with:
editorRef.current?.onDidBlurEditorWidget(() => {
onBlur();
});
x-pack/plugins/observability_ai_assistant/public/hooks/use_json_editor_model.ts
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just nits left
x-pack/plugins/observability_ai_assistant/public/components/chat/chat_body.tsx
Outdated
Show resolved
Hide resolved
x-pack/plugins/observability_ai_assistant/public/components/chat/function_list_popover.tsx
Outdated
Show resolved
Hide resolved
if (innerMessage && !disabled && !invalid && hasFocus) { | ||
if (!event.shiftKey && event.key === keys.ENTER) { | ||
event.preventDefault(); | ||
handleSubmit(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a complicated if, can we simplify? (I don't think we need two if
s anyway?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, the idea was future proofing, allowing easier additional other keyboard commands. First if
checking if it should continue, send the key combination. But if we think no additional kb commands will be added I can consolidate.
return () => { | ||
onBlur(); | ||
}; | ||
}, [onBlur]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh right, it just re-creates the unmount hook. I think it's better to use a ref here though, that way we don't call this hook on every render. I'm not too worried about performance, but more so about bugs creeping in and testability.
💛 Build succeeded, but was flaky
Failed CI StepsTest Failures
Metrics [docs]Async chunks
History
To update your PR or re-run it, just comment with: |
💔 All backports failed
Manual backportTo create the backport manually run:
Questions ?Please refer to the Backport tool documentation |
Friendly reminder: Looks like this PR hasn’t been backported yet. |
## Summary This fixes the following edge case when using the chat interface: * When the main editor has a value in the text area, and the user edits an existing message, and presses `<enter>` on the keyboard, the value that was in the main editor is appended as a new message, instead of editing the existing message. It also does a bit of cleanup (moving of ChatPromptEditor components to `/components/prompt_editor`, and renaming to `PromptEditor`.) ### Additional fixes * [Don't stick to bottom when changing to edit mode, re-stick to bottom when done editing](elastic@e8a01c1) * [Autofocus function popover list search box upon opening](elastic@2329d1c) * [Remove focus trap as it wasn't doing anything anymore](elastic@7fcb4e0) * [Move constants used when creating monaco model inside function scope to avoid sharing of model between multiple editor instances](elastic@c9cab2c) * [Disable submitting function editor when json is not valid](elastic@2a6f1e1)
Friendly reminder: Looks like this PR hasn’t been backported yet. |
💚 All backports created successfully
Note: Successful backport PRs will be merged automatically after passing CI. Questions ?Please refer to the Backport tool documentation |
💚 All backports created successfully
Note: Successful backport PRs will be merged automatically after passing CI. Questions ?Please refer to the Backport tool documentation |
## Summary This fixes the following edge case when using the chat interface: * When the main editor has a value in the text area, and the user edits an existing message, and presses `<enter>` on the keyboard, the value that was in the main editor is appended as a new message, instead of editing the existing message. It also does a bit of cleanup (moving of ChatPromptEditor components to `/components/prompt_editor`, and renaming to `PromptEditor`.) ### Additional fixes * [Don't stick to bottom when changing to edit mode, re-stick to bottom when done editing](elastic@e8a01c1) * [Autofocus function popover list search box upon opening](elastic@2329d1c) * [Remove focus trap as it wasn't doing anything anymore](elastic@7fcb4e0) * [Move constants used when creating monaco model inside function scope to avoid sharing of model between multiple editor instances](elastic@c9cab2c) * [Disable submitting function editor when json is not valid](elastic@2a6f1e1) (cherry picked from commit f4265ca) # Conflicts: # x-pack/plugins/observability_ai_assistant/public/components/prompt_editor/prompt_editor_function.tsx
## Summary This fixes the following edge case when using the chat interface: * When the main editor has a value in the text area, and the user edits an existing message, and presses `<enter>` on the keyboard, the value that was in the main editor is appended as a new message, instead of editing the existing message. It also does a bit of cleanup (moving of ChatPromptEditor components to `/components/prompt_editor`, and renaming to `PromptEditor`.) ### Additional fixes * [Don't stick to bottom when changing to edit mode, re-stick to bottom when done editing](elastic@e8a01c1) * [Autofocus function popover list search box upon opening](elastic@2329d1c) * [Remove focus trap as it wasn't doing anything anymore](elastic@7fcb4e0) * [Move constants used when creating monaco model inside function scope to avoid sharing of model between multiple editor instances](elastic@c9cab2c) * [Disable submitting function editor when json is not valid](elastic@2a6f1e1) (cherry picked from commit f4265ca) # Conflicts: # x-pack/plugins/observability_ai_assistant/public/components/prompt_editor/prompt_editor_function.tsx
# Backport This will backport the following commits from `main` to `8.12`: - [Tweaks to prompt editor (#174030)](#174030) <!--- Backport version: 8.9.8 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT [{"author":{"name":"Coen Warmer","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-01-08T15:59:07Z","message":"Tweaks to prompt editor (#174030)\n\n## Summary\r\n\r\nThis fixes the following edge case when using the chat interface:\r\n\r\n* When the main editor has a value in the text area, and the user edits\r\nan existing message, and presses `<enter>` on the keyboard, the value\r\nthat was in the main editor is appended as a new message, instead of\r\nediting the existing message.\r\n\r\nIt also does a bit of cleanup (moving of ChatPromptEditor components to\r\n`/components/prompt_editor`, and renaming to `PromptEditor`.)\r\n\r\n### Additional fixes\r\n* [Don't stick to bottom when changing to edit mode, re-stick to bottom\r\nwhen done\r\nediting](https://github.com/elastic/kibana/pull/174030/commits/e8a01c1d4ddd449fdf85f0fef11de3d7cc9b2637)\r\n\r\n* [Autofocus function popover list search box upon\r\nopening](https://github.com/elastic/kibana/pull/174030/commits/2329d1c0a791716bf192b5e567c49336853edbd4)\r\n\r\n* [Remove focus trap as it wasn't doing anything\r\nanymore](https://github.com/elastic/kibana/pull/174030/commits/7fcb4e0b775a768c07b79c9c362f030c8f6036cb)\r\n\r\n* [Move constants used when creating monaco model inside function scope\r\nto avoid sharing of model between multiple editor\r\ninstances](https://github.com/elastic/kibana/pull/174030/commits/c9cab2c15566a01f21342dcef66964c13574939d)\r\n\r\n* [Disable submitting function editor when json is not\r\nvalid](https://github.com/elastic/kibana/pull/174030/commits/2a6f1e1cfb2ee5f917ac4862b68aff02813341be)","sha":"f4265ca731be471481518a24794a3664a46774ff","branchLabelMapping":{"^v8.13.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","backport missing","backport:prev-minor","v8.12.0","v8.13.0"],"number":174030,"url":"https://github.com/elastic/kibana/pull/174030","mergeCommit":{"message":"Tweaks to prompt editor (#174030)\n\n## Summary\r\n\r\nThis fixes the following edge case when using the chat interface:\r\n\r\n* When the main editor has a value in the text area, and the user edits\r\nan existing message, and presses `<enter>` on the keyboard, the value\r\nthat was in the main editor is appended as a new message, instead of\r\nediting the existing message.\r\n\r\nIt also does a bit of cleanup (moving of ChatPromptEditor components to\r\n`/components/prompt_editor`, and renaming to `PromptEditor`.)\r\n\r\n### Additional fixes\r\n* [Don't stick to bottom when changing to edit mode, re-stick to bottom\r\nwhen done\r\nediting](https://github.com/elastic/kibana/pull/174030/commits/e8a01c1d4ddd449fdf85f0fef11de3d7cc9b2637)\r\n\r\n* [Autofocus function popover list search box upon\r\nopening](https://github.com/elastic/kibana/pull/174030/commits/2329d1c0a791716bf192b5e567c49336853edbd4)\r\n\r\n* [Remove focus trap as it wasn't doing anything\r\nanymore](https://github.com/elastic/kibana/pull/174030/commits/7fcb4e0b775a768c07b79c9c362f030c8f6036cb)\r\n\r\n* [Move constants used when creating monaco model inside function scope\r\nto avoid sharing of model between multiple editor\r\ninstances](https://github.com/elastic/kibana/pull/174030/commits/c9cab2c15566a01f21342dcef66964c13574939d)\r\n\r\n* [Disable submitting function editor when json is not\r\nvalid](https://github.com/elastic/kibana/pull/174030/commits/2a6f1e1cfb2ee5f917ac4862b68aff02813341be)","sha":"f4265ca731be471481518a24794a3664a46774ff"}},"sourceBranch":"main","suggestedTargetBranches":["8.12"],"targetPullRequestStates":[{"branch":"8.12","label":"v8.12.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.13.0","labelRegex":"^v8.13.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/174030","number":174030,"mergeCommit":{"message":"Tweaks to prompt editor (#174030)\n\n## Summary\r\n\r\nThis fixes the following edge case when using the chat interface:\r\n\r\n* When the main editor has a value in the text area, and the user edits\r\nan existing message, and presses `<enter>` on the keyboard, the value\r\nthat was in the main editor is appended as a new message, instead of\r\nediting the existing message.\r\n\r\nIt also does a bit of cleanup (moving of ChatPromptEditor components to\r\n`/components/prompt_editor`, and renaming to `PromptEditor`.)\r\n\r\n### Additional fixes\r\n* [Don't stick to bottom when changing to edit mode, re-stick to bottom\r\nwhen done\r\nediting](https://github.com/elastic/kibana/pull/174030/commits/e8a01c1d4ddd449fdf85f0fef11de3d7cc9b2637)\r\n\r\n* [Autofocus function popover list search box upon\r\nopening](https://github.com/elastic/kibana/pull/174030/commits/2329d1c0a791716bf192b5e567c49336853edbd4)\r\n\r\n* [Remove focus trap as it wasn't doing anything\r\nanymore](https://github.com/elastic/kibana/pull/174030/commits/7fcb4e0b775a768c07b79c9c362f030c8f6036cb)\r\n\r\n* [Move constants used when creating monaco model inside function scope\r\nto avoid sharing of model between multiple editor\r\ninstances](https://github.com/elastic/kibana/pull/174030/commits/c9cab2c15566a01f21342dcef66964c13574939d)\r\n\r\n* [Disable submitting function editor when json is not\r\nvalid](https://github.com/elastic/kibana/pull/174030/commits/2a6f1e1cfb2ee5f917ac4862b68aff02813341be)","sha":"f4265ca731be471481518a24794a3664a46774ff"}}]}] BACKPORT--> --------- Co-authored-by: kibanamachine <[email protected]>
Summary
This fixes the following edge case when using the chat interface:
<enter>
on the keyboard, the value that was in the main editor is appended as a new message, instead of editing the existing message.It also does a bit of cleanup (moving of ChatPromptEditor components to
/components/prompt_editor
, and renaming toPromptEditor
.)Additional fixes
Don't stick to bottom when changing to edit mode, re-stick to bottom when done editing
Autofocus function popover list search box upon opening
Remove focus trap as it wasn't doing anything anymore
Move constants used when creating monaco model inside function scope to avoid sharing of model between multiple editor instances
Disable submitting function editor when json is not valid