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

[Maps] Migrate Maps server to NP #66510

Merged
merged 27 commits into from
May 21, 2020
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
42d3eec
Set up NP config handling
May 12, 2020
51e68a3
Move sample data, test utils, tutorials, telemetry over to NP
May 13, 2020
d260cd0
Move index pattern settings to NP
May 13, 2020
f714d5c
Migrate server side routing to NP
May 14, 2020
7b02928
Clean up
May 14, 2020
72d7a03
Completely remove server, config init and injected vars in legacy
May 14, 2020
ca6ae71
Merge remote-tracking branch 'upstream/master' into np-migrate-maps-s…
May 14, 2020
0381779
Replace injected var refs with config refs. General clean up
May 14, 2020
6815df6
Include new args from legacy side on services init
May 14, 2020
4c43f90
Get proxyElasticMapsService from map config, not xpack.maps
May 15, 2020
d3e9d81
Review feedback. TS updates
May 15, 2020
35c1aff
Merge remote-tracking branch 'upstream/master' into np-migrate-maps-s…
May 15, 2020
d258035
Keep small Joi config presence while in legacy to support tests
May 15, 2020
d555b35
Merge remote-tracking branch 'upstream/master' into np-migrate-maps-s…
May 15, 2020
4a824e1
Pass the correct new maps config consistently to init services from l…
May 19, 2020
a1eef2c
Add params and query validation. Fix index settings request
May 19, 2020
15ae73c
Merge remote-tracking branch 'upstream/master' into np-migrate-maps-s…
May 19, 2020
04b7541
Ignore ts errors in legacy code that will be going away
May 19, 2020
c8f61f4
Get config in legacy in safe way to accomodate karma tests
May 19, 2020
0321801
Safely obtain other config ref for karma tests
May 19, 2020
223471e
Ignore config warning
May 19, 2020
53c883b
Review feedback. Change config ConfigSchema -> MapsXPackConfig. Sever…
May 20, 2020
9b37c86
Merge remote-tracking branch 'upstream/master' into np-migrate-maps-s…
May 20, 2020
6a54a1f
Update telemetry config ts refs
May 20, 2020
db5a3a2
Review feedback. TS updates and clarifying comment
May 20, 2020
998aa82
Review feedback. Remove ts-ignore
May 21, 2020
dfb495d
Merge remote-tracking branch 'upstream/master' into np-migrate-maps-s…
May 21, 2020
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.

20 changes: 20 additions & 0 deletions x-pack/plugins/maps/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* 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 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 ConfigSchema = TypeOf<typeof configSchema>;
kindsun marked this conversation as resolved.
Show resolved Hide resolved
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
17 changes: 15 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,23 @@
*/

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

export const plugin: PluginInitializer<MapsPluginSetup, MapsPluginStart> = () => {
return new MapsPlugin();
export interface MapsConfigType {
enabled: boolean;
showMapVisualizationTypes: boolean;
showMapsInspectorAdapter: boolean;
preserveDrawingBuffer: boolean;
enableVectorTiles: boolean;
}

// @ts-ignore
kindsun marked this conversation as resolved.
Show resolved Hide resolved
export const plugin: PluginInitializer<MapsPluginSetup, MapsPluginStart> = (
initContext: PluginInitializerContext
kindsun marked this conversation as resolved.
Show resolved Hide resolved
) => {
// @ts-ignore
return new MapsPlugin(initContext);
};

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