Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[7.x] [Maps] Migrate Maps server to NP (#66510) #67198

Merged
merged 1 commit into from
May 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 7 additions & 62 deletions x-pack/legacy/plugins/maps/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import { i18n } from '@kbn/i18n';
import { resolve } from 'path';
import { getAppTitle } from '../../../plugins/maps/common/i18n_getters';
import { MapPlugin } from './server/plugin';
import { APP_ID, APP_ICON } from '../../../plugins/maps/common/constants';
import { DEFAULT_APP_CATEGORIES } from '../../../../src/core/server';

Expand All @@ -17,6 +16,13 @@ export function maps(kibana) {
id: APP_ID,
configPrefix: 'xpack.maps',
publicDir: resolve(__dirname, 'public'),
config(Joi) {
return Joi.object({
enabled: Joi.boolean().default(true),
})
.unknown()
.default();
},
uiExports: {
app: {
title: getAppTitle(),
Expand All @@ -29,68 +35,7 @@ export function maps(kibana) {
category: DEFAULT_APP_CATEGORIES.kibana,
order: 4000,
},
injectDefaultVars(server) {
const serverConfig = server.config();

return {
showMapVisualizationTypes: serverConfig.get('xpack.maps.showMapVisualizationTypes'),
showMapsInspectorAdapter: serverConfig.get('xpack.maps.showMapsInspectorAdapter'),
enableVectorTiles: serverConfig.get('xpack.maps.enableVectorTiles'),
preserveDrawingBuffer: serverConfig.get('xpack.maps.preserveDrawingBuffer'),
kbnPkgVersion: serverConfig.get('pkg.version'),
};
},
styleSheetPaths: `${__dirname}/public/index.scss`,
},
config(Joi) {
return Joi.object({
enabled: Joi.boolean().default(true),
showMapVisualizationTypes: Joi.boolean().default(false),
showMapsInspectorAdapter: Joi.boolean().default(false), // flag used in functional testing
preserveDrawingBuffer: Joi.boolean().default(false), // flag used in functional testing
enableVectorTiles: Joi.boolean().default(false), // flag used to enable/disable vector-tiles
}).default();
},

init(server) {
const mapsEnabled = server.config().get('xpack.maps.enabled');
if (!mapsEnabled) {
server.log(['info', 'maps'], 'Maps app disabled by configuration');
return;
}

// Init saved objects client deps
const callCluster = server.plugins.elasticsearch.getCluster('admin').callWithInternalUser;
const { SavedObjectsClient, getSavedObjectsRepository } = server.savedObjects;
const internalRepository = getSavedObjectsRepository(callCluster);

const coreSetup = server.newPlatform.setup.core;
const newPlatformPlugins = server.newPlatform.setup.plugins;
const pluginsSetup = {
featuresPlugin: newPlatformPlugins.features,
licensing: newPlatformPlugins.licensing,
home: newPlatformPlugins.home,
usageCollection: newPlatformPlugins.usageCollection,
mapsLegacy: newPlatformPlugins.mapsLegacy,
};

// legacy dependencies
const __LEGACY = {
config: server.config,
route: server.route.bind(server),
plugins: {
elasticsearch: server.plugins.elasticsearch,
},
savedObjects: {
savedObjectsClient: new SavedObjectsClient(internalRepository),
getSavedObjectsRepository: server.savedObjects.getSavedObjectsRepository,
},
injectUiAppVars: server.injectUiAppVars,
getInjectedUiAppVars: server.getInjectedUiAppVars,
};

const mapPlugin = new MapPlugin();
mapPlugin.setup(coreSetup, pluginsSetup, __LEGACY);
},
});
}
4 changes: 3 additions & 1 deletion x-pack/legacy/plugins/maps/public/angular/map_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ const REACT_ANCHOR_DOM_ELEMENT_ID = 'react-maps-root';
const app = uiModules.get(MAP_APP_PATH, []);

// Init required services. Necessary while in legacy
bindNpSetupCoreAndPlugins(npSetup.core, npSetup.plugins);
const config = _.get(npSetup, 'plugins.maps.config', {});
const kibanaVersion = npSetup.core.injectedMetadata.getKibanaVersion();
bindNpSetupCoreAndPlugins(npSetup.core, npSetup.plugins, config, kibanaVersion);
bindNpStartCoreAndPlugins(npStart.core, npStart.plugins);

loadKbnTopNavDirectives(getNavigation().ui);
Expand Down
8 changes: 7 additions & 1 deletion x-pack/legacy/plugins/maps/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import _ from 'lodash';
import { Plugin, CoreStart, CoreSetup } from 'src/core/public';
// @ts-ignore
import { Start as InspectorStartContract } from 'src/plugins/inspector/public';
Expand Down Expand Up @@ -55,7 +56,12 @@ export class MapsPlugin implements Plugin<MapsPluginSetup, MapsPluginStart> {
return reactDirective(wrapInI18nContext(MapListing));
});

bindNpSetupCoreAndPlugins(core, np);
// @ts-ignore
const config = _.get(np, 'maps.config', {});
// @ts-ignore
const kibanaVersion = core.injectedMetadata.getKibanaVersion();
// @ts-ignore
bindNpSetupCoreAndPlugins(core, np, config, kibanaVersion);
}

public start(core: CoreStart, plugins: MapsPluginStartDependencies) {
Expand Down
115 changes: 0 additions & 115 deletions x-pack/legacy/plugins/maps/server/plugin.js

This file was deleted.

28 changes: 28 additions & 0 deletions x-pack/plugins/maps/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* 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 { schema, TypeOf } from '@kbn/config-schema';

export interface MapsConfigType {
enabled: boolean;
showMapVisualizationTypes: boolean;
showMapsInspectorAdapter: boolean;
preserveDrawingBuffer: boolean;
enableVectorTiles: boolean;
}

export const configSchema = schema.object({
enabled: schema.boolean({ defaultValue: true }),
showMapVisualizationTypes: schema.boolean({ defaultValue: false }),
// flag used in functional testing
showMapsInspectorAdapter: schema.boolean({ defaultValue: false }),
// flag used in functional testing
preserveDrawingBuffer: schema.boolean({ defaultValue: false }),
// flag used to enable/disable vector-tiles
enableVectorTiles: schema.boolean({ defaultValue: false }),
});

export type MapsXPackConfig = TypeOf<typeof configSchema>;
3 changes: 2 additions & 1 deletion x-pack/plugins/maps/kibana.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"navigation",
"visualizations",
"embeddable",
"mapsLegacy"
"mapsLegacy",
"usageCollection"
],
"ui": true,
"server": true
Expand Down
19 changes: 6 additions & 13 deletions x-pack/plugins/maps/public/angular/get_initial_layers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const layerListNotProvided = undefined;

describe('Saved object has layer list', () => {
beforeEach(() => {
require('../kibana_services').getInjectedVarFunc = () => jest.fn();
require('../kibana_services').getIsEmsEnabled = () => true;
});

it('Should get initial layers from saved object', () => {
Expand Down Expand Up @@ -66,18 +66,11 @@ describe('EMS is enabled', () => {
return null;
};
require('../kibana_services').getIsEmsEnabled = () => true;
require('../kibana_services').getInjectedVarFunc = () => key => {
switch (key) {
case 'emsTileLayerId':
return {
bright: 'road_map',
desaturated: 'road_map_desaturated',
dark: 'dark_map',
};
default:
throw new Error(`Unexpected call to getInjectedVarFunc with key ${key}`);
}
};
require('../kibana_services').getEmsTileLayerId = () => ({
bright: 'road_map',
desaturated: 'road_map_desaturated',
dark: 'dark_map',
});
});

it('Should get initial layer with EMS tile source', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { tmsLayerWizardConfig } from '../sources/xyz_tms_source';
import { wmsLayerWizardConfig } from '../sources/wms_source';
import { mvtVectorSourceWizardConfig } from '../sources/mvt_single_layer_vector_source';
import { ObservabilityLayerWizardConfig } from './solution_layers/observability';
import { getInjectedVarFunc } from '../../kibana_services';
import { getEnableVectorTiles } from '../../kibana_services';

let registered = false;
export function registerLayerWizards() {
Expand Down Expand Up @@ -56,8 +56,7 @@ export function registerLayerWizards() {
// @ts-ignore
registerLayerWizard(wmsLayerWizardConfig);

const getInjectedVar = getInjectedVarFunc();
if (getInjectedVar && getInjectedVar('enableVectorTiles', false)) {
if (getEnableVectorTiles()) {
// eslint-disable-next-line no-console
console.warn('Vector tiles are an experimental feature and should not be used in production.');
registerLayerWizard(mvtVectorSourceWizardConfig);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ import { DrawControl } from './draw_control';
import { TooltipControl } from './tooltip_control';
import { clampToLatBounds, clampToLonBounds } from '../../../elasticsearch_geo_utils';
import { getInitialView } from './get_initial_view';

import { getInjectedVarFunc } from '../../../kibana_services';
import { getPreserveDrawingBuffer } from '../../../kibana_services';

mapboxgl.workerUrl = mbWorkerUrl;
mapboxgl.setRTLTextPlugin(mbRtlPlugin);
Expand Down Expand Up @@ -130,7 +129,7 @@ export class MBMapContainer extends React.Component {
container: this.refs.mapContainer,
style: mbStyle,
scrollZoom: this.props.scrollZoom,
preserveDrawingBuffer: getInjectedVarFunc()('preserveDrawingBuffer', false),
preserveDrawingBuffer: getPreserveDrawingBuffer(),
interactive: !this.props.disableInteractive,
maxZoom: this.props.settings.maxZoom,
minZoom: this.props.settings.minZoom,
Expand Down
9 changes: 7 additions & 2 deletions x-pack/plugins/maps/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,15 @@
*/

import { PluginInitializer } from 'kibana/public';
import { PluginInitializerContext } from 'kibana/public';
import { MapsPlugin, MapsPluginSetup, MapsPluginStart } from './plugin';
import { MapsXPackConfig } from '../config';

export const plugin: PluginInitializer<MapsPluginSetup, MapsPluginStart> = () => {
return new MapsPlugin();
export const plugin: PluginInitializer<MapsPluginSetup, MapsPluginStart> = (
initContext: PluginInitializerContext<MapsXPackConfig>
) => {
// @ts-ignore
return new MapsPlugin(initContext);
};

export { MAP_SAVED_OBJECT_TYPE } from '../common/constants';
Expand Down
Loading