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

[Console] Move out of quarantined #52270

Merged
merged 22 commits into from Dec 10, 2019

Conversation

jloleysens
Copy link
Contributor

@jloleysens jloleysens commented Dec 5, 2019

Summary

This is a continuation (and completion) of a refactor to the public code in Console started with #43346.

Primary objectives

  1. Move all code out of public/quarantined. This entails reviewing and ensuring that we minimise/demarcate direct usage of brace. We are not planning on switching to Monaco in the immediate future, but this contribution should help a lot with any such future effort.
  2. Finish the CoreEditor interface and implement the new SenseEditor model which uses it.
  3. Leave no test behind! We want to bring along all of our existing test coverage.

Overview of public/np_ready directory structure (and architecture):

  1. application should contain all application relevant logic
    1. models: contain business logic for our special console language (legacy_core_editor) and knowledge of requests (sense_editor).
      1. legacy_core_editor should contain all wiring up of brace
    2. containers: all UI components that interact with context
    3. components: all pure/function UI components
    4. contexts: contain the mechanism for how we share our flux-like stores ([Console] Refactoring more legacy code and implementing minor fixes #51312)
    5. stores: contain the logic for how state can change and the shape of state slices
    6. hooks: contain all actions that can affect state changes and don't directly speak to rendering UI
  2. lib
    1. Logic which is self-contained and only interacts with our contracts defined in types should live here (e.g., ace_token_provider) surfaces an implementation of TokenProvider without leaking Ace interfaces.
  3. types - folder can be renamed, but named is types to follow conventions in ES UI management apps. This houses only types + interfaces, no real values.

How to review

  • A lot of changes are just implementing use of the new CoreEditor and SenseEditor interfaces. They contain new logic and will benefit from having their interfaces reviewed!
  • After moving from row -> lineNumber for our position interfaces there is risk of "off-by-one" regressions. These will probably be very hard to spot, but manual and automated testing has caught a large number of these - but still keep an eye out for them!
  • I don't expect there is much scope for making a lot of changes to architecture of the application here, it's not that complex, but if there is anything weird please point it out!
  • Manually test!
    • Start Kibana and open Console
    • Open History (interact with it)
    • Adjust settings
    • Send requests, send multi-doc requests

Other goodies

Some fixes were made as part of this PR:

  1. Off by one issue in RowParser.ts's getRowParseMode which had an off-by-one regression (example of fix: if (lineNumber < linesCount + 1)...)
  2. sense_editor.test.js had an issue where tests where not correctly reporting failure 🤦‍♂
  3. Fix for restoring a request by double-clicking: onDoubleClick inside of console_history container

@jloleysens jloleysens added Feature:Console Dev Tools Console Feature v8.0.0 Team:Kibana Management Dev Tools, Index Management, Upgrade Assistant, ILM, Ingest Node Pipelines, and more release_note:skip Skip the PR/issue when compiling release notes v7.6.0 labels Dec 5, 2019
@elasticmachine
Copy link
Contributor

Pinging @elastic/es-ui (Team:Elasticsearch UI)

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

Clean up use of jquery
Remove use of `done` inside async tests (input_tokenization.test.js)
Capitalize elasticsearch
Introduce helper for converting to AceRange inside legacy core editor
Update typings
Clean up imports
Cleaner variable assignment
import { CoreEditor, Token } from '../types';
import { TokenIterator } from './token_iterator';

export const MODE = {
Copy link
Contributor

Choose a reason for hiding this comment

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

Feels like a good candidate for conversion to an enum, but not in this PR.

@@ -120,6 +136,11 @@ export interface CoreEditor {
*/
clearSelection(): void;

/**
* TODO: Document
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this TODO supposed to be completed in this PR? The other new functions have documentation.

@elasticmachine
Copy link
Contributor

💔 Build Failed

…dels/sense_editor/curl.ts

Co-Authored-By: Rory Hunter <pugnascotia@users.noreply.github.com>
@elasticmachine
Copy link
Contributor

💚 Build Succeeded

Copy link
Contributor

@cjcenizal cjcenizal left a comment

Choose a reason for hiding this comment

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

Great work @jloleysens! I tested the scenarios listed in #42029, tried out the different settings, and used the history dropdown. Everything behaved as expected. Code LGTM, just had a few nitpicks and questions but nothing worth blocking on.

The architecture looks like a big improvement. I think we can continue to look for ways to make the the roles of and relationship between SenseEditor and LegacyCoreEditor more apparent. This could be as simple as a name change, or maybe we reconsider whether SenseEditor should be a class and is better broken up into a number of pure functions (just speculating!). Just a casual thought based on some initial confusion I had about these two entities that was partially resolved by reading the source.

return false;
}

export function parseCURL(text: string) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Wow, I had no idea Console supported curl! This is really impressive but it seems like an undocumented feature which adds maintenance overhead, and I'm not sure it's particularly useful or if people even know about it. What do you think about planning for deprecating this feature in the future, e.g. 8.0?

Copy link
Contributor

Choose a reason for hiding this comment

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

Check with the Training folks - I have a feeling it was mentioned when I took the ES Engineer 1 training recently.

"Copy as curl" I can see being more useful, but auto-parsing curl is unexpected. Well, to me, anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, tbh I didn't really know about this feature either 😅 happy to remove in future!

Copy link
Contributor

Choose a reason for hiding this comment

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

I created #52570 to track my proposal.

pos: any,
prefix: any,
callback: any
DO_NOT_USE_SESSION: IEditSession,
Copy link
Contributor

Choose a reason for hiding this comment

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

I love the way you've named things that are deprecated!

@jloleysens
Copy link
Contributor Author

@elasticmachine merge upstream

.replace('^s*\n', '')
.replace('\ns*^', '');
.replace('^\s*\n', '') // prettier-ignore
.replace('\n\s*$', ''); // prettier-ignore
Copy link
Contributor

Choose a reason for hiding this comment

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

I think Prettier is correct here - these patterns be surrounded in forward-slashes.

      const jsonValue = JSON.parse(rawStringifiedValue)
        .replace(/^\s*\n/, '')
        .replace(/\n\s*$/, '');

I see what you mean about the difference with trim() - it would remove all whitespace at the start or end of string, whereas these patterns are a little more subtle. Maybe it would be worth a comment, in case someone comes along later and replaces it with trim(). 😀

Copy link
Contributor

Choose a reason for hiding this comment

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

(Although I still query the usefulness of this vs. a simple trim())

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Come to think of it, this replace behaviour was part of legacy and was carried over from a previous alteration. I'm not convinced we want replace behaviour here at all. The value being altered was inside of """ which means string literal in Console. Newlines and whitespace should be preserved. I don't think those replace functions where actually doing anything when the behaviour was considered "correct":

"\n    SELECT * FROM \"TABLE\"\n    "
        .replace('^\s*\n', '')
        .replace('\n\s*$', '')

===

"\n    SELECT * FROM \"TABLE\"\n    "

// true

Automated and manual testing seem to confirm this. Would you mind taking a look too @pugnascotia ?

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

History

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

@jloleysens jloleysens merged commit b4a2751 into elastic:master Dec 10, 2019
@jloleysens jloleysens deleted the console/sense-editor-core-editor branch December 10, 2019 12:16
jloleysens added a commit to jloleysens/kibana that referenced this pull request Dec 10, 2019
* WiP, lotta broken things, working through new editor.ts

* RowParser -> TS

* Utils to TS and regular module

* Finished first version of core & sense editor wrappers. Tokenizer provider test working. Still need to delete some files

* WiP - moved A LOT of code around and busy fixing sense-editor tests

* Fix sense editor test

* Clean up mocks

* Moved A LOT of code out of quarantined.
Still working on sense editor's integration test
Not running yet.

* WiP still finishing up manual testing

* Fix use of Ace Range and fix open documentation

* Move out of quarantined!

* Remove load remote editor state for now

* - fix use of token iterator
- remove ace ranges from sense editor spec and fix spec 🤦

* Address getSelectionRange document TODO
Clean up use of jquery
Remove use of `done` inside async tests (input_tokenization.test.js)
Capitalize elasticsearch
Introduce helper for converting to AceRange inside legacy core editor
Update typings
Clean up imports
Cleaner variable assignment

* Update src/legacy/core_plugins/console/public/np_ready/application/models/sense_editor/curl.ts

Co-Authored-By: Rory Hunter <pugnascotia@users.noreply.github.com>

* Remove commented-out code
lib/utils.js -> lib/utils.ts
Rename engulfling range (sense_editor)

* Rename format request function

* utils.ts default export usage cleanup

* Update replace regex and add another utils test

* Remove legacy replace behaviour

* Fix typo in comment
jloleysens added a commit that referenced this pull request Dec 10, 2019
* WiP, lotta broken things, working through new editor.ts

* RowParser -> TS

* Utils to TS and regular module

* Finished first version of core & sense editor wrappers. Tokenizer provider test working. Still need to delete some files

* WiP - moved A LOT of code around and busy fixing sense-editor tests

* Fix sense editor test

* Clean up mocks

* Moved A LOT of code out of quarantined.
Still working on sense editor's integration test
Not running yet.

* WiP still finishing up manual testing

* Fix use of Ace Range and fix open documentation

* Move out of quarantined!

* Remove load remote editor state for now

* - fix use of token iterator
- remove ace ranges from sense editor spec and fix spec 🤦

* Address getSelectionRange document TODO
Clean up use of jquery
Remove use of `done` inside async tests (input_tokenization.test.js)
Capitalize elasticsearch
Introduce helper for converting to AceRange inside legacy core editor
Update typings
Clean up imports
Cleaner variable assignment

* Update src/legacy/core_plugins/console/public/np_ready/application/models/sense_editor/curl.ts

Co-Authored-By: Rory Hunter <pugnascotia@users.noreply.github.com>

* Remove commented-out code
lib/utils.js -> lib/utils.ts
Rename engulfling range (sense_editor)

* Rename format request function

* utils.ts default export usage cleanup

* Update replace regex and add another utils test

* Remove legacy replace behaviour

* Fix typo in comment
@jloleysens jloleysens mentioned this pull request Dec 11, 2019
4 tasks
timductive pushed a commit to timductive/kibana that referenced this pull request Dec 16, 2019
* WiP, lotta broken things, working through new editor.ts

* RowParser -> TS

* Utils to TS and regular module

* Finished first version of core & sense editor wrappers. Tokenizer provider test working. Still need to delete some files

* WiP - moved A LOT of code around and busy fixing sense-editor tests

* Fix sense editor test

* Clean up mocks

* Moved A LOT of code out of quarantined.
Still working on sense editor's integration test
Not running yet.

* WiP still finishing up manual testing

* Fix use of Ace Range and fix open documentation

* Move out of quarantined!

* Remove load remote editor state for now

* - fix use of token iterator
- remove ace ranges from sense editor spec and fix spec 🤦

* Address getSelectionRange document TODO
Clean up use of jquery
Remove use of `done` inside async tests (input_tokenization.test.js)
Capitalize elasticsearch
Introduce helper for converting to AceRange inside legacy core editor
Update typings
Clean up imports
Cleaner variable assignment

* Update src/legacy/core_plugins/console/public/np_ready/application/models/sense_editor/curl.ts

Co-Authored-By: Rory Hunter <pugnascotia@users.noreply.github.com>

* Remove commented-out code
lib/utils.js -> lib/utils.ts
Rename engulfling range (sense_editor)

* Rename format request function

* utils.ts default export usage cleanup

* Update replace regex and add another utils test

* Remove legacy replace behaviour

* Fix typo in comment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:Console Dev Tools Console Feature 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.6.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants