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] Clean up use of any #95065

Merged
merged 9 commits into from
Mar 24, 2021

Conversation

jloleysens
Copy link
Contributor

@jloleysens jloleysens commented Mar 22, 2021

Summary

Focus for this PR is to remove as many uses of any in the Console plugin as possible. This involved searching the code for instances of : any and as any and replacing them with unknown or proper types where possible.

The changes here limit the scope to introducing changes that would be update types only; functionality has been changed as little as possible, but it would be good to do a smoke test of Console locally when reviewing.

There is one fix in the code where range replacement was not using the correct Position interface as the other logic branches (see usage of column: anchorToken.position.column in diff code below). This would lead to a situation where range replacement would insert duplicated text in front of the "anchor" token - resulting in a nonsense update (see gif). We can be extract to a separate PR, but I think it is nice to include the type fix (and the actual fix) here. This is an edge case it seems. Leaving this behaviour as is since it is outside the scope of this PR to address.

Gif of how faulty behaviour would manifest

range-replacement-bug

There are some instances of any that remain because they either involved to many functionality related changes or overly complex code:

  • src/plugins/console/public/application/containers/editor/legacy/subscribe_console_resize_checker.ts
  • src/plugins/console/public/application/models/sense_editor/sense_editor.ts
  • src/plugins/console/public/lib/es/es.ts
  • src/plugins/console/server/lib/proxy_config_collection.ts
  • src/plugins/console/public/application/containers/console_history/console_history.tsx

Not counting use of any in test files this leaves ~6 usages of any in the Console plugin.

This PR did not address all of the remaining @ts-ignores that still need to be addressed (mostly by migrating JS files to TS).

Diff of compiled JS as of current commit
diff --git 1/./a/public/application/components/console_menu.js 2/./b/public/application/components/console_menu.js
index e38cbac..6e1b7aa 100644
--- 1/./a/public/application/components/console_menu.js
+++ 2/./b/public/application/components/console_menu.js
@@ -40,7 +40,6 @@ class ConsoleMenu extends react_1.Component {
             }
             window.open(documentation, '_blank');
         };
-        // Using `any` here per this issue: https://github.com/elastic/eui/issues/2265
         this.autoIndent = (event) => {
             this.closePopover();
             this.props.autoIndent(event);
diff --git 1/./a/public/application/models/legacy_core_editor/legacy_core_editor.js 2/./b/public/application/models/legacy_core_editor/legacy_core_editor.js
index 2a57f8b..2828ecf 100644
--- 1/./a/public/application/models/legacy_core_editor/legacy_core_editor.js
+++ 2/./b/public/application/models/legacy_core_editor/legacy_core_editor.js
@@ -42,7 +42,7 @@ class LegacyCoreEditor {
             }
         };
         this.hideActionsBar = () => {
-            this.setActionsBar();
+            this.setActionsBar(null);
         };
         this.$actions = jquery_1.default(actions);
         this.editor.setShowPrintMargin(false);
diff --git 1/./a/public/console.chunk.0.js 2/./b/public/console.chunk.0.js
index 35f0c38..840740f 100644
--- 1/./a/public/console.chunk.0.js
+++ 2/./b/public/console.chunk.0.js
@@ -29197,8 +29197,8 @@ __webpack_require__.r(__webpack_exports__);
 
 
 
-const EditorReadContext = /*#__PURE__*/Object(react__WEBPACK_IMPORTED_MODULE_0__["createContext"])(null);
-const EditorActionContext = /*#__PURE__*/Object(react__WEBPACK_IMPORTED_MODULE_0__["createContext"])(null);
+const EditorReadContext = /*#__PURE__*/Object(react__WEBPACK_IMPORTED_MODULE_0__["createContext"])(_stores_editor__WEBPACK_IMPORTED_MODULE_1__["initialValue"]);
+const EditorActionContext = /*#__PURE__*/Object(react__WEBPACK_IMPORTED_MODULE_0__["createContext"])(() => {});
 function EditorContextProvider({
   children,
   settings
@@ -29352,8 +29352,8 @@ __webpack_require__.r(__webpack_exports__);
 
 
 
-const RequestReadContext = /*#__PURE__*/Object(react__WEBPACK_IMPORTED_MODULE_0__["createContext"])(null);
-const RequestActionContext = /*#__PURE__*/Object(react__WEBPACK_IMPORTED_MODULE_0__["createContext"])(null);
+const RequestReadContext = /*#__PURE__*/Object(react__WEBPACK_IMPORTED_MODULE_0__["createContext"])(_stores_request__WEBPACK_IMPORTED_MODULE_2__["initialValue"]);
+const RequestActionContext = /*#__PURE__*/Object(react__WEBPACK_IMPORTED_MODULE_0__["createContext"])(() => {});
 function RequestContextProvider({
   children
 }) {
@@ -29406,7 +29406,7 @@ function ServicesContextProvider({
 const useServicesContext = () => {
   const context = Object(react__WEBPACK_IMPORTED_MODULE_0__["useContext"])(ServicesContext);
 
-  if (context === undefined) {
+  if (context == null) {
     throw new Error('useServicesContext must be used inside the ServicesContextProvider.');
   }
 
@@ -29693,11 +29693,6 @@ __webpack_require__.r(__webpack_exports__);
  * Side Public License, v 1.
  */
 
-
-/**
- * This function is considered legacy and should not be changed or updated before we have editor
- * interfaces in place (it's using a customized version of Ace directly).
- */
 function restoreRequestFromHistory(editor, req) {
   const coreEditor = editor.getCoreEditor();
   let pos = coreEditor.getCurrentPosition();
@@ -29869,12 +29864,12 @@ __webpack_require__.r(__webpack_exports__);
  * Side Public License, v 1.
  */
 
+ // @ts-ignore
+
 
 const {
   collapseLiteralStrings
-} = _es_ui_shared_public__WEBPACK_IMPORTED_MODULE_1__["XJson"]; // @ts-ignore
-
-
+} = _es_ui_shared_public__WEBPACK_IMPORTED_MODULE_1__["XJson"];
 let CURRENT_REQ_ID = 0;
 function sendRequestToES(args) {
   const requests = args.requests.slice();
@@ -30675,7 +30670,7 @@ class LegacyCoreEditor {
     });
 
     _defineProperty(this, "hideActionsBar", () => {
-      this.setActionsBar();
+      this.setActionsBar(null);
     });
 
     this.$actions = jquery__WEBPACK_IMPORTED_MODULE_1___default()(actions);
@@ -30858,7 +30853,6 @@ class LegacyCoreEditor {
   }
 
   isCompleterActive() {
-    // Secrets of the arcane here.
     return Boolean(this.editor.completer && this.editor.completer.activated);
   }
 
@@ -31390,8 +31384,8 @@ __webpack_require__.r(__webpack_exports__);
  * in compliance with, at your election, the Elastic License 2.0 or the Server
  * Side Public License, v 1.
  */
- // eslint-disable-next-line import/no-default-export
 
+// eslint-disable-next-line import/no-default-export
 /* harmony default export */ __webpack_exports__["default"] = (function (editor) {
   const resize = editor.resize;
   const throttledResize = Object(lodash__WEBPACK_IMPORTED_MODULE_0__["throttle"])(() => {
@@ -31702,9 +31696,9 @@ __webpack_require__.r(__webpack_exports__);
 /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "SenseEditor", function() { return SenseEditor; });
 /* harmony import */ var lodash__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! lodash */ "lodash");
 /* harmony import */ var lodash__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(lodash__WEBPACK_IMPORTED_MODULE_0__);
-/* harmony import */ var _lib_row_parser__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../../lib/row_parser */ "./public/lib/row_parser.ts");
-/* harmony import */ var _es_ui_shared_public__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../../../../../es_ui_shared/public */ "plugin/esUiShared/public");
-/* harmony import */ var _es_ui_shared_public__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_es_ui_shared_public__WEBPACK_IMPORTED_MODULE_2__);
+/* harmony import */ var _es_ui_shared_public__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../../../../es_ui_shared/public */ "plugin/esUiShared/public");
+/* harmony import */ var _es_ui_shared_public__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_es_ui_shared_public__WEBPACK_IMPORTED_MODULE_1__);
+/* harmony import */ var _lib_row_parser__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../../../lib/row_parser */ "./public/lib/row_parser.ts");
 /* harmony import */ var _lib_utils__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../../../lib/utils */ "./public/lib/utils/index.ts");
 /* harmony import */ var _lib_es_es__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../../../lib/es/es */ "./public/lib/es/es.ts");
 /* harmony import */ var _factories__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../../factories */ "./public/application/factories/index.ts");
@@ -31728,9 +31722,8 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
 
 const {
   collapseLiteralStrings
-} = _es_ui_shared_public__WEBPACK_IMPORTED_MODULE_2__["XJson"];
+} = _es_ui_shared_public__WEBPACK_IMPORTED_MODULE_1__["XJson"];
 class SenseEditor {
-  // @ts-ignore
   constructor(coreEditor) {
     this.coreEditor = coreEditor;
 
@@ -31908,7 +31901,7 @@ class SenseEditor {
       const request = {
         method: '',
         data: [],
-        url: null,
+        url: '',
         range
       };
       const pos = range.start;
@@ -32190,8 +32183,8 @@ class SenseEditor {
     _defineProperty(this, "updateActionsBar", () => this.coreEditor.legacyUpdateUI(this.currentReqRange));
 
     this.currentReqRange = null;
-    this.parser = new _lib_row_parser__WEBPACK_IMPORTED_MODULE_1__["default"](this.coreEditor);
-    this.autocomplete = new _lib_autocomplete_autocomplete__WEBPACK_IMPORTED_MODULE_6__["default"]({
+    this.parser = new _lib_row_parser__WEBPACK_IMPORTED_MODULE_2__["default"](this.coreEditor);
+    this.autocomplete = Object(_lib_autocomplete_autocomplete__WEBPACK_IMPORTED_MODULE_6__["default"])({
       coreEditor,
       parser: this.parser
     });
@@ -32224,6 +32217,7 @@ __webpack_require__.r(__webpack_exports__);
 /* harmony import */ var immer__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(immer__WEBPACK_IMPORTED_MODULE_0__);
 /* harmony import */ var fp_ts_lib_function__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! fp-ts/lib/function */ "../../../node_modules/fp-ts/lib/function.js");
 /* harmony import */ var fp_ts_lib_function__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(fp_ts_lib_function__WEBPACK_IMPORTED_MODULE_1__);
+/* harmony import */ var _services__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../../services */ "./public/services/index.ts");
 /*
  * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
  * or more contributor license agreements. Licensed under the Elastic License
@@ -32233,9 +32227,10 @@ __webpack_require__.r(__webpack_exports__);
  */
 
 
+
 const initialValue = Object(immer__WEBPACK_IMPORTED_MODULE_0__["produce"])({
   ready: false,
-  settings: null,
+  settings: _services__WEBPACK_IMPORTED_MODULE_2__["DEFAULT_SETTINGS"],
   currentTextObject: null
 }, fp_ts_lib_function__WEBPACK_IMPORTED_MODULE_1__["identity"]);
 const reducer = (state, action) => Object(immer__WEBPACK_IMPORTED_MODULE_0__["produce"])(state, draft => {
@@ -32448,10 +32443,10 @@ __webpack_require__.r(__webpack_exports__);
 /* harmony import */ var _kbn_i18n__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @kbn/i18n */ "@kbn/i18n");
 /* harmony import */ var _kbn_i18n__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_kbn_i18n__WEBPACK_IMPORTED_MODULE_1__);
 /* harmony import */ var _kb_kb__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../kb/kb */ "./public/lib/kb/kb.js");
-/* harmony import */ var _utils__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../utils */ "./public/lib/utils/index.ts");
-/* harmony import */ var _engine__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./engine */ "./public/lib/autocomplete/engine.js");
-/* harmony import */ var _components_index__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./components/index */ "./public/lib/autocomplete/components/index.js");
-/* harmony import */ var _application_factories__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ../../application/factories */ "./public/application/factories/index.ts");
+/* harmony import */ var _application_factories__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../../application/factories */ "./public/application/factories/index.ts");
+/* harmony import */ var _utils__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../utils */ "./public/lib/utils/index.ts");
+/* harmony import */ var _engine__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./engine */ "./public/lib/autocomplete/engine.js");
+/* harmony import */ var _components_index__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./components/index */ "./public/lib/autocomplete/components/index.js");
 /*
  * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
  * or more contributor license agreements. Licensed under the Elastic License
@@ -32463,11 +32458,11 @@ __webpack_require__.r(__webpack_exports__);
  // TODO: All of these imports need to be moved to the core editor so that it can inject components from there.
 
 
- // @ts-ignore
 
  // @ts-ignore
 
 
+// @ts-ignore
 
 let lastEvaluatedToken = null;
 
@@ -32497,7 +32492,7 @@ function isUrlParamsToken(token) {
 function getCurrentMethodAndTokenPaths(editor, pos, parser, forceEndOfUrl)
 /* Flag for indicating whether we want to avoid early escape optimization. */
 {
-  const tokenIter = Object(_application_factories__WEBPACK_IMPORTED_MODULE_6__["createTokenIterator"])({
+  const tokenIter = Object(_application_factories__WEBPACK_IMPORTED_MODULE_3__["createTokenIterator"])({
     editor,
     position: pos
   });
@@ -32658,7 +32653,7 @@ function getCurrentMethodAndTokenPaths(editor, pos, parser, forceEndOfUrl)
       // we are forcing the end of the url for the purposes of determining an endpoint
       if (forceEndOfUrl && t.type === 'url.part') {
         ret.urlTokenPath.push(t.value);
-        ret.urlTokenPath.push(_components_index__WEBPACK_IMPORTED_MODULE_5__["URL_PATH_END_MARKER"]);
+        ret.urlTokenPath.push(_components_index__WEBPACK_IMPORTED_MODULE_6__["URL_PATH_END_MARKER"]);
       } // we are on the same line as cursor and dealing with a url. Current token is not part of the context
 
 
@@ -32766,7 +32761,7 @@ function getCurrentMethodAndTokenPaths(editor, pos, parser, forceEndOfUrl)
     }
   } else {
     // mark the url as completed.
-    ret.urlTokenPath.push(_components_index__WEBPACK_IMPORTED_MODULE_5__["URL_PATH_END_MARKER"]);
+    ret.urlTokenPath.push(_components_index__WEBPACK_IMPORTED_MODULE_6__["URL_PATH_END_MARKER"]);
   }
 
   if (t && t.type === 'method') {
@@ -32833,7 +32828,7 @@ function getCurrentMethodAndTokenPaths(editor, pos, parser, forceEndOfUrl)
       if (term.template.__raw && term.template.value) {
         indentedTemplateLines = term.template.value.split('\n');
       } else {
-        indentedTemplateLines = _utils__WEBPACK_IMPORTED_MODULE_3__["jsonToString"](term.template, true).split('\n');
+        indentedTemplateLines = _utils__WEBPACK_IMPORTED_MODULE_4__["jsonToString"](term.template, true).split('\n');
       }
 
       let currentIndentation = editor.getLineValue(context.rangeToReplace.start.lineNumber);
@@ -32875,7 +32870,7 @@ function getCurrentMethodAndTokenPaths(editor, pos, parser, forceEndOfUrl)
       lineNumber: context.rangeToReplace.start.lineNumber,
       column: context.rangeToReplace.start.column + termAsString.length + context.prefixToAdd.length + (templateInserted ? 0 : context.suffixToAdd.length)
     };
-    const tokenIter = Object(_application_factories__WEBPACK_IMPORTED_MODULE_6__["createTokenIterator"])({
+    const tokenIter = Object(_application_factories__WEBPACK_IMPORTED_MODULE_3__["createTokenIterator"])({
       editor,
       position: newPos
     });
@@ -32978,7 +32973,7 @@ function getCurrentMethodAndTokenPaths(editor, pos, parser, forceEndOfUrl)
 
     if (rowMode & parser.MODE.REQUEST_START) {
       // on url path, url params or method.
-      const tokenIter = Object(_application_factories__WEBPACK_IMPORTED_MODULE_6__["createTokenIterator"])({
+      const tokenIter = Object(_application_factories__WEBPACK_IMPORTED_MODULE_3__["createTokenIterator"])({
         editor,
         position: pos
       });
@@ -33116,7 +33111,7 @@ function getCurrentMethodAndTokenPaths(editor, pos, parser, forceEndOfUrl)
           context.rangeToReplace = {
             start: {
               lineNumber: pos.lineNumber,
-              column: anchorToken.column
+              column: anchorToken.position.column
             },
             end: {
               lineNumber: pos.lineNumber,
@@ -33172,7 +33167,7 @@ function getCurrentMethodAndTokenPaths(editor, pos, parser, forceEndOfUrl)
     // -> token : {} or token ]/} or token , but not token : SOMETHING ELSE
     context.prefixToAdd = '';
     context.suffixToAdd = '';
-    let tokenIter = Object(_application_factories__WEBPACK_IMPORTED_MODULE_6__["createTokenIterator"])({
+    let tokenIter = Object(_application_factories__WEBPACK_IMPORTED_MODULE_3__["createTokenIterator"])({
       editor,
       position: editor.getCurrentPosition()
     });
@@ -33229,7 +33224,7 @@ function getCurrentMethodAndTokenPaths(editor, pos, parser, forceEndOfUrl)
     } // go back to see whether we have one of ( : { & [ do not require a comma. All the rest do.
 
 
-    tokenIter = Object(_application_factories__WEBPACK_IMPORTED_MODULE_6__["createTokenIterator"])({
+    tokenIter = Object(_application_factories__WEBPACK_IMPORTED_MODULE_3__["createTokenIterator"])({
       editor,
       position: editor.getCurrentPosition()
     });
@@ -33281,7 +33276,7 @@ function getCurrentMethodAndTokenPaths(editor, pos, parser, forceEndOfUrl)
   function addMethodPrefixSuffixToContext(context) {
     context.prefixToAdd = '';
     context.suffixToAdd = '';
-    const tokenIter = Object(_application_factories__WEBPACK_IMPORTED_MODULE_6__["createTokenIterator"])({
+    const tokenIter = Object(_application_factories__WEBPACK_IMPORTED_MODULE_3__["createTokenIterator"])({
       editor,
       position: editor.getCurrentPosition()
     });
@@ -33316,7 +33311,7 @@ function getCurrentMethodAndTokenPaths(editor, pos, parser, forceEndOfUrl)
     context.otherTokenValues = ret.otherTokenValues;
     context.urlTokenPath = ret.urlTokenPath;
     const components = Object(_kb_kb__WEBPACK_IMPORTED_MODULE_2__["getTopLevelUrlCompleteComponents"])(context.method);
-    Object(_engine__WEBPACK_IMPORTED_MODULE_4__["populateContext"])(ret.urlTokenPath, context, editor, true, components);
+    Object(_engine__WEBPACK_IMPORTED_MODULE_5__["populateContext"])(ret.urlTokenPath, context, editor, true, components);
     context.autoCompleteSet = addMetaToTermsList(context.autoCompleteSet, 'endpoint');
   }
 
@@ -33331,7 +33326,7 @@ function getCurrentMethodAndTokenPaths(editor, pos, parser, forceEndOfUrl)
       return context;
     }
 
-    Object(_engine__WEBPACK_IMPORTED_MODULE_4__["populateContext"])(ret.urlTokenPath, context, editor, false, Object(_kb_kb__WEBPACK_IMPORTED_MODULE_2__["getTopLevelUrlCompleteComponents"])(context.method));
+    Object(_engine__WEBPACK_IMPORTED_MODULE_5__["populateContext"])(ret.urlTokenPath, context, editor, false, Object(_kb_kb__WEBPACK_IMPORTED_MODULE_2__["getTopLevelUrlCompleteComponents"])(context.method));
 
     if (!context.endpoint) {
       return context;
@@ -33351,7 +33346,7 @@ function getCurrentMethodAndTokenPaths(editor, pos, parser, forceEndOfUrl)
       context.otherTokenValues = currentParam[tokenPath[0]];
     }
 
-    Object(_engine__WEBPACK_IMPORTED_MODULE_4__["populateContext"])(tokenPath, context, editor, true, context.endpoint.paramsAutocomplete.getTopLevelComponents(context.method));
+    Object(_engine__WEBPACK_IMPORTED_MODULE_5__["populateContext"])(tokenPath, context, editor, true, context.endpoint.paramsAutocomplete.getTopLevelComponents(context.method));
     return context;
   }
 
@@ -33367,7 +33362,7 @@ function getCurrentMethodAndTokenPaths(editor, pos, parser, forceEndOfUrl)
       return context;
     }
 
-    Object(_engine__WEBPACK_IMPORTED_MODULE_4__["populateContext"])(ret.urlTokenPath, context, editor, false, Object(_kb_kb__WEBPACK_IMPORTED_MODULE_2__["getTopLevelUrlCompleteComponents"])(context.method));
+    Object(_engine__WEBPACK_IMPORTED_MODULE_5__["populateContext"])(ret.urlTokenPath, context, editor, false, Object(_kb_kb__WEBPACK_IMPORTED_MODULE_2__["getTopLevelUrlCompleteComponents"])(context.method));
     context.bodyTokenPath = ret.bodyTokenPath;
 
     if (!ret.bodyTokenPath) {
@@ -33386,7 +33381,7 @@ function getCurrentMethodAndTokenPaths(editor, pos, parser, forceEndOfUrl)
       components = Object(_kb_kb__WEBPACK_IMPORTED_MODULE_2__["getUnmatchedEndpointComponents"])();
     }
 
-    Object(_engine__WEBPACK_IMPORTED_MODULE_4__["populateContext"])(ret.bodyTokenPath, context, editor, true, components);
+    Object(_engine__WEBPACK_IMPORTED_MODULE_5__["populateContext"])(ret.bodyTokenPath, context, editor, true, components);
     return context;
   }
 
@@ -35211,8 +35206,8 @@ __webpack_require__.r(__webpack_exports__);
  * in compliance with, at your election, the Elastic License 2.0 or the Server
  * Side Public License, v 1.
  */
- // @ts-ignore
 
+// @ts-ignore
  // @ts-ignore
 
 
@@ -36750,7 +36745,7 @@ function createHistory(deps) {
 /*!**********************************!*\
   !*** ./public/services/index.ts ***!
   \**********************************/
-/*! exports provided: createHistory, History, createStorage, Storage, StorageKeys, createSettings, Settings, DevToolsSettings */
+/*! exports provided: createHistory, History, createStorage, Storage, StorageKeys, createSettings, Settings, DevToolsSettings, DEFAULT_SETTINGS */
 /***/ (function(module, __webpack_exports__, __webpack_require__) {
 
 "use strict";
@@ -36774,6 +36769,8 @@ __webpack_require__.r(__webpack_exports__);
 
 /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "DevToolsSettings", function() { return _settings__WEBPACK_IMPORTED_MODULE_2__["DevToolsSettings"]; });
 
+/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "DEFAULT_SETTINGS", function() { return _settings__WEBPACK_IMPORTED_MODULE_2__["DEFAULT_SETTINGS"]; });
+
 /*
  * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
  * or more contributor license agreements. Licensed under the Elastic License
@@ -36791,11 +36788,12 @@ __webpack_require__.r(__webpack_exports__);
 /*!*************************************!*\
   !*** ./public/services/settings.ts ***!
   \*************************************/
-/*! exports provided: Settings, createSettings */
+/*! exports provided: DEFAULT_SETTINGS, Settings, createSettings */
 /***/ (function(module, __webpack_exports__, __webpack_require__) {
 
 "use strict";
 __webpack_require__.r(__webpack_exports__);
+/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "DEFAULT_SETTINGS", function() { return DEFAULT_SETTINGS; });
 /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "Settings", function() { return Settings; });
 /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "createSettings", function() { return createSettings; });
 /*
@@ -36805,13 +36803,24 @@ __webpack_require__.r(__webpack_exports__);
  * in compliance with, at your election, the Elastic License 2.0 or the Server
  * Side Public License, v 1.
  */
+const DEFAULT_SETTINGS = Object.freeze({
+  fontSize: 14,
+  polling: true,
+  tripleQuotes: true,
+  wrapMode: true,
+  autocomplete: Object.freeze({
+    fields: true,
+    indices: true,
+    templates: true
+  })
+});
 class Settings {
   constructor(storage) {
     this.storage = storage;
   }
 
   getFontSize() {
-    return this.storage.get('font_size', 14);
+    return this.storage.get('font_size', DEFAULT_SETTINGS.fontSize);
   }
 
   setFontSize(size) {
@@ -36820,7 +36829,7 @@ class Settings {
   }
 
   getWrapMode() {
-    return this.storage.get('wrap_mode', true);
+    return this.storage.get('wrap_mode', DEFAULT_SETTINGS.wrapMode);
   }
 
   setWrapMode(mode) {
@@ -36834,15 +36843,11 @@ class Settings {
   }
 
   getTripleQuotes() {
-    return this.storage.get('triple_quotes', true);
+    return this.storage.get('triple_quotes', DEFAULT_SETTINGS.tripleQuotes);
   }
 
   getAutocomplete() {
-    return this.storage.get('autocomplete_settings', {
-      fields: true,
-      indices: true,
-      templates: true
-    });
+    return this.storage.get('autocomplete_settings', DEFAULT_SETTINGS.autocomplete);
   }
 
   setAutocomplete(settings) {
@@ -36851,7 +36856,7 @@ class Settings {
   }
 
   getPolling() {
-    return this.storage.get('console_polling', true);
+    return this.storage.get('console_polling', DEFAULT_SETTINGS.polling);
   }
 
   setPolling(polling) {
diff --git 1/./a/public/lib/autocomplete/autocomplete.js 2/./b/public/lib/autocomplete/autocomplete.js
index 127714a..2987086 100644
--- 1/./a/public/lib/autocomplete/autocomplete.js
+++ 2/./b/public/lib/autocomplete/autocomplete.js
@@ -12,12 +12,12 @@ const lodash_1 = tslib_1.__importDefault(require("lodash"));
 const i18n_1 = require("@kbn/i18n");
 // TODO: All of these imports need to be moved to the core editor so that it can inject components from there.
 const kb_1 = require("../kb/kb");
+const factories_1 = require("../../application/factories");
 const utils = tslib_1.__importStar(require("../utils"));
 // @ts-ignore
 const engine_1 = require("./engine");
 // @ts-ignore
 const index_1 = require("./components/index");
-const factories_1 = require("../../application/factories");
 let lastEvaluatedToken = null;
 function isUrlParamsToken(token) {
     switch ((token || {}).type) {
@@ -274,7 +274,7 @@ function getCurrentMethodAndTokenPaths(editor, pos, parser, forceEndOfUrl /* Fla
 }
 exports.getCurrentMethodAndTokenPaths = getCurrentMethodAndTokenPaths;
 // eslint-disable-next-line
-function default_1({ coreEditor: editor, parser }) {
+function default_1({ coreEditor: editor, parser, }) {
     function isUrlPathToken(token) {
         switch ((token || {}).type) {
             case 'url.slash':
@@ -547,7 +547,7 @@ function default_1({ coreEditor: editor, parser }) {
             default:
                 if (replacingTerm && context.updatedForToken.value === replacingTerm) {
                     context.rangeToReplace = {
-                        start: { lineNumber: pos.lineNumber, column: anchorToken.column },
+                        start: { lineNumber: pos.lineNumber, column: anchorToken.position.column },
                         end: {
                             lineNumber: pos.lineNumber,
                             column: context.updatedForToken.position.column + context.updatedForToken.value.length,

@jloleysens jloleysens added Feature:Console Dev Tools Console Feature Feature:Dev Tools 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.13.0 v7.12.1 labels Mar 22, 2021
@jloleysens jloleysens requested a review from a team as a code owner March 22, 2021 14:53
@elasticmachine
Copy link
Contributor

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

Copy link
Contributor

@alisonelizabeth alisonelizabeth left a comment

Choose a reason for hiding this comment

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

Thanks for working on this @jloleysens! It's great to see the removal of any 🎉 ! Code LGTM. I did a smoke test of console and did not notice any regressions.

Copy link
Contributor

@alisonelizabeth alisonelizabeth left a comment

Choose a reason for hiding this comment

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

Latest LGTM. Did a quick smoke test again to confirm everything is still working as expected.

@cjcenizal
Copy link
Contributor

@jloleysens Thanks for tackling this migration! Maybe we'll get a mention in the Kibana contributor newsletter. 😄 Is the fix that you mentioned for an existing bug, or for a bug that the any->unknown migration introduced? If it's for an existing bug, could you describe it more detail with repro steps, change the label for this PR to release-note:fix, and add a release note? Might also be a good idea to check existing bug reports and see if it fixes any of them.

@jloleysens
Copy link
Contributor Author

@elasticmachine merge upstream

@jloleysens
Copy link
Contributor Author

@cjcenizal thanks for raising that point!

Is the fix that you mentioned for an existing bug

This is an existing behaviour; not sure when it was introduced though 😅, possibly as part of my previous Console refactors.

I could not find any open issues for this and upon closer inspection I am not certain under what conditions this logic will be triggered. I simulated how this bug would manifest by adding a gif to the PR description if this code path actually ran.

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

Async chunks

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

id before after diff
console 890.0KB 890.4KB +405.0B

History

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

@jloleysens jloleysens merged commit edfdb78 into elastic:master Mar 24, 2021
@jloleysens jloleysens deleted the console/cleaning-up-anys branch March 24, 2021 13:05
jloleysens added a commit to jloleysens/kibana that referenced this pull request Mar 24, 2021
* cleaned up autocomplete.ts and get_endpoint_from_postition.ts of anys

* general clean up of lowering hanging fruit

* cleaned up remaining anys, still need to test

* fix remaining TS compilation issues

* also tidy up use of "as any" and some more ": any"

* addressed type issues and introduced the default editor settings object

* clean up @ts-ignore

* added comments to interface

Co-authored-by: Kibana Machine <[email protected]>
jloleysens added a commit that referenced this pull request Mar 24, 2021
* cleaned up autocomplete.ts and get_endpoint_from_postition.ts of anys

* general clean up of lowering hanging fruit

* cleaned up remaining anys, still need to test

* fix remaining TS compilation issues

* also tidy up use of "as any" and some more ": any"

* addressed type issues and introduced the default editor settings object

* clean up @ts-ignore

* added comments to interface

Co-authored-by: Kibana Machine <[email protected]>

Co-authored-by: Kibana Machine <[email protected]>
jloleysens added a commit that referenced this pull request Mar 24, 2021
* cleaned up autocomplete.ts and get_endpoint_from_postition.ts of anys

* general clean up of lowering hanging fruit

* cleaned up remaining anys, still need to test

* fix remaining TS compilation issues

* also tidy up use of "as any" and some more ": any"

* addressed type issues and introduced the default editor settings object

* clean up @ts-ignore

* added comments to interface

Co-authored-by: Kibana Machine <[email protected]>

Co-authored-by: Kibana Machine <[email protected]>
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 Feature:Dev Tools 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.12.1 v7.13.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants