Skip to content

Commit

Permalink
[Maps] Isolate maps-setting froms maps_legacy (#92918) (#94588)
Browse files Browse the repository at this point in the history
Creates a new plugins, maps_ems, with `map.*` configs and shared EMS-settings. `maps_legacy` now only supports the `region_map` and `coordinate_map` plugins.
# Conflicts:
#	packages/kbn-optimizer/limits.yml
  • Loading branch information
thomasneirynck authored Mar 15, 2021
1 parent d1ded01 commit 366ad49
Show file tree
Hide file tree
Showing 80 changed files with 550 additions and 350 deletions.
4 changes: 4 additions & 0 deletions docs/developer/plugin-list.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ in Kibana, e.g. visualizations. It has the form of a flyout panel.
|WARNING: Missing README.
|{kib-repo}blob/{branch}/src/plugins/maps_ems/README.md[mapsEms]
|Configuration of kibana-wide EMS settings and some higher level utilities.
|{kib-repo}blob/{branch}/src/plugins/maps_legacy/README.md[mapsLegacy]
|Internal objects used by the Coordinate, Region, and Vega visualizations.
Expand Down
3 changes: 2 additions & 1 deletion packages/kbn-optimizer/limits.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ pageLoadAssetSize:
logstash: 53548
management: 46112
maps: 183754
mapsLegacy: 116961
mapsLegacy: 87859
mapsLegacyLicensing: 20214
ml: 82187
monitoring: 80000
Expand Down Expand Up @@ -107,3 +107,4 @@ pageLoadAssetSize:
osquery: 107090
fileUpload: 25664
banners: 17946
mapsEms: 26072
3 changes: 3 additions & 0 deletions src/plugins/maps_ems/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Maps EMS

Configuration of kibana-wide EMS settings and some higher level utilities.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@

export const TMS_IN_YML_ID = 'TMS in config/kibana.yml';

export * from './ems_defaults';
export { ORIGIN } from './origin';
File renamed without changes.
87 changes: 87 additions & 0 deletions src/plugins/maps_ems/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import { schema, TypeOf } from '@kbn/config-schema';

import {
DEFAULT_EMS_FONT_LIBRARY_URL,
DEFAULT_EMS_LANDING_PAGE_URL,
DEFAULT_EMS_TILE_API_URL,
DEFAULT_EMS_FILE_API_URL,
} from './common';

const tileMapConfigOptionsSchema = schema.object({
attribution: schema.string({ defaultValue: '' }),
minZoom: schema.number({ defaultValue: 0, min: 0 }),
maxZoom: schema.number({ defaultValue: 10 }),
tileSize: schema.maybe(schema.number()),
subdomains: schema.maybe(schema.arrayOf(schema.string())),
errorTileUrl: schema.maybe(schema.string()),
tms: schema.maybe(schema.boolean()),
reuseTiles: schema.maybe(schema.boolean()),
bounds: schema.maybe(schema.arrayOf(schema.number({ min: 2 }))),
default: schema.maybe(schema.boolean()),
});

export const tilemapConfigSchema = schema.object({
url: schema.maybe(schema.string()),
options: tileMapConfigOptionsSchema,
});

const layerConfigSchema = schema.object({
url: schema.string(),
format: schema.object({
type: schema.string({ defaultValue: 'geojson' }),
}),
meta: schema.object({
feature_collection_path: schema.string({ defaultValue: 'data' }),
}),
attribution: schema.string(),
name: schema.string(),
fields: schema.arrayOf(
schema.object({
name: schema.string(),
description: schema.string(),
})
),
});

export type LayerConfig = TypeOf<typeof layerConfigSchema>;

const regionmapConfigSchema = schema.object({
includeElasticMapsService: schema.boolean({ defaultValue: true }),
layers: schema.arrayOf(layerConfigSchema, { defaultValue: [] }),
});

export const emsConfigSchema = schema.object({
regionmap: regionmapConfigSchema,
tilemap: tilemapConfigSchema,
includeElasticMapsService: schema.boolean({ defaultValue: true }),
proxyElasticMapsServiceInMaps: schema.boolean({ defaultValue: false }),
manifestServiceUrl: schema.string({ defaultValue: '' }),
emsUrl: schema.conditional(
schema.siblingRef('proxyElasticMapsServiceInMaps'),
true,
schema.never(),
schema.string({ defaultValue: '' })
),
emsFileApiUrl: schema.string({ defaultValue: DEFAULT_EMS_FILE_API_URL }),
emsTileApiUrl: schema.string({ defaultValue: DEFAULT_EMS_TILE_API_URL }),
emsLandingPageUrl: schema.string({ defaultValue: DEFAULT_EMS_LANDING_PAGE_URL }),
emsFontLibraryUrl: schema.string({
defaultValue: DEFAULT_EMS_FONT_LIBRARY_URL,
}),
emsTileLayerId: schema.object({
bright: schema.string({ defaultValue: 'road_map' }),
desaturated: schema.string({ defaultValue: 'road_map_desaturated' }),
dark: schema.string({ defaultValue: 'dark_map' }),
}),
});

export type MapsEmsConfig = TypeOf<typeof emsConfigSchema>;
export type TileMapConfig = TypeOf<typeof tilemapConfigSchema>;
13 changes: 13 additions & 0 deletions src/plugins/maps_ems/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

module.exports = {
preset: '@kbn/test',
rootDir: '../../..',
roots: ['<rootDir>/src/plugins/maps_ems'],
};
9 changes: 9 additions & 0 deletions src/plugins/maps_ems/kibana.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"id": "mapsEms",
"version": "8.0.0",
"kibanaVersion": "kibana",
"configPath": ["map"],
"ui": true,
"server": true,
"extraPublicDirs": ["common"]
}
35 changes: 35 additions & 0 deletions src/plugins/maps_ems/public/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import { PluginInitializerContext } from 'kibana/public';
import { MapsEmsPlugin } from './plugin';
import { IServiceSettings } from './service_settings';
import type { MapsEmsConfig } from '../config';

/** @public */
export {
VectorLayer,
FileLayerField,
FileLayer,
TmsLayer,
IServiceSettings,
} from './service_settings';

export function plugin(initializerContext: PluginInitializerContext) {
return new MapsEmsPlugin(initializerContext);
}

export type { MapsEmsConfig, LayerConfig } from '../config';

export * from '../common';

export interface MapsEmsPluginSetup {
config: MapsEmsConfig;
getServiceSettings: () => Promise<IServiceSettings>;
}
export type MapsEmsPluginStart = ReturnType<MapsEmsPlugin['start']>;
17 changes: 17 additions & 0 deletions src/plugins/maps_ems/public/kibana_services.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import type { MapsEmsConfig } from '../config';

let kibanaVersion: string;
export const setKibanaVersion = (version: string) => (kibanaVersion = version);
export const getKibanaVersion = (): string => kibanaVersion;

let mapsEmsConfig: MapsEmsConfig;
export const setMapsEmsConfig = (config: MapsEmsConfig) => (mapsEmsConfig = config);
export const getMapsEmsConfig = () => mapsEmsConfig;
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@
* Side Public License, v 1.
*/

import { lazyLoadMapsLegacyModules } from './lazy_load_bundle';
// @ts-expect-error
import { getMapsLegacyConfig } from './kibana_services';
import { IServiceSettings } from './map/service_settings_types';
import type { IServiceSettings } from '../service_settings/service_settings_types';
import { getMapsEmsConfig } from '../kibana_services';

let loadPromise: Promise<IServiceSettings>;

Expand All @@ -19,10 +17,9 @@ export async function getServiceSettings(): Promise<IServiceSettings> {
}

loadPromise = new Promise(async (resolve) => {
const modules = await lazyLoadMapsLegacyModules();
const config = getMapsLegacyConfig();
// @ts-expect-error
resolve(new modules.ServiceSettings(config, config.tilemap));
const { ServiceSettings } = await import('./lazy');
const config = getMapsEmsConfig();
resolve(new ServiceSettings(config, config.tilemap));
});
return loadPromise;
}
9 changes: 9 additions & 0 deletions src/plugins/maps_ems/public/lazy_load_bundle/lazy/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

export { ServiceSettings } from '../../service_settings/service_settings';
50 changes: 50 additions & 0 deletions src/plugins/maps_ems/public/plugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

// @ts-ignore
import { CoreSetup, CoreStart, Plugin, PluginInitializerContext } from 'kibana/public';
// @ts-ignore
import { setKibanaVersion, setMapsEmsConfig } from './kibana_services';
// @ts-ignore
import { MapsEmsPluginSetup, MapsEmsPluginStart } from './index';
import type { MapsEmsConfig } from '../config';
import { getServiceSettings } from './lazy_load_bundle/get_service_settings';

/**
* These are the interfaces with your public contracts. You should export these
* for other plugins to use in _their_ `SetupDeps`/`StartDeps` interfaces.
* @public
*/

// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface MapsEmsStartDependencies {}
// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface MapsEmsSetupDependencies {}

export class MapsEmsPlugin implements Plugin<MapsEmsPluginSetup, MapsEmsPluginStart> {
readonly _initializerContext: PluginInitializerContext<MapsEmsConfig>;

constructor(initializerContext: PluginInitializerContext<MapsEmsConfig>) {
this._initializerContext = initializerContext;
}

public setup(core: CoreSetup, plugins: MapsEmsSetupDependencies) {
const config = this._initializerContext.config.get<MapsEmsConfig>();
const kibanaVersion = this._initializerContext.env.packageInfo.version;

setKibanaVersion(kibanaVersion);
setMapsEmsConfig(config);

return {
getServiceSettings,
config,
};
}

public start(core: CoreStart, plugins: MapsEmsStartDependencies) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
* Side Public License, v 1.
*/

export * from './ems_defaults';
export * from './service_settings_types';
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ jest.mock('../kibana_services', () => ({

import url from 'url';

import EMS_FILES from '../__tests__/map/ems_mocks/sample_files.json';
import EMS_TILES from '../__tests__/map/ems_mocks/sample_tiles.json';
import EMS_STYLE_ROAD_MAP_BRIGHT from '../__tests__/map/ems_mocks/sample_style_bright';
import EMS_STYLE_ROAD_MAP_DESATURATED from '../__tests__/map/ems_mocks/sample_style_desaturated';
import EMS_STYLE_DARK_MAP from '../__tests__/map/ems_mocks/sample_style_dark';
import { ORIGIN } from '../common/constants/origin';
import EMS_FILES from '../../__tests__/map/ems_mocks/sample_files.json';
import EMS_TILES from '../../__tests__/map/ems_mocks/sample_tiles.json';
import EMS_STYLE_ROAD_MAP_BRIGHT from '../../__tests__/map/ems_mocks/sample_style_bright';
import EMS_STYLE_ROAD_MAP_DESATURATED from '../../__tests__/map/ems_mocks/sample_style_desaturated';
import EMS_STYLE_DARK_MAP from '../../__tests__/map/ems_mocks/sample_style_dark';
import { ORIGIN } from '../../common';
import { ServiceSettings } from './service_settings';

describe('service_settings (FKA tile_map test)', function () {
Expand Down
Loading

0 comments on commit 366ad49

Please sign in to comment.