From 504a5726d8c56c4e0bedcbff49880578151609b7 Mon Sep 17 00:00:00 2001 From: Aaron Caldwell Date: Fri, 6 Mar 2020 12:23:27 -0700 Subject: [PATCH 01/14] Layers dir up through sources migrated. Kibana services updated --- .../plugins/maps/public/kibana_services.js | 21 ++++++++++++ .../sources/ems_tms_source/ems_tms_source.js | 6 ++-- .../layers/sources/ems_unavailable_message.js | 4 +-- .../es_pew_pew_source/create_source_editor.js | 5 ++- .../es_search_source/create_source_editor.js | 14 +++++--- .../es_search_source/load_index_settings.js | 6 ++-- .../maps/public/layers/sources/es_source.js | 4 ++- x-pack/legacy/plugins/maps/public/plugin.ts | 34 +++++++++++++++---- 8 files changed, 71 insertions(+), 23 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/kibana_services.js b/x-pack/legacy/plugins/maps/public/kibana_services.js index 5702eb1c6f846..9a53f187b4e1b 100644 --- a/x-pack/legacy/plugins/maps/public/kibana_services.js +++ b/x-pack/legacy/plugins/maps/public/kibana_services.js @@ -31,6 +31,27 @@ export const getFileUploadComponent = () => { return fileUploadPlugin.JsonUploadAndParse; }; +let getInjectedVar; +export const setInjectedVarFunc = getInjectedVarFunc => (getInjectedVar = getInjectedVarFunc); +export const getInjectedVarFunc = () => getInjectedVar; + +let uiSettings; +export const setUiSettings = coreUiSettings => (uiSettings = coreUiSettings); +export const getUiSettings = () => uiSettings; + +let indexPatternSelectComponent; +export const setIndexPatternSelect = indexPatternSelect => + (indexPatternSelectComponent = indexPatternSelect); +export const getIndexPatternSelectComponent = () => indexPatternSelectComponent; + +let coreHttp; +export const setHttp = http => (coreHttp = http); +export const getHttp = () => coreHttp; + +let dataTimeFilter; +export const setTimeFilter = timeFilter => (dataTimeFilter = timeFilter); +export const getTimeFilter = () => dataTimeFilter; + export async function fetchSearchSourceAndRecordWithInspector({ searchSource, requestId, diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/ems_tms_source/ems_tms_source.js b/x-pack/legacy/plugins/maps/public/layers/sources/ems_tms_source/ems_tms_source.js index 76ecc18f2f7d7..5a2124622694c 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/ems_tms_source/ems_tms_source.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/ems_tms_source/ems_tms_source.js @@ -5,7 +5,6 @@ */ import _ from 'lodash'; -import chrome from 'ui/chrome'; import React from 'react'; import { AbstractTMSSource } from '../tms_source'; import { VectorTileLayer } from '../../vector_tile_layer'; @@ -16,6 +15,7 @@ import { UpdateSourceEditor } from './update_source_editor'; import { i18n } from '@kbn/i18n'; import { getDataSourceLabel } from '../../../../common/i18n_getters'; import { EMS_TMS } from '../../../../common/constants'; +import { getInjectedVarFunc, getUiSettings } from '../../../kibana_services'; export class EMSTMSSource extends AbstractTMSSource { static type = EMS_TMS; @@ -152,8 +152,8 @@ export class EMSTMSSource extends AbstractTMSSource { return this._descriptor.id; } - const isDarkMode = chrome.getUiSettingsClient().get('theme:darkMode', false); - const emsTileLayerId = chrome.getInjected('emsTileLayerId'); + const isDarkMode = getUiSettings().get('theme:darkMode', false); + const emsTileLayerId = getInjectedVarFunc()('emsTileLayerId'); return isDarkMode ? emsTileLayerId.dark : emsTileLayerId.bright; } } diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/ems_unavailable_message.js b/x-pack/legacy/plugins/maps/public/layers/sources/ems_unavailable_message.js index 22b1088047539..bc50890a0f4a3 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/ems_unavailable_message.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/ems_unavailable_message.js @@ -4,11 +4,11 @@ * you may not use this file except in compliance with the Elastic License. */ -import chrome from 'ui/chrome'; +import { getInjectedVarFunc } from '../../kibana_services'; import { i18n } from '@kbn/i18n'; export function getEmsUnavailableMessage() { - const isEmsEnabled = chrome.getInjected('isEmsEnabled', true); + const isEmsEnabled = getInjectedVarFunc()('isEmsEnabled', true); if (isEmsEnabled) { return i18n.translate('xpack.maps.source.ems.noAccessDescription', { defaultMessage: diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_pew_pew_source/create_source_editor.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_pew_pew_source/create_source_editor.js index 5e4727cd7ab0c..f1524f67b79a4 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_pew_pew_source/create_source_editor.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_pew_pew_source/create_source_editor.js @@ -9,7 +9,7 @@ import React, { Fragment, Component } from 'react'; import PropTypes from 'prop-types'; import { SingleFieldSelect } from '../../../components/single_field_select'; -import { indexPatternService } from '../../../kibana_services'; +import { indexPatternService, getIndexPatternSelectComponent } from '../../../kibana_services'; import { i18n } from '@kbn/i18n'; import { FormattedMessage } from '@kbn/i18n/react'; @@ -19,8 +19,7 @@ import { getAggregatableGeoFields, } from '../../../index_pattern_util'; -import { npStart } from 'ui/new_platform'; -const { IndexPatternSelect } = npStart.plugins.data.ui; +const IndexPatternSelect = getIndexPatternSelectComponent(); export class CreateSourceEditor extends Component { static propTypes = { diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/create_source_editor.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/create_source_editor.js index b7b63ce8082bc..bfc63ef73f24f 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/create_source_editor.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/create_source_editor.js @@ -10,11 +10,14 @@ import PropTypes from 'prop-types'; import { EuiFormRow, EuiSpacer, EuiSwitch, EuiCallOut } from '@elastic/eui'; import { SingleFieldSelect } from '../../../components/single_field_select'; -import { indexPatternService } from '../../../kibana_services'; +import { + indexPatternService, + getIndexPatternSelectComponent, + getHttp, +} from '../../../kibana_services'; import { NoIndexPatternCallout } from '../../../components/no_index_pattern_callout'; import { FormattedMessage } from '@kbn/i18n/react'; import { i18n } from '@kbn/i18n'; -import { kfetch } from 'ui/kfetch'; import { ES_GEO_FIELD_TYPE, GIS_API_PATH, @@ -23,8 +26,8 @@ import { import { DEFAULT_FILTER_BY_MAP_BOUNDS } from './constants'; import { indexPatterns } from '../../../../../../../../src/plugins/data/public'; -import { npStart } from 'ui/new_platform'; -const { IndexPatternSelect } = npStart.plugins.data.ui; +const IndexPatternSelect = getIndexPatternSelectComponent(); +const http = getHttp(); function getGeoFields(fields) { return fields.filter(field => { @@ -81,7 +84,8 @@ export class CreateSourceEditor extends Component { }; loadIndexDocCount = async indexPatternTitle => { - const { count } = await kfetch({ + const { count } = await http({ + method: 'GET', pathname: `../${GIS_API_PATH}/indexCount`, query: { index: indexPatternTitle, diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/load_index_settings.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/load_index_settings.js index 1a58b5b073b08..86266e469d0fe 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/load_index_settings.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/load_index_settings.js @@ -9,12 +9,13 @@ import { DEFAULT_MAX_INNER_RESULT_WINDOW, INDEX_SETTINGS_API_PATH, } from '../../../../common/constants'; -import { kfetch } from 'ui/kfetch'; +import { getHttp } from '../../../kibana_services'; import { toastNotifications } from 'ui/notify'; import { i18n } from '@kbn/i18n'; let toastDisplayed = false; const indexSettings = new Map(); +const http = getHttp(); export async function loadIndexSettings(indexPatternTitle) { if (indexSettings.has(indexPatternTitle)) { @@ -28,7 +29,8 @@ export async function loadIndexSettings(indexPatternTitle) { async function fetchIndexSettings(indexPatternTitle) { try { - const indexSettings = await kfetch({ + const indexSettings = await http({ + method: 'GET', pathname: `../${INDEX_SETTINGS_API_PATH}`, query: { indexPatternTitle, diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_source.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_source.js index 1552db277e609..3792f978d2889 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_source.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_source.js @@ -10,9 +10,9 @@ import { fetchSearchSourceAndRecordWithInspector, indexPatternService, SearchSource, + getTimeFilter, } from '../../kibana_services'; import { createExtentFilter } from '../../elasticsearch_geo_utils'; -import { timefilter } from 'ui/timefilter'; import _ from 'lodash'; import { i18n } from '@kbn/i18n'; import uuid from 'uuid/v4'; @@ -22,6 +22,8 @@ import { ES_GEO_FIELD_TYPE } from '../../../common/constants'; import { DataRequestAbortError } from '../util/data_request'; import { expandToTileBoundaries } from './es_geo_grid_source/geo_tile_utils'; +const timefilter = getTimeFilter(); + export class AbstractESSource extends AbstractVectorSource { static icon = 'logoElasticsearch'; diff --git a/x-pack/legacy/plugins/maps/public/plugin.ts b/x-pack/legacy/plugins/maps/public/plugin.ts index e2d1d43295646..534637657fe2b 100644 --- a/x-pack/legacy/plugins/maps/public/plugin.ts +++ b/x-pack/legacy/plugins/maps/public/plugin.ts @@ -9,13 +9,21 @@ import { Plugin, CoreStart, CoreSetup } from 'src/core/public'; import { wrapInI18nContext } from 'ui/i18n'; // @ts-ignore import { MapListing } from './components/map_listing'; -// @ts-ignore -import { setInjectedVarFunc } from '../../../../plugins/maps/public/kibana_services'; // eslint-disable-line @kbn/eslint/no-restricted-paths -// @ts-ignore -import { setLicenseId, setInspector, setFileUpload } from './kibana_services'; +// eslint-disable-next-line @kbn/eslint/no-restricted-paths +import { setInjectedVarFunc } from '../../../../plugins/maps/public/kibana_services'; +import { + setLicenseId, + setInspector, + setFileUpload, + setIndexPatternSelect, + setHttp, + setTimeFilter, +} from './kibana_services'; import { HomePublicPluginSetup } from '../../../../../src/plugins/home/public'; import { LicensingPluginSetup } from '../../../../plugins/licensing/public'; import { featureCatalogueEntry } from './feature_catalogue_entry'; +import { DataPublicPluginStart } from '../../../../../src/plugins/data/public'; +import { Start as InspectorPluginStart } from '../../../plugins/inspector/public'; /** * These are the interfaces with your public contracts. You should export these @@ -30,16 +38,26 @@ interface MapsPluginSetupDependencies { np: { licensing?: LicensingPluginSetup; home: HomePublicPluginSetup; + data: DataPublicPluginStart; + }; +} + +interface MapsPluginStartDependencies { + np: { + data: DataPublicPluginStart; + inspector: InspectorPluginStart; + file_upload: any; // TODO: Export type from file upload and use here }; } export const bindSetupCoreAndPlugins = (core: CoreSetup, plugins: any) => { const { licensing } = plugins; - const { injectedMetadata } = core; + const { injectedMetadata, http } = core; if (licensing) { licensing.license$.subscribe(({ uid }: { uid: string }) => setLicenseId(uid)); } setInjectedVarFunc(injectedMetadata.getInjectedVar); + setHttp(http); }; /** @internal */ @@ -56,9 +74,11 @@ export class MapsPlugin implements Plugin { np.home.featureCatalogue.register(featureCatalogueEntry); } - public start(core: CoreStart, plugins: any) { - const { inspector, file_upload } = plugins.np; + public start(core: CoreStart, plugins: MapsPluginStartDependencies) { + const { inspector, file_upload, data } = plugins.np; setInspector(inspector); setFileUpload(file_upload); + setIndexPatternSelect(data.ui.IndexPatternSelect); + setTimeFilter(data.timefilter.timefilter); } } From 8906c4c7a98f2b3cc4203ea31b483a11388b1f21 Mon Sep 17 00:00:00 2001 From: Aaron Caldwell Date: Tue, 17 Mar 2020 10:00:00 -0600 Subject: [PATCH 02/14] Create separate init method for plugin setup, leverage in embeddable factory --- .../embeddable/map_embeddable_factory.js | 6 ++++-- x-pack/legacy/plugins/maps/public/plugin.ts | 19 +++++++++++++------ 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/embeddable/map_embeddable_factory.js b/x-pack/legacy/plugins/maps/public/embeddable/map_embeddable_factory.js index 710b7f737e861..af86e5bf7e903 100644 --- a/x-pack/legacy/plugins/maps/public/embeddable/map_embeddable_factory.js +++ b/x-pack/legacy/plugins/maps/public/embeddable/map_embeddable_factory.js @@ -24,8 +24,8 @@ import { getQueryableUniqueIndexPatternIds } from '../selectors/map_selectors'; import { getInitialLayers } from '../angular/get_initial_layers'; import { mergeInputWithSavedMap } from './merge_input_with_saved_map'; import '../angular/services/gis_map_saved_object_loader'; -import { bindSetupCoreAndPlugins } from '../plugin'; -import { npSetup } from 'ui/new_platform'; +import { bindSetupCoreAndPlugins, bindStartCoreAndPlugins } from '../plugin'; +import { npSetup, npStart } from 'ui/new_platform'; export class MapEmbeddableFactory extends EmbeddableFactory { type = MAP_SAVED_OBJECT_TYPE; @@ -40,7 +40,9 @@ export class MapEmbeddableFactory extends EmbeddableFactory { getIconForSavedObject: () => APP_ICON, }, }); + // Init required services. Necessary while in legacy bindSetupCoreAndPlugins(npSetup.core, npSetup.plugins); + bindStartCoreAndPlugins(npStart.core, npStart.plugins); } isEditable() { return capabilities.get().maps.save; diff --git a/x-pack/legacy/plugins/maps/public/plugin.ts b/x-pack/legacy/plugins/maps/public/plugin.ts index 534637657fe2b..3ed0e4a48ca7c 100644 --- a/x-pack/legacy/plugins/maps/public/plugin.ts +++ b/x-pack/legacy/plugins/maps/public/plugin.ts @@ -10,7 +10,6 @@ import { wrapInI18nContext } from 'ui/i18n'; // @ts-ignore import { MapListing } from './components/map_listing'; // eslint-disable-next-line @kbn/eslint/no-restricted-paths -import { setInjectedVarFunc } from '../../../../plugins/maps/public/kibana_services'; import { setLicenseId, setInspector, @@ -18,6 +17,8 @@ import { setIndexPatternSelect, setHttp, setTimeFilter, + setUiSettings, + setInjectedVarFunc, } from './kibana_services'; import { HomePublicPluginSetup } from '../../../../../src/plugins/home/public'; import { LicensingPluginSetup } from '../../../../plugins/licensing/public'; @@ -58,6 +59,16 @@ export const bindSetupCoreAndPlugins = (core: CoreSetup, plugins: any) => { } setInjectedVarFunc(injectedMetadata.getInjectedVar); setHttp(http); + setUiSettings(core.uiSettings); + setInjectedVarFunc(core.injectedMetadata.getInjectedVar); +}; + +export const bindStartCoreAndPlugins = (core: CoreStart, plugins: any) => { + const { inspector, file_upload, data } = plugins; + setInspector(inspector); + setFileUpload(file_upload); + setIndexPatternSelect(data.ui.IndexPatternSelect); + setTimeFilter(data.query.timefilter.timefilter); }; /** @internal */ @@ -75,10 +86,6 @@ export class MapsPlugin implements Plugin { } public start(core: CoreStart, plugins: MapsPluginStartDependencies) { - const { inspector, file_upload, data } = plugins.np; - setInspector(inspector); - setFileUpload(file_upload); - setIndexPatternSelect(data.ui.IndexPatternSelect); - setTimeFilter(data.timefilter.timefilter); + bindStartCoreAndPlugins(core, plugins.np); } } From 6654914f24610e7d94ce721a33e4d812010e913b Mon Sep 17 00:00:00 2001 From: Aaron Caldwell Date: Tue, 17 Mar 2020 10:02:24 -0600 Subject: [PATCH 03/14] Add NP timefilter, http, IndexPatternSelect --- .../plugins/maps/public/angular/map_controller.js | 8 ++++---- .../join_editor/resources/join_expression.js | 7 ++----- .../sources/es_geo_grid_source/create_source_editor.js | 7 +++---- .../sources/es_pew_pew_source/create_source_editor.js | 4 ++-- .../sources/es_search_source/create_source_editor.js | 10 +++++----- .../sources/es_search_source/load_index_settings.js | 6 +++--- .../plugins/maps/public/layers/sources/es_source.js | 6 ++---- .../plugins/maps/public/selectors/map_selectors.js | 6 +++--- 8 files changed, 24 insertions(+), 30 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/angular/map_controller.js b/x-pack/legacy/plugins/maps/public/angular/map_controller.js index 7b3dc74d777b2..fc45c0446445c 100644 --- a/x-pack/legacy/plugins/maps/public/angular/map_controller.js +++ b/x-pack/legacy/plugins/maps/public/angular/map_controller.js @@ -15,7 +15,7 @@ import { i18n } from '@kbn/i18n'; import { capabilities } from 'ui/capabilities'; import { render, unmountComponentAtNode } from 'react-dom'; import { uiModules } from 'ui/modules'; -import { timefilter } from 'ui/timefilter'; +import { getTimeFilter, indexPatternService, getInspector } from '../kibana_services'; import { Provider } from 'react-redux'; // eslint-disable-next-line @kbn/eslint/no-restricted-paths import { createMapStore } from '../../../../../plugins/maps/public/reducers/store'; @@ -52,7 +52,7 @@ import { // eslint-disable-next-line @kbn/eslint/no-restricted-paths import { getInspectorAdapters } from '../../../../../plugins/maps/public/reducers/non_serializable_instances'; import { docTitle } from 'ui/doc_title'; -import { indexPatternService, getInspector } from '../kibana_services'; + import { toastNotifications } from 'ui/notify'; import { getInitialLayers } from './get_initial_layers'; import { getInitialQuery } from './get_initial_query'; @@ -519,8 +519,8 @@ app.controller( } // Hide angular timepicer/refresh UI from top nav - timefilter.disableTimeRangeSelector(); - timefilter.disableAutoRefreshSelector(); + getTimeFilter().disableTimeRangeSelector(); + getTimeFilter().disableAutoRefreshSelector(); $scope.showDatePicker = true; // used by query-bar directive to enable timepikcer in query bar $scope.topNavMenu = [ { diff --git a/x-pack/legacy/plugins/maps/public/connected_components/layer_panel/join_editor/resources/join_expression.js b/x-pack/legacy/plugins/maps/public/connected_components/layer_panel/join_editor/resources/join_expression.js index 777c8ae0923fe..fb77857f731b9 100644 --- a/x-pack/legacy/plugins/maps/public/connected_components/layer_panel/join_editor/resources/join_expression.js +++ b/x-pack/legacy/plugins/maps/public/connected_components/layer_panel/join_editor/resources/join_expression.js @@ -19,11 +19,7 @@ import { i18n } from '@kbn/i18n'; import { SingleFieldSelect } from '../../../../components/single_field_select'; import { FormattedMessage } from '@kbn/i18n/react'; import { getTermsFields } from '../../../../index_pattern_util'; - -import { indexPatternService } from '../../../../kibana_services'; - -import { npStart } from 'ui/new_platform'; -const { IndexPatternSelect } = npStart.plugins.data.ui; +import { indexPatternService, getIndexPatternSelectComponent } from '../../../../kibana_services'; export class JoinExpression extends Component { state = { @@ -106,6 +102,7 @@ export class JoinExpression extends Component { if (!this.props.leftValue) { return null; } + const IndexPatternSelect = getIndexPatternSelectComponent(); return ( { return ( @@ -84,9 +81,10 @@ export class CreateSourceEditor extends Component { }; loadIndexDocCount = async indexPatternTitle => { - const { count } = await http({ + const http = getHttp(); + const { count } = await http.fetch(`../${GIS_API_PATH}/indexCount`, { method: 'GET', - pathname: `../${GIS_API_PATH}/indexCount`, + credentials: 'same-origin', query: { index: indexPatternTitle, }, @@ -253,6 +251,8 @@ export class CreateSourceEditor extends Component { } render() { + const IndexPatternSelect = getIndexPatternSelectComponent(); + return ( {this._renderNoIndexPatternWarning()} diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/load_index_settings.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/load_index_settings.js index 86266e469d0fe..5723e52beacd0 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/load_index_settings.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/load_index_settings.js @@ -15,7 +15,6 @@ import { i18n } from '@kbn/i18n'; let toastDisplayed = false; const indexSettings = new Map(); -const http = getHttp(); export async function loadIndexSettings(indexPatternTitle) { if (indexSettings.has(indexPatternTitle)) { @@ -28,10 +27,11 @@ export async function loadIndexSettings(indexPatternTitle) { } async function fetchIndexSettings(indexPatternTitle) { + const http = getHttp(); try { - const indexSettings = await http({ + const indexSettings = await http.fetch(`../${INDEX_SETTINGS_API_PATH}`, { method: 'GET', - pathname: `../${INDEX_SETTINGS_API_PATH}`, + credentials: 'same-origin', query: { indexPatternTitle, }, diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_source.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_source.js index 3792f978d2889..46164b660a6ef 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_source.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_source.js @@ -22,8 +22,6 @@ import { ES_GEO_FIELD_TYPE } from '../../../common/constants'; import { DataRequestAbortError } from '../util/data_request'; import { expandToTileBoundaries } from './es_geo_grid_source/geo_tile_utils'; -const timefilter = getTimeFilter(); - export class AbstractESSource extends AbstractVectorSource { static icon = 'logoElasticsearch'; @@ -123,7 +121,7 @@ export class AbstractESSource extends AbstractVectorSource { allFilters.push(createExtentFilter(buffer, geoField.name, geoField.type)); } if (isTimeAware) { - allFilters.push(timefilter.createFilter(indexPattern, searchFilters.timeFilters)); + allFilters.push(getTimeFilter().createFilter(indexPattern, searchFilters.timeFilters)); } const searchSource = new SearchSource(initialSearchContext); @@ -295,7 +293,7 @@ export class AbstractESSource extends AbstractVectorSource { } if (style.isTimeAware() && (await this.isTimeAware())) { searchSource.setField('filter', [ - timefilter.createFilter(indexPattern, searchFilters.timeFilters), + getTimeFilter().createFilter(indexPattern, searchFilters.timeFilters), ]); } diff --git a/x-pack/legacy/plugins/maps/public/selectors/map_selectors.js b/x-pack/legacy/plugins/maps/public/selectors/map_selectors.js index e5eaf8870aa77..9d404f800651f 100644 --- a/x-pack/legacy/plugins/maps/public/selectors/map_selectors.js +++ b/x-pack/legacy/plugins/maps/public/selectors/map_selectors.js @@ -11,7 +11,7 @@ import { VectorTileLayer } from '../layers/vector_tile_layer'; import { VectorLayer } from '../layers/vector_layer'; import { HeatmapLayer } from '../layers/heatmap_layer'; import { ALL_SOURCES } from '../layers/sources/all_sources'; -import { timefilter } from 'ui/timefilter'; +import { getTimeFilter } from '../kibana_services'; // eslint-disable-next-line @kbn/eslint/no-restricted-paths import { getInspectorAdapters } from '../../../../../plugins/maps/public/reducers/non_serializable_instances'; import { @@ -106,7 +106,7 @@ export const getMapCenter = ({ map }) => export const getMouseCoordinates = ({ map }) => map.mapState.mouseCoordinates; export const getTimeFilters = ({ map }) => - map.mapState.timeFilters ? map.mapState.timeFilters : timefilter.getTime(); + map.mapState.timeFilters ? map.mapState.timeFilters : getTimeFilter().getTime(); export const getQuery = ({ map }) => map.mapState.query; @@ -129,7 +129,7 @@ export const getRefreshConfig = ({ map }) => { return map.mapState.refreshConfig; } - const refreshInterval = timefilter.getRefreshInterval(); + const refreshInterval = getTimeFilter().getRefreshInterval(); return { isPaused: refreshInterval.pause, interval: refreshInterval.value, From be6bdd52a6e528ed618a5c08f154c4ec6a81f814 Mon Sep 17 00:00:00 2001 From: Aaron Caldwell Date: Tue, 17 Mar 2020 10:36:17 -0600 Subject: [PATCH 04/14] Pull vis color utils into Maps --- .../maps/public/layers/styles/color_utils.js | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/color_utils.js b/x-pack/legacy/plugins/maps/public/layers/styles/color_utils.js index fc305f8daed59..a619eaba21aef 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/color_utils.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/color_utils.js @@ -7,11 +7,7 @@ import React from 'react'; import tinycolor from 'tinycolor2'; import chroma from 'chroma-js'; - import { euiPaletteColorBlind } from '@elastic/eui/lib/services'; - -import { getLegendColors, getColor } from 'ui/vis/map/color_util'; - import { ColorGradient } from './components/color_gradient'; import { COLOR_PALETTE_MAX_SIZE } from '../../../common/constants'; import { vislibColorMaps } from '../../../../../../../src/plugins/charts/public'; @@ -30,6 +26,24 @@ export const DEFAULT_LINE_COLORS = [ '#FFF', ]; +function getLegendColors(colorRamp, numLegendColors = 4) { + const colors = []; + colors[0] = getColor(colorRamp, 0); + for (let i = 1; i < numLegendColors - 1; i++) { + colors[i] = getColor(colorRamp, Math.floor((colorRamp.length * i) / numLegendColors)); + } + colors[numLegendColors - 1] = getColor(colorRamp, colorRamp.length - 1); + return colors; +} + +function getColor(colorRamp, i) { + const color = colorRamp[i][1]; + const red = Math.floor(color[0] * 255); + const green = Math.floor(color[1] * 255); + const blue = Math.floor(color[2] * 255); + return `rgb(${red},${green},${blue})`; +} + function getColorRamp(colorRampName) { const colorRamp = vislibColorMaps[colorRampName]; if (!colorRamp) { From 223c8765934cab5d801ff8f3fc7ed5bad3b239fd Mon Sep 17 00:00:00 2001 From: Aaron Caldwell Date: Tue, 17 Mar 2020 10:58:36 -0600 Subject: [PATCH 05/14] Add NP dark mode and toast handling. Some fixes --- x-pack/legacy/plugins/maps/public/kibana_services.js | 4 ++++ .../layers/sources/es_search_source/load_index_settings.js | 6 +++--- .../vector/components/symbol/vector_style_icon_editor.js | 6 +++--- .../public/layers/styles/vector/vector_style_defaults.js | 4 ++-- x-pack/legacy/plugins/maps/public/plugin.ts | 2 ++ 5 files changed, 14 insertions(+), 8 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/kibana_services.js b/x-pack/legacy/plugins/maps/public/kibana_services.js index 9a53f187b4e1b..e59bbeebd02f4 100644 --- a/x-pack/legacy/plugins/maps/public/kibana_services.js +++ b/x-pack/legacy/plugins/maps/public/kibana_services.js @@ -52,6 +52,10 @@ let dataTimeFilter; export const setTimeFilter = timeFilter => (dataTimeFilter = timeFilter); export const getTimeFilter = () => dataTimeFilter; +let toast; +export const setToasts = notificationToast => (toast = notificationToast); +export const getToasts = () => toast; + export async function fetchSearchSourceAndRecordWithInspector({ searchSource, requestId, diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/load_index_settings.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/load_index_settings.js index 5723e52beacd0..811291de26d35 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/load_index_settings.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/load_index_settings.js @@ -9,8 +9,7 @@ import { DEFAULT_MAX_INNER_RESULT_WINDOW, INDEX_SETTINGS_API_PATH, } from '../../../../common/constants'; -import { getHttp } from '../../../kibana_services'; -import { toastNotifications } from 'ui/notify'; +import { getHttp, getToasts } from '../../../kibana_services'; import { i18n } from '@kbn/i18n'; let toastDisplayed = false; @@ -28,6 +27,7 @@ export async function loadIndexSettings(indexPatternTitle) { async function fetchIndexSettings(indexPatternTitle) { const http = getHttp(); + const toasts = getToasts(); try { const indexSettings = await http.fetch(`../${INDEX_SETTINGS_API_PATH}`, { method: 'GET', @@ -49,7 +49,7 @@ async function fetchIndexSettings(indexPatternTitle) { if (!toastDisplayed) { // Only show toast for first failure to avoid flooding user with warnings toastDisplayed = true; - toastNotifications.addWarning(warningMsg); + toasts.addWarning(warningMsg); } console.warn(warningMsg); return { diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/symbol/vector_style_icon_editor.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/symbol/vector_style_icon_editor.js index d5ec09f515954..36b6c1a76470c 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/symbol/vector_style_icon_editor.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/symbol/vector_style_icon_editor.js @@ -6,7 +6,7 @@ import React from 'react'; -import chrome from 'ui/chrome'; +import { getUiSettings } from '../../../../../kibana_services'; import { StylePropEditor } from '../style_prop_editor'; import { DynamicIconForm } from './dynamic_icon_form'; import { StaticIconForm } from './static_icon_form'; @@ -16,13 +16,13 @@ export function VectorStyleIconEditor(props) { const iconForm = props.styleProperty.isDynamic() ? ( ) : ( ); diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style_defaults.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style_defaults.js index 8bc397dd98b56..956390e051b82 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style_defaults.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style_defaults.js @@ -12,7 +12,7 @@ import { DEFAULT_FILL_COLORS, DEFAULT_LINE_COLORS, } from '../color_utils'; -import chrome from 'ui/chrome'; +import { getUiSettings } from '../../../kibana_services'; export const MIN_SIZE = 1; export const MAX_SIZE = 64; @@ -67,7 +67,7 @@ export function getDefaultStaticProperties(mapColors = []) { const nextFillColor = DEFAULT_FILL_COLORS[nextColorIndex]; const nextLineColor = DEFAULT_LINE_COLORS[nextColorIndex]; - const isDarkMode = chrome.getUiSettingsClient().get('theme:darkMode', false); + const isDarkMode = getUiSettings().get('theme:darkMode', false); return { [VECTOR_STYLES.ICON]: { diff --git a/x-pack/legacy/plugins/maps/public/plugin.ts b/x-pack/legacy/plugins/maps/public/plugin.ts index 3ed0e4a48ca7c..a33136753a994 100644 --- a/x-pack/legacy/plugins/maps/public/plugin.ts +++ b/x-pack/legacy/plugins/maps/public/plugin.ts @@ -19,6 +19,7 @@ import { setTimeFilter, setUiSettings, setInjectedVarFunc, + setToasts, } from './kibana_services'; import { HomePublicPluginSetup } from '../../../../../src/plugins/home/public'; import { LicensingPluginSetup } from '../../../../plugins/licensing/public'; @@ -61,6 +62,7 @@ export const bindSetupCoreAndPlugins = (core: CoreSetup, plugins: any) => { setHttp(http); setUiSettings(core.uiSettings); setInjectedVarFunc(core.injectedMetadata.getInjectedVar); + setToasts(core.notifications.toasts); }; export const bindStartCoreAndPlugins = (core: CoreStart, plugins: any) => { From 6335ab4569a1423ea553a8acb441c58b36a4fb90 Mon Sep 17 00:00:00 2001 From: Aaron Caldwell Date: Tue, 17 Mar 2020 16:53:26 -0600 Subject: [PATCH 06/14] Init autocomplete and indexPattern via normal paths --- x-pack/legacy/plugins/maps/public/kibana_services.js | 12 +++++++++--- x-pack/legacy/plugins/maps/public/plugin.ts | 4 ++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/kibana_services.js b/x-pack/legacy/plugins/maps/public/kibana_services.js index e59bbeebd02f4..77a28c3d08bf4 100644 --- a/x-pack/legacy/plugins/maps/public/kibana_services.js +++ b/x-pack/legacy/plugins/maps/public/kibana_services.js @@ -6,12 +6,18 @@ import { esFilters, search } from '../../../../../src/plugins/data/public'; const { getRequestInspectorStats, getResponseInspectorStats } = search; -import { npStart } from 'ui/new_platform'; export const SPATIAL_FILTER_TYPE = esFilters.FILTERS.SPATIAL_FILTER; export { SearchSource } from '../../../../../src/plugins/data/public'; -export const indexPatternService = npStart.plugins.data.indexPatterns; -export const autocompleteService = npStart.plugins.data.autocomplete; + +let indexPatternService; +export const setIndexPatternService = dataIndexPatterns => + (indexPatternService = dataIndexPatterns); +export const getIndexPatternService = indexPatternService; + +let autocompleteService; +export const setAutocompleteService = dataAutoComplete => (autocompleteService = dataAutoComplete); +export const getAutocompleteService = autocompleteService; let licenseId; export const setLicenseId = latestLicenseId => (licenseId = latestLicenseId); diff --git a/x-pack/legacy/plugins/maps/public/plugin.ts b/x-pack/legacy/plugins/maps/public/plugin.ts index a33136753a994..e1fe0ec24560f 100644 --- a/x-pack/legacy/plugins/maps/public/plugin.ts +++ b/x-pack/legacy/plugins/maps/public/plugin.ts @@ -20,6 +20,8 @@ import { setUiSettings, setInjectedVarFunc, setToasts, + setIndexPatternService, + setAutocompleteService, } from './kibana_services'; import { HomePublicPluginSetup } from '../../../../../src/plugins/home/public'; import { LicensingPluginSetup } from '../../../../plugins/licensing/public'; @@ -71,6 +73,8 @@ export const bindStartCoreAndPlugins = (core: CoreStart, plugins: any) => { setFileUpload(file_upload); setIndexPatternSelect(data.ui.IndexPatternSelect); setTimeFilter(data.query.timefilter.timefilter); + setIndexPatternService(data.indexPatterns); + setAutocompleteService(data.autocompleteService); }; /** @internal */ From 09557bb6b0ec5fca62f90af7ef42afacbd73632e Mon Sep 17 00:00:00 2001 From: Aaron Caldwell Date: Tue, 17 Mar 2020 16:55:49 -0600 Subject: [PATCH 07/14] Test fixes and clean up --- .../maps/public/angular/get_initial_layers.js | 4 ++-- .../public/angular/get_initial_layers.test.js | 17 +++++++++-------- .../maps/public/layers/joins/inner_join.test.js | 1 - .../maps/public/layers/sources/es_source.js | 8 ++++---- .../layers/styles/vector/vector_style.test.js | 11 +++++++++-- 5 files changed, 24 insertions(+), 17 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/angular/get_initial_layers.js b/x-pack/legacy/plugins/maps/public/angular/get_initial_layers.js index 3cae75231d28e..8fc32aef54770 100644 --- a/x-pack/legacy/plugins/maps/public/angular/get_initial_layers.js +++ b/x-pack/legacy/plugins/maps/public/angular/get_initial_layers.js @@ -6,7 +6,7 @@ import _ from 'lodash'; import { KibanaTilemapSource } from '../layers/sources/kibana_tilemap_source'; import { EMSTMSSource } from '../layers/sources/ems_tms_source'; -import chrome from 'ui/chrome'; +import { getInjectedVarFunc } from '../kibana_services'; import { getKibanaTileMap } from '../meta'; export function getInitialLayers(layerListJSON, initialLayers = []) { @@ -22,7 +22,7 @@ export function getInitialLayers(layerListJSON, initialLayers = []) { return [layer.toLayerDescriptor(), ...initialLayers]; } - const isEmsEnabled = chrome.getInjected('isEmsEnabled', true); + const isEmsEnabled = getInjectedVarFunc()('isEmsEnabled', true); if (isEmsEnabled) { const descriptor = EMSTMSSource.createDescriptor({ isAutoSelect: true }); const source = new EMSTMSSource(descriptor); diff --git a/x-pack/legacy/plugins/maps/public/angular/get_initial_layers.test.js b/x-pack/legacy/plugins/maps/public/angular/get_initial_layers.test.js index a62d46475a549..f41ed26b2a05d 100644 --- a/x-pack/legacy/plugins/maps/public/angular/get_initial_layers.test.js +++ b/x-pack/legacy/plugins/maps/public/angular/get_initial_layers.test.js @@ -7,16 +7,17 @@ jest.mock('../meta', () => { return {}; }); - -jest.mock('ui/chrome', () => { - return {}; -}); +jest.mock('../kibana_services'); import { getInitialLayers } from './get_initial_layers'; const layerListNotProvided = undefined; describe('Saved object has layer list', () => { + beforeEach(() => { + require('../kibana_services').getInjectedVarFunc = () => jest.fn(); + }); + it('Should get initial layers from saved object', () => { const layerListFromSavedObject = [ { @@ -64,7 +65,7 @@ describe('EMS is enabled', () => { require('../meta').getKibanaTileMap = () => { return null; }; - require('ui/chrome').getInjected = key => { + require('../kibana_services').getInjectedVarFunc = () => key => { switch (key) { case 'emsTileLayerId': return { @@ -75,7 +76,7 @@ describe('EMS is enabled', () => { case 'isEmsEnabled': return true; default: - throw new Error(`Unexpected call to chrome.getInjected with key ${key}`); + throw new Error(`Unexpected call to getInjectedVarFunc with key ${key}`); } }; }); @@ -109,12 +110,12 @@ describe('EMS is not enabled', () => { return null; }; - require('ui/chrome').getInjected = key => { + require('../kibana_services').getInjectedVarFunc = () => key => { switch (key) { case 'isEmsEnabled': return false; default: - throw new Error(`Unexpected call to chrome.getInjected with key ${key}`); + throw new Error(`Unexpected call to getInjectedVarFunc with key ${key}`); } }; }); diff --git a/x-pack/legacy/plugins/maps/public/layers/joins/inner_join.test.js b/x-pack/legacy/plugins/maps/public/layers/joins/inner_join.test.js index 4a91ed3a3eafb..65c37860ffa18 100644 --- a/x-pack/legacy/plugins/maps/public/layers/joins/inner_join.test.js +++ b/x-pack/legacy/plugins/maps/public/layers/joins/inner_join.test.js @@ -7,7 +7,6 @@ import { InnerJoin } from './inner_join'; jest.mock('../../kibana_services', () => {}); -jest.mock('ui/timefilter', () => {}); jest.mock('../vector_layer', () => {}); const rightSource = { diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_source.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_source.js index 46164b660a6ef..257fda2abfbfb 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_source.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_source.js @@ -6,9 +6,9 @@ import { AbstractVectorSource } from './vector_source'; import { - autocompleteService, + getAutocompleteService, fetchSearchSourceAndRecordWithInspector, - indexPatternService, + getIndexPatternService, SearchSource, getTimeFilter, } from '../../kibana_services'; @@ -196,7 +196,7 @@ export class AbstractESSource extends AbstractVectorSource { } try { - this.indexPattern = await indexPatternService.get(this._descriptor.indexPatternId); + this.indexPattern = await getIndexPatternService().get(this._descriptor.indexPatternId); return this.indexPattern; } catch (error) { throw new Error( @@ -320,7 +320,7 @@ export class AbstractESSource extends AbstractVectorSource { getValueSuggestions = async (field, query) => { try { const indexPattern = await this.getIndexPattern(); - return await autocompleteService.getValueSuggestions({ + return await getAutocompleteService().getValueSuggestions({ indexPattern, field: indexPattern.fields.getByName(field.getRootName()), query, diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.test.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.test.js index 66b7ae5e02c5f..b3f653a70f472 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.test.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.test.js @@ -9,6 +9,7 @@ import { DataRequest } from '../../util/data_request'; import { VECTOR_SHAPE_TYPES } from '../../sources/vector_feature_types'; import { FIELD_ORIGIN } from '../../../../common/constants'; +jest.mock('../../../kibana_services'); jest.mock('ui/new_platform'); class MockField { @@ -65,7 +66,13 @@ describe('getDescriptorWithMissingStylePropsRemoved', () => { }, }; - it('Should return no changes when next oridinal fields contain existing style property fields', () => { + beforeEach(() => { + require('../../../kibana_services').getUiSettings = () => ({ + get: jest.fn(), + }); + }); + + it('Should return no changes when next ordinal fields contain existing style property fields', () => { const vectorStyle = new VectorStyle({ properties }, new MockSource()); const nextFields = [new MockField({ fieldName })]; @@ -73,7 +80,7 @@ describe('getDescriptorWithMissingStylePropsRemoved', () => { expect(hasChanges).toBe(false); }); - it('Should clear missing fields when next oridinal fields do not contain existing style property fields', () => { + it('Should clear missing fields when next ordinal fields do not contain existing style property fields', () => { const vectorStyle = new VectorStyle({ properties }, new MockSource()); const nextFields = []; From bb30b0aca95837dea03a6928c564a584579942da Mon Sep 17 00:00:00 2001 From: Aaron Caldwell Date: Tue, 17 Mar 2020 17:11:38 -0600 Subject: [PATCH 08/14] Update index pattern and autocomplete refs. Make getters functions --- .../legacy/plugins/maps/public/angular/map_controller.js | 4 ++-- .../plugins/maps/public/components/geo_field_with_index.ts | 2 +- .../layer_panel/filter_editor/filter_editor.js | 4 ++-- .../layer_panel/join_editor/resources/join.js | 4 ++-- .../layer_panel/join_editor/resources/join_expression.js | 7 +++++-- .../maps/public/embeddable/map_embeddable_factory.js | 4 ++-- x-pack/legacy/plugins/maps/public/index_pattern_util.js | 4 ++-- x-pack/legacy/plugins/maps/public/kibana_services.js | 4 ++-- .../sources/es_geo_grid_source/create_source_editor.js | 4 ++-- .../sources/es_geo_grid_source/update_source_editor.js | 4 ++-- .../sources/es_pew_pew_source/create_source_editor.js | 4 ++-- .../sources/es_pew_pew_source/update_source_editor.js | 4 ++-- .../sources/es_search_source/create_source_editor.js | 4 ++-- .../sources/es_search_source/update_source_editor.js | 6 +++--- .../maps/public/layers/sources/es_term_source.test.js | 1 - 15 files changed, 31 insertions(+), 29 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/angular/map_controller.js b/x-pack/legacy/plugins/maps/public/angular/map_controller.js index fc45c0446445c..519ba0b1e3d96 100644 --- a/x-pack/legacy/plugins/maps/public/angular/map_controller.js +++ b/x-pack/legacy/plugins/maps/public/angular/map_controller.js @@ -15,7 +15,7 @@ import { i18n } from '@kbn/i18n'; import { capabilities } from 'ui/capabilities'; import { render, unmountComponentAtNode } from 'react-dom'; import { uiModules } from 'ui/modules'; -import { getTimeFilter, indexPatternService, getInspector } from '../kibana_services'; +import { getTimeFilter, getIndexPatternService, getInspector } from '../kibana_services'; import { Provider } from 'react-redux'; // eslint-disable-next-line @kbn/eslint/no-restricted-paths import { createMapStore } from '../../../../../plugins/maps/public/reducers/store'; @@ -396,7 +396,7 @@ app.controller( const indexPatterns = []; const getIndexPatternPromises = nextIndexPatternIds.map(async indexPatternId => { try { - const indexPattern = await indexPatternService.get(indexPatternId); + const indexPattern = await getIndexPatternService().get(indexPatternId); indexPatterns.push(indexPattern); } catch (err) { // unable to fetch index pattern diff --git a/x-pack/legacy/plugins/maps/public/components/geo_field_with_index.ts b/x-pack/legacy/plugins/maps/public/components/geo_field_with_index.ts index 863e0adda8fb2..3962da23bd073 100644 --- a/x-pack/legacy/plugins/maps/public/components/geo_field_with_index.ts +++ b/x-pack/legacy/plugins/maps/public/components/geo_field_with_index.ts @@ -7,7 +7,7 @@ // Maps can contain geo fields from multiple index patterns. GeoFieldWithIndex is used to: // 1) Combine the geo field along with associated index pattern state. -// 2) Package asynchronously looked up state via indexPatternService to avoid +// 2) Package asynchronously looked up state via getIndexPatternService() to avoid // PITA of looking up async state in downstream react consumers. export type GeoFieldWithIndex = { geoFieldName: string; diff --git a/x-pack/legacy/plugins/maps/public/connected_components/layer_panel/filter_editor/filter_editor.js b/x-pack/legacy/plugins/maps/public/connected_components/layer_panel/filter_editor/filter_editor.js index 94e855fc6708f..5bdba953788c7 100644 --- a/x-pack/legacy/plugins/maps/public/connected_components/layer_panel/filter_editor/filter_editor.js +++ b/x-pack/legacy/plugins/maps/public/connected_components/layer_panel/filter_editor/filter_editor.js @@ -22,7 +22,7 @@ import { import { FormattedMessage } from '@kbn/i18n/react'; import { i18n } from '@kbn/i18n'; -import { indexPatternService } from '../../../kibana_services'; +import { getIndexPatternService } from '../../../kibana_services'; import { GlobalFilterCheckbox } from '../../../components/global_filter_checkbox'; import { npStart } from 'ui/new_platform'; @@ -49,7 +49,7 @@ export class FilterEditor extends Component { const indexPatterns = []; const getIndexPatternPromises = indexPatternIds.map(async indexPatternId => { try { - const indexPattern = await indexPatternService.get(indexPatternId); + const indexPattern = await getIndexPatternService().get(indexPatternId); indexPatterns.push(indexPattern); } catch (err) { // unable to fetch index pattern diff --git a/x-pack/legacy/plugins/maps/public/connected_components/layer_panel/join_editor/resources/join.js b/x-pack/legacy/plugins/maps/public/connected_components/layer_panel/join_editor/resources/join.js index c2c9f333a675c..0df6bd40d1a31 100644 --- a/x-pack/legacy/plugins/maps/public/connected_components/layer_panel/join_editor/resources/join.js +++ b/x-pack/legacy/plugins/maps/public/connected_components/layer_panel/join_editor/resources/join.js @@ -14,7 +14,7 @@ import { WhereExpression } from './where_expression'; import { GlobalFilterCheckbox } from '../../../../components/global_filter_checkbox'; import { indexPatterns } from '../../../../../../../../../src/plugins/data/public'; -import { indexPatternService } from '../../../../kibana_services'; +import { getIndexPatternService } from '../../../../kibana_services'; export class Join extends Component { state = { @@ -39,7 +39,7 @@ export class Join extends Component { let indexPattern; try { - indexPattern = await indexPatternService.get(indexPatternId); + indexPattern = await getIndexPatternService().get(indexPatternId); } catch (err) { if (this._isMounted) { this.setState({ diff --git a/x-pack/legacy/plugins/maps/public/connected_components/layer_panel/join_editor/resources/join_expression.js b/x-pack/legacy/plugins/maps/public/connected_components/layer_panel/join_editor/resources/join_expression.js index fb77857f731b9..f7edcf6e85e25 100644 --- a/x-pack/legacy/plugins/maps/public/connected_components/layer_panel/join_editor/resources/join_expression.js +++ b/x-pack/legacy/plugins/maps/public/connected_components/layer_panel/join_editor/resources/join_expression.js @@ -19,7 +19,10 @@ import { i18n } from '@kbn/i18n'; import { SingleFieldSelect } from '../../../../components/single_field_select'; import { FormattedMessage } from '@kbn/i18n/react'; import { getTermsFields } from '../../../../index_pattern_util'; -import { indexPatternService, getIndexPatternSelectComponent } from '../../../../kibana_services'; +import { + getIndexPatternService, + getIndexPatternSelectComponent, +} from '../../../../kibana_services'; export class JoinExpression extends Component { state = { @@ -40,7 +43,7 @@ export class JoinExpression extends Component { _onRightSourceChange = async indexPatternId => { try { - const indexPattern = await indexPatternService.get(indexPatternId); + const indexPattern = await getIndexPatternService().get(indexPatternId); this.props.onRightSourceChange({ indexPatternId, indexPatternTitle: indexPattern.title, diff --git a/x-pack/legacy/plugins/maps/public/embeddable/map_embeddable_factory.js b/x-pack/legacy/plugins/maps/public/embeddable/map_embeddable_factory.js index af86e5bf7e903..fcbae894dffa4 100644 --- a/x-pack/legacy/plugins/maps/public/embeddable/map_embeddable_factory.js +++ b/x-pack/legacy/plugins/maps/public/embeddable/map_embeddable_factory.js @@ -14,7 +14,7 @@ import { } from '../../../../../../src/legacy/core_plugins/embeddable_api/public/np_ready/public'; import { setup } from '../../../../../../src/legacy/core_plugins/embeddable_api/public/np_ready/public/legacy'; import { MapEmbeddable } from './map_embeddable'; -import { indexPatternService } from '../kibana_services'; +import { getIndexPatternService } from '../kibana_services'; import { createMapPath, MAP_SAVED_OBJECT_TYPE, APP_ICON } from '../../common/constants'; // eslint-disable-next-line @kbn/eslint/no-restricted-paths @@ -78,7 +78,7 @@ export class MapEmbeddableFactory extends EmbeddableFactory { const promises = queryableIndexPatternIds.map(async indexPatternId => { try { - return await indexPatternService.get(indexPatternId); + return await getIndexPatternService().get(indexPatternId); } catch (error) { // Unable to load index pattern, better to not throw error so map embeddable can render // Error will be surfaced by map embeddable since it too will be unable to locate the index pattern diff --git a/x-pack/legacy/plugins/maps/public/index_pattern_util.js b/x-pack/legacy/plugins/maps/public/index_pattern_util.js index 7aa87ab32cdf5..30a0a6826db83 100644 --- a/x-pack/legacy/plugins/maps/public/index_pattern_util.js +++ b/x-pack/legacy/plugins/maps/public/index_pattern_util.js @@ -4,14 +4,14 @@ * you may not use this file except in compliance with the Elastic License. */ -import { indexPatternService } from './kibana_services'; +import { getIndexPatternService } from './kibana_services'; import { indexPatterns } from '../../../../../src/plugins/data/public'; import { ES_GEO_FIELD_TYPE } from '../common/constants'; export async function getIndexPatternsFromIds(indexPatternIds = []) { const promises = []; indexPatternIds.forEach(id => { - const indexPatternPromise = indexPatternService.get(id); + const indexPatternPromise = getIndexPatternService().get(id); if (indexPatternPromise) { promises.push(indexPatternPromise); } diff --git a/x-pack/legacy/plugins/maps/public/kibana_services.js b/x-pack/legacy/plugins/maps/public/kibana_services.js index 77a28c3d08bf4..3b0f501dc0f60 100644 --- a/x-pack/legacy/plugins/maps/public/kibana_services.js +++ b/x-pack/legacy/plugins/maps/public/kibana_services.js @@ -13,11 +13,11 @@ export { SearchSource } from '../../../../../src/plugins/data/public'; let indexPatternService; export const setIndexPatternService = dataIndexPatterns => (indexPatternService = dataIndexPatterns); -export const getIndexPatternService = indexPatternService; +export const getIndexPatternService = () => indexPatternService; let autocompleteService; export const setAutocompleteService = dataAutoComplete => (autocompleteService = dataAutoComplete); -export const getAutocompleteService = autocompleteService; +export const getAutocompleteService = () => autocompleteService; let licenseId; export const setLicenseId = latestLicenseId => (licenseId = latestLicenseId); diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/create_source_editor.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/create_source_editor.js index 25ef628c4589f..148683269ef78 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/create_source_editor.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/create_source_editor.js @@ -10,7 +10,7 @@ import PropTypes from 'prop-types'; import { SingleFieldSelect } from '../../../components/single_field_select'; import { RENDER_AS } from '../../../../common/constants'; -import { indexPatternService, getIndexPatternSelectComponent } from '../../../kibana_services'; +import { getIndexPatternService, getIndexPatternSelectComponent } from '../../../kibana_services'; import { NoIndexPatternCallout } from '../../../components/no_index_pattern_callout'; import { i18n } from '@kbn/i18n'; @@ -89,7 +89,7 @@ export class CreateSourceEditor extends Component { let indexPattern; try { - indexPattern = await indexPatternService.get(indexPatternId); + indexPattern = await getIndexPatternService().get(indexPatternId); } catch (err) { // index pattern no longer exists return; diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/update_source_editor.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/update_source_editor.js index 7b91e6ddb55d5..269c2a8b8633a 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/update_source_editor.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/update_source_editor.js @@ -8,7 +8,7 @@ import React, { Fragment, Component } from 'react'; import { RENDER_AS } from '../../../../common/constants'; import { MetricsEditor } from '../../../components/metrics_editor'; -import { indexPatternService } from '../../../kibana_services'; +import { getIndexPatternService } from '../../../kibana_services'; import { ResolutionEditor } from './resolution_editor'; import { i18n } from '@kbn/i18n'; import { FormattedMessage } from '@kbn/i18n/react'; @@ -33,7 +33,7 @@ export class UpdateSourceEditor extends Component { async _loadFields() { let indexPattern; try { - indexPattern = await indexPatternService.get(this.props.indexPatternId); + indexPattern = await getIndexPatternService().get(this.props.indexPatternId); } catch (err) { if (this._isMounted) { this.setState({ diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_pew_pew_source/create_source_editor.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_pew_pew_source/create_source_editor.js index 6e8d383cb0160..a4af1a3c19c83 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_pew_pew_source/create_source_editor.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_pew_pew_source/create_source_editor.js @@ -9,7 +9,7 @@ import React, { Fragment, Component } from 'react'; import PropTypes from 'prop-types'; import { SingleFieldSelect } from '../../../components/single_field_select'; -import { indexPatternService, getIndexPatternSelectComponent } from '../../../kibana_services'; +import { getIndexPatternService, getIndexPatternSelectComponent } from '../../../kibana_services'; import { i18n } from '@kbn/i18n'; import { FormattedMessage } from '@kbn/i18n/react'; @@ -70,7 +70,7 @@ export class CreateSourceEditor extends Component { let indexPattern; try { - indexPattern = await indexPatternService.get(indexPatternId); + indexPattern = await getIndexPatternService().get(indexPatternId); } catch (err) { // index pattern no longer exists return; diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_pew_pew_source/update_source_editor.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_pew_pew_source/update_source_editor.js index ff00f472e9edf..ce1f53c33ba53 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_pew_pew_source/update_source_editor.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_pew_pew_source/update_source_editor.js @@ -7,7 +7,7 @@ import React, { Component, Fragment } from 'react'; import { MetricsEditor } from '../../../components/metrics_editor'; -import { indexPatternService } from '../../../kibana_services'; +import { getIndexPatternService } from '../../../kibana_services'; import { i18n } from '@kbn/i18n'; import { EuiPanel, EuiTitle, EuiSpacer } from '@elastic/eui'; import { FormattedMessage } from '@kbn/i18n/react'; @@ -30,7 +30,7 @@ export class UpdateSourceEditor extends Component { async _loadFields() { let indexPattern; try { - indexPattern = await indexPatternService.get(this.props.indexPatternId); + indexPattern = await getIndexPatternService().get(this.props.indexPatternId); } catch (err) { if (this._isMounted) { this.setState({ diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/create_source_editor.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/create_source_editor.js index 2ac68a73e12db..895ad12f107d9 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/create_source_editor.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/create_source_editor.js @@ -11,7 +11,7 @@ import { EuiFormRow, EuiSpacer, EuiSwitch, EuiCallOut } from '@elastic/eui'; import { SingleFieldSelect } from '../../../components/single_field_select'; import { - indexPatternService, + getIndexPatternService, getIndexPatternSelectComponent, getHttp, } from '../../../kibana_services'; @@ -99,7 +99,7 @@ export class CreateSourceEditor extends Component { let indexPattern; try { - indexPattern = await indexPatternService.get(indexPatternId); + indexPattern = await getIndexPatternService().get(indexPatternId); } catch (err) { // index pattern no longer exists return; diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/update_source_editor.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/update_source_editor.js index 52702c1f4ecc7..b1fc9713f98c4 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/update_source_editor.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/update_source_editor.js @@ -18,7 +18,7 @@ import { import { SingleFieldSelect } from '../../../components/single_field_select'; import { TooltipSelector } from '../../../components/tooltip_selector'; -import { indexPatternService } from '../../../kibana_services'; +import { getIndexPatternService } from '../../../kibana_services'; import { i18n } from '@kbn/i18n'; import { getTermsFields, getSourceFields } from '../../../index_pattern_util'; import { ValidatedRange } from '../../../components/validated_range'; @@ -60,7 +60,7 @@ export class UpdateSourceEditor extends Component { async loadIndexSettings() { try { - const indexPattern = await indexPatternService.get(this.props.indexPatternId); + const indexPattern = await getIndexPatternService().get(this.props.indexPatternId); const { maxInnerResultWindow } = await loadIndexSettings(indexPattern.title); if (this._isMounted) { this.setState({ maxInnerResultWindow }); @@ -73,7 +73,7 @@ export class UpdateSourceEditor extends Component { async loadFields() { let indexPattern; try { - indexPattern = await indexPatternService.get(this.props.indexPatternId); + indexPattern = await getIndexPatternService().get(this.props.indexPatternId); } catch (err) { if (this._isMounted) { this.setState({ diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_term_source.test.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_term_source.test.js index 890b1e3aaac1f..14ffd068df465 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_term_source.test.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_term_source.test.js @@ -8,7 +8,6 @@ import { ESTermSource, extractPropertiesMap } from './es_term_source'; jest.mock('ui/new_platform'); jest.mock('../vector_layer', () => {}); -jest.mock('ui/timefilter', () => {}); const indexPatternTitle = 'myIndex'; const termFieldName = 'myTermField'; From 6bcf09546cf8c29ff389875f973e08fd393b5e80 Mon Sep 17 00:00:00 2001 From: Aaron Caldwell Date: Wed, 18 Mar 2020 08:24:30 -0600 Subject: [PATCH 09/14] Fix remaining broken jest tests --- .../sources/es_search_source/es_search_source.test.ts | 6 ++++++ .../plugins/maps/public/selectors/map_selectors.test.js | 6 +++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/es_search_source.test.ts b/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/es_search_source.test.ts index 1e10923cea1d0..26ddb2e728152 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/es_search_source.test.ts +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/es_search_source.test.ts @@ -4,6 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ jest.mock('ui/new_platform'); +jest.mock('../../../kibana_services'); import { ESSearchSource } from './es_search_source'; import { VectorLayer } from '../../vector_layer'; @@ -18,6 +19,11 @@ const descriptor: ESSearchSourceDescriptor = { }; describe('ES Search Source', () => { + beforeEach(() => { + require('../../../kibana_services').getUiSettings = () => ({ + get: jest.fn(), + }); + }); it('should create a vector layer', () => { const source = new ESSearchSource(descriptor, null); const layer = source.createDefaultLayer(); diff --git a/x-pack/legacy/plugins/maps/public/selectors/map_selectors.test.js b/x-pack/legacy/plugins/maps/public/selectors/map_selectors.test.js index 5ec40a57ebc7f..88275b04b16ff 100644 --- a/x-pack/legacy/plugins/maps/public/selectors/map_selectors.test.js +++ b/x-pack/legacy/plugins/maps/public/selectors/map_selectors.test.js @@ -14,15 +14,15 @@ jest.mock('../../../../../plugins/maps/public/reducers/non_serializable_instance return {}; }, })); -jest.mock('ui/timefilter', () => ({ - timefilter: { +jest.mock('../kibana_services', () => ({ + getTimeFilter: () => ({ getTime: () => { return { to: 'now', from: 'now-15m', }; }, - }, + }), })); import { getTimeFilters } from './map_selectors'; From a901ae9a5ed9a8a2a8c2c7a2b29d7111ce24735c Mon Sep 17 00:00:00 2001 From: Aaron Caldwell Date: Wed, 18 Mar 2020 09:32:52 -0600 Subject: [PATCH 10/14] Update inspector start contract --- x-pack/legacy/plugins/maps/public/plugin.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/plugin.ts b/x-pack/legacy/plugins/maps/public/plugin.ts index e1fe0ec24560f..69aaaf458db35 100644 --- a/x-pack/legacy/plugins/maps/public/plugin.ts +++ b/x-pack/legacy/plugins/maps/public/plugin.ts @@ -8,6 +8,7 @@ import { Plugin, CoreStart, CoreSetup } from 'src/core/public'; // @ts-ignore import { wrapInI18nContext } from 'ui/i18n'; // @ts-ignore +import { Start as InspectorStartContract } from 'src/plugins/inspector/public'; import { MapListing } from './components/map_listing'; // eslint-disable-next-line @kbn/eslint/no-restricted-paths import { @@ -27,7 +28,6 @@ import { HomePublicPluginSetup } from '../../../../../src/plugins/home/public'; import { LicensingPluginSetup } from '../../../../plugins/licensing/public'; import { featureCatalogueEntry } from './feature_catalogue_entry'; import { DataPublicPluginStart } from '../../../../../src/plugins/data/public'; -import { Start as InspectorPluginStart } from '../../../plugins/inspector/public'; /** * These are the interfaces with your public contracts. You should export these @@ -49,7 +49,7 @@ interface MapsPluginSetupDependencies { interface MapsPluginStartDependencies { np: { data: DataPublicPluginStart; - inspector: InspectorPluginStart; + inspector: InspectorStartContract; file_upload: any; // TODO: Export type from file upload and use here }; } From 43efb9c2736e21358c1db9fa9f418943cf5028a5 Mon Sep 17 00:00:00 2001 From: Aaron Caldwell Date: Wed, 18 Mar 2020 10:04:08 -0600 Subject: [PATCH 11/14] Clean up plugin and legacy files. Fix type issues --- x-pack/legacy/plugins/maps/public/legacy.ts | 6 +----- x-pack/legacy/plugins/maps/public/plugin.ts | 19 +++++++++++-------- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/legacy.ts b/x-pack/legacy/plugins/maps/public/legacy.ts index 6adab529daf86..96d9e09c1d09a 100644 --- a/x-pack/legacy/plugins/maps/public/legacy.ts +++ b/x-pack/legacy/plugins/maps/public/legacy.ts @@ -19,9 +19,5 @@ const setupPlugins = { np: npSetup.plugins, }; -const startPlugins = { - np: npStart.plugins, -}; - export const setup = pluginInstance.setup(npSetup.core, setupPlugins); -export const start = pluginInstance.start(npStart.core, startPlugins); +export const start = pluginInstance.start(npStart.core, npStart.plugins); diff --git a/x-pack/legacy/plugins/maps/public/plugin.ts b/x-pack/legacy/plugins/maps/public/plugin.ts index 69aaaf458db35..bec6564a28837 100644 --- a/x-pack/legacy/plugins/maps/public/plugin.ts +++ b/x-pack/legacy/plugins/maps/public/plugin.ts @@ -9,6 +9,7 @@ import { Plugin, CoreStart, CoreSetup } from 'src/core/public'; import { wrapInI18nContext } from 'ui/i18n'; // @ts-ignore import { Start as InspectorStartContract } from 'src/plugins/inspector/public'; +// @ts-ignore import { MapListing } from './components/map_listing'; // eslint-disable-next-line @kbn/eslint/no-restricted-paths import { @@ -23,11 +24,15 @@ import { setToasts, setIndexPatternService, setAutocompleteService, + // @ts-ignore } from './kibana_services'; import { HomePublicPluginSetup } from '../../../../../src/plugins/home/public'; import { LicensingPluginSetup } from '../../../../plugins/licensing/public'; import { featureCatalogueEntry } from './feature_catalogue_entry'; -import { DataPublicPluginStart } from '../../../../../src/plugins/data/public'; +import { + DataPublicPluginSetup, + DataPublicPluginStart, +} from '../../../../../src/plugins/data/public'; /** * These are the interfaces with your public contracts. You should export these @@ -42,16 +47,14 @@ interface MapsPluginSetupDependencies { np: { licensing?: LicensingPluginSetup; home: HomePublicPluginSetup; - data: DataPublicPluginStart; + data: DataPublicPluginSetup; }; } interface MapsPluginStartDependencies { - np: { - data: DataPublicPluginStart; - inspector: InspectorStartContract; - file_upload: any; // TODO: Export type from file upload and use here - }; + data: DataPublicPluginStart; + inspector: InspectorStartContract; + // file_upload TODO: Export type from file upload and use here } export const bindSetupCoreAndPlugins = (core: CoreSetup, plugins: any) => { @@ -92,6 +95,6 @@ export class MapsPlugin implements Plugin { } public start(core: CoreStart, plugins: MapsPluginStartDependencies) { - bindStartCoreAndPlugins(core, plugins.np); + bindStartCoreAndPlugins(core, plugins); } } From b07589b76a257a84f48b55c6f2bf50fa471fdace Mon Sep 17 00:00:00 2001 From: Aaron Caldwell Date: Wed, 18 Mar 2020 15:06:51 -0600 Subject: [PATCH 12/14] Set inspector in plugin start method not external function --- x-pack/legacy/plugins/maps/public/plugin.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/plugin.ts b/x-pack/legacy/plugins/maps/public/plugin.ts index bec6564a28837..25a9e663015a4 100644 --- a/x-pack/legacy/plugins/maps/public/plugin.ts +++ b/x-pack/legacy/plugins/maps/public/plugin.ts @@ -71,8 +71,7 @@ export const bindSetupCoreAndPlugins = (core: CoreSetup, plugins: any) => { }; export const bindStartCoreAndPlugins = (core: CoreStart, plugins: any) => { - const { inspector, file_upload, data } = plugins; - setInspector(inspector); + const { file_upload, data } = plugins; setFileUpload(file_upload); setIndexPatternSelect(data.ui.IndexPatternSelect); setTimeFilter(data.query.timefilter.timefilter); @@ -95,6 +94,7 @@ export class MapsPlugin implements Plugin { } public start(core: CoreStart, plugins: MapsPluginStartDependencies) { + setInspector(plugins.inspector); bindStartCoreAndPlugins(core, plugins); } } From db6c7f39ce1f1b9acac8389aa7c4caf903c1386b Mon Sep 17 00:00:00 2001 From: Aaron Caldwell Date: Thu, 19 Mar 2020 09:20:41 -0600 Subject: [PATCH 13/14] Keep both injected var functions (legacy and NP). Move inspector init back to separate init function --- x-pack/legacy/plugins/maps/public/plugin.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/plugin.ts b/x-pack/legacy/plugins/maps/public/plugin.ts index 25a9e663015a4..474155bf17869 100644 --- a/x-pack/legacy/plugins/maps/public/plugin.ts +++ b/x-pack/legacy/plugins/maps/public/plugin.ts @@ -26,6 +26,7 @@ import { setAutocompleteService, // @ts-ignore } from './kibana_services'; +import { setInjectedVarFunc as npSetInjectedVarFunc } from '../../../../plugins/maps/public/kibana_services'; // eslint-disable-line @kbn/eslint/no-restricted-paths import { HomePublicPluginSetup } from '../../../../../src/plugins/home/public'; import { LicensingPluginSetup } from '../../../../plugins/licensing/public'; import { featureCatalogueEntry } from './feature_catalogue_entry'; @@ -67,11 +68,13 @@ export const bindSetupCoreAndPlugins = (core: CoreSetup, plugins: any) => { setHttp(http); setUiSettings(core.uiSettings); setInjectedVarFunc(core.injectedMetadata.getInjectedVar); + npSetInjectedVarFunc(core.injectedMetadata.getInjectedVar); setToasts(core.notifications.toasts); }; export const bindStartCoreAndPlugins = (core: CoreStart, plugins: any) => { - const { file_upload, data } = plugins; + const { file_upload, data, inspector } = plugins; + setInspector(inspector); setFileUpload(file_upload); setIndexPatternSelect(data.ui.IndexPatternSelect); setTimeFilter(data.query.timefilter.timefilter); @@ -94,7 +97,6 @@ export class MapsPlugin implements Plugin { } public start(core: CoreStart, plugins: MapsPluginStartDependencies) { - setInspector(plugins.inspector); bindStartCoreAndPlugins(core, plugins); } } From b0a7e5da94bc8eb31d88b5a0151a09c9d2db89ca Mon Sep 17 00:00:00 2001 From: Aaron Caldwell Date: Thu, 19 Mar 2020 10:28:41 -0600 Subject: [PATCH 14/14] Add back ts-ignore on NP kibana services import --- x-pack/legacy/plugins/maps/public/plugin.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/x-pack/legacy/plugins/maps/public/plugin.ts b/x-pack/legacy/plugins/maps/public/plugin.ts index 474155bf17869..1f8f83e44a769 100644 --- a/x-pack/legacy/plugins/maps/public/plugin.ts +++ b/x-pack/legacy/plugins/maps/public/plugin.ts @@ -26,6 +26,7 @@ import { setAutocompleteService, // @ts-ignore } from './kibana_services'; +// @ts-ignore import { setInjectedVarFunc as npSetInjectedVarFunc } from '../../../../plugins/maps/public/kibana_services'; // eslint-disable-line @kbn/eslint/no-restricted-paths import { HomePublicPluginSetup } from '../../../../../src/plugins/home/public'; import { LicensingPluginSetup } from '../../../../plugins/licensing/public';