-
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
[ResponseOps] Migrate EUI CodeEditor in the triggers actions ui to use the monaco based editor #122734
[ResponseOps] Migrate EUI CodeEditor in the triggers actions ui to use the monaco based editor #122734
Conversation
Pinging @elastic/response-ops (Team:ResponseOps) |
const editor = editorRef.current; | ||
if (!editor) { | ||
return; | ||
} |
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 would the UX be if the monaco reference is lost for some reason?
Will it just render an empty space?
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.
Yea good question, so this is mainly here to appease typescript's null checks (instead of doing reference checks all the time).
In theory this would never be called if editor
reference is unavailable since we maintain the reference as soon as the component mounts. There isn't any way to lose the reference right now.
But yea if somehow we lost a reference, this function would no-op and the contents within the editor would remain unchanged
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.
Fair enough :)
In that case, I think we should throw, so that if an edgecase happens we'll at least show the user some feedback :)
@@ -31,7 +31,8 @@ interface Props { | |||
} | |||
|
|||
const { useXJsonMode } = XJson; | |||
const xJsonMode = new XJsonMode(); | |||
// Source used to insert text imperatively into the code editor | |||
const EDITOR_SOURCE = 'json-editor-with-message-variables'; |
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, this is probably down to me not being familiar with monaco, but what is the impact of this source string?
Does it denote some kind of unique identifier?
What happens if there are multiple monaco editors on the page and they all use this same string?
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.
It's just something to uniquely ID the edit I believe. Multiple editors do no share the same editor reference, so you can use the same source ID
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.
gotcha, I think an improved comment to this effect would help here
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.
Multiple editors do no share the same editor reference, so you can use the same source ID
Cool :)
Lets verify ;) but sound good 👍
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.
I've tried several on the same page and it looks great :)
const editor = editorRef.current; | ||
if (!editor) { | ||
return; | ||
} |
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.
Lets think about what happens if the editor is null here...
We don't want nothing to happen, as that leaves users confused and unable to progress.
An explicit error is preferred as they can report it.
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.
Yea sure I'm open to suggestions, although this is a guard for the initial register call since we're reusing this method in the useEffect
, which will call this method once before we get a reference to the editor.
We could add a console.error/warn, or maybe split it into 2 cases, 1 where the editor exists, another when it doesn't exist, just to be more clear
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.
Yea I wonder if we can show something in the UI in this scenario - some kind of <EuiCallout>
to indicate what the problem and what the user can do about it (I'm not sure if we even know this TBH)
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.
I'd opt for a UX that the user sees so that they know something went wrong and they can report it.
); | ||
}, [onBlur]); | ||
|
||
const unregisterEditorListeners = () => { |
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.
Is there example code somewhere for how to use this new editor? I tried following the issue trail but didn't see much in terms of "this is how you implement it"
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.
there is some precedence for this pattern in the lens plugin formula_editor.tsx
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.
Gotcha, I don't really know how to review this part honestly. It seems okay but is it worth reaching out to folks who know more about the EUI CodeEditor to make sure this is looks right (no edge cases unresolved, no memory leaks, etc)?
💚 Build Succeeded
Metrics [docs]Module Count
Async chunks
Page load bundle
History
To update your PR or re-run it, just comment with: |
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.
Looked over the Code Editor usage and all looked good to me 👍
Resolves #107203
The JSON code editor in the triggers actions UI now uses the monaco based editor.
Checklist