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

Add EuiCodeEditor to ES UI Shared. #108318

Merged
merged 9 commits into from
Aug 13, 2021

Conversation

cjcenizal
Copy link
Contributor

@cjcenizal cjcenizal commented Aug 12, 2021

This PR transplants the EuiCodeEditor component from EUI to the es_ui_shared plugin. This is a stopgap solution for removal of this component from EUI before we get to #107215.

Developers can consume this component by importing it:

import { EuiCodeEditor } from '<path>/src/plugins/es_ui_shared/public';

I suggest creating a file called shared_imports.ts in the root of your plugin's public directory and re-exporting it there, for consumption by your plugin.

This PR also:

  • Converts src/plugins/es_ui_shared/public/components/json_editor/json_editor.tsx to consume this transplanted EuiCodeEditor. JsonEditor is consumed by Index Management and Ingest Node Pipelines.
  • Converts the Grok Debugger plugin to consume this component.

Lazy-loading

This component is lazy-loaded to prevent it from bloating the EsUiShared plugin bundle. Here's how it appears when the network has been throttled to simulate a "Slow 3G" connection.

lazy_load_code_editor

Steps to test

This is a drop-in replacement for EuiCodeEditor since it's identical code. Testers can interact with Grok Debugger and the JSON editor in the Ingest Node Pipelines "Load from JSON" modal to verify that this change hasn't broken anything.

@cjcenizal cjcenizal added the Team:Kibana Management Dev Tools, Index Management, Upgrade Assistant, ILM, Ingest Node Pipelines, and more label Aug 12, 2021
@cjcenizal cjcenizal changed the title [skip-ci] Add EuiCodeEditor to ES UI Shared. Add EuiCodeEditor to ES UI Shared. Aug 12, 2021
@cjcenizal cjcenizal marked this pull request as ready for review August 12, 2021 15:25
@cjcenizal cjcenizal requested review from a team as code owners August 12, 2021 15:25
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-stack-management (Team:Stack Management)

@cjcenizal cjcenizal added chore v7.15.0 v8.0.0 release_note:skip Skip the PR/issue when compiling release notes labels Aug 12, 2021
@@ -336,7 +336,7 @@
"re-resizable": "^6.1.1",
"re2": "^1.15.4",
"react": "^16.12.0",
"react-ace": "^5.9.0",
"react-ace": "^7.0.5",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@timroes Any suggestions on the best way to verify this hasn't broken anything?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we have any better way besides manually testing a couple of places we use the editor. I'd suggest looking into at least one read only case, one write case, and advanced settings (which I think is the only place using dynamic heights on EuiCodeEditor).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Tim! Tested Advanced Settings to cover both the write and dynamic heights use cases, and tested the Rollup Jobs JSON tab for the read-only case. All seems to behave as expected.


// TODO: Fix this. document.activeElement resolves to be <body />, but the component behaves
// as expected in the browser.
test.skip('pressing escape in ace textbox will enable overlay', () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chandlerprall Do you or anyone on the EUI team have any suggestions as to why this test might be failing?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kibana's version of jsdom (16.4.0) is newer than EUI's version (11.12.0), and the newer one is preventing the call to .focus() from doing work because of this additional check: https://github.com/jsdom/jsdom/blob/16.4.0/lib/jsdom/living/helpers/focusing.js#L25-L27

    if (!elImpl.isConnected) {
      return false;
    }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! This helped a ton.

@cjcenizal
Copy link
Contributor Author

@elasticmachine merge upstream

Copy link
Contributor

@yuliacech yuliacech left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @cjcenizal,
thank you so much for creating this workaround!
I tested locally the 3 apps: Ingest pipelines, Index Management and Grok debugger and haven't noticed any regressions. Do we need to migrate the rest of the apps listed in #107215?
For the mocks in the test files, I think maybe a global mock file in es_ui_shared that can be imported everywhere could work better. Similar to a mock file in ILM that is being imported when needed. But I don't want to block on it.

@cjcenizal
Copy link
Contributor Author

cjcenizal commented Aug 13, 2021

Thanks for your review @yuliacech! I will migrate the rest of our apps in a separate PR. I like your suggestion of a global mock file and I think it's worth implementing. The challenge is that some of the mocks are subtly different than others, but I'll see if I can reconcile their differences.

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
esUiShared 155 183 +28
grokdebugger 75 76 +1
total +29

Async chunks

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

id before after diff
esUiShared 0.0B 557.9KB ⚠️ +557.9KB
grokdebugger 531.9KB 531.8KB -39.0B
total +557.8KB

Page load bundle

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

id before after diff
esUiShared 192.5KB 195.6KB +3.2KB
grokdebugger 7.5KB 7.7KB +237.0B
kbnUiSharedDeps-elastic 2.6MB 2.6MB -21.6KB
kbnUiSharedDeps-js 6.5MB 6.5MB +21.6KB
total +3.4KB
Unknown metric groups

API count

id before after diff
esUiShared 92 106 +14

API count missing comments

id before after diff
esUiShared 90 102 +12

async chunk count

id before after diff
esUiShared 0 1 +1

History

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

@cjcenizal cjcenizal merged commit bfea4a1 into elastic:master Aug 13, 2021
@cjcenizal cjcenizal deleted the es-ui-shared/code-editor branch August 13, 2021 23:50
cjcenizal added a commit to cjcenizal/kibana that referenced this pull request Aug 13, 2021
* Export EuiCodeEditor from es_ui_shared and consume it in Grok Debugger. Remove warning from EuiCodeEditor.
* Lazy-load code editor so it doesn't bloat the EsUiShared plugin bundle.
* Refactor mocks into a shared jest_mock.tsx file.
cjcenizal added a commit that referenced this pull request Aug 14, 2021
* Export EuiCodeEditor from es_ui_shared and consume it in Grok Debugger. Remove warning from EuiCodeEditor.
* Lazy-load code editor so it doesn't bloat the EsUiShared plugin bundle.
* Refactor mocks into a shared jest_mock.tsx file.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chore release_note:skip Skip the PR/issue when compiling release notes Team:Kibana Management Dev Tools, Index Management, Upgrade Assistant, ILM, Ingest Node Pipelines, and more v7.15.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants