Skip to content
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

Merged
merged 3 commits into from
Jan 26, 2022
Merged

[ResponseOps] Migrate EUI CodeEditor in the triggers actions ui to use the monaco based editor #122734

merged 3 commits into from
Jan 26, 2022

Conversation

JiaweiWu
Copy link
Contributor

Resolves #107203

The JSON code editor in the triggers actions UI now uses the monaco based editor.

Screenshot from 2022-01-11 16-51-25

Checklist

@JiaweiWu JiaweiWu added Team:ResponseOps Label for the ResponseOps team (formerly the Cases and Alerting teams) auto-backport Deprecated - use backport:version if exact versions are needed Feature:Alerting/RuleActions Issues related to the Actions attached to Rules on the Alerting Framework v8.1.0 labels Jan 12, 2022
@JiaweiWu JiaweiWu requested a review from gmmorris January 12, 2022 01:19
@elasticmachine
Copy link
Contributor

Pinging @elastic/response-ops (Team:ResponseOps)

@JiaweiWu JiaweiWu added the release_note:skip Skip the PR/issue when compiling release notes label Jan 12, 2022
Comment on lines 54 to 77
const editor = editorRef.current;
if (!editor) {
return;
}
Copy link
Contributor

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?

Copy link
Contributor Author

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

Copy link
Contributor

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';
Copy link
Contributor

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?

Copy link
Contributor Author

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

Copy link
Contributor

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

Copy link
Contributor

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 👍

Copy link
Contributor

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 :)

Comment on lines +79 to +103
const editor = editorRef.current;
if (!editor) {
return;
}
Copy link
Contributor

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.

Copy link
Contributor Author

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

Copy link
Contributor

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)

Copy link
Contributor

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.

@JiaweiWu
Copy link
Contributor Author

Screenshot from 2022-01-17 14-07-34

Screenshot of the new error message

);
}, [onBlur]);

const unregisterEditorListeners = () => {
Copy link
Contributor

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"

Copy link
Contributor Author

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

Copy link
Contributor

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)?

@chrisronline chrisronline requested a review from crob611 January 24, 2022 19:22
@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
triggersActionsUi 333 320 -13

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
triggersActionsUi 782.8KB 674.8KB -107.9KB

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
triggersActionsUi 53.9KB 53.9KB +7.0B
Unknown metric groups

async chunk count

id before after diff
triggersActionsUi 67 66 -1

History

  • 💔 Build #17881 failed acc17fbd56f32bada508dcfce268a1f6b198f80d
  • 💔 Build #17141 failed 0a516ee826b2d7cbfa4616df3e986c3ec2bd7082
  • 💔 Build #16870 failed 25e0e9057e143cc5d9a31d3db5f99fa07259f07d

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@JiaweiWu JiaweiWu added backport:skip This commit does not require backporting and removed auto-backport Deprecated - use backport:version if exact versions are needed labels Jan 26, 2022
Copy link
Contributor

@crob611 crob611 left a 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 👍

@JiaweiWu JiaweiWu merged commit 4d3a792 into elastic:main Jan 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:skip This commit does not require backporting Feature:Alerting/RuleActions Issues related to the Actions attached to Rules on the Alerting Framework release_note:skip Skip the PR/issue when compiling release notes Team:ResponseOps Label for the ResponseOps team (formerly the Cases and Alerting teams) v8.1.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Migrate actions JSON editor to use the monaco-based editor
6 participants