Skip to content
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
2 changes: 0 additions & 2 deletions x-pack/legacy/plugins/maps/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,13 @@ export function maps(kibana) {

// legacy dependencies
const __LEGACY = {
pluginRef: this,
config: server.config,
mapConfig() {
return server.config().get('map');
},
route: server.route.bind(server),
plugins: {
elasticsearch: server.plugins.elasticsearch,
xpackMainPlugin: server.plugins.xpack_main,
},
savedObjects: {
getSavedObjectsRepository: server.savedObjects.getSavedObjectsRepository,
Expand Down
7 changes: 6 additions & 1 deletion x-pack/legacy/plugins/maps/public/kibana_services.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,19 @@ import {
getRequestInspectorStats,
getResponseInspectorStats,
} from '../../../../../src/legacy/ui/public/courier';
export { xpackInfo } from 'plugins/xpack_main/services/xpack_info';
import { esFilters } from '../../../../../src/plugins/data/public';
import { npStart } from 'ui/new_platform';

export const SPATIAL_FILTER_TYPE = esFilters.FILTERS.SPATIAL_FILTER;
export { SearchSource } from '../../../../../src/legacy/ui/public/courier';
export const indexPatternService = npStart.plugins.data.indexPatterns;

let licenseId;
export const setLicenseId = latestLicenseId => (licenseId = latestLicenseId);
export const getLicenseId = () => {
return licenseId;
};

export async function fetchSearchSourceAndRecordWithInspector({
searchSource,
requestId,
Expand Down
4 changes: 2 additions & 2 deletions x-pack/legacy/plugins/maps/public/legacy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ const setupPlugins = {
__LEGACY: {
uiModules,
},
plugins: npSetup.plugins,
np: npSetup.plugins,
};

const startPlugins = {
plugins: npStart.plugins,
np: npStart.plugins,
};

export const setup = pluginInstance.setup(npSetup.core, setupPlugins);
Expand Down
6 changes: 2 additions & 4 deletions x-pack/legacy/plugins/maps/public/meta.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { GIS_API_PATH, EMS_CATALOGUE_PATH, EMS_GLYPHS_PATH } from '../common/con
import chrome from 'ui/chrome';
import { i18n } from '@kbn/i18n';
import { EMSClient } from '@elastic/ems-client';
import { xpackInfo } from './kibana_services';
import { getLicenseId } from './kibana_services';
import fetch from 'node-fetch';

const GIS_API_RELATIVE = `../${GIS_API_PATH}`;
Expand Down Expand Up @@ -68,9 +68,7 @@ export function getEMSClient() {
};
}
}
const xpackMapsFeature = xpackInfo.get('features.maps');
const licenseId =
xpackMapsFeature && xpackMapsFeature.maps && xpackMapsFeature.uid ? xpackMapsFeature.uid : '';
const licenseId = getLicenseId();
if (latestLicenseId !== licenseId) {
latestLicenseId = licenseId;
emsClient.addQueryParams({ license: licenseId });
Expand Down
6 changes: 2 additions & 4 deletions x-pack/legacy/plugins/maps/public/meta.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,8 @@ jest.mock('ui/chrome', () => ({

jest.mock('./kibana_services', () => {
return {
xpackInfo: {
get() {
return 'foobarlicenseid';
},
getLicenseId() {
return 'foobarlicenseid';
},
};
});
Expand Down
20 changes: 16 additions & 4 deletions x-pack/legacy/plugins/maps/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { Plugin, CoreStart } from 'src/core/public';
import { wrapInI18nContext } from 'ui/i18n';
// @ts-ignore
import { MapListing } from './components/map_listing';
// @ts-ignore
import { setLicenseId } from './kibana_services';

/**
* These are the interfaces with your public contracts. You should export these
Expand All @@ -21,10 +23,20 @@ export type MapsPluginStart = ReturnType<MapsPlugin['start']>;
/** @internal */
export class MapsPlugin implements Plugin<MapsPluginSetup, MapsPluginStart> {
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));
});
const {
__LEGACY: { uiModules },
np: { licensing },
} = plugins;

uiModules
.get('app/maps', ['ngRoute', 'react'])
.directive('mapListing', function(reactDirective: any) {
return reactDirective(wrapInI18nContext(MapListing));
});

if (licensing) {
licensing.license$.subscribe(({ uid }: { uid: string }) => setLicenseId(uid));
}
}

public start(core: CoreStart, plugins: any) {}
Expand Down
26 changes: 9 additions & 17 deletions x-pack/legacy/plugins/maps/server/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,15 @@
*/
import { i18n } from '@kbn/i18n';
import { APP_ID, APP_ICON, createMapPath, MAP_SAVED_OBJECT_TYPE } from '../common/constants';
import { initRoutes } from './routes';
import { getEcommerceSavedObjects } from './sample_data/ecommerce_saved_objects';
import { getFlightsSavedObjects } from './sample_data/flights_saved_objects.js';
import { getWebLogsSavedObjects } from './sample_data/web_logs_saved_objects.js';
import { checkLicense } from '../check_license';
import { watchStatusAndLicenseToInitialize } from '../../../server/lib/watch_status_and_license_to_initialize';
import { LICENSE_CHECK_STATE } from '../../../../plugins/licensing/server';
import { initRoutes } from './routes';

export class MapPlugin {
setup(core, plugins, __LEGACY) {
const { featuresPlugin } = plugins;
const { featuresPlugin, licensing } = plugins;
let routesInitialized = false;

featuresPlugin.registerFeature({
Expand Down Expand Up @@ -44,20 +43,13 @@ export class MapPlugin {
},
});

watchStatusAndLicenseToInitialize(
__LEGACY.plugins.xpackMainPlugin,
__LEGACY.pluginRef,
async license => {
if (license && license.maps && !routesInitialized) {
routesInitialized = true;
initRoutes(__LEGACY, license.uid);
}
licensing.license$.subscribe(license => {
const { state } = license.check('maps', 'basic');
if (state === LICENSE_CHECK_STATE.Valid && !routesInitialized) {
routesInitialized = true;
initRoutes(__LEGACY, license.uid);
}
);

__LEGACY.plugins.xpackMainPlugin.info
.feature(APP_ID)
.registerLicenseCheckResultsGenerator(checkLicense);
});

const sampleDataLinkLabel = i18n.translate('xpack.maps.sampleDataLinkLabel', {
defaultMessage: 'Map',
Expand Down