From e740133357c45ceacd8abfe8f08bc77156a5df94 Mon Sep 17 00:00:00 2001 From: Aaron Caldwell Date: Thu, 12 Dec 2019 07:43:44 -0700 Subject: [PATCH] [Maps] Get basic structure of NP client shim in place (#52551) (#52837) * Move ui routes init to separate file * Add index and general maps plugin template * Add legacy shim. Pass uimodules in as legacy service * Move ts-ignore * Fix N/A ts error on uiModules * Point index file toward legacy file. Minor NP additions --- .../plugins/file_upload/public/plugin.ts | 2 -- x-pack/legacy/plugins/maps/index.js | 2 +- x-pack/legacy/plugins/maps/public/index.ts | 29 +++++++++++++++++ x-pack/legacy/plugins/maps/public/legacy.ts | 27 ++++++++++++++++ x-pack/legacy/plugins/maps/public/plugin.ts | 31 +++++++++++++++++++ .../maps/public/{index.js => routes.js} | 25 --------------- 6 files changed, 88 insertions(+), 28 deletions(-) create mode 100644 x-pack/legacy/plugins/maps/public/index.ts create mode 100644 x-pack/legacy/plugins/maps/public/legacy.ts create mode 100644 x-pack/legacy/plugins/maps/public/plugin.ts rename x-pack/legacy/plugins/maps/public/{index.js => routes.js} (79%) diff --git a/x-pack/legacy/plugins/file_upload/public/plugin.ts b/x-pack/legacy/plugins/file_upload/public/plugin.ts index cc9ebbfc15b39..53b292b02760f 100644 --- a/x-pack/legacy/plugins/file_upload/public/plugin.ts +++ b/x-pack/legacy/plugins/file_upload/public/plugin.ts @@ -6,8 +6,6 @@ import { Plugin, CoreStart } from 'src/core/public'; // @ts-ignore -import { initResources } from './util/indexing_service'; -// @ts-ignore import { JsonUploadAndParse } from './components/json_upload_and_parse'; // @ts-ignore import { initServicesAndConstants } from './kibana_services'; diff --git a/x-pack/legacy/plugins/maps/index.js b/x-pack/legacy/plugins/maps/index.js index e5b3d5c615013..4f5bca6af7feb 100644 --- a/x-pack/legacy/plugins/maps/index.js +++ b/x-pack/legacy/plugins/maps/index.js @@ -28,7 +28,7 @@ export function maps(kibana) { description: i18n.translate('xpack.maps.appDescription', { defaultMessage: 'Map application' }), - main: 'plugins/maps/index', + main: 'plugins/maps/legacy', icon: 'plugins/maps/icon.svg', euiIconType: APP_ICON, }, diff --git a/x-pack/legacy/plugins/maps/public/index.ts b/x-pack/legacy/plugins/maps/public/index.ts new file mode 100644 index 0000000000000..404909c5c51b8 --- /dev/null +++ b/x-pack/legacy/plugins/maps/public/index.ts @@ -0,0 +1,29 @@ +/* + * 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. + */ + +import './kibana_services'; + +// import the uiExports that we want to "use" +import 'uiExports/inspectorViews'; +import 'uiExports/search'; +import 'uiExports/embeddableFactories'; +import 'uiExports/embeddableActions'; +import 'ui/agg_types'; + +import 'ui/kbn_top_nav'; +import 'ui/autoload/all'; +import 'react-vis/dist/style.css'; + +import './angular/services/gis_map_saved_object_loader'; +import './angular/map_controller'; +import './routes'; +// @ts-ignore +import { PluginInitializerContext } from 'kibana/public'; +import { MapsPlugin } from './plugin'; + +export const plugin = (initializerContext: PluginInitializerContext) => { + return new MapsPlugin(); +}; diff --git a/x-pack/legacy/plugins/maps/public/legacy.ts b/x-pack/legacy/plugins/maps/public/legacy.ts new file mode 100644 index 0000000000000..684d7b16fbb3b --- /dev/null +++ b/x-pack/legacy/plugins/maps/public/legacy.ts @@ -0,0 +1,27 @@ +/* + * 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. + */ + +import { npSetup, npStart } from 'ui/new_platform'; +// @ts-ignore Untyped Module +import { uiModules } from 'ui/modules'; +import { PluginInitializerContext } from 'kibana/public'; // eslint-disable-line import/order +import { plugin } from '.'; + +const pluginInstance = plugin({} as PluginInitializerContext); + +const setupPlugins = { + __LEGACY: { + uiModules, + }, + plugins: npSetup.plugins, +}; + +const startPlugins = { + plugins: npStart.plugins, +}; + +export const setup = pluginInstance.setup(npSetup.core, setupPlugins); +export const start = pluginInstance.start(npStart.core, startPlugins); diff --git a/x-pack/legacy/plugins/maps/public/plugin.ts b/x-pack/legacy/plugins/maps/public/plugin.ts new file mode 100644 index 0000000000000..4e6d52d20db64 --- /dev/null +++ b/x-pack/legacy/plugins/maps/public/plugin.ts @@ -0,0 +1,31 @@ +/* + * 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. + */ + +import { Plugin, CoreStart } from 'src/core/public'; +// @ts-ignore +import { wrapInI18nContext } from 'ui/i18n'; +// @ts-ignore +import { MapListing } from './components/map_listing'; + +/** + * These are the interfaces with your public contracts. You should export these + * for other plugins to use in _their_ `SetupDeps`/`StartDeps` interfaces. + * @public + */ +export type MapsPluginSetup = ReturnType; +export type MapsPluginStart = ReturnType; + +/** @internal */ +export class MapsPlugin implements Plugin { + public setup(core: any, plugins: any) { + const app = plugins.__LEGACY.uiModules.get('app/maps', ['ngRoute', 'react']); + app.directive('mapListing', function(reactDirective: any) { + return reactDirective(wrapInI18nContext(MapListing)); + }); + } + + public start(core: CoreStart, plugins: any) {} +} diff --git a/x-pack/legacy/plugins/maps/public/index.js b/x-pack/legacy/plugins/maps/public/routes.js similarity index 79% rename from x-pack/legacy/plugins/maps/public/index.js rename to x-pack/legacy/plugins/maps/public/routes.js index 964753f464d95..ce8ae1359d3b6 100644 --- a/x-pack/legacy/plugins/maps/public/index.js +++ b/x-pack/legacy/plugins/maps/public/routes.js @@ -4,40 +4,15 @@ * you may not use this file except in compliance with the Elastic License. */ -import './kibana_services'; - -import { wrapInI18nContext } from 'ui/i18n'; import { i18n } from '@kbn/i18n'; - -// import the uiExports that we want to "use" -import 'uiExports/inspectorViews'; -import 'uiExports/search'; -import 'uiExports/embeddableFactories'; -import 'uiExports/embeddableActions'; -import 'ui/agg_types'; - import { capabilities } from 'ui/capabilities'; import chrome from 'ui/chrome'; import routes from 'ui/routes'; -import 'ui/kbn_top_nav'; -import { uiModules } from 'ui/modules'; import { docTitle } from 'ui/doc_title'; -import 'ui/autoload/all'; -import 'react-vis/dist/style.css'; - -import './angular/services/gis_map_saved_object_loader'; -import './angular/map_controller'; import listingTemplate from './angular/listing_ng_wrapper.html'; import mapTemplate from './angular/map.html'; -import { MapListing } from './components/map_listing'; import { npStart } from 'ui/new_platform'; -const app = uiModules.get('app/maps', ['ngRoute', 'react']); - -app.directive('mapListing', function (reactDirective) { - return reactDirective(wrapInI18nContext(MapListing)); -}); - routes.enable(); routes