From 504a5726d8c56c4e0bedcbff49880578151609b7 Mon Sep 17 00:00:00 2001 From: Aaron Caldwell Date: Fri, 6 Mar 2020 12:23:27 -0700 Subject: [PATCH] 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 5702eb1c6f846f..9a53f187b4e1be 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 76ecc18f2f7d76..5a2124622694cd 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 22b10880475394..bc50890a0f4a30 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 5e4727cd7ab0c5..f1524f67b79a47 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 b7b63ce8082bcc..bfc63ef73f24f1 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 1a58b5b073b083..86266e469d0fed 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 1552db277e609e..3792f978d28898 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 e2d1d432956466..534637657fe2b4 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); } }