From fe0441e23fd62bc9c891664dcad5525a64754f8f Mon Sep 17 00:00:00 2001 From: Aaron Caldwell Date: Thu, 9 Apr 2020 14:28:19 -0600 Subject: [PATCH 01/16] Routes dependencies updated (except for routes itself) --- .../plugins/maps/public/kibana_services.d.ts | 4 ++++ .../plugins/maps/public/kibana_services.js | 19 ++++++++++++++++++ x-pack/legacy/plugins/maps/public/plugin.ts | 11 ++++++++-- .../maps/public/register_vis_type_alias.js | 4 ++-- x-pack/legacy/plugins/maps/public/routes.js | 20 +++++++++---------- 5 files changed, 44 insertions(+), 14 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/kibana_services.d.ts b/x-pack/legacy/plugins/maps/public/kibana_services.d.ts index 89b1fee1aa842..cbe7b61aa5409 100644 --- a/x-pack/legacy/plugins/maps/public/kibana_services.d.ts +++ b/x-pack/legacy/plugins/maps/public/kibana_services.d.ts @@ -21,3 +21,7 @@ export function setInjectedVarFunc(args: unknown): void; export function setToasts(args: unknown): void; export function setIndexPatternService(args: unknown): void; export function setAutocompleteService(args: unknown): void; +export function setSavedObjectsClient(args: unknown): void; +export function setRecentlyAccessed(args: unknown): void; +export function setDocTitle(args: unknown): void; +export function setSaveCapabilities(args: unknown): void; diff --git a/x-pack/legacy/plugins/maps/public/kibana_services.js b/x-pack/legacy/plugins/maps/public/kibana_services.js index a6491fe1aa6d4..4abd21d14507c 100644 --- a/x-pack/legacy/plugins/maps/public/kibana_services.js +++ b/x-pack/legacy/plugins/maps/public/kibana_services.js @@ -27,3 +27,22 @@ export const getIndexPatternSelectComponent = () => indexPatternSelectComponent; let dataTimeFilter; export const setTimeFilter = timeFilter => (dataTimeFilter = timeFilter); export const getTimeFilter = () => dataTimeFilter; + +let savedObjectsClient; +export const setSavedObjectsClient = coreSavedObjectsClient => + (savedObjectsClient = coreSavedObjectsClient); +export const getSavedObjectsClient = () => savedObjectsClient; + +let recentlyAccessed; +export const setRecentlyAccessed = coreChromeRecentlyAccessed => + (recentlyAccessed = coreChromeRecentlyAccessed); +export const getRecentlyAccessed = () => recentlyAccessed; + +let docTitle; +export const setDocTitle = coreChromeDocTitle => (docTitle = coreChromeDocTitle); +export const getDocTitle = () => docTitle; + +let mapsSaveCapabilities; +export const setSaveCapabilities = coreAppMapsSaveCapabilities => + (mapsSaveCapabilities = coreAppMapsSaveCapabilities); +export const getSaveCapabilities = () => mapsSaveCapabilities; diff --git a/x-pack/legacy/plugins/maps/public/plugin.ts b/x-pack/legacy/plugins/maps/public/plugin.ts index 0fa7e1106a6df..3562f652defdd 100644 --- a/x-pack/legacy/plugins/maps/public/plugin.ts +++ b/x-pack/legacy/plugins/maps/public/plugin.ts @@ -13,10 +13,9 @@ import '../../../../plugins/maps/public/layers/load_layer_wizards'; 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'; // @ts-ignore +import { wrapInI18nContext } from 'ui/i18n'; import { MapListing } from './components/map_listing'; // eslint-disable-next-line @kbn/eslint/no-restricted-paths import { @@ -25,6 +24,10 @@ import { setTimeFilter, setInjectedVarFunc, setIndexPatternService, + setSavedObjectsClient, + setRecentlyAccessed, + setDocTitle, + setSaveCapabilities, } from './kibana_services'; // @ts-ignore import { @@ -74,6 +77,10 @@ export const bindStartCoreAndPlugins = (core: CoreStart, plugins: any) => { setIndexPatternSelect(data.ui.IndexPatternSelect); setTimeFilter(data.query.timefilter.timefilter); setIndexPatternService(data.indexPatterns); + setSavedObjectsClient(core.savedObjects.client); + setRecentlyAccessed(core.chrome.recentlyAccessed); + setDocTitle(core.chrome.docTitle); + setSaveCapabilities(core.application.capabilities.maps.save); }; /** @internal */ diff --git a/x-pack/legacy/plugins/maps/public/register_vis_type_alias.js b/x-pack/legacy/plugins/maps/public/register_vis_type_alias.js index 64a42173098ee..903037e357bb8 100644 --- a/x-pack/legacy/plugins/maps/public/register_vis_type_alias.js +++ b/x-pack/legacy/plugins/maps/public/register_vis_type_alias.js @@ -4,12 +4,12 @@ * you may not use this file except in compliance with the Elastic License. */ -import chrome from 'ui/chrome'; import { npSetup } from '../../../../../src/legacy/ui/public/new_platform'; import { i18n } from '@kbn/i18n'; import { APP_ID, APP_ICON, MAP_BASE_URL } from '../common/constants'; +import { getInjectedVarFunc } from './kibana_services'; -const showMapVisualizationTypes = chrome.getInjected('showMapVisualizationTypes', false); +const showMapVisualizationTypes = getInjectedVarFunc()('showMapVisualizationTypes', false); const description = i18n.translate('xpack.maps.visTypeAlias.description', { defaultMessage: 'Create and style maps with multiple layers and indices.', diff --git a/x-pack/legacy/plugins/maps/public/routes.js b/x-pack/legacy/plugins/maps/public/routes.js index 49705acb417e2..7d19c4287c45b 100644 --- a/x-pack/legacy/plugins/maps/public/routes.js +++ b/x-pack/legacy/plugins/maps/public/routes.js @@ -5,13 +5,15 @@ */ import { i18n } from '@kbn/i18n'; -import { capabilities } from 'ui/capabilities'; -import chrome from 'ui/chrome'; import routes from 'ui/routes'; -import { docTitle } from 'ui/doc_title'; import listingTemplate from './angular/listing_ng_wrapper.html'; import mapTemplate from './angular/map.html'; -import { npStart } from 'ui/new_platform'; +import { + getSavedObjectsClient, + getRecentlyAccessed, + getDocTitle, + getSaveCapabilities, +} from './kibana_services'; routes.enable(); @@ -43,19 +45,17 @@ routes $scope.delete = ids => { return gisMapSavedObjectLoader.delete(ids); }; - $scope.readOnly = !capabilities.get().maps.save; + $scope.readOnly = !getSaveCapabilities(); }, resolve: { hasMaps: function(kbnUrl) { - chrome - .getSavedObjectsClient() + getSavedObjectsClient() .find({ type: 'map', perPage: 1 }) .then(resp => { // Do not show empty listing page, just redirect to a new map if (resp.savedObjects.length === 0) { kbnUrl.redirect('/map'); } - return true; }); }, @@ -83,8 +83,8 @@ routes return gisMapSavedObjectLoader .get(id) .then(savedMap => { - npStart.core.chrome.recentlyAccessed.add(savedMap.getFullPath(), savedMap.title, id); - docTitle.change(savedMap.title); + getRecentlyAccessed().add(savedMap.getFullPath(), savedMap.title, id); + getDocTitle().change(savedMap.title); return savedMap; }) .catch( From 25b586a7679b7317c28ba27fdf6c0d3a2a7e6ce1 Mon Sep 17 00:00:00 2001 From: Aaron Caldwell Date: Fri, 10 Apr 2020 15:48:16 -0600 Subject: [PATCH 02/16] Replace all chrome deps except map controller --- .../maps/public/angular/get_initial_query.js | 6 +-- .../angular/get_initial_refresh_config.js | 6 +-- .../angular/get_initial_time_filters.js | 6 +-- .../maps/public/angular/map_controller.js | 2 +- .../services/gis_map_saved_object_loader.js | 33 +++++++++----- .../maps/public/components/map_listing.js | 3 +- .../connected_components/map/mb/view.js | 4 +- .../embeddable/map_embeddable_factory.ts | 10 ++--- .../plugins/maps/public/help_menu_util.js | 8 ++-- .../plugins/maps/public/kibana_services.d.ts | 11 +++-- .../plugins/maps/public/kibana_services.js | 45 +++++++++++++------ x-pack/legacy/plugins/maps/public/plugin.ts | 26 +++++++---- .../maps/public/register_vis_type_alias.js | 7 ++- x-pack/legacy/plugins/maps/public/routes.js | 13 ++---- 14 files changed, 106 insertions(+), 74 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/angular/get_initial_query.js b/x-pack/legacy/plugins/maps/public/angular/get_initial_query.js index fc8305b252cc3..4f61142413671 100644 --- a/x-pack/legacy/plugins/maps/public/angular/get_initial_query.js +++ b/x-pack/legacy/plugins/maps/public/angular/get_initial_query.js @@ -4,11 +4,11 @@ * you may not use this file except in compliance with the Elastic License. */ -import chrome from 'ui/chrome'; - -const settings = chrome.getUiSettingsClient(); +import { getUiSettings } from '../kibana_services'; export function getInitialQuery({ mapStateJSON, appState = {}, userQueryLanguage }) { + const settings = getUiSettings(); + if (appState.query) { return appState.query; } diff --git a/x-pack/legacy/plugins/maps/public/angular/get_initial_refresh_config.js b/x-pack/legacy/plugins/maps/public/angular/get_initial_refresh_config.js index 10a2580b78e6d..0b9f0484f7a70 100644 --- a/x-pack/legacy/plugins/maps/public/angular/get_initial_refresh_config.js +++ b/x-pack/legacy/plugins/maps/public/angular/get_initial_refresh_config.js @@ -3,11 +3,11 @@ * or more contributor license agreements. Licensed under the Elastic License; * you may not use this file except in compliance with the Elastic License. */ -import chrome from 'ui/chrome'; - -const uiSettings = chrome.getUiSettingsClient(); +import { getUiSettings } from '../kibana_services'; export function getInitialRefreshConfig({ mapStateJSON, globalState = {} }) { + const uiSettings = getUiSettings(); + if (mapStateJSON) { const mapState = JSON.parse(mapStateJSON); if (mapState.refreshConfig) { diff --git a/x-pack/legacy/plugins/maps/public/angular/get_initial_time_filters.js b/x-pack/legacy/plugins/maps/public/angular/get_initial_time_filters.js index 82439175841b2..b97eae7a6d42d 100644 --- a/x-pack/legacy/plugins/maps/public/angular/get_initial_time_filters.js +++ b/x-pack/legacy/plugins/maps/public/angular/get_initial_time_filters.js @@ -3,9 +3,7 @@ * or more contributor license agreements. Licensed under the Elastic License; * you may not use this file except in compliance with the Elastic License. */ -import chrome from 'ui/chrome'; - -const uiSettings = chrome.getUiSettingsClient(); +import { getUiSettings } from '../kibana_services'; export function getInitialTimeFilters({ mapStateJSON, globalState = {} }) { if (mapStateJSON) { @@ -15,6 +13,6 @@ export function getInitialTimeFilters({ mapStateJSON, globalState = {} }) { } } - const defaultTime = uiSettings.get('timepicker:timeDefaults'); + const defaultTime = getUiSettings()('timepicker:timeDefaults'); return { ...defaultTime, ...globalState.time }; } 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 bc97643689e12..a74cdc3908cf1 100644 --- a/x-pack/legacy/plugins/maps/public/angular/map_controller.js +++ b/x-pack/legacy/plugins/maps/public/angular/map_controller.js @@ -482,7 +482,7 @@ app.controller( }; updateBreadcrumbs(); - addHelpMenuToAppChrome(chrome); + addHelpMenuToAppChrome(); async function doSave(saveOptions) { await store.dispatch(clearTransientLayerStateAndCloseFlyout()); diff --git a/x-pack/legacy/plugins/maps/public/angular/services/gis_map_saved_object_loader.js b/x-pack/legacy/plugins/maps/public/angular/services/gis_map_saved_object_loader.js index bc636c0b200f8..6e6ebbb0926d4 100644 --- a/x-pack/legacy/plugins/maps/public/angular/services/gis_map_saved_object_loader.js +++ b/x-pack/legacy/plugins/maps/public/angular/services/gis_map_saved_object_loader.js @@ -7,21 +7,30 @@ import { createSavedGisMapClass } from './saved_gis_map'; import { uiModules } from 'ui/modules'; import { SavedObjectLoader } from '../../../../../../../src/plugins/saved_objects/public'; -import { npStart } from '../../../../../../../src/legacy/ui/public/new_platform'; +import { + getCoreChrome, + getSavedObjectsClient, + getIndexPatternService, + getCoreOverlays, + getDataSearch, +} from '../../kibana_services'; -const module = uiModules.get('app/maps'); - -// This is the only thing that gets injected into controllers -module.service('gisMapSavedObjectLoader', function() { - const savedObjectsClient = npStart.core.savedObjects.client; +export function getMapsSavedObjectLoader() { const services = { - savedObjectsClient, - indexPatterns: npStart.plugins.data.indexPatterns, - search: npStart.plugins.data.search, - chrome: npStart.core.chrome, - overlays: npStart.core.overlays, + savedObjectsClient: getSavedObjectsClient(), + indexPatterns: getIndexPatternService(), + search: getDataSearch(), + chrome: getCoreChrome(), + overlays: getCoreOverlays(), }; const SavedGisMap = createSavedGisMapClass(services); - return new SavedObjectLoader(SavedGisMap, npStart.core.savedObjects.client, npStart.core.chrome); + return new SavedObjectLoader(SavedGisMap, getSavedObjectsClient(), getCoreChrome()); +} + +const module = uiModules.get('app/maps'); + +// This is the only thing that gets injected into controllers +module.service('gisMapSavedObjectLoader', function() { + return getMapsSavedObjectLoader(); }); diff --git a/x-pack/legacy/plugins/maps/public/components/map_listing.js b/x-pack/legacy/plugins/maps/public/components/map_listing.js index 6fb5930e81a20..7047146f387cf 100644 --- a/x-pack/legacy/plugins/maps/public/components/map_listing.js +++ b/x-pack/legacy/plugins/maps/public/components/map_listing.js @@ -27,7 +27,6 @@ import { import { i18n } from '@kbn/i18n'; import { FormattedMessage } from '@kbn/i18n/react'; import { addHelpMenuToAppChrome } from '../help_menu_util'; -import chrome from 'ui/chrome'; export const EMPTY_FILTER = ''; @@ -55,7 +54,7 @@ export class MapListing extends React.Component { componentDidMount() { this.fetchItems(); - addHelpMenuToAppChrome(chrome); + addHelpMenuToAppChrome(); } debouncedFetch = _.debounce(async filter => { diff --git a/x-pack/legacy/plugins/maps/public/connected_components/map/mb/view.js b/x-pack/legacy/plugins/maps/public/connected_components/map/mb/view.js index fedc1902d80a2..48f3b9e72a59e 100644 --- a/x-pack/legacy/plugins/maps/public/connected_components/map/mb/view.js +++ b/x-pack/legacy/plugins/maps/public/connected_components/map/mb/view.js @@ -18,7 +18,6 @@ import { DECIMAL_DEGREES_PRECISION, ZOOM_PRECISION } from '../../../../common/co import mapboxgl from 'mapbox-gl/dist/mapbox-gl-csp'; import mbWorkerUrl from '!!file-loader!mapbox-gl/dist/mapbox-gl-csp-worker'; import mbRtlPlugin from '!!file-loader!@mapbox/mapbox-gl-rtl-text/mapbox-gl-rtl-text.min.js'; -import chrome from 'ui/chrome'; import { spritesheet } from '@elastic/maki'; import sprites1 from '@elastic/maki/dist/sprite@1.png'; import sprites2 from '@elastic/maki/dist/sprite@2.png'; @@ -29,6 +28,7 @@ import { clampToLonBounds, // eslint-disable-next-line @kbn/eslint/no-restricted-paths } from '../../../../../../../plugins/maps/public/elasticsearch_geo_utils'; +import { getInjectedVarFunc } from '../../../kibana_services'; mapboxgl.workerUrl = mbWorkerUrl; mapboxgl.setRTLTextPlugin(mbRtlPlugin); @@ -129,7 +129,7 @@ export class MBMapContainer extends React.Component { container: this.refs.mapContainer, style: mbStyle, scrollZoom: this.props.scrollZoom, - preserveDrawingBuffer: chrome.getInjected('preserveDrawingBuffer', false), + preserveDrawingBuffer: getInjectedVarFunc('preserveDrawingBuffer', false), interactive: !this.props.disableInteractive, }; const initialView = _.get(this.props.goto, 'center'); diff --git a/x-pack/legacy/plugins/maps/public/embeddable/map_embeddable_factory.ts b/x-pack/legacy/plugins/maps/public/embeddable/map_embeddable_factory.ts index 5deb3057a449e..ab476d292488d 100644 --- a/x-pack/legacy/plugins/maps/public/embeddable/map_embeddable_factory.ts +++ b/x-pack/legacy/plugins/maps/public/embeddable/map_embeddable_factory.ts @@ -5,14 +5,13 @@ */ import _ from 'lodash'; -import chrome from 'ui/chrome'; import { capabilities } from 'ui/capabilities'; import { i18n } from '@kbn/i18n'; import { npSetup, npStart } from 'ui/new_platform'; -import { SavedObjectLoader } from 'src/plugins/saved_objects/public'; import { IIndexPattern } from 'src/plugins/data/public'; +import { getMapsSavedObjectLoader } from '../angular/services/gis_map_saved_object_loader'; import { MapEmbeddable, MapEmbeddableInput } from './map_embeddable'; -import { getIndexPatternService } from '../kibana_services'; +import { getIndexPatternService, getHttp } from '../kibana_services'; import { EmbeddableFactoryDefinition, IContainer, @@ -96,8 +95,7 @@ export class MapEmbeddableFactory implements EmbeddableFactoryDefinition { } async _fetchSavedMap(savedObjectId: string) { - const $injector = await chrome.dangerouslyGetActiveInjector(); - const savedObjectLoader = $injector.get('gisMapSavedObjectLoader'); + const savedObjectLoader = getMapsSavedObjectLoader(); return await savedObjectLoader.get(savedObjectId); } @@ -114,7 +112,7 @@ export class MapEmbeddableFactory implements EmbeddableFactoryDefinition { { layerList, title: savedMap.title, - editUrl: chrome.addBasePath(createMapPath(savedObjectId)), + editUrl: getHttp().basePath.prepend(createMapPath(savedObjectId)), indexPatterns, editable: await this.isEditable(), }, diff --git a/x-pack/legacy/plugins/maps/public/help_menu_util.js b/x-pack/legacy/plugins/maps/public/help_menu_util.js index 72d51cc180eb3..25ea96d3e7088 100644 --- a/x-pack/legacy/plugins/maps/public/help_menu_util.js +++ b/x-pack/legacy/plugins/maps/public/help_menu_util.js @@ -3,10 +3,12 @@ * or more contributor license agreements. Licensed under the Elastic License; * you may not use this file except in compliance with the Elastic License. */ -import { ELASTIC_WEBSITE_URL, DOC_LINK_VERSION } from 'ui/documentation_links'; +import { getDocLinks, getCoreChrome } from './kibana_services'; -export function addHelpMenuToAppChrome(chrome) { - chrome.helpExtension.set({ +export function addHelpMenuToAppChrome() { + const { ELASTIC_WEBSITE_URL, DOC_LINK_VERSION } = getDocLinks(); + + getCoreChrome().helpExtension.set({ appName: 'Maps', links: [ { diff --git a/x-pack/legacy/plugins/maps/public/kibana_services.d.ts b/x-pack/legacy/plugins/maps/public/kibana_services.d.ts index cbe7b61aa5409..57ecb644dc2d1 100644 --- a/x-pack/legacy/plugins/maps/public/kibana_services.d.ts +++ b/x-pack/legacy/plugins/maps/public/kibana_services.d.ts @@ -16,12 +16,15 @@ export function setFileUpload(args: unknown): void; export function setIndexPatternSelect(args: unknown): void; export function setHttp(args: unknown): void; export function setTimeFilter(args: unknown): void; -export function setUiSettings(args: unknown): void; export function setInjectedVarFunc(args: unknown): void; export function setToasts(args: unknown): void; export function setIndexPatternService(args: unknown): void; export function setAutocompleteService(args: unknown): void; export function setSavedObjectsClient(args: unknown): void; -export function setRecentlyAccessed(args: unknown): void; -export function setDocTitle(args: unknown): void; -export function setSaveCapabilities(args: unknown): void; +export function setMapsCapabilities(args: unknown): void; +export function setVisualizations(args: unknown): void; +export function setDocLinks(args: unknown): void; +export function setCoreChrome(args: unknown): void; +export function setUiSettings(args: unknown): void; +export function setCoreOverlays(args: unknown): void; +export function setDataSearch(args: unknown): void; diff --git a/x-pack/legacy/plugins/maps/public/kibana_services.js b/x-pack/legacy/plugins/maps/public/kibana_services.js index 4abd21d14507c..4197ce4cd56f4 100644 --- a/x-pack/legacy/plugins/maps/public/kibana_services.js +++ b/x-pack/legacy/plugins/maps/public/kibana_services.js @@ -33,16 +33,35 @@ export const setSavedObjectsClient = coreSavedObjectsClient => (savedObjectsClient = coreSavedObjectsClient); export const getSavedObjectsClient = () => savedObjectsClient; -let recentlyAccessed; -export const setRecentlyAccessed = coreChromeRecentlyAccessed => - (recentlyAccessed = coreChromeRecentlyAccessed); -export const getRecentlyAccessed = () => recentlyAccessed; - -let docTitle; -export const setDocTitle = coreChromeDocTitle => (docTitle = coreChromeDocTitle); -export const getDocTitle = () => docTitle; - -let mapsSaveCapabilities; -export const setSaveCapabilities = coreAppMapsSaveCapabilities => - (mapsSaveCapabilities = coreAppMapsSaveCapabilities); -export const getSaveCapabilities = () => mapsSaveCapabilities; +let chrome; +export const setCoreChrome = coreChrome => (chrome = coreChrome); +export const getCoreChrome = () => chrome; + +let mapsCapabilities; +export const setMapsCapabilities = coreAppMapsCapabilities => + (mapsCapabilities = coreAppMapsCapabilities); +export const getMapsCapabilities = () => mapsCapabilities; + +let visualizations; +export const setVisualizations = visPlugin => (visualizations = visPlugin); +export const getVisualizations = () => visualizations; + +let docLinks; +export const setDocLinks = coreDocLinks => (docLinks = coreDocLinks); +export const getDocLinks = () => docLinks; + +let uiSettings; +export const setUiSettings = coreUiSettings => (uiSettings = coreUiSettings); +export const getUiSettings = () => uiSettings; + +let overlays; +export const setCoreOverlays = coreOverlays => (overlays = coreOverlays); +export const getCoreOverlays = () => overlays; + +let search; +export const setDataSearch = dataSearch => (search = dataSearch); +export const getDataSearch = () => search; + +let coreHttp; +export const setHttp = http => (coreHttp = http); +export const getHttp = () => coreHttp; diff --git a/x-pack/legacy/plugins/maps/public/plugin.ts b/x-pack/legacy/plugins/maps/public/plugin.ts index 3562f652defdd..06798ad88adf9 100644 --- a/x-pack/legacy/plugins/maps/public/plugin.ts +++ b/x-pack/legacy/plugins/maps/public/plugin.ts @@ -25,9 +25,14 @@ import { setInjectedVarFunc, setIndexPatternService, setSavedObjectsClient, - setRecentlyAccessed, - setDocTitle, - setSaveCapabilities, + setCoreChrome, + setMapsCapabilities, + setVisualizations, + setDocLinks, + setUiSettings, + setCoreOverlays, + setDataSearch, + setHttp, } from './kibana_services'; // @ts-ignore import { @@ -66,9 +71,12 @@ interface MapsPluginStartDependencies { } export const bindSetupCoreAndPlugins = (core: CoreSetup, plugins: any) => { - const { injectedMetadata } = core; + const { injectedMetadata, uiSettings, http } = core; setInjectedVarFunc(injectedMetadata.getInjectedVar); - setInjectedVarFunc(core.injectedMetadata.getInjectedVar); + setInjectedVarFunc(injectedMetadata.getInjectedVar); + setVisualizations(plugins.visualizations); + setUiSettings(core.uiSettings); + setHttp(http); }; export const bindStartCoreAndPlugins = (core: CoreStart, plugins: any) => { @@ -78,9 +86,11 @@ export const bindStartCoreAndPlugins = (core: CoreStart, plugins: any) => { setTimeFilter(data.query.timefilter.timefilter); setIndexPatternService(data.indexPatterns); setSavedObjectsClient(core.savedObjects.client); - setRecentlyAccessed(core.chrome.recentlyAccessed); - setDocTitle(core.chrome.docTitle); - setSaveCapabilities(core.application.capabilities.maps.save); + setCoreChrome(core.chrome); + setCoreOverlays(core.overlays); + setMapsCapabilities(core.application.capabilities.maps); + setDocLinks(core.docLinks); + setDataSearch(plugins.data.search); }; /** @internal */ diff --git a/x-pack/legacy/plugins/maps/public/register_vis_type_alias.js b/x-pack/legacy/plugins/maps/public/register_vis_type_alias.js index 903037e357bb8..33f3caae9ec8d 100644 --- a/x-pack/legacy/plugins/maps/public/register_vis_type_alias.js +++ b/x-pack/legacy/plugins/maps/public/register_vis_type_alias.js @@ -4,10 +4,9 @@ * you may not use this file except in compliance with the Elastic License. */ -import { npSetup } from '../../../../../src/legacy/ui/public/new_platform'; import { i18n } from '@kbn/i18n'; import { APP_ID, APP_ICON, MAP_BASE_URL } from '../common/constants'; -import { getInjectedVarFunc } from './kibana_services'; +import { getInjectedVarFunc, getVisualizations } from './kibana_services'; const showMapVisualizationTypes = getInjectedVarFunc()('showMapVisualizationTypes', false); @@ -23,7 +22,7 @@ The Maps app offers more functionality and is easier to use.`, } ); -npSetup.plugins.visualizations.registerAlias({ +getVisualizations().registerAlias({ aliasUrl: MAP_BASE_URL, name: APP_ID, title: i18n.translate('xpack.maps.visTypeAlias.title', { @@ -37,5 +36,5 @@ npSetup.plugins.visualizations.registerAlias({ }); if (!showMapVisualizationTypes) { - npSetup.plugins.visualizations.hideTypes(['region_map', 'tile_map']); + getVisualizations().hideTypes(['region_map', 'tile_map']); } diff --git a/x-pack/legacy/plugins/maps/public/routes.js b/x-pack/legacy/plugins/maps/public/routes.js index 7d19c4287c45b..bf3b2d4dcc185 100644 --- a/x-pack/legacy/plugins/maps/public/routes.js +++ b/x-pack/legacy/plugins/maps/public/routes.js @@ -8,12 +8,7 @@ import { i18n } from '@kbn/i18n'; import routes from 'ui/routes'; import listingTemplate from './angular/listing_ng_wrapper.html'; import mapTemplate from './angular/map.html'; -import { - getSavedObjectsClient, - getRecentlyAccessed, - getDocTitle, - getSaveCapabilities, -} from './kibana_services'; +import { getSavedObjectsClient, getCoreChrome, getMapsCapabilities } from './kibana_services'; routes.enable(); @@ -45,7 +40,7 @@ routes $scope.delete = ids => { return gisMapSavedObjectLoader.delete(ids); }; - $scope.readOnly = !getSaveCapabilities(); + $scope.readOnly = !getMapsCapabilities().save; }, resolve: { hasMaps: function(kbnUrl) { @@ -83,8 +78,8 @@ routes return gisMapSavedObjectLoader .get(id) .then(savedMap => { - getRecentlyAccessed().add(savedMap.getFullPath(), savedMap.title, id); - getDocTitle().change(savedMap.title); + getCoreChrome().recentlyAccessed.add(savedMap.getFullPath(), savedMap.title, id); + getCoreChrome().docTitle.change(savedMap.title); return savedMap; }) .catch( From 30b5aa6786dca3d0e543f827ee8a4987e8db822b Mon Sep 17 00:00:00 2001 From: Aaron Caldwell Date: Mon, 13 Apr 2020 10:16:33 -0600 Subject: [PATCH 03/16] Replace npSetup and npStart with normal plugin init logic. Some clean up --- .../services/gis_map_saved_object_loader.js | 4 ++-- .../layer_panel/filter_editor/filter_editor.js | 8 +++----- .../join_editor/resources/where_expression.js | 8 +++----- .../connected_components/layer_panel/view.js | 8 +++----- .../maps/public/embeddable/map_embeddable.tsx | 4 ++-- .../plugins/maps/public/kibana_services.d.ts | 4 +++- .../legacy/plugins/maps/public/kibana_services.js | 14 +++++++++++--- x-pack/legacy/plugins/maps/public/plugin.ts | 11 +++++++---- 8 files changed, 34 insertions(+), 27 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/angular/services/gis_map_saved_object_loader.js b/x-pack/legacy/plugins/maps/public/angular/services/gis_map_saved_object_loader.js index 6e6ebbb0926d4..70d1e2e7537cb 100644 --- a/x-pack/legacy/plugins/maps/public/angular/services/gis_map_saved_object_loader.js +++ b/x-pack/legacy/plugins/maps/public/angular/services/gis_map_saved_object_loader.js @@ -12,14 +12,14 @@ import { getSavedObjectsClient, getIndexPatternService, getCoreOverlays, - getDataSearch, + getData, } from '../../kibana_services'; export function getMapsSavedObjectLoader() { const services = { savedObjectsClient: getSavedObjectsClient(), indexPatterns: getIndexPatternService(), - search: getDataSearch(), + search: getData().search, chrome: getCoreChrome(), overlays: getCoreOverlays(), }; 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 f6bcac0dfc339..fba2ec05d0b1d 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 @@ -20,12 +20,9 @@ import { import { FormattedMessage } from '@kbn/i18n/react'; import { i18n } from '@kbn/i18n'; -import { getIndexPatternService } from '../../../kibana_services'; +import { getIndexPatternService, getUiSettings, getData } from '../../../kibana_services'; import { GlobalFilterCheckbox } from '../../../components/global_filter_checkbox'; -import { npStart } from 'ui/new_platform'; -const { SearchBar } = npStart.plugins.data.ui; - export class FilterEditor extends Component { state = { isPopoverOpen: false, @@ -84,7 +81,8 @@ export class FilterEditor extends Component { _renderQueryPopover() { const layerQuery = this.props.layer.getQuery(); - const { uiSettings } = npStart.core; + const uiSettings = getUiSettings(); + const { SearchBar } = getData().ui; return ( diff --git a/x-pack/legacy/plugins/maps/public/embeddable/map_embeddable.tsx b/x-pack/legacy/plugins/maps/public/embeddable/map_embeddable.tsx index bdd2d863e6920..ab2c553c117f3 100644 --- a/x-pack/legacy/plugins/maps/public/embeddable/map_embeddable.tsx +++ b/x-pack/legacy/plugins/maps/public/embeddable/map_embeddable.tsx @@ -11,7 +11,6 @@ import { render, unmountComponentAtNode } from 'react-dom'; import 'mapbox-gl/dist/mapbox-gl.css'; import { I18nContext } from 'ui/i18n'; -import { npStart } from 'ui/new_platform'; import { Subscription } from 'rxjs'; import { Unsubscribe } from 'redux'; import { @@ -59,6 +58,7 @@ import { getMapCenter, getMapZoom, getHiddenLayerIds } from '../selectors/map_se import { MAP_SAVED_OBJECT_TYPE } from '../../common/constants'; // eslint-disable-next-line @kbn/eslint/no-restricted-paths import { RenderToolTipContent } from '../../../../../plugins/maps/public/layers/tooltips/tooltip_property'; +import { getUiActions } from '../kibana_services'; interface MapEmbeddableConfig { editUrl?: string; @@ -269,7 +269,7 @@ export class MapEmbeddable extends Embeddable { - npStart.plugins.uiActions.executeTriggerActions(APPLY_FILTER_TRIGGER, { + getUiActions().executeTriggerActions(APPLY_FILTER_TRIGGER, { embeddable: this, filters, }); diff --git a/x-pack/legacy/plugins/maps/public/kibana_services.d.ts b/x-pack/legacy/plugins/maps/public/kibana_services.d.ts index 57ecb644dc2d1..d3e3e9bb3624e 100644 --- a/x-pack/legacy/plugins/maps/public/kibana_services.d.ts +++ b/x-pack/legacy/plugins/maps/public/kibana_services.d.ts @@ -27,4 +27,6 @@ export function setDocLinks(args: unknown): void; export function setCoreChrome(args: unknown): void; export function setUiSettings(args: unknown): void; export function setCoreOverlays(args: unknown): void; -export function setDataSearch(args: unknown): void; +export function setData(args: unknown): void; +export function setUiActions(args: unknown): void; +export function setCore(args: unknown): void; diff --git a/x-pack/legacy/plugins/maps/public/kibana_services.js b/x-pack/legacy/plugins/maps/public/kibana_services.js index 4197ce4cd56f4..b2b64d81f7ac4 100644 --- a/x-pack/legacy/plugins/maps/public/kibana_services.js +++ b/x-pack/legacy/plugins/maps/public/kibana_services.js @@ -58,10 +58,18 @@ let overlays; export const setCoreOverlays = coreOverlays => (overlays = coreOverlays); export const getCoreOverlays = () => overlays; -let search; -export const setDataSearch = dataSearch => (search = dataSearch); -export const getDataSearch = () => search; +let data; +export const setData = dataPlugin => (data = dataPlugin); +export const getData = () => data; let coreHttp; export const setHttp = http => (coreHttp = http); export const getHttp = () => coreHttp; + +let uiActions; +export const setUiActions = pluginUiActions => (uiActions = pluginUiActions); +export const getUiActions = () => uiActions; + +let core; +export const setCore = kibanaCore => (core = kibanaCore); +export const getCore = () => core; diff --git a/x-pack/legacy/plugins/maps/public/plugin.ts b/x-pack/legacy/plugins/maps/public/plugin.ts index 06798ad88adf9..b47d93fa1fded 100644 --- a/x-pack/legacy/plugins/maps/public/plugin.ts +++ b/x-pack/legacy/plugins/maps/public/plugin.ts @@ -31,8 +31,10 @@ import { setDocLinks, setUiSettings, setCoreOverlays, - setDataSearch, + setData, + setCore, setHttp, + setUiActions, } from './kibana_services'; // @ts-ignore import { @@ -73,14 +75,14 @@ interface MapsPluginStartDependencies { export const bindSetupCoreAndPlugins = (core: CoreSetup, plugins: any) => { const { injectedMetadata, uiSettings, http } = core; setInjectedVarFunc(injectedMetadata.getInjectedVar); - setInjectedVarFunc(injectedMetadata.getInjectedVar); setVisualizations(plugins.visualizations); - setUiSettings(core.uiSettings); + setUiSettings(uiSettings); setHttp(http); }; export const bindStartCoreAndPlugins = (core: CoreStart, plugins: any) => { const { data, inspector } = plugins; + setCore(core); setInspector(inspector); setIndexPatternSelect(data.ui.IndexPatternSelect); setTimeFilter(data.query.timefilter.timefilter); @@ -90,7 +92,8 @@ export const bindStartCoreAndPlugins = (core: CoreStart, plugins: any) => { setCoreOverlays(core.overlays); setMapsCapabilities(core.application.capabilities.maps); setDocLinks(core.docLinks); - setDataSearch(plugins.data.search); + setData(plugins.data); + setUiActions(plugins.uiActions); }; /** @internal */ From 5c657a78fe22eb884b97c5880cd83297b6b7af6d Mon Sep 17 00:00:00 2001 From: Aaron Caldwell Date: Mon, 13 Apr 2020 10:39:27 -0600 Subject: [PATCH 04/16] Bind kibana services in map controller --- .../legacy/plugins/maps/public/angular/map_controller.js | 8 +++++++- x-pack/legacy/plugins/maps/public/help_menu_util.js | 2 +- 2 files changed, 8 insertions(+), 2 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 a74cdc3908cf1..8a091c05b8f90 100644 --- a/x-pack/legacy/plugins/maps/public/angular/map_controller.js +++ b/x-pack/legacy/plugins/maps/public/angular/map_controller.js @@ -59,13 +59,15 @@ import { getInitialQuery } from './get_initial_query'; import { getInitialTimeFilters } from './get_initial_time_filters'; import { getInitialRefreshConfig } from './get_initial_refresh_config'; import { MAP_SAVED_OBJECT_TYPE, MAP_APP_PATH } from '../../common/constants'; -import { npStart } from 'ui/new_platform'; +import { npSetup, npStart } from 'ui/new_platform'; import { esFilters } from '../../../../../../src/plugins/data/public'; import { SavedObjectSaveModal, showSaveModal, } from '../../../../../../src/plugins/saved_objects/public'; import { loadKbnTopNavDirectives } from '../../../../../../src/plugins/kibana_legacy/public'; +import { bindSetupCoreAndPlugins, bindStartCoreAndPlugins } from '../plugin'; + loadKbnTopNavDirectives(npStart.plugins.navigation.ui); const savedQueryService = npStart.plugins.data.query.savedQueries; @@ -103,6 +105,10 @@ function getInitialLayersFromUrlParam() { app.controller( 'GisMapController', ($scope, $route, kbnUrl, localStorage, AppState, globalState) => { + // Bind kibana services + bindSetupCoreAndPlugins(npSetup.core, npSetup.plugins); + bindStartCoreAndPlugins(npStart.core, npStart.plugins); + const { filterManager } = npStart.plugins.data.query; const savedMap = $route.current.locals.map; $scope.screenTitle = savedMap.title; diff --git a/x-pack/legacy/plugins/maps/public/help_menu_util.js b/x-pack/legacy/plugins/maps/public/help_menu_util.js index 25ea96d3e7088..06d7e196524b5 100644 --- a/x-pack/legacy/plugins/maps/public/help_menu_util.js +++ b/x-pack/legacy/plugins/maps/public/help_menu_util.js @@ -8,7 +8,7 @@ import { getDocLinks, getCoreChrome } from './kibana_services'; export function addHelpMenuToAppChrome() { const { ELASTIC_WEBSITE_URL, DOC_LINK_VERSION } = getDocLinks(); - getCoreChrome().helpExtension.set({ + getCoreChrome().setHelpExtension({ appName: 'Maps', links: [ { From bd9b707422e5d33cba7782c9404ed6ef105f5a25 Mon Sep 17 00:00:00 2001 From: Aaron Caldwell Date: Mon, 13 Apr 2020 11:12:03 -0600 Subject: [PATCH 05/16] Use kibana services in map controller --- .../maps/public/angular/map_controller.js | 61 +++++++++++-------- .../plugins/maps/public/kibana_services.d.ts | 2 + .../plugins/maps/public/kibana_services.js | 8 +++ x-pack/legacy/plugins/maps/public/plugin.ts | 4 ++ 4 files changed, 50 insertions(+), 25 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 8a091c05b8f90..025b65334ea5c 100644 --- a/x-pack/legacy/plugins/maps/public/angular/map_controller.js +++ b/x-pack/legacy/plugins/maps/public/angular/map_controller.js @@ -5,17 +5,26 @@ */ import _ from 'lodash'; -import chrome from 'ui/chrome'; import rison from 'rison-node'; import 'ui/directives/listen'; import 'ui/directives/storage'; import React from 'react'; import { I18nProvider } from '@kbn/i18n/react'; import { i18n } from '@kbn/i18n'; -import { capabilities } from 'ui/capabilities'; import { render, unmountComponentAtNode } from 'react-dom'; import { uiModules } from 'ui/modules'; -import { getTimeFilter, getIndexPatternService, getInspector } from '../kibana_services'; +import { + getTimeFilter, + getIndexPatternService, + getInspector, + getNavigation, + getData, + getCoreI18n, + getCoreChrome, + getMapsCapabilities, +} from '../kibana_services'; +// eslint-disable-next-line @kbn/eslint/no-restricted-paths +import { getToasts } from '../../../../../plugins/maps/public/kibana_services'; import { Provider } from 'react-redux'; // eslint-disable-next-line @kbn/eslint/no-restricted-paths import { createMapStore } from '../../../../../plugins/maps/public/reducers/store'; @@ -51,9 +60,6 @@ import { } from '../selectors/map_selectors'; // 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 { toastNotifications } from 'ui/notify'; import { getInitialLayers } from './get_initial_layers'; import { getInitialQuery } from './get_initial_query'; import { getInitialTimeFilters } from './get_initial_time_filters'; @@ -67,15 +73,23 @@ import { } from '../../../../../../src/plugins/saved_objects/public'; import { loadKbnTopNavDirectives } from '../../../../../../src/plugins/kibana_legacy/public'; import { bindSetupCoreAndPlugins, bindStartCoreAndPlugins } from '../plugin'; - -loadKbnTopNavDirectives(npStart.plugins.navigation.ui); - -const savedQueryService = npStart.plugins.data.query.savedQueries; +import { + bindSetupCoreAndPlugins as bindNpSetupCoreAndPlugins, + bindStartCoreAndPlugins as bindNpStartCoreAndPlugins, +} from '../../../../../plugins/maps/public/plugin'; // eslint-disable-line @kbn/eslint/no-restricted-paths const REACT_ANCHOR_DOM_ELEMENT_ID = 'react-maps-root'; const app = uiModules.get(MAP_APP_PATH, []); +// Init required services. Necessary while in legacy +bindSetupCoreAndPlugins(npSetup.core, npSetup.plugins); +bindNpSetupCoreAndPlugins(npSetup.core, npSetup.plugins); +bindStartCoreAndPlugins(npStart.core, npStart.plugins); +bindNpStartCoreAndPlugins(npStart.core, npStart.plugins); + +loadKbnTopNavDirectives(getNavigation().ui); + function getInitialLayersFromUrlParam() { const locationSplit = window.location.href.split('?'); if (locationSplit.length <= 1) { @@ -89,7 +103,7 @@ function getInitialLayersFromUrlParam() { try { return rison.decode_array(mapAppParams.get('initialLayers')); } catch (e) { - toastNotifications.addWarning({ + getToasts().addWarning({ title: i18n.translate('xpack.maps.initialLayers.unableToParseTitle', { defaultMessage: `Inital layers not added to map`, }), @@ -105,11 +119,8 @@ function getInitialLayersFromUrlParam() { app.controller( 'GisMapController', ($scope, $route, kbnUrl, localStorage, AppState, globalState) => { - // Bind kibana services - bindSetupCoreAndPlugins(npSetup.core, npSetup.plugins); - bindStartCoreAndPlugins(npStart.core, npStart.plugins); - - const { filterManager } = npStart.plugins.data.query; + const savedQueryService = getData().query.savedQueries; + const { filterManager } = getData().query; const savedMap = $route.current.locals.map; $scope.screenTitle = savedMap.title; let unsubscribe; @@ -175,10 +186,10 @@ app.controller( }); /* Saved Queries */ - $scope.showSaveQuery = capabilities.get().maps.saveQuery; + $scope.showSaveQuery = getMapsCapabilities().saveQuery; $scope.$watch( - () => capabilities.get().maps.saveQuery, + () => getMapsCapabilities().saveQuery, newCapability => { $scope.showSaveQuery = newCapability; } @@ -348,7 +359,7 @@ app.controller( // clear old UI state store.dispatch(setSelectedLayer(null)); store.dispatch(updateFlyout(FLYOUT_STATE.NONE)); - store.dispatch(setReadOnly(!capabilities.get().maps.save)); + store.dispatch(setReadOnly(!getMapsCapabilities().save)); handleStoreChanges(store); unsubscribe = store.subscribe(() => { @@ -463,7 +474,7 @@ app.controller( }); const updateBreadcrumbs = () => { - chrome.breadcrumbs.set([ + getCoreChrome().setBreadcrumbs([ { text: i18n.translate('xpack.maps.mapController.mapsBreadcrumbLabel', { defaultMessage: 'Maps', @@ -497,9 +508,9 @@ app.controller( try { id = await savedMap.save(saveOptions); - docTitle.change(savedMap.title); + getCoreChrome().docTitle.change(savedMap.title); } catch (err) { - toastNotifications.addDanger({ + getToasts().addDanger({ title: i18n.translate('xpack.maps.mapController.saveErrorMessage', { defaultMessage: `Error on saving '{title}'`, values: { title: savedMap.title }, @@ -511,7 +522,7 @@ app.controller( } if (id) { - toastNotifications.addSuccess({ + getToasts().addSuccess({ title: i18n.translate('xpack.maps.mapController.saveSuccessMessage', { defaultMessage: `Saved '{title}'`, values: { title: savedMap.title }, @@ -562,7 +573,7 @@ app.controller( getInspector().open(inspectorAdapters, {}); }, }, - ...(capabilities.get().maps.save + ...(getMapsCapabilities().save ? [ { id: 'save', @@ -617,7 +628,7 @@ app.controller( showDescription={false} /> ); - showSaveModal(saveModal, npStart.core.i18n.Context); + showSaveModal(saveModal, getCoreI18n().Context); }, }, ] diff --git a/x-pack/legacy/plugins/maps/public/kibana_services.d.ts b/x-pack/legacy/plugins/maps/public/kibana_services.d.ts index d3e3e9bb3624e..bf22e5077e74e 100644 --- a/x-pack/legacy/plugins/maps/public/kibana_services.d.ts +++ b/x-pack/legacy/plugins/maps/public/kibana_services.d.ts @@ -30,3 +30,5 @@ export function setCoreOverlays(args: unknown): void; export function setData(args: unknown): void; export function setUiActions(args: unknown): void; export function setCore(args: unknown): void; +export function setNavigation(args: unknown): void; +export function setCoreI18n(args: unknown): void; diff --git a/x-pack/legacy/plugins/maps/public/kibana_services.js b/x-pack/legacy/plugins/maps/public/kibana_services.js index b2b64d81f7ac4..367dfe1609edd 100644 --- a/x-pack/legacy/plugins/maps/public/kibana_services.js +++ b/x-pack/legacy/plugins/maps/public/kibana_services.js @@ -73,3 +73,11 @@ export const getUiActions = () => uiActions; let core; export const setCore = kibanaCore => (core = kibanaCore); export const getCore = () => core; + +let navigation; +export const setNavigation = pluginNavigation => (navigation = pluginNavigation); +export const getNavigation = () => navigation; + +let coreI18n; +export const setCoreI18n = kibanaCoreI18n => (coreI18n = kibanaCoreI18n); +export const getCoreI18n = () => coreI18n; diff --git a/x-pack/legacy/plugins/maps/public/plugin.ts b/x-pack/legacy/plugins/maps/public/plugin.ts index b47d93fa1fded..e2d7bb3e384ff 100644 --- a/x-pack/legacy/plugins/maps/public/plugin.ts +++ b/x-pack/legacy/plugins/maps/public/plugin.ts @@ -35,6 +35,8 @@ import { setCore, setHttp, setUiActions, + setNavigation, + setCoreI18n, } from './kibana_services'; // @ts-ignore import { @@ -94,6 +96,8 @@ export const bindStartCoreAndPlugins = (core: CoreStart, plugins: any) => { setDocLinks(core.docLinks); setData(plugins.data); setUiActions(plugins.uiActions); + setNavigation(plugins.navigation); + setCoreI18n(core.i18n); }; /** @internal */ From cd6cdd96b2d480ec4128e553628e5dd96a76d53c Mon Sep 17 00:00:00 2001 From: Aaron Caldwell Date: Mon, 13 Apr 2020 11:58:38 -0600 Subject: [PATCH 06/16] Convert remaining deps that aren't critical to legacy operation --- x-pack/legacy/plugins/maps/public/components/map_listing.js | 5 +++-- .../plugins/maps/public/connected_components/gis_map/view.js | 3 ++- .../map/features_tooltip/feature_geometry_filter_form.js | 3 ++- .../plugins/maps/public/embeddable/map_embeddable_factory.ts | 5 ++--- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/components/map_listing.js b/x-pack/legacy/plugins/maps/public/components/map_listing.js index 7047146f387cf..ef1d524cb91dd 100644 --- a/x-pack/legacy/plugins/maps/public/components/map_listing.js +++ b/x-pack/legacy/plugins/maps/public/components/map_listing.js @@ -7,7 +7,8 @@ import React from 'react'; import PropTypes from 'prop-types'; import _ from 'lodash'; -import { toastNotifications } from 'ui/notify'; +// eslint-disable-next-line @kbn/eslint/no-restricted-paths +import { getToasts } from '../../../../../plugins/maps/public/kibana_services'; import { EuiTitle, EuiFieldSearch, @@ -90,7 +91,7 @@ export class MapListing extends React.Component { try { await this.props.delete(this.state.selectedIds); } catch (error) { - toastNotifications.addDanger({ + getToasts().addDanger({ title: i18n.translate('xpack.maps.mapListing.unableToDeleteToastTitle', { defaultMessage: `Unable to delete map(s)`, }), diff --git a/x-pack/legacy/plugins/maps/public/connected_components/gis_map/view.js b/x-pack/legacy/plugins/maps/public/connected_components/gis_map/view.js index 358313b8f5b6d..06097ebea1900 100644 --- a/x-pack/legacy/plugins/maps/public/connected_components/gis_map/view.js +++ b/x-pack/legacy/plugins/maps/public/connected_components/gis_map/view.js @@ -12,7 +12,8 @@ import { ToolbarOverlay } from '../toolbar_overlay/index'; import { LayerPanel } from '../layer_panel/index'; import { AddLayerPanel } from '../layer_addpanel/index'; import { EuiFlexGroup, EuiFlexItem, EuiCallOut } from '@elastic/eui'; -import { ExitFullScreenButton } from 'ui/exit_full_screen'; +import { ExitFullScreenButton } from '../../../../../../../src/plugins/kibana_react/public'; + // eslint-disable-next-line @kbn/eslint/no-restricted-paths import { getIndexPatternsFromIds } from '../../../../../../plugins/maps/public/index_pattern_util'; import { ES_GEO_FIELD_TYPE } from '../../../common/constants'; diff --git a/x-pack/legacy/plugins/maps/public/connected_components/map/features_tooltip/feature_geometry_filter_form.js b/x-pack/legacy/plugins/maps/public/connected_components/map/features_tooltip/feature_geometry_filter_form.js index 7063c50edad6a..15824b82965e8 100644 --- a/x-pack/legacy/plugins/maps/public/connected_components/map/features_tooltip/feature_geometry_filter_form.js +++ b/x-pack/legacy/plugins/maps/public/connected_components/map/features_tooltip/feature_geometry_filter_form.js @@ -12,7 +12,8 @@ import { i18n } from '@kbn/i18n'; import { createSpatialFilterWithGeometry } from '../../../../../../../plugins/maps/public/elasticsearch_geo_utils'; import { GEO_JSON_TYPE } from '../../../../common/constants'; import { GeometryFilterForm } from '../../../components/geometry_filter_form'; -import { UrlOverflowService } from 'ui/error_url_overflow'; +// eslint-disable-next-line @kbn/eslint/no-restricted-paths +import { UrlOverflowService } from '../../../../../../../../src/plugins/kibana_legacy/public'; import rison from 'rison-node'; // over estimated and imprecise value to ensure filter has additional room for any meta keys added when filter is mapped. diff --git a/x-pack/legacy/plugins/maps/public/embeddable/map_embeddable_factory.ts b/x-pack/legacy/plugins/maps/public/embeddable/map_embeddable_factory.ts index ab476d292488d..e3add828db0a2 100644 --- a/x-pack/legacy/plugins/maps/public/embeddable/map_embeddable_factory.ts +++ b/x-pack/legacy/plugins/maps/public/embeddable/map_embeddable_factory.ts @@ -5,13 +5,12 @@ */ import _ from 'lodash'; -import { capabilities } from 'ui/capabilities'; import { i18n } from '@kbn/i18n'; import { npSetup, npStart } from 'ui/new_platform'; import { IIndexPattern } from 'src/plugins/data/public'; import { getMapsSavedObjectLoader } from '../angular/services/gis_map_saved_object_loader'; import { MapEmbeddable, MapEmbeddableInput } from './map_embeddable'; -import { getIndexPatternService, getHttp } from '../kibana_services'; +import { getIndexPatternService, getHttp, getMapsCapabilties } from '../kibana_services'; import { EmbeddableFactoryDefinition, IContainer, @@ -50,7 +49,7 @@ export class MapEmbeddableFactory implements EmbeddableFactoryDefinition { } async isEditable() { - return capabilities.get().maps.save as boolean; + return getMapsCapabilties().save as boolean; } // Not supported yet for maps types. From ca40d71ca82717cc651f2d9c9181fed2066371ee Mon Sep 17 00:00:00 2001 From: Aaron Caldwell Date: Mon, 13 Apr 2020 16:05:27 -0600 Subject: [PATCH 07/16] Remove last angular bindings to gis map saved object loader --- .../services/gis_map_saved_object_loader.js | 11 ++--------- .../public/embeddable/map_embeddable_factory.ts | 4 ++-- x-pack/legacy/plugins/maps/public/routes.js | 15 ++++++++++----- 3 files changed, 14 insertions(+), 16 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/angular/services/gis_map_saved_object_loader.js b/x-pack/legacy/plugins/maps/public/angular/services/gis_map_saved_object_loader.js index 70d1e2e7537cb..e4dccf07cc9ed 100644 --- a/x-pack/legacy/plugins/maps/public/angular/services/gis_map_saved_object_loader.js +++ b/x-pack/legacy/plugins/maps/public/angular/services/gis_map_saved_object_loader.js @@ -4,8 +4,8 @@ * you may not use this file except in compliance with the Elastic License. */ +import _ from 'lodash'; import { createSavedGisMapClass } from './saved_gis_map'; -import { uiModules } from 'ui/modules'; import { SavedObjectLoader } from '../../../../../../../src/plugins/saved_objects/public'; import { getCoreChrome, @@ -15,7 +15,7 @@ import { getData, } from '../../kibana_services'; -export function getMapsSavedObjectLoader() { +export const getMapsSavedObjectLoader = _.once(function() { const services = { savedObjectsClient: getSavedObjectsClient(), indexPatterns: getIndexPatternService(), @@ -26,11 +26,4 @@ export function getMapsSavedObjectLoader() { const SavedGisMap = createSavedGisMapClass(services); return new SavedObjectLoader(SavedGisMap, getSavedObjectsClient(), getCoreChrome()); -} - -const module = uiModules.get('app/maps'); - -// This is the only thing that gets injected into controllers -module.service('gisMapSavedObjectLoader', function() { - return getMapsSavedObjectLoader(); }); diff --git a/x-pack/legacy/plugins/maps/public/embeddable/map_embeddable_factory.ts b/x-pack/legacy/plugins/maps/public/embeddable/map_embeddable_factory.ts index e3add828db0a2..93529c165464b 100644 --- a/x-pack/legacy/plugins/maps/public/embeddable/map_embeddable_factory.ts +++ b/x-pack/legacy/plugins/maps/public/embeddable/map_embeddable_factory.ts @@ -10,7 +10,7 @@ import { npSetup, npStart } from 'ui/new_platform'; import { IIndexPattern } from 'src/plugins/data/public'; import { getMapsSavedObjectLoader } from '../angular/services/gis_map_saved_object_loader'; import { MapEmbeddable, MapEmbeddableInput } from './map_embeddable'; -import { getIndexPatternService, getHttp, getMapsCapabilties } from '../kibana_services'; +import { getIndexPatternService, getHttp, getMapsCapabilities } from '../kibana_services'; import { EmbeddableFactoryDefinition, IContainer, @@ -49,7 +49,7 @@ export class MapEmbeddableFactory implements EmbeddableFactoryDefinition { } async isEditable() { - return getMapsCapabilties().save as boolean; + return getMapsCapabilities().save as boolean; } // Not supported yet for maps types. diff --git a/x-pack/legacy/plugins/maps/public/routes.js b/x-pack/legacy/plugins/maps/public/routes.js index bf3b2d4dcc185..26d0232fc78a7 100644 --- a/x-pack/legacy/plugins/maps/public/routes.js +++ b/x-pack/legacy/plugins/maps/public/routes.js @@ -9,13 +9,14 @@ import routes from 'ui/routes'; import listingTemplate from './angular/listing_ng_wrapper.html'; import mapTemplate from './angular/map.html'; import { getSavedObjectsClient, getCoreChrome, getMapsCapabilities } from './kibana_services'; +import { getMapsSavedObjectLoader } from './angular/services/gis_map_saved_object_loader'; routes.enable(); routes .defaults(/.*/, { - badge: uiCapabilities => { - if (uiCapabilities.maps.save) { + badge: () => { + if (getMapsCapabilities().save) { return undefined; } @@ -32,7 +33,8 @@ routes }) .when('/', { template: listingTemplate, - controller($scope, gisMapSavedObjectLoader, config) { + controller($scope, config) { + const gisMapSavedObjectLoader = getMapsSavedObjectLoader(); $scope.listingLimit = config.get('savedObjects:listingLimit'); $scope.find = search => { return gisMapSavedObjectLoader.find(search, $scope.listingLimit); @@ -60,7 +62,9 @@ routes template: mapTemplate, controller: 'GisMapController', resolve: { - map: function(gisMapSavedObjectLoader, redirectWhenMissing) { + map: function(redirectWhenMissing, $scope, config) { + const gisMapSavedObjectLoader = getMapsSavedObjectLoader(); + $scope.listingLimit = config.get('savedObjects:listingLimit'); return gisMapSavedObjectLoader.get().catch( redirectWhenMissing({ map: '/', @@ -73,7 +77,8 @@ routes template: mapTemplate, controller: 'GisMapController', resolve: { - map: function(gisMapSavedObjectLoader, redirectWhenMissing, $route) { + map: function(redirectWhenMissing, $route) { + const gisMapSavedObjectLoader = getMapsSavedObjectLoader(); const id = $route.current.params.id; return gisMapSavedObjectLoader .get(id) From 4e3ed3a4ff82f90ed96c82add8d5c8bef5ff6788 Mon Sep 17 00:00:00 2001 From: Aaron Caldwell Date: Tue, 14 Apr 2020 08:27:00 -0600 Subject: [PATCH 08/16] Consolidate kibana services in NP --- .../maps/public/angular/get_initial_layers.js | 3 +- .../public/angular/get_initial_layers.test.js | 7 +- .../maps/public/angular/get_initial_query.js | 3 +- .../angular/get_initial_refresh_config.js | 3 +- .../angular/get_initial_time_filters.js | 3 +- .../maps/public/angular/map_controller.js | 11 +-- .../services/gis_map_saved_object_loader.js | 3 +- .../filter_editor/filter_editor.js | 7 +- .../layer_panel/join_editor/resources/join.js | 3 +- .../join_editor/resources/join_expression.js | 3 +- .../join_editor/resources/where_expression.js | 6 +- .../connected_components/layer_panel/view.js | 3 +- .../connected_components/map/mb/view.js | 3 +- .../maps/public/embeddable/map_embeddable.tsx | 3 +- .../embeddable/map_embeddable_factory.ts | 10 ++- .../plugins/maps/public/help_menu_util.js | 3 +- x-pack/legacy/plugins/maps/public/index.ts | 3 +- .../plugins/maps/public/kibana_services.js | 83 ------------------- x-pack/legacy/plugins/maps/public/plugin.ts | 49 ----------- .../maps/public/register_vis_type_alias.js | 6 +- x-pack/legacy/plugins/maps/public/routes.js | 9 +- .../maps/public/selectors/map_selectors.js | 3 +- .../plugins/maps/public/kibana_services.d.ts | 0 x-pack/plugins/maps/public/kibana_services.js | 46 ++++++++++ x-pack/plugins/maps/public/plugin.ts | 30 ++++++- 25 files changed, 136 insertions(+), 167 deletions(-) delete mode 100644 x-pack/legacy/plugins/maps/public/kibana_services.js rename x-pack/{legacy => }/plugins/maps/public/kibana_services.d.ts (100%) 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 5e497ff0736b2..ed2230eef6b95 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 @@ -8,7 +8,8 @@ import _ from 'lodash'; import { KibanaTilemapSource } from '../../../../../plugins/maps/public/layers/sources/kibana_tilemap_source'; // eslint-disable-next-line @kbn/eslint/no-restricted-paths import { EMSTMSSource } from '../../../../../plugins/maps/public/layers/sources/ems_tms_source'; -import { getInjectedVarFunc } from '../kibana_services'; +// eslint-disable-next-line @kbn/eslint/no-restricted-paths +import { getInjectedVarFunc } from '../../../../../plugins/maps/public/kibana_services'; // eslint-disable-next-line @kbn/eslint/no-restricted-paths import { getKibanaTileMap } from '../../../../../plugins/maps/public/meta'; 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 5334beaaf714a..b3cacf03f2fe9 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 @@ -15,7 +15,8 @@ const layerListNotProvided = undefined; describe('Saved object has layer list', () => { beforeEach(() => { - require('../kibana_services').getInjectedVarFunc = () => jest.fn(); + require('../../../../../plugins/maps/public/kibana_services').getInjectedVarFunc = () => + jest.fn(); }); it('Should get initial layers from saved object', () => { @@ -65,7 +66,7 @@ describe('EMS is enabled', () => { require('../../../../../plugins/maps/public/meta').getKibanaTileMap = () => { return null; }; - require('../kibana_services').getInjectedVarFunc = () => key => { + require('../../../../../plugins/maps/public/kibana_services').getInjectedVarFunc = () => key => { switch (key) { case 'emsTileLayerId': return { @@ -110,7 +111,7 @@ describe('EMS is not enabled', () => { return null; }; - require('../kibana_services').getInjectedVarFunc = () => key => { + require('../../../../../plugins/maps/public/kibana_services').getInjectedVarFunc = () => key => { switch (key) { case 'isEmsEnabled': return false; diff --git a/x-pack/legacy/plugins/maps/public/angular/get_initial_query.js b/x-pack/legacy/plugins/maps/public/angular/get_initial_query.js index 4f61142413671..c50ecb2b05dc0 100644 --- a/x-pack/legacy/plugins/maps/public/angular/get_initial_query.js +++ b/x-pack/legacy/plugins/maps/public/angular/get_initial_query.js @@ -4,7 +4,8 @@ * you may not use this file except in compliance with the Elastic License. */ -import { getUiSettings } from '../kibana_services'; +// eslint-disable-next-line @kbn/eslint/no-restricted-paths +import { getUiSettings } from '../../../../../plugins/maps/public/kibana_services'; export function getInitialQuery({ mapStateJSON, appState = {}, userQueryLanguage }) { const settings = getUiSettings(); diff --git a/x-pack/legacy/plugins/maps/public/angular/get_initial_refresh_config.js b/x-pack/legacy/plugins/maps/public/angular/get_initial_refresh_config.js index 0b9f0484f7a70..8735d45debfc4 100644 --- a/x-pack/legacy/plugins/maps/public/angular/get_initial_refresh_config.js +++ b/x-pack/legacy/plugins/maps/public/angular/get_initial_refresh_config.js @@ -3,7 +3,8 @@ * or more contributor license agreements. Licensed under the Elastic License; * you may not use this file except in compliance with the Elastic License. */ -import { getUiSettings } from '../kibana_services'; +// eslint-disable-next-line @kbn/eslint/no-restricted-paths +import { getUiSettings } from '../../../../../plugins/maps/public/kibana_services'; export function getInitialRefreshConfig({ mapStateJSON, globalState = {} }) { const uiSettings = getUiSettings(); diff --git a/x-pack/legacy/plugins/maps/public/angular/get_initial_time_filters.js b/x-pack/legacy/plugins/maps/public/angular/get_initial_time_filters.js index b97eae7a6d42d..4cdacf3a7b50f 100644 --- a/x-pack/legacy/plugins/maps/public/angular/get_initial_time_filters.js +++ b/x-pack/legacy/plugins/maps/public/angular/get_initial_time_filters.js @@ -3,7 +3,8 @@ * or more contributor license agreements. Licensed under the Elastic License; * you may not use this file except in compliance with the Elastic License. */ -import { getUiSettings } from '../kibana_services'; +// eslint-disable-next-line @kbn/eslint/no-restricted-paths +import { getUiSettings } from '../../../../../plugins/maps/public/kibana_services'; export function getInitialTimeFilters({ mapStateJSON, globalState = {} }) { if (mapStateJSON) { 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 025b65334ea5c..37f1edefd8719 100644 --- a/x-pack/legacy/plugins/maps/public/angular/map_controller.js +++ b/x-pack/legacy/plugins/maps/public/angular/map_controller.js @@ -22,12 +22,12 @@ import { getCoreI18n, getCoreChrome, getMapsCapabilities, -} from '../kibana_services'; -// eslint-disable-next-line @kbn/eslint/no-restricted-paths -import { getToasts } from '../../../../../plugins/maps/public/kibana_services'; -import { Provider } from 'react-redux'; + getToasts, + // eslint-disable-next-line @kbn/eslint/no-restricted-paths +} from '../../../../../plugins/maps/public/kibana_services'; // eslint-disable-next-line @kbn/eslint/no-restricted-paths import { createMapStore } from '../../../../../plugins/maps/public/reducers/store'; +import { Provider } from 'react-redux'; import { GisMap } from '../connected_components/gis_map'; import { addHelpMenuToAppChrome } from '../help_menu_util'; import { @@ -72,7 +72,6 @@ import { showSaveModal, } from '../../../../../../src/plugins/saved_objects/public'; import { loadKbnTopNavDirectives } from '../../../../../../src/plugins/kibana_legacy/public'; -import { bindSetupCoreAndPlugins, bindStartCoreAndPlugins } from '../plugin'; import { bindSetupCoreAndPlugins as bindNpSetupCoreAndPlugins, bindStartCoreAndPlugins as bindNpStartCoreAndPlugins, @@ -83,9 +82,7 @@ const REACT_ANCHOR_DOM_ELEMENT_ID = 'react-maps-root'; const app = uiModules.get(MAP_APP_PATH, []); // Init required services. Necessary while in legacy -bindSetupCoreAndPlugins(npSetup.core, npSetup.plugins); bindNpSetupCoreAndPlugins(npSetup.core, npSetup.plugins); -bindStartCoreAndPlugins(npStart.core, npStart.plugins); bindNpStartCoreAndPlugins(npStart.core, npStart.plugins); loadKbnTopNavDirectives(getNavigation().ui); diff --git a/x-pack/legacy/plugins/maps/public/angular/services/gis_map_saved_object_loader.js b/x-pack/legacy/plugins/maps/public/angular/services/gis_map_saved_object_loader.js index e4dccf07cc9ed..710997a9c0d7f 100644 --- a/x-pack/legacy/plugins/maps/public/angular/services/gis_map_saved_object_loader.js +++ b/x-pack/legacy/plugins/maps/public/angular/services/gis_map_saved_object_loader.js @@ -13,7 +13,8 @@ import { getIndexPatternService, getCoreOverlays, getData, -} from '../../kibana_services'; + // eslint-disable-next-line @kbn/eslint/no-restricted-paths +} from '../../../../../../plugins/maps/public/kibana_services'; export const getMapsSavedObjectLoader = _.once(function() { const services = { 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 fba2ec05d0b1d..40fdac38493d4 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 @@ -20,7 +20,12 @@ import { import { FormattedMessage } from '@kbn/i18n/react'; import { i18n } from '@kbn/i18n'; -import { getIndexPatternService, getUiSettings, getData } from '../../../kibana_services'; +import { + getIndexPatternService, + getUiSettings, + getData, + // eslint-disable-next-line @kbn/eslint/no-restricted-paths +} from '../../../../../../../plugins/maps/public/kibana_services'; import { GlobalFilterCheckbox } from '../../../components/global_filter_checkbox'; export class FilterEditor extends Component { 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 0df6bd40d1a31..9c4e1cfdb5467 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,8 @@ import { WhereExpression } from './where_expression'; import { GlobalFilterCheckbox } from '../../../../components/global_filter_checkbox'; import { indexPatterns } from '../../../../../../../../../src/plugins/data/public'; -import { getIndexPatternService } from '../../../../kibana_services'; +// eslint-disable-next-line @kbn/eslint/no-restricted-paths +import { getIndexPatternService } from '../../../../../../../../plugins/maps/public/kibana_services'; export class Join extends Component { state = { 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 6c080ace4442a..73600c81d221e 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 @@ -24,7 +24,8 @@ import { getTermsFields } from '../../../../../../../../plugins/maps/public/inde import { getIndexPatternService, getIndexPatternSelectComponent, -} from '../../../../kibana_services'; + // eslint-disable-next-line @kbn/eslint/no-restricted-paths +} from '../../../../../../../../plugins/maps/public/kibana_services'; export class JoinExpression extends Component { state = { diff --git a/x-pack/legacy/plugins/maps/public/connected_components/layer_panel/join_editor/resources/where_expression.js b/x-pack/legacy/plugins/maps/public/connected_components/layer_panel/join_editor/resources/where_expression.js index 7c9b4f7b7b9a4..54ec0ac46fa3d 100644 --- a/x-pack/legacy/plugins/maps/public/connected_components/layer_panel/join_editor/resources/where_expression.js +++ b/x-pack/legacy/plugins/maps/public/connected_components/layer_panel/join_editor/resources/where_expression.js @@ -8,7 +8,11 @@ import React, { Component } from 'react'; import { i18n } from '@kbn/i18n'; import { EuiButton, EuiPopover, EuiExpression, EuiFormHelpText } from '@elastic/eui'; import { FormattedMessage } from '@kbn/i18n/react'; -import { getUiSettings, getData } from '../../../../kibana_services'; +import { + getUiSettings, + getData, + // eslint-disable-next-line @kbn/eslint/no-restricted-paths +} from '../../../../../../../../plugins/maps/public/kibana_services'; export class WhereExpression extends Component { state = { diff --git a/x-pack/legacy/plugins/maps/public/connected_components/layer_panel/view.js b/x-pack/legacy/plugins/maps/public/connected_components/layer_panel/view.js index c893b8d719285..2521318f0b3c9 100644 --- a/x-pack/legacy/plugins/maps/public/connected_components/layer_panel/view.js +++ b/x-pack/legacy/plugins/maps/public/connected_components/layer_panel/view.js @@ -30,7 +30,8 @@ import { i18n } from '@kbn/i18n'; import { FormattedMessage } from '@kbn/i18n/react'; import { KibanaContextProvider } from '../../../../../../../src/plugins/kibana_react/public'; import { Storage } from '../../../../../../../src/plugins/kibana_utils/public'; -import { getData, getCore } from '../../kibana_services'; +// eslint-disable-next-line @kbn/eslint/no-restricted-paths +import { getData, getCore } from '../../../../../../plugins/maps/public/kibana_services'; const localStorage = new Storage(window.localStorage); diff --git a/x-pack/legacy/plugins/maps/public/connected_components/map/mb/view.js b/x-pack/legacy/plugins/maps/public/connected_components/map/mb/view.js index 48f3b9e72a59e..3112024898f45 100644 --- a/x-pack/legacy/plugins/maps/public/connected_components/map/mb/view.js +++ b/x-pack/legacy/plugins/maps/public/connected_components/map/mb/view.js @@ -28,7 +28,8 @@ import { clampToLonBounds, // eslint-disable-next-line @kbn/eslint/no-restricted-paths } from '../../../../../../../plugins/maps/public/elasticsearch_geo_utils'; -import { getInjectedVarFunc } from '../../../kibana_services'; +// eslint-disable-next-line @kbn/eslint/no-restricted-paths +import { getInjectedVarFunc } from '../../../../../../../plugins/maps/public/kibana_services'; mapboxgl.workerUrl = mbWorkerUrl; mapboxgl.setRTLTextPlugin(mbRtlPlugin); diff --git a/x-pack/legacy/plugins/maps/public/embeddable/map_embeddable.tsx b/x-pack/legacy/plugins/maps/public/embeddable/map_embeddable.tsx index ab2c553c117f3..b8e4c84ad56a1 100644 --- a/x-pack/legacy/plugins/maps/public/embeddable/map_embeddable.tsx +++ b/x-pack/legacy/plugins/maps/public/embeddable/map_embeddable.tsx @@ -58,7 +58,8 @@ import { getMapCenter, getMapZoom, getHiddenLayerIds } from '../selectors/map_se import { MAP_SAVED_OBJECT_TYPE } from '../../common/constants'; // eslint-disable-next-line @kbn/eslint/no-restricted-paths import { RenderToolTipContent } from '../../../../../plugins/maps/public/layers/tooltips/tooltip_property'; -import { getUiActions } from '../kibana_services'; +// eslint-disable-next-line @kbn/eslint/no-restricted-paths +import { getUiActions } from '../../../../../plugins/maps/public/kibana_services'; interface MapEmbeddableConfig { editUrl?: string; diff --git a/x-pack/legacy/plugins/maps/public/embeddable/map_embeddable_factory.ts b/x-pack/legacy/plugins/maps/public/embeddable/map_embeddable_factory.ts index 93529c165464b..1b219c614c88b 100644 --- a/x-pack/legacy/plugins/maps/public/embeddable/map_embeddable_factory.ts +++ b/x-pack/legacy/plugins/maps/public/embeddable/map_embeddable_factory.ts @@ -10,7 +10,12 @@ import { npSetup, npStart } from 'ui/new_platform'; import { IIndexPattern } from 'src/plugins/data/public'; import { getMapsSavedObjectLoader } from '../angular/services/gis_map_saved_object_loader'; import { MapEmbeddable, MapEmbeddableInput } from './map_embeddable'; -import { getIndexPatternService, getHttp, getMapsCapabilities } from '../kibana_services'; +import { + getIndexPatternService, + getHttp, + getMapsCapabilities, + // eslint-disable-next-line @kbn/eslint/no-restricted-paths +} from '../../../../../plugins/maps/public/kibana_services'; import { EmbeddableFactoryDefinition, IContainer, @@ -24,7 +29,6 @@ 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, bindStartCoreAndPlugins } from '../plugin'; // @ts-ignore import { bindSetupCoreAndPlugins as bindNpSetupCoreAndPlugins, @@ -42,9 +46,7 @@ export class MapEmbeddableFactory implements EmbeddableFactoryDefinition { }; constructor() { // Init required services. Necessary while in legacy - bindSetupCoreAndPlugins(npSetup.core, npSetup.plugins); bindNpSetupCoreAndPlugins(npSetup.core, npSetup.plugins); - bindStartCoreAndPlugins(npStart.core, npStart.plugins); bindNpStartCoreAndPlugins(npStart.core, npStart.plugins); } diff --git a/x-pack/legacy/plugins/maps/public/help_menu_util.js b/x-pack/legacy/plugins/maps/public/help_menu_util.js index 06d7e196524b5..70b9340b562cd 100644 --- a/x-pack/legacy/plugins/maps/public/help_menu_util.js +++ b/x-pack/legacy/plugins/maps/public/help_menu_util.js @@ -3,7 +3,8 @@ * or more contributor license agreements. Licensed under the Elastic License; * you may not use this file except in compliance with the Elastic License. */ -import { getDocLinks, getCoreChrome } from './kibana_services'; +// eslint-disable-next-line @kbn/eslint/no-restricted-paths +import { getDocLinks, getCoreChrome } from '../../../../plugins/maps/public/kibana_services'; export function addHelpMenuToAppChrome() { const { ELASTIC_WEBSITE_URL, DOC_LINK_VERSION } = getDocLinks(); diff --git a/x-pack/legacy/plugins/maps/public/index.ts b/x-pack/legacy/plugins/maps/public/index.ts index b69485e251be4..8555594e909d3 100644 --- a/x-pack/legacy/plugins/maps/public/index.ts +++ b/x-pack/legacy/plugins/maps/public/index.ts @@ -4,7 +4,8 @@ * you may not use this file except in compliance with the Elastic License. */ -import './kibana_services'; +// eslint-disable-next-line @kbn/eslint/no-restricted-paths +import '../../../../plugins/maps/public/kibana_services'; // import the uiExports that we want to "use" import 'uiExports/inspectorViews'; diff --git a/x-pack/legacy/plugins/maps/public/kibana_services.js b/x-pack/legacy/plugins/maps/public/kibana_services.js deleted file mode 100644 index 367dfe1609edd..0000000000000 --- a/x-pack/legacy/plugins/maps/public/kibana_services.js +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - -let indexPatternService; -export const setIndexPatternService = dataIndexPatterns => - (indexPatternService = dataIndexPatterns); -export const getIndexPatternService = () => indexPatternService; - -let inspector; -export const setInspector = newInspector => (inspector = newInspector); -export const getInspector = () => { - return inspector; -}; - -let getInjectedVar; -export const setInjectedVarFunc = getInjectedVarFunc => (getInjectedVar = getInjectedVarFunc); -export const getInjectedVarFunc = () => getInjectedVar; - -let indexPatternSelectComponent; -export const setIndexPatternSelect = indexPatternSelect => - (indexPatternSelectComponent = indexPatternSelect); -export const getIndexPatternSelectComponent = () => indexPatternSelectComponent; - -let dataTimeFilter; -export const setTimeFilter = timeFilter => (dataTimeFilter = timeFilter); -export const getTimeFilter = () => dataTimeFilter; - -let savedObjectsClient; -export const setSavedObjectsClient = coreSavedObjectsClient => - (savedObjectsClient = coreSavedObjectsClient); -export const getSavedObjectsClient = () => savedObjectsClient; - -let chrome; -export const setCoreChrome = coreChrome => (chrome = coreChrome); -export const getCoreChrome = () => chrome; - -let mapsCapabilities; -export const setMapsCapabilities = coreAppMapsCapabilities => - (mapsCapabilities = coreAppMapsCapabilities); -export const getMapsCapabilities = () => mapsCapabilities; - -let visualizations; -export const setVisualizations = visPlugin => (visualizations = visPlugin); -export const getVisualizations = () => visualizations; - -let docLinks; -export const setDocLinks = coreDocLinks => (docLinks = coreDocLinks); -export const getDocLinks = () => docLinks; - -let uiSettings; -export const setUiSettings = coreUiSettings => (uiSettings = coreUiSettings); -export const getUiSettings = () => uiSettings; - -let overlays; -export const setCoreOverlays = coreOverlays => (overlays = coreOverlays); -export const getCoreOverlays = () => overlays; - -let data; -export const setData = dataPlugin => (data = dataPlugin); -export const getData = () => data; - -let coreHttp; -export const setHttp = http => (coreHttp = http); -export const getHttp = () => coreHttp; - -let uiActions; -export const setUiActions = pluginUiActions => (uiActions = pluginUiActions); -export const getUiActions = () => uiActions; - -let core; -export const setCore = kibanaCore => (core = kibanaCore); -export const getCore = () => core; - -let navigation; -export const setNavigation = pluginNavigation => (navigation = pluginNavigation); -export const getNavigation = () => navigation; - -let coreI18n; -export const setCoreI18n = kibanaCoreI18n => (coreI18n = kibanaCoreI18n); -export const getCoreI18n = () => coreI18n; diff --git a/x-pack/legacy/plugins/maps/public/plugin.ts b/x-pack/legacy/plugins/maps/public/plugin.ts index e2d7bb3e384ff..4edfa75643d6e 100644 --- a/x-pack/legacy/plugins/maps/public/plugin.ts +++ b/x-pack/legacy/plugins/maps/public/plugin.ts @@ -17,27 +17,6 @@ import { Start as InspectorStartContract } from 'src/plugins/inspector/public'; // @ts-ignore import { wrapInI18nContext } from 'ui/i18n'; import { MapListing } from './components/map_listing'; -// eslint-disable-next-line @kbn/eslint/no-restricted-paths -import { - setInspector, - setIndexPatternSelect, - setTimeFilter, - setInjectedVarFunc, - setIndexPatternService, - setSavedObjectsClient, - setCoreChrome, - setMapsCapabilities, - setVisualizations, - setDocLinks, - setUiSettings, - setCoreOverlays, - setData, - setCore, - setHttp, - setUiActions, - setNavigation, - setCoreI18n, -} from './kibana_services'; // @ts-ignore import { bindSetupCoreAndPlugins as bindNpSetupCoreAndPlugins, @@ -74,32 +53,6 @@ interface MapsPluginStartDependencies { // file_upload TODO: Export type from file upload and use here } -export const bindSetupCoreAndPlugins = (core: CoreSetup, plugins: any) => { - const { injectedMetadata, uiSettings, http } = core; - setInjectedVarFunc(injectedMetadata.getInjectedVar); - setVisualizations(plugins.visualizations); - setUiSettings(uiSettings); - setHttp(http); -}; - -export const bindStartCoreAndPlugins = (core: CoreStart, plugins: any) => { - const { data, inspector } = plugins; - setCore(core); - setInspector(inspector); - setIndexPatternSelect(data.ui.IndexPatternSelect); - setTimeFilter(data.query.timefilter.timefilter); - setIndexPatternService(data.indexPatterns); - setSavedObjectsClient(core.savedObjects.client); - setCoreChrome(core.chrome); - setCoreOverlays(core.overlays); - setMapsCapabilities(core.application.capabilities.maps); - setDocLinks(core.docLinks); - setData(plugins.data); - setUiActions(plugins.uiActions); - setNavigation(plugins.navigation); - setCoreI18n(core.i18n); -}; - /** @internal */ export class MapsPlugin implements Plugin { public setup(core: CoreSetup, { __LEGACY: { uiModules }, np }: MapsPluginSetupDependencies) { @@ -109,14 +62,12 @@ export class MapsPlugin implements Plugin { return reactDirective(wrapInI18nContext(MapListing)); }); - bindSetupCoreAndPlugins(core, np); bindNpSetupCoreAndPlugins(core, np); np.home.featureCatalogue.register(featureCatalogueEntry); } public start(core: CoreStart, plugins: MapsPluginStartDependencies) { - bindStartCoreAndPlugins(core, plugins); bindNpStartCoreAndPlugins(core, plugins); } } diff --git a/x-pack/legacy/plugins/maps/public/register_vis_type_alias.js b/x-pack/legacy/plugins/maps/public/register_vis_type_alias.js index 33f3caae9ec8d..f6e55700afe13 100644 --- a/x-pack/legacy/plugins/maps/public/register_vis_type_alias.js +++ b/x-pack/legacy/plugins/maps/public/register_vis_type_alias.js @@ -6,7 +6,11 @@ import { i18n } from '@kbn/i18n'; import { APP_ID, APP_ICON, MAP_BASE_URL } from '../common/constants'; -import { getInjectedVarFunc, getVisualizations } from './kibana_services'; +import { + getInjectedVarFunc, + getVisualizations, + // eslint-disable-next-line @kbn/eslint/no-restricted-paths +} from '../../../../plugins/maps/public/kibana_services'; const showMapVisualizationTypes = getInjectedVarFunc()('showMapVisualizationTypes', false); diff --git a/x-pack/legacy/plugins/maps/public/routes.js b/x-pack/legacy/plugins/maps/public/routes.js index 26d0232fc78a7..f85d5dfc75fda 100644 --- a/x-pack/legacy/plugins/maps/public/routes.js +++ b/x-pack/legacy/plugins/maps/public/routes.js @@ -8,7 +8,12 @@ import { i18n } from '@kbn/i18n'; import routes from 'ui/routes'; import listingTemplate from './angular/listing_ng_wrapper.html'; import mapTemplate from './angular/map.html'; -import { getSavedObjectsClient, getCoreChrome, getMapsCapabilities } from './kibana_services'; +import { + getSavedObjectsClient, + getCoreChrome, + getMapsCapabilities, + // eslint-disable-next-line @kbn/eslint/no-restricted-paths +} from '../../../../plugins/maps/public/kibana_services'; import { getMapsSavedObjectLoader } from './angular/services/gis_map_saved_object_loader'; routes.enable(); @@ -63,7 +68,9 @@ routes controller: 'GisMapController', resolve: { map: function(redirectWhenMissing, $scope, config) { + console.log($scope, config); const gisMapSavedObjectLoader = getMapsSavedObjectLoader(); + console.log(gisMapSavedObjectLoader); $scope.listingLimit = config.get('savedObjects:listingLimit'); return gisMapSavedObjectLoader.get().catch( redirectWhenMissing({ 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 59346e4c6fb98..f350a2c944756 100644 --- a/x-pack/legacy/plugins/maps/public/selectors/map_selectors.js +++ b/x-pack/legacy/plugins/maps/public/selectors/map_selectors.js @@ -16,7 +16,8 @@ import { VectorLayer } from '../../../../../plugins/maps/public/layers/vector_la import { HeatmapLayer } from '../../../../../plugins/maps/public/layers/heatmap_layer'; // eslint-disable-next-line @kbn/eslint/no-restricted-paths import { BlendedVectorLayer } from '../../../../../plugins/maps/public/layers/blended_vector_layer'; -import { getTimeFilter } from '../kibana_services'; +// eslint-disable-next-line @kbn/eslint/no-restricted-paths +import { getTimeFilter } from '../../../../../plugins/maps/public/kibana_services'; // eslint-disable-next-line @kbn/eslint/no-restricted-paths import { getInspectorAdapters } from '../../../../../plugins/maps/public/reducers/non_serializable_instances'; import { diff --git a/x-pack/legacy/plugins/maps/public/kibana_services.d.ts b/x-pack/plugins/maps/public/kibana_services.d.ts similarity index 100% rename from x-pack/legacy/plugins/maps/public/kibana_services.d.ts rename to x-pack/plugins/maps/public/kibana_services.d.ts diff --git a/x-pack/plugins/maps/public/kibana_services.js b/x-pack/plugins/maps/public/kibana_services.js index d2ddecfdf915b..2a79314380330 100644 --- a/x-pack/plugins/maps/public/kibana_services.js +++ b/x-pack/plugins/maps/public/kibana_services.js @@ -89,3 +89,49 @@ export async function fetchSearchSourceAndRecordWithInspector({ return resp; } + +let savedObjectsClient; +export const setSavedObjectsClient = coreSavedObjectsClient => + (savedObjectsClient = coreSavedObjectsClient); +export const getSavedObjectsClient = () => savedObjectsClient; + +let chrome; +export const setCoreChrome = coreChrome => (chrome = coreChrome); +export const getCoreChrome = () => chrome; + +let mapsCapabilities; +export const setMapsCapabilities = coreAppMapsCapabilities => + (mapsCapabilities = coreAppMapsCapabilities); +export const getMapsCapabilities = () => mapsCapabilities; + +let visualizations; +export const setVisualizations = visPlugin => (visualizations = visPlugin); +export const getVisualizations = () => visualizations; + +let docLinks; +export const setDocLinks = coreDocLinks => (docLinks = coreDocLinks); +export const getDocLinks = () => docLinks; + +let overlays; +export const setCoreOverlays = coreOverlays => (overlays = coreOverlays); +export const getCoreOverlays = () => overlays; + +let data; +export const setData = dataPlugin => (data = dataPlugin); +export const getData = () => data; + +let uiActions; +export const setUiActions = pluginUiActions => (uiActions = pluginUiActions); +export const getUiActions = () => uiActions; + +let core; +export const setCore = kibanaCore => (core = kibanaCore); +export const getCore = () => core; + +let navigation; +export const setNavigation = pluginNavigation => (navigation = pluginNavigation); +export const getNavigation = () => navigation; + +let coreI18n; +export const setCoreI18n = kibanaCoreI18n => (coreI18n = kibanaCoreI18n); +export const getCoreI18n = () => coreI18n; diff --git a/x-pack/plugins/maps/public/plugin.ts b/x-pack/plugins/maps/public/plugin.ts index 14487b615e759..649627690ec9a 100644 --- a/x-pack/plugins/maps/public/plugin.ts +++ b/x-pack/plugins/maps/public/plugin.ts @@ -10,6 +10,12 @@ import { Setup as InspectorSetupContract } from 'src/plugins/inspector/public'; import { MapView } from './inspector/views/map_view'; import { setAutocompleteService, + setCore, + setCoreChrome, + setCoreI18n, + setCoreOverlays, + setData, + setDocLinks, setFileUpload, setHttp, setIndexPatternSelect, @@ -17,9 +23,14 @@ import { setInjectedVarFunc, setInspector, setLicenseId, + setMapsCapabilities, + setNavigation, + setSavedObjectsClient, setTimeFilter, setToasts, + setUiActions, setUiSettings, + setVisualizations, // @ts-ignore } from './kibana_services'; @@ -31,15 +42,16 @@ export interface MapsPluginStartDependencies {} export const bindSetupCoreAndPlugins = (core: CoreSetup, plugins: any) => { const { licensing } = plugins; - const { injectedMetadata, http } = core; + const { injectedMetadata, uiSettings, http, notifications } = core; if (licensing) { licensing.license$.subscribe(({ uid }: { uid: string }) => setLicenseId(uid)); } setInjectedVarFunc(injectedMetadata.getInjectedVar); setHttp(http); - setUiSettings(core.uiSettings); - setInjectedVarFunc(core.injectedMetadata.getInjectedVar); - setToasts(core.notifications.toasts); + setToasts(notifications.toasts); + setInjectedVarFunc(injectedMetadata.getInjectedVar); + setVisualizations(plugins.visualizations); + setUiSettings(uiSettings); }; export const bindStartCoreAndPlugins = (core: CoreStart, plugins: any) => { @@ -50,6 +62,16 @@ export const bindStartCoreAndPlugins = (core: CoreStart, plugins: any) => { setTimeFilter(data.query.timefilter.timefilter); setIndexPatternService(data.indexPatterns); setAutocompleteService(data.autocomplete); + setCore(core); + setSavedObjectsClient(core.savedObjects.client); + setCoreChrome(core.chrome); + setCoreOverlays(core.overlays); + setMapsCapabilities(core.application.capabilities.maps); + setDocLinks(core.docLinks); + setData(plugins.data); + setUiActions(plugins.uiActions); + setNavigation(plugins.navigation); + setCoreI18n(core.i18n); }; /** From e36abee8efb5bde56962a0d5674426adcb9d313f Mon Sep 17 00:00:00 2001 From: Aaron Caldwell Date: Tue, 14 Apr 2020 09:18:35 -0600 Subject: [PATCH 09/16] Some fixes. Remove console logs --- .../plugins/maps/public/angular/get_initial_time_filters.js | 2 +- x-pack/legacy/plugins/maps/public/routes.js | 5 +---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/angular/get_initial_time_filters.js b/x-pack/legacy/plugins/maps/public/angular/get_initial_time_filters.js index 4cdacf3a7b50f..74fbf603e99f5 100644 --- a/x-pack/legacy/plugins/maps/public/angular/get_initial_time_filters.js +++ b/x-pack/legacy/plugins/maps/public/angular/get_initial_time_filters.js @@ -14,6 +14,6 @@ export function getInitialTimeFilters({ mapStateJSON, globalState = {} }) { } } - const defaultTime = getUiSettings()('timepicker:timeDefaults'); + const defaultTime = getUiSettings().get('timepicker:timeDefaults'); return { ...defaultTime, ...globalState.time }; } diff --git a/x-pack/legacy/plugins/maps/public/routes.js b/x-pack/legacy/plugins/maps/public/routes.js index f85d5dfc75fda..c082e0e1352c0 100644 --- a/x-pack/legacy/plugins/maps/public/routes.js +++ b/x-pack/legacy/plugins/maps/public/routes.js @@ -67,11 +67,8 @@ routes template: mapTemplate, controller: 'GisMapController', resolve: { - map: function(redirectWhenMissing, $scope, config) { - console.log($scope, config); + map: function(redirectWhenMissing) { const gisMapSavedObjectLoader = getMapsSavedObjectLoader(); - console.log(gisMapSavedObjectLoader); - $scope.listingLimit = config.get('savedObjects:listingLimit'); return gisMapSavedObjectLoader.get().catch( redirectWhenMissing({ map: '/', From 4db6223ec87287ca9b470be9451163bc0c9f1171 Mon Sep 17 00:00:00 2001 From: Aaron Caldwell Date: Tue, 14 Apr 2020 12:00:43 -0600 Subject: [PATCH 10/16] Fix type errors --- .../embeddable/map_embeddable_factory.ts | 1 + x-pack/legacy/plugins/maps/public/plugin.ts | 1 + .../plugins/maps/public/kibana_services.d.ts | 21 +++++++++++++++++++ 3 files changed, 23 insertions(+) diff --git a/x-pack/legacy/plugins/maps/public/embeddable/map_embeddable_factory.ts b/x-pack/legacy/plugins/maps/public/embeddable/map_embeddable_factory.ts index 1b219c614c88b..96c3baf634a83 100644 --- a/x-pack/legacy/plugins/maps/public/embeddable/map_embeddable_factory.ts +++ b/x-pack/legacy/plugins/maps/public/embeddable/map_embeddable_factory.ts @@ -8,6 +8,7 @@ import _ from 'lodash'; import { i18n } from '@kbn/i18n'; import { npSetup, npStart } from 'ui/new_platform'; import { IIndexPattern } from 'src/plugins/data/public'; +// @ts-ignore import { getMapsSavedObjectLoader } from '../angular/services/gis_map_saved_object_loader'; import { MapEmbeddable, MapEmbeddableInput } from './map_embeddable'; import { diff --git a/x-pack/legacy/plugins/maps/public/plugin.ts b/x-pack/legacy/plugins/maps/public/plugin.ts index 4edfa75643d6e..4ec068ff44029 100644 --- a/x-pack/legacy/plugins/maps/public/plugin.ts +++ b/x-pack/legacy/plugins/maps/public/plugin.ts @@ -16,6 +16,7 @@ import { Plugin, CoreStart, CoreSetup } from 'src/core/public'; import { Start as InspectorStartContract } from 'src/plugins/inspector/public'; // @ts-ignore import { wrapInI18nContext } from 'ui/i18n'; +// @ts-ignore import { MapListing } from './components/map_listing'; // @ts-ignore import { diff --git a/x-pack/plugins/maps/public/kibana_services.d.ts b/x-pack/plugins/maps/public/kibana_services.d.ts index bf22e5077e74e..4ea8185d68476 100644 --- a/x-pack/plugins/maps/public/kibana_services.d.ts +++ b/x-pack/plugins/maps/public/kibana_services.d.ts @@ -6,9 +6,30 @@ import { IIndexPattern } from 'src/plugins/data/public'; +export function getLicenseId(): any; +export function getInspector(): any; +export function getFileUpload(): any; +export function getIndexPatternSelect(): any; +export function getHttp(): any; +export function getTimeFilter(): any; +export function getInjectedVarFunc(): any; +export function getToasts(): any; export function getIndexPatternService(): { get: (id: string) => IIndexPattern | undefined; }; +export function getAutocompleteService(): any; +export function getSavedObjectsClient(): any; +export function getMapsCapabilities(): any; +export function getVisualizations(): any; +export function getDocLinks(): any; +export function getCoreChrome(): any; +export function getUiSettings(): any; +export function getCoreOverlays(): any; +export function getData(): any; +export function getUiActions(): any; +export function getCore(): any; +export function getNavigation(): any; +export function getCoreI18n(): any; export function setLicenseId(args: unknown): void; export function setInspector(args: unknown): void; From b95101b7a2b33275906ad541f786d307a9ae2508 Mon Sep 17 00:00:00 2001 From: Aaron Caldwell Date: Tue, 14 Apr 2020 14:32:48 -0600 Subject: [PATCH 11/16] Fix jest test path refs --- x-pack/legacy/plugins/maps/public/actions/map_actions.test.js | 2 +- .../plugins/maps/public/angular/get_initial_layers.test.js | 2 +- .../legacy/plugins/maps/public/selectors/map_selectors.test.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/actions/map_actions.test.js b/x-pack/legacy/plugins/maps/public/actions/map_actions.test.js index c280b8af7ab80..7e2a3c827fa88 100644 --- a/x-pack/legacy/plugins/maps/public/actions/map_actions.test.js +++ b/x-pack/legacy/plugins/maps/public/actions/map_actions.test.js @@ -5,7 +5,7 @@ */ jest.mock('../selectors/map_selectors', () => ({})); -jest.mock('../kibana_services', () => ({})); +jest.mock('../../../../../plugins/maps/public/kibana_services', () => ({})); import { mapExtentChanged, setMouseCoordinates } from './map_actions'; 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 b3cacf03f2fe9..8c9185a16ea0e 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,7 +7,7 @@ jest.mock('../../../../../plugins/maps/public/meta', () => { return {}; }); -jest.mock('../kibana_services'); +jest.mock('../../../../../plugins/maps/public/kibana_services'); import { getInitialLayers } from './get_initial_layers'; 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 77bd29259647c..b83be301653b8 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,7 +14,7 @@ jest.mock('../../../../../plugins/maps/public/reducers/non_serializable_instance return {}; }, })); -jest.mock('../kibana_services', () => ({ +jest.mock('../../../../../plugins/maps/public/kibana_services', () => ({ getTimeFilter: () => ({ getTime: () => { return { From ef3972c92b47880194ac473d7239951905456124 Mon Sep 17 00:00:00 2001 From: Aaron Caldwell Date: Wed, 15 Apr 2020 09:29:39 -0600 Subject: [PATCH 12/16] Accomodate legacy 'hacks' and init services for vis type alias --- .../plugins/maps/public/connected_components/map/mb/view.js | 2 +- x-pack/legacy/plugins/maps/public/register_vis_type_alias.js | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/x-pack/legacy/plugins/maps/public/connected_components/map/mb/view.js b/x-pack/legacy/plugins/maps/public/connected_components/map/mb/view.js index 3112024898f45..1fe3d0d493ee7 100644 --- a/x-pack/legacy/plugins/maps/public/connected_components/map/mb/view.js +++ b/x-pack/legacy/plugins/maps/public/connected_components/map/mb/view.js @@ -130,7 +130,7 @@ export class MBMapContainer extends React.Component { container: this.refs.mapContainer, style: mbStyle, scrollZoom: this.props.scrollZoom, - preserveDrawingBuffer: getInjectedVarFunc('preserveDrawingBuffer', false), + preserveDrawingBuffer: getInjectedVarFunc()('preserveDrawingBuffer', false), interactive: !this.props.disableInteractive, }; const initialView = _.get(this.props.goto, 'center'); diff --git a/x-pack/legacy/plugins/maps/public/register_vis_type_alias.js b/x-pack/legacy/plugins/maps/public/register_vis_type_alias.js index f6e55700afe13..9dc07bcb5dc0e 100644 --- a/x-pack/legacy/plugins/maps/public/register_vis_type_alias.js +++ b/x-pack/legacy/plugins/maps/public/register_vis_type_alias.js @@ -11,6 +11,11 @@ import { getVisualizations, // eslint-disable-next-line @kbn/eslint/no-restricted-paths } from '../../../../plugins/maps/public/kibana_services'; +import { npSetup } from 'ui/new_platform'; +// eslint-disable-next-line @kbn/eslint/no-restricted-paths +import { bindSetupCoreAndPlugins } from '../../../../plugins/maps/public/plugin'; + +bindSetupCoreAndPlugins(npSetup.core, npSetup.plugins); const showMapVisualizationTypes = getInjectedVarFunc()('showMapVisualizationTypes', false); From 401dda1b2d0ebd124d454c9594eb99e65a2becba Mon Sep 17 00:00:00 2001 From: Aaron Caldwell Date: Wed, 15 Apr 2020 09:43:15 -0600 Subject: [PATCH 13/16] Review feedback. Remove/update unused declarations --- x-pack/plugins/maps/public/kibana_services.d.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/x-pack/plugins/maps/public/kibana_services.d.ts b/x-pack/plugins/maps/public/kibana_services.d.ts index 4ea8185d68476..cf64dcd0f6445 100644 --- a/x-pack/plugins/maps/public/kibana_services.d.ts +++ b/x-pack/plugins/maps/public/kibana_services.d.ts @@ -8,8 +8,7 @@ import { IIndexPattern } from 'src/plugins/data/public'; export function getLicenseId(): any; export function getInspector(): any; -export function getFileUpload(): any; -export function getIndexPatternSelect(): any; +export function getIndexPatternSelectComponent(): any; export function getHttp(): any; export function getTimeFilter(): any; export function getInjectedVarFunc(): any; From 2e1ca3644020f5284b8c429f1dc478b56567df62 Mon Sep 17 00:00:00 2001 From: Aaron Caldwell Date: Wed, 15 Apr 2020 09:54:47 -0600 Subject: [PATCH 14/16] getFileUpload actually just needed Component tacked on the end --- x-pack/plugins/maps/public/kibana_services.d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/x-pack/plugins/maps/public/kibana_services.d.ts b/x-pack/plugins/maps/public/kibana_services.d.ts index cf64dcd0f6445..867557c296292 100644 --- a/x-pack/plugins/maps/public/kibana_services.d.ts +++ b/x-pack/plugins/maps/public/kibana_services.d.ts @@ -8,6 +8,7 @@ import { IIndexPattern } from 'src/plugins/data/public'; export function getLicenseId(): any; export function getInspector(): any; +export function getFileUploadComponent(): any; export function getIndexPatternSelectComponent(): any; export function getHttp(): any; export function getTimeFilter(): any; From 0b2e6839845f2c9446b9819ebdb98067288322e1 Mon Sep 17 00:00:00 2001 From: Aaron Caldwell Date: Wed, 15 Apr 2020 18:03:12 -0600 Subject: [PATCH 15/16] Handle visibility of toolbars for full screen mode using new core chrome. Should fix test --- x-pack/legacy/plugins/maps/public/angular/map.html | 6 +++--- .../plugins/maps/public/angular/map_controller.js | 11 +++++++++++ .../maps/public/connected_components/gis_map/index.js | 7 ++++++- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/angular/map.html b/x-pack/legacy/plugins/maps/public/angular/map.html index 2f34ffa660d6e..7d7dcf6f9c9a9 100644 --- a/x-pack/legacy/plugins/maps/public/angular/map.html +++ b/x-pack/legacy/plugins/maps/public/angular/map.html @@ -3,11 +3,11 @@
{ + $scope.$evalAsync(() => { + $scope.isVisible = isVisible; + }); + }); + $scope.$listen(globalState, 'fetch_with_changes', diff => { if (diff.includes('time') || diff.includes('filters')) { onQueryChange({ @@ -460,6 +468,8 @@ app.controller( $scope.$on('$destroy', () => { window.removeEventListener('beforeunload', beforeUnload); + visibleSubscription.unsubscribe(); + getCoreChrome().setIsVisible(true); if (unsubscribe) { unsubscribe(); @@ -553,6 +563,7 @@ app.controller( }), testId: 'mapsFullScreenMode', run() { + getCoreChrome().setIsVisible(false); store.dispatch(enableFullScreen()); }, }, diff --git a/x-pack/legacy/plugins/maps/public/connected_components/gis_map/index.js b/x-pack/legacy/plugins/maps/public/connected_components/gis_map/index.js index 39cb2c469e054..2d8265bae9387 100644 --- a/x-pack/legacy/plugins/maps/public/connected_components/gis_map/index.js +++ b/x-pack/legacy/plugins/maps/public/connected_components/gis_map/index.js @@ -18,6 +18,8 @@ import { getQueryableUniqueIndexPatternIds, isToolbarOverlayHidden, } from '../../selectors/map_selectors'; +// eslint-disable-next-line @kbn/eslint/no-restricted-paths +import { getCoreChrome } from '../../../../../../plugins/maps/public/kibana_services'; function mapStateToProps(state = {}) { const flyoutDisplay = getFlyoutDisplay(state); @@ -37,7 +39,10 @@ function mapStateToProps(state = {}) { function mapDispatchToProps(dispatch) { return { triggerRefreshTimer: () => dispatch(triggerRefreshTimer()), - exitFullScreen: () => dispatch(exitFullScreen()), + exitFullScreen: () => { + dispatch(exitFullScreen()); + getCoreChrome().setIsVisible(true); + }, cancelAllInFlightRequests: () => dispatch(cancelAllInFlightRequests()), }; } From a64a9427d7344aaf314cb1c25484dc14a89f6e88 Mon Sep 17 00:00:00 2001 From: Aaron Caldwell Date: Wed, 15 Apr 2020 20:38:18 -0600 Subject: [PATCH 16/16] Import source types in getInitialLayers to ensure registry --- .../maps/public/angular/get_initial_layers.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) 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 ed2230eef6b95..686259aeaaba4 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 @@ -4,6 +4,22 @@ * you may not use this file except in compliance with the Elastic License. */ import _ from 'lodash'; +// Import each layer type, even those not used, to init in registry +// eslint-disable-next-line @kbn/eslint/no-restricted-paths +import '../../../../../plugins/maps/public/layers/sources/wms_source'; +// eslint-disable-next-line @kbn/eslint/no-restricted-paths +import '../../../../../plugins/maps/public/layers/sources/ems_file_source'; +// eslint-disable-next-line @kbn/eslint/no-restricted-paths +import '../../../../../plugins/maps/public/layers/sources/es_search_source'; +// eslint-disable-next-line @kbn/eslint/no-restricted-paths +import '../../../../../plugins/maps/public/layers/sources/es_pew_pew_source/es_pew_pew_source'; +// eslint-disable-next-line @kbn/eslint/no-restricted-paths +import '../../../../../plugins/maps/public/layers/sources/kibana_regionmap_source'; +// eslint-disable-next-line @kbn/eslint/no-restricted-paths +import '../../../../../plugins/maps/public/layers/sources/es_geo_grid_source'; +// eslint-disable-next-line @kbn/eslint/no-restricted-paths +import '../../../../../plugins/maps/public/layers/sources/xyz_tms_source'; + // eslint-disable-next-line @kbn/eslint/no-restricted-paths import { KibanaTilemapSource } from '../../../../../plugins/maps/public/layers/sources/kibana_tilemap_source'; // eslint-disable-next-line @kbn/eslint/no-restricted-paths