mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
[Maps] convert kibana_services to TS (#74901)
* [Maps] convert kibana_services to TS * tslint * fix jest test * tslint Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
This commit is contained in:
parent
4c2f0760dc
commit
b07db9dec8
18 changed files with 236 additions and 454 deletions
|
@ -48,6 +48,10 @@ export interface MapsLegacyConfigType {
|
|||
includeElasticMapsService: boolean;
|
||||
proxyElasticMapsServiceInMaps: boolean;
|
||||
tilemap: any;
|
||||
emsFontLibraryUrl: string;
|
||||
emsFileApiUrl: string;
|
||||
emsTileApiUrl: string;
|
||||
emsLandingPageUrl: string;
|
||||
}
|
||||
|
||||
export function plugin(initializerContext: PluginInitializerContext) {
|
||||
|
|
|
@ -10,4 +10,5 @@ export function plugin() {
|
|||
return new FileUploadPlugin();
|
||||
}
|
||||
|
||||
export { StartContract } from './plugin';
|
||||
export { FileUploadComponentProps } from './get_file_upload_component';
|
||||
|
|
|
@ -4,33 +4,31 @@
|
|||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import { CoreSetup, CoreStart, Plugin } from 'kibana/server';
|
||||
import { getFileUploadComponent } from './get_file_upload_component';
|
||||
import { FileUploadComponentProps, getFileUploadComponent } from './get_file_upload_component';
|
||||
// @ts-ignore
|
||||
import { setupInitServicesAndConstants, startInitServicesAndConstants } from './kibana_services';
|
||||
import { IDataPluginServices } from '../../../../src/plugins/data/public';
|
||||
|
||||
/**
|
||||
* 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 FileUploadPluginSetupDependencies {}
|
||||
export interface FileUploadPluginStartDependencies {
|
||||
export interface SetupDependencies {}
|
||||
export interface StartDependencies {
|
||||
data: IDataPluginServices;
|
||||
}
|
||||
|
||||
export type FileUploadPluginSetup = ReturnType<FileUploadPlugin['setup']>;
|
||||
export type FileUploadPluginStart = ReturnType<FileUploadPlugin['start']>;
|
||||
export type SetupContract = ReturnType<FileUploadPlugin['setup']>;
|
||||
export interface StartContract {
|
||||
getFileUploadComponent: () => Promise<React.ComponentType<FileUploadComponentProps>>;
|
||||
}
|
||||
|
||||
export class FileUploadPlugin implements Plugin<FileUploadPluginSetup, FileUploadPluginStart> {
|
||||
public setup(core: CoreSetup, plugins: FileUploadPluginSetupDependencies) {
|
||||
export class FileUploadPlugin
|
||||
implements Plugin<SetupContract, StartContract, SetupDependencies, StartDependencies> {
|
||||
public setup(core: CoreSetup, plugins: SetupDependencies) {
|
||||
setupInitServicesAndConstants(core);
|
||||
}
|
||||
|
||||
public start(core: CoreStart, plugins: FileUploadPluginStartDependencies) {
|
||||
public start(core: CoreStart, plugins: StartDependencies) {
|
||||
startInitServicesAndConstants(core, plugins);
|
||||
return {
|
||||
getFileUploadComponent,
|
||||
|
|
|
@ -17,7 +17,7 @@ import { LAYER_WIZARD_CATEGORY } from '../../../../common/constants';
|
|||
|
||||
export const emsBoundariesLayerWizardConfig: LayerWizard = {
|
||||
categories: [LAYER_WIZARD_CATEGORY.REFERENCE],
|
||||
checkVisibility: () => {
|
||||
checkVisibility: async () => {
|
||||
return getIsEmsEnabled();
|
||||
},
|
||||
description: i18n.translate('xpack.maps.source.emsFileDescription', {
|
||||
|
|
|
@ -18,7 +18,7 @@ import { LAYER_WIZARD_CATEGORY } from '../../../../common/constants';
|
|||
|
||||
export const emsBaseMapLayerWizardConfig: LayerWizard = {
|
||||
categories: [LAYER_WIZARD_CATEGORY.REFERENCE],
|
||||
checkVisibility: () => {
|
||||
checkVisibility: async () => {
|
||||
return getIsEmsEnabled();
|
||||
},
|
||||
description: i18n.translate('xpack.maps.source.emsTileDescription', {
|
||||
|
|
|
@ -8,11 +8,7 @@ import { MapExtent, MapFilters } from '../../../../common/descriptor_types';
|
|||
jest.mock('../../../kibana_services');
|
||||
jest.mock('ui/new_platform');
|
||||
|
||||
import {
|
||||
getIndexPatternService,
|
||||
getSearchService,
|
||||
fetchSearchSourceAndRecordWithInspector,
|
||||
} from '../../../kibana_services';
|
||||
import { getIndexPatternService, getSearchService } from '../../../kibana_services';
|
||||
import { ESGeoGridSource } from './es_geo_grid_source';
|
||||
import {
|
||||
ES_GEO_FIELD_TYPE,
|
||||
|
@ -54,6 +50,51 @@ describe('ESGeoGridSource', () => {
|
|||
},
|
||||
{}
|
||||
);
|
||||
geogridSource._runEsQuery = async (args: unknown) => {
|
||||
return {
|
||||
took: 71,
|
||||
timed_out: false,
|
||||
_shards: {
|
||||
total: 1,
|
||||
successful: 1,
|
||||
skipped: 0,
|
||||
failed: 0,
|
||||
},
|
||||
hits: {
|
||||
total: 748 + 683,
|
||||
max_score: null,
|
||||
hits: [],
|
||||
},
|
||||
aggregations: {
|
||||
gridSplit: {
|
||||
buckets: [
|
||||
{
|
||||
key: '4/4/6',
|
||||
doc_count: 748,
|
||||
gridCentroid: {
|
||||
location: {
|
||||
lat: 35.64189018148127,
|
||||
lon: -82.84314106196105,
|
||||
},
|
||||
count: 748,
|
||||
},
|
||||
},
|
||||
{
|
||||
key: '4/3/6',
|
||||
doc_count: 683,
|
||||
gridCentroid: {
|
||||
location: {
|
||||
lat: 35.24134021274211,
|
||||
lon: -98.45945192042787,
|
||||
},
|
||||
count: 683,
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
describe('getGeoJsonWithMeta', () => {
|
||||
let mockSearchSource: unknown;
|
||||
|
@ -71,50 +112,6 @@ describe('ESGeoGridSource', () => {
|
|||
getIndexPatternService.mockReturnValue(mockIndexPatternService);
|
||||
// @ts-expect-error
|
||||
getSearchService.mockReturnValue(mockSearchService);
|
||||
// @ts-expect-error
|
||||
fetchSearchSourceAndRecordWithInspector.mockReturnValue({
|
||||
took: 71,
|
||||
timed_out: false,
|
||||
_shards: {
|
||||
total: 1,
|
||||
successful: 1,
|
||||
skipped: 0,
|
||||
failed: 0,
|
||||
},
|
||||
hits: {
|
||||
total: 748 + 683,
|
||||
max_score: null,
|
||||
hits: [],
|
||||
},
|
||||
aggregations: {
|
||||
gridSplit: {
|
||||
buckets: [
|
||||
{
|
||||
key: '4/4/6',
|
||||
doc_count: 748,
|
||||
gridCentroid: {
|
||||
location: {
|
||||
lat: 35.64189018148127,
|
||||
lon: -82.84314106196105,
|
||||
},
|
||||
count: 748,
|
||||
},
|
||||
},
|
||||
{
|
||||
key: '4/3/6',
|
||||
doc_count: 683,
|
||||
gridCentroid: {
|
||||
location: {
|
||||
lat: 35.24134021274211,
|
||||
lon: -98.45945192042787,
|
||||
},
|
||||
count: 683,
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
const extent: MapExtent = {
|
||||
|
|
|
@ -52,4 +52,17 @@ export class AbstractESSource extends AbstractVectorSource implements IESSource
|
|||
registerCancelCallback: (requestToken: symbol, callback: () => void) => void,
|
||||
searchFilters: VectorSourceRequestMeta
|
||||
): Promise<unknown>;
|
||||
_runEsQuery: ({
|
||||
requestId,
|
||||
requestName,
|
||||
requestDescription,
|
||||
searchSource,
|
||||
registerCancelCallback,
|
||||
}: {
|
||||
requestId: string;
|
||||
requestName: string;
|
||||
requestDescription: string;
|
||||
searchSource: ISearchSource;
|
||||
registerCancelCallback: () => void;
|
||||
}) => Promise<unknown>;
|
||||
}
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
import { AbstractVectorSource } from '../vector_source';
|
||||
import {
|
||||
getAutocompleteService,
|
||||
fetchSearchSourceAndRecordWithInspector,
|
||||
getIndexPatternService,
|
||||
getTimeFilter,
|
||||
getSearchService,
|
||||
|
@ -20,6 +19,7 @@ import uuid from 'uuid/v4';
|
|||
import { copyPersistentState } from '../../../reducers/util';
|
||||
import { DataRequestAbortError } from '../../util/data_request';
|
||||
import { expandToTileBoundaries } from '../es_geo_grid_source/geo_tile_utils';
|
||||
import { search } from '../../../../../../../src/plugins/data/public';
|
||||
|
||||
export class AbstractESSource extends AbstractVectorSource {
|
||||
constructor(descriptor, inspectorAdapters) {
|
||||
|
@ -84,16 +84,22 @@ export class AbstractESSource extends AbstractVectorSource {
|
|||
const abortController = new AbortController();
|
||||
registerCancelCallback(() => abortController.abort());
|
||||
|
||||
const inspectorRequest = this._inspectorAdapters.requests.start(requestName, {
|
||||
id: requestId,
|
||||
description: requestDescription,
|
||||
});
|
||||
let resp;
|
||||
try {
|
||||
return await fetchSearchSourceAndRecordWithInspector({
|
||||
inspectorAdapters: this._inspectorAdapters,
|
||||
searchSource,
|
||||
requestName,
|
||||
requestId,
|
||||
requestDesc: requestDescription,
|
||||
abortSignal: abortController.signal,
|
||||
inspectorRequest.stats(search.getRequestInspectorStats(searchSource));
|
||||
searchSource.getSearchRequestBody().then((body) => {
|
||||
inspectorRequest.json(body);
|
||||
});
|
||||
resp = await searchSource.fetch({ abortSignal: abortController.signal });
|
||||
inspectorRequest
|
||||
.stats(search.getResponseInspectorStats(resp, searchSource))
|
||||
.ok({ json: resp });
|
||||
} catch (error) {
|
||||
inspectorRequest.error({ error });
|
||||
if (error.name === 'AbortError') {
|
||||
throw new DataRequestAbortError();
|
||||
}
|
||||
|
@ -105,6 +111,8 @@ export class AbstractESSource extends AbstractVectorSource {
|
|||
})
|
||||
);
|
||||
}
|
||||
|
||||
return resp;
|
||||
}
|
||||
|
||||
async makeSearchSource(searchFilters, limit, initialSearchContext) {
|
||||
|
|
|
@ -5,7 +5,7 @@ exports[`LayerPanel is rendered 1`] = `
|
|||
services={
|
||||
Object {
|
||||
"appName": "maps",
|
||||
"data": undefined,
|
||||
"data": Object {},
|
||||
"storage": Storage {
|
||||
"clear": [Function],
|
||||
"get": [Function],
|
||||
|
|
|
@ -40,6 +40,17 @@ jest.mock('./layer_settings', () => ({
|
|||
},
|
||||
}));
|
||||
|
||||
jest.mock('../../kibana_services', () => {
|
||||
return {
|
||||
getData() {
|
||||
return {};
|
||||
},
|
||||
getCore() {
|
||||
return {};
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
import React from 'react';
|
||||
import { shallowWithIntl } from 'test_utils/enzyme_helpers';
|
||||
|
||||
|
|
92
x-pack/plugins/maps/public/kibana_services.d.ts
vendored
92
x-pack/plugins/maps/public/kibana_services.d.ts
vendored
|
@ -1,92 +0,0 @@
|
|||
/*
|
||||
* 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 React from 'react';
|
||||
import { DataPublicPluginStart } from 'src/plugins/data/public';
|
||||
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
|
||||
import { IndexPatternsService } from 'src/plugins/data/public/index_patterns';
|
||||
import { NavigateToAppOptions } from 'kibana/public';
|
||||
import { MapsConfigType } from '../config';
|
||||
import { MapsLegacyConfigType } from '../../../../src/plugins/maps_legacy/public';
|
||||
import { EmbeddableStart } from '../../../../src/plugins/embeddable/public';
|
||||
import { FileUploadComponentProps } from '../../file_upload/public';
|
||||
|
||||
export function getLicenseId(): any;
|
||||
export function getInspector(): any;
|
||||
export function getFileUploadComponent(): Promise<React.ComponentType<FileUploadComponentProps>>;
|
||||
export function getIndexPatternSelectComponent(): any;
|
||||
export function getHttp(): any;
|
||||
export function getTimeFilter(): any;
|
||||
export function getToasts(): any;
|
||||
export function getIndexPatternService(): IndexPatternsService;
|
||||
export function getAutocompleteService(): any;
|
||||
export function getSavedObjectsClient(): any;
|
||||
export function getMapsCapabilities(): any;
|
||||
export function getVisualizations(): any;
|
||||
export function getDocLinks(): any;
|
||||
export function getCoreChrome(): any;
|
||||
export function getUiSettings(): any;
|
||||
export function getIsDarkMode(): boolean;
|
||||
export function getCoreOverlays(): any;
|
||||
export function getData(): any;
|
||||
export function getUiActions(): any;
|
||||
export function getCore(): any;
|
||||
export function getNavigation(): any;
|
||||
export function getCoreI18n(): any;
|
||||
export function getSearchService(): DataPublicPluginStart['search'];
|
||||
export function getKibanaCommonConfig(): MapsLegacyConfigType;
|
||||
export function getMapAppConfig(): MapsConfigType;
|
||||
export function getIsEmsEnabled(): any;
|
||||
export function getEmsFontLibraryUrl(): any;
|
||||
export function getEmsTileLayerId(): any;
|
||||
export function getEmsFileApiUrl(): any;
|
||||
export function getEmsTileApiUrl(): any;
|
||||
export function getEmsLandingPageUrl(): any;
|
||||
export function getRegionmapLayers(): any;
|
||||
export function getTilemap(): any;
|
||||
export function getKibanaVersion(): string;
|
||||
export function getEnabled(): boolean;
|
||||
export function getShowMapVisualizationTypes(): boolean;
|
||||
export function getShowMapsInspectorAdapter(): boolean;
|
||||
export function getPreserveDrawingBuffer(): boolean;
|
||||
export function getProxyElasticMapsServiceInMaps(): boolean;
|
||||
export function getIsGoldPlus(): boolean;
|
||||
export function fetchSearchSourceAndRecordWithInspector(args: unknown): any;
|
||||
|
||||
export function setLicenseId(args: unknown): void;
|
||||
export function setInspector(args: unknown): void;
|
||||
export function setFileUpload(args: unknown): void;
|
||||
export function setIndexPatternSelect(args: unknown): void;
|
||||
export function setHttp(args: unknown): void;
|
||||
export function setTimeFilter(args: unknown): void;
|
||||
export function setToasts(args: unknown): void;
|
||||
export function setIndexPatternService(args: unknown): void;
|
||||
export function setAutocompleteService(args: unknown): void;
|
||||
export function setSavedObjectsClient(args: unknown): void;
|
||||
export function setMapsCapabilities(args: unknown): void;
|
||||
export function setVisualizations(args: unknown): void;
|
||||
export function setDocLinks(args: unknown): void;
|
||||
export function setCoreChrome(args: unknown): void;
|
||||
export function setUiSettings(args: unknown): void;
|
||||
export function setCoreOverlays(args: unknown): void;
|
||||
export function setData(args: unknown): void;
|
||||
export function setUiActions(args: unknown): void;
|
||||
export function setCore(args: unknown): void;
|
||||
export function setNavigation(args: unknown): void;
|
||||
export function setCoreI18n(args: unknown): void;
|
||||
export function setSearchService(args: DataPublicPluginStart['search']): void;
|
||||
export function setKibanaCommonConfig(config: MapsLegacyConfigType): void;
|
||||
export function setMapAppConfig(config: MapsConfigType): void;
|
||||
export function setKibanaVersion(version: string): void;
|
||||
export function setIsGoldPlus(isGoldPlus: boolean): void;
|
||||
export function setEmbeddableService(embeddableService: EmbeddableStart): void;
|
||||
export function getEmbeddableService(): EmbeddableStart;
|
||||
export function setNavigateToApp(
|
||||
navigateToApp: (appId: string, options?: NavigateToAppOptions | undefined) => Promise<void>
|
||||
): void;
|
||||
export const navigateToApp: (
|
||||
appId: string,
|
||||
options?: NavigateToAppOptions | undefined
|
||||
) => Promise<void>;
|
|
@ -1,192 +0,0 @@
|
|||
/*
|
||||
* 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 { esFilters, search } from '../../../../src/plugins/data/public';
|
||||
import _ from 'lodash';
|
||||
|
||||
export const SPATIAL_FILTER_TYPE = esFilters.FILTERS.SPATIAL_FILTER;
|
||||
const { getRequestInspectorStats, getResponseInspectorStats } = search;
|
||||
|
||||
let indexPatternService;
|
||||
export const setIndexPatternService = (dataIndexPatterns) =>
|
||||
(indexPatternService = dataIndexPatterns);
|
||||
export const getIndexPatternService = () => indexPatternService;
|
||||
|
||||
let autocompleteService;
|
||||
export const setAutocompleteService = (dataAutoComplete) =>
|
||||
(autocompleteService = dataAutoComplete);
|
||||
export const getAutocompleteService = () => autocompleteService;
|
||||
|
||||
let licenseId;
|
||||
export const setLicenseId = (latestLicenseId) => (licenseId = latestLicenseId);
|
||||
export const getLicenseId = () => {
|
||||
return licenseId;
|
||||
};
|
||||
|
||||
let inspector;
|
||||
export const setInspector = (newInspector) => (inspector = newInspector);
|
||||
export const getInspector = () => {
|
||||
return inspector;
|
||||
};
|
||||
|
||||
let fileUploadPlugin;
|
||||
export const setFileUpload = (fileUpload) => (fileUploadPlugin = fileUpload);
|
||||
export const getFileUploadComponent = async () => {
|
||||
return await fileUploadPlugin.getFileUploadComponent();
|
||||
};
|
||||
|
||||
let uiSettings;
|
||||
export const setUiSettings = (coreUiSettings) => (uiSettings = coreUiSettings);
|
||||
export const getUiSettings = () => uiSettings;
|
||||
export const getIsDarkMode = () => {
|
||||
return getUiSettings().get('theme:darkMode', false);
|
||||
};
|
||||
|
||||
let indexPatternSelectComponent;
|
||||
export const setIndexPatternSelect = (indexPatternSelect) =>
|
||||
(indexPatternSelectComponent = indexPatternSelect);
|
||||
export const getIndexPatternSelectComponent = () => indexPatternSelectComponent;
|
||||
|
||||
let coreHttp;
|
||||
export const setHttp = (http) => (coreHttp = http);
|
||||
export const getHttp = () => coreHttp;
|
||||
|
||||
let dataTimeFilter;
|
||||
export const setTimeFilter = (timeFilter) => (dataTimeFilter = timeFilter);
|
||||
export const getTimeFilter = () => dataTimeFilter;
|
||||
|
||||
let toast;
|
||||
export const setToasts = (notificationToast) => (toast = notificationToast);
|
||||
export const getToasts = () => toast;
|
||||
|
||||
export async function fetchSearchSourceAndRecordWithInspector({
|
||||
searchSource,
|
||||
requestId,
|
||||
requestName,
|
||||
requestDesc,
|
||||
inspectorAdapters,
|
||||
abortSignal,
|
||||
}) {
|
||||
const inspectorRequest = inspectorAdapters.requests.start(requestName, {
|
||||
id: requestId,
|
||||
description: requestDesc,
|
||||
});
|
||||
let resp;
|
||||
try {
|
||||
inspectorRequest.stats(getRequestInspectorStats(searchSource));
|
||||
searchSource.getSearchRequestBody().then((body) => {
|
||||
inspectorRequest.json(body);
|
||||
});
|
||||
resp = await searchSource.fetch({ abortSignal });
|
||||
inspectorRequest.stats(getResponseInspectorStats(resp, searchSource)).ok({ json: resp });
|
||||
} catch (error) {
|
||||
inspectorRequest.error({ error });
|
||||
throw error;
|
||||
}
|
||||
|
||||
return resp;
|
||||
}
|
||||
|
||||
let savedObjectsClient;
|
||||
export const setSavedObjectsClient = (coreSavedObjectsClient) =>
|
||||
(savedObjectsClient = coreSavedObjectsClient);
|
||||
export const getSavedObjectsClient = () => savedObjectsClient;
|
||||
|
||||
let chrome;
|
||||
export const setCoreChrome = (coreChrome) => (chrome = coreChrome);
|
||||
export const getCoreChrome = () => chrome;
|
||||
|
||||
let mapsCapabilities;
|
||||
export const setMapsCapabilities = (coreAppMapsCapabilities) =>
|
||||
(mapsCapabilities = coreAppMapsCapabilities);
|
||||
export const getMapsCapabilities = () => mapsCapabilities;
|
||||
|
||||
let visualizations;
|
||||
export const setVisualizations = (visPlugin) => (visualizations = visPlugin);
|
||||
export const getVisualizations = () => visualizations;
|
||||
|
||||
let docLinks;
|
||||
export const setDocLinks = (coreDocLinks) => (docLinks = coreDocLinks);
|
||||
export const getDocLinks = () => docLinks;
|
||||
|
||||
let overlays;
|
||||
export const setCoreOverlays = (coreOverlays) => (overlays = coreOverlays);
|
||||
export const getCoreOverlays = () => overlays;
|
||||
|
||||
let data;
|
||||
export const setData = (dataPlugin) => (data = dataPlugin);
|
||||
export const getData = () => data;
|
||||
|
||||
let uiActions;
|
||||
export const setUiActions = (pluginUiActions) => (uiActions = pluginUiActions);
|
||||
export const getUiActions = () => uiActions;
|
||||
|
||||
let core;
|
||||
export const setCore = (kibanaCore) => (core = kibanaCore);
|
||||
export const getCore = () => core;
|
||||
|
||||
let navigation;
|
||||
export const setNavigation = (pluginNavigation) => (navigation = pluginNavigation);
|
||||
export const getNavigation = () => navigation;
|
||||
|
||||
let coreI18n;
|
||||
export const setCoreI18n = (kibanaCoreI18n) => (coreI18n = kibanaCoreI18n);
|
||||
export const getCoreI18n = () => coreI18n;
|
||||
|
||||
let dataSearchService;
|
||||
export const setSearchService = (searchService) => (dataSearchService = searchService);
|
||||
export const getSearchService = () => dataSearchService;
|
||||
|
||||
let kibanaVersion;
|
||||
export const setKibanaVersion = (version) => (kibanaVersion = version);
|
||||
export const getKibanaVersion = () => kibanaVersion;
|
||||
|
||||
// xpack.maps.* kibana.yml settings from this plugin
|
||||
let mapAppConfig;
|
||||
export const setMapAppConfig = (config) => (mapAppConfig = config);
|
||||
export const getMapAppConfig = () => mapAppConfig;
|
||||
|
||||
export const getEnabled = () => getMapAppConfig().enabled;
|
||||
export const getShowMapVisualizationTypes = () => getMapAppConfig().showMapVisualizationTypes;
|
||||
export const getShowMapsInspectorAdapter = () => getMapAppConfig().showMapsInspectorAdapter;
|
||||
export const getPreserveDrawingBuffer = () => getMapAppConfig().preserveDrawingBuffer;
|
||||
|
||||
// map.* kibana.yml settings from maps_legacy plugin that are shared between OSS map visualizations and maps app
|
||||
let kibanaCommonConfig;
|
||||
export const setKibanaCommonConfig = (config) => (kibanaCommonConfig = config);
|
||||
export const getKibanaCommonConfig = () => kibanaCommonConfig;
|
||||
|
||||
export const getIsEmsEnabled = () => getKibanaCommonConfig().includeElasticMapsService;
|
||||
export const getEmsFontLibraryUrl = () => getKibanaCommonConfig().emsFontLibraryUrl;
|
||||
export const getEmsTileLayerId = () => getKibanaCommonConfig().emsTileLayerId;
|
||||
export const getEmsFileApiUrl = () => getKibanaCommonConfig().emsFileApiUrl;
|
||||
export const getEmsTileApiUrl = () => getKibanaCommonConfig().emsTileApiUrl;
|
||||
export const getEmsLandingPageUrl = () => getKibanaCommonConfig().emsLandingPageUrl;
|
||||
export const getProxyElasticMapsServiceInMaps = () =>
|
||||
getKibanaCommonConfig().proxyElasticMapsServiceInMaps;
|
||||
export const getRegionmapLayers = () => _.get(getKibanaCommonConfig(), 'regionmap.layers', []);
|
||||
export const getTilemap = () => _.get(getKibanaCommonConfig(), 'tilemap', []);
|
||||
|
||||
let isGoldPlus = false;
|
||||
export const setIsGoldPlus = (igp) => {
|
||||
isGoldPlus = igp;
|
||||
};
|
||||
|
||||
export const getIsGoldPlus = () => {
|
||||
return isGoldPlus;
|
||||
};
|
||||
|
||||
let embeddableService;
|
||||
export const setEmbeddableService = (_embeddableService) => {
|
||||
embeddableService = _embeddableService;
|
||||
};
|
||||
export const getEmbeddableService = () => {
|
||||
return embeddableService;
|
||||
};
|
||||
|
||||
export let navigateToApp;
|
||||
export function setNavigateToApp(_navigateToApp) {
|
||||
navigateToApp = _navigateToApp;
|
||||
}
|
83
x-pack/plugins/maps/public/kibana_services.ts
Normal file
83
x-pack/plugins/maps/public/kibana_services.ts
Normal file
|
@ -0,0 +1,83 @@
|
|||
/*
|
||||
* 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 _ from 'lodash';
|
||||
import { esFilters } from '../../../../src/plugins/data/public';
|
||||
import { MapsLegacyConfigType } from '../../../../src/plugins/maps_legacy/public';
|
||||
import { MapsConfigType } from '../config';
|
||||
import { MapsPluginStartDependencies } from './plugin';
|
||||
import { CoreStart } from '../../../../src/core/public';
|
||||
|
||||
export const SPATIAL_FILTER_TYPE = esFilters.FILTERS.SPATIAL_FILTER;
|
||||
|
||||
let licenseId: string | undefined;
|
||||
export const setLicenseId = (latestLicenseId: string | undefined) => (licenseId = latestLicenseId);
|
||||
export const getLicenseId = () => licenseId;
|
||||
let isGoldPlus: boolean = false;
|
||||
export const setIsGoldPlus = (igp: boolean) => (isGoldPlus = igp);
|
||||
export const getIsGoldPlus = () => isGoldPlus;
|
||||
|
||||
let kibanaVersion: string;
|
||||
export const setKibanaVersion = (version: string) => (kibanaVersion = version);
|
||||
export const getKibanaVersion = () => kibanaVersion;
|
||||
|
||||
let coreStart: CoreStart;
|
||||
let pluginsStart: MapsPluginStartDependencies;
|
||||
export function setStartServices(core: CoreStart, plugins: MapsPluginStartDependencies) {
|
||||
coreStart = core;
|
||||
pluginsStart = plugins;
|
||||
}
|
||||
export const getIndexPatternService = () => pluginsStart.data.indexPatterns;
|
||||
export const getAutocompleteService = () => pluginsStart.data.autocomplete;
|
||||
export const getInspector = () => pluginsStart.inspector;
|
||||
export const getFileUploadComponent = async () => {
|
||||
return await pluginsStart.fileUpload.getFileUploadComponent();
|
||||
};
|
||||
export const getUiSettings = () => coreStart.uiSettings;
|
||||
export const getIsDarkMode = () => getUiSettings().get('theme:darkMode', false);
|
||||
export const getIndexPatternSelectComponent = (): any => pluginsStart.data.ui.IndexPatternSelect;
|
||||
export const getHttp = () => coreStart.http;
|
||||
export const getTimeFilter = () => pluginsStart.data.query.timefilter.timefilter;
|
||||
export const getToasts = () => coreStart.notifications.toasts;
|
||||
export const getSavedObjectsClient = () => coreStart.savedObjects.client;
|
||||
export const getCoreChrome = () => coreStart.chrome;
|
||||
export const getMapsCapabilities = () => coreStart.application.capabilities.maps;
|
||||
export const getDocLinks = () => coreStart.docLinks;
|
||||
export const getCoreOverlays = () => coreStart.overlays;
|
||||
export const getData = () => pluginsStart.data;
|
||||
export const getUiActions = () => pluginsStart.uiActions;
|
||||
export const getCore = () => coreStart;
|
||||
export const getNavigation = () => pluginsStart.navigation;
|
||||
export const getCoreI18n = () => coreStart.i18n;
|
||||
export const getSearchService = () => pluginsStart.data.search;
|
||||
export const getEmbeddableService = () => pluginsStart.embeddable;
|
||||
export const getNavigateToApp = () => coreStart.application.navigateToApp;
|
||||
|
||||
// xpack.maps.* kibana.yml settings from this plugin
|
||||
let mapAppConfig: MapsConfigType;
|
||||
export const setMapAppConfig = (config: MapsConfigType) => (mapAppConfig = config);
|
||||
export const getMapAppConfig = () => mapAppConfig;
|
||||
|
||||
export const getEnabled = () => getMapAppConfig().enabled;
|
||||
export const getShowMapsInspectorAdapter = () => getMapAppConfig().showMapsInspectorAdapter;
|
||||
export const getPreserveDrawingBuffer = () => getMapAppConfig().preserveDrawingBuffer;
|
||||
|
||||
// map.* kibana.yml settings from maps_legacy plugin that are shared between OSS map visualizations and maps app
|
||||
let kibanaCommonConfig: MapsLegacyConfigType;
|
||||
export const setKibanaCommonConfig = (config: MapsLegacyConfigType) =>
|
||||
(kibanaCommonConfig = config);
|
||||
export const getKibanaCommonConfig = () => kibanaCommonConfig;
|
||||
|
||||
export const getIsEmsEnabled = () => getKibanaCommonConfig().includeElasticMapsService;
|
||||
export const getEmsFontLibraryUrl = () => getKibanaCommonConfig().emsFontLibraryUrl;
|
||||
export const getEmsTileLayerId = () => getKibanaCommonConfig().emsTileLayerId;
|
||||
export const getEmsFileApiUrl = () => getKibanaCommonConfig().emsFileApiUrl;
|
||||
export const getEmsTileApiUrl = () => getKibanaCommonConfig().emsTileApiUrl;
|
||||
export const getEmsLandingPageUrl = () => getKibanaCommonConfig().emsLandingPageUrl;
|
||||
export const getProxyElasticMapsServiceInMaps = () =>
|
||||
getKibanaCommonConfig().proxyElasticMapsServiceInMaps;
|
||||
export const getRegionmapLayers = () => _.get(getKibanaCommonConfig(), 'regionmap.layers', []);
|
||||
export const getTilemap = () => _.get(getKibanaCommonConfig(), 'tilemap', []);
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
import { AnyAction } from 'redux';
|
||||
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
|
||||
import { IndexPatternsService } from 'src/plugins/data/public/index_patterns';
|
||||
import { IndexPatternsContract } from 'src/plugins/data/public/index_patterns';
|
||||
import { ReactElement } from 'react';
|
||||
import { IndexPattern } from 'src/plugins/data/public';
|
||||
import { Embeddable, IContainer } from '../../../../../src/plugins/embeddable/public';
|
||||
|
@ -29,7 +29,7 @@ interface LazyLoadedMapModules {
|
|||
renderTooltipContent?: RenderToolTipContent,
|
||||
eventHandlers?: EventHandlers
|
||||
) => Embeddable<MapEmbeddableInput, MapEmbeddableOutput>;
|
||||
getIndexPatternService: () => IndexPatternsService;
|
||||
getIndexPatternService: () => IndexPatternsContract;
|
||||
getHttp: () => any;
|
||||
getMapsCapabilities: () => any;
|
||||
createMapStore: () => MapStore;
|
||||
|
|
|
@ -6,12 +6,10 @@
|
|||
|
||||
import { i18n } from '@kbn/i18n';
|
||||
import { APP_ID, APP_ICON, MAP_PATH } from '../common/constants';
|
||||
import { getShowMapVisualizationTypes, getVisualizations } from './kibana_services';
|
||||
|
||||
export function getMapsVisTypeAlias() {
|
||||
const showMapVisualizationTypes = getShowMapVisualizationTypes();
|
||||
export function getMapsVisTypeAlias(visualizations, showMapVisualizationTypes) {
|
||||
if (!showMapVisualizationTypes) {
|
||||
getVisualizations().hideTypes(['region_map', 'tile_map']);
|
||||
visualizations.hideTypes(['region_map', 'tile_map']);
|
||||
}
|
||||
|
||||
const description = i18n.translate('xpack.maps.visTypeAlias.description', {
|
||||
|
|
|
@ -61,7 +61,7 @@ function relativeToAbsolute(url: string): string {
|
|||
}
|
||||
|
||||
let emsClient: EMSClient | null = null;
|
||||
let latestLicenseId: string | null = null;
|
||||
let latestLicenseId: string | undefined;
|
||||
export function getEMSClient(): EMSClient {
|
||||
if (!emsClient) {
|
||||
const proxyElasticMapsServiceInMaps = getProxyElasticMapsServiceInMaps();
|
||||
|
@ -93,7 +93,7 @@ export function getEMSClient(): EMSClient {
|
|||
const licenseId = getLicenseId();
|
||||
if (latestLicenseId !== licenseId) {
|
||||
latestLicenseId = licenseId;
|
||||
emsClient.addQueryParams({ license: licenseId });
|
||||
emsClient.addQueryParams({ license: licenseId ? licenseId : '' });
|
||||
}
|
||||
return emsClient;
|
||||
}
|
||||
|
|
|
@ -5,6 +5,9 @@
|
|||
*/
|
||||
|
||||
import { Setup as InspectorSetupContract } from 'src/plugins/inspector/public';
|
||||
import { UiActionsStart } from 'src/plugins/ui_actions/public';
|
||||
import { NavigationPublicPluginStart } from 'src/plugins/navigation/public';
|
||||
import { Start as InspectorStartContract } from 'src/plugins/inspector/public';
|
||||
import {
|
||||
CoreSetup,
|
||||
CoreStart,
|
||||
|
@ -15,34 +18,12 @@ import {
|
|||
// @ts-ignore
|
||||
import { MapView } from './inspector/views/map_view';
|
||||
import {
|
||||
setAutocompleteService,
|
||||
setCore,
|
||||
setCoreChrome,
|
||||
setCoreI18n,
|
||||
setCoreOverlays,
|
||||
setData,
|
||||
setDocLinks,
|
||||
setFileUpload,
|
||||
setHttp,
|
||||
setIndexPatternSelect,
|
||||
setIndexPatternService,
|
||||
setInspector,
|
||||
setIsGoldPlus,
|
||||
setKibanaCommonConfig,
|
||||
setKibanaVersion,
|
||||
setLicenseId,
|
||||
setMapAppConfig,
|
||||
setMapsCapabilities,
|
||||
setNavigation,
|
||||
setSavedObjectsClient,
|
||||
setSearchService,
|
||||
setTimeFilter,
|
||||
setToasts,
|
||||
setUiActions,
|
||||
setUiSettings,
|
||||
setVisualizations,
|
||||
setEmbeddableService,
|
||||
setNavigateToApp,
|
||||
setStartServices,
|
||||
} from './kibana_services';
|
||||
import { featureCatalogueEntry } from './feature_catalogue_entry';
|
||||
// @ts-ignore
|
||||
|
@ -58,66 +39,29 @@ import { ILicense } from '../../licensing/common/types';
|
|||
import { lazyLoadMapModules } from './lazy_load_bundle';
|
||||
import { MapsStartApi } from './api';
|
||||
import { createSecurityLayerDescriptors, registerLayerWizard, registerSource } from './api';
|
||||
import { EmbeddableStart } from '../../../../src/plugins/embeddable/public';
|
||||
import { MapsLegacyConfigType } from '../../../../src/plugins/maps_legacy/public';
|
||||
import { DataPublicPluginStart } from '../../../../src/plugins/data/public';
|
||||
import { LicensingPluginStart } from '../../licensing/public';
|
||||
import { StartContract as FileUploadStartContract } from '../../file_upload/public';
|
||||
|
||||
export interface MapsPluginSetupDependencies {
|
||||
inspector: InspectorSetupContract;
|
||||
home: HomePublicPluginSetup;
|
||||
visualizations: VisualizationsSetup;
|
||||
embeddable: EmbeddableSetup;
|
||||
mapsLegacy: { config: unknown };
|
||||
mapsLegacy: { config: MapsLegacyConfigType };
|
||||
}
|
||||
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
||||
export interface MapsPluginStartDependencies {}
|
||||
|
||||
export const bindSetupCoreAndPlugins = (
|
||||
core: CoreSetup,
|
||||
plugins: any,
|
||||
config: MapsConfigType,
|
||||
kibanaVersion: string
|
||||
) => {
|
||||
const { licensing, mapsLegacy } = plugins;
|
||||
const { uiSettings, http, notifications } = core;
|
||||
if (licensing) {
|
||||
licensing.license$.subscribe(({ uid }: { uid: string }) => setLicenseId(uid));
|
||||
}
|
||||
setHttp(http);
|
||||
setToasts(notifications.toasts);
|
||||
setVisualizations(plugins.visualizations);
|
||||
setUiSettings(uiSettings);
|
||||
setKibanaCommonConfig(mapsLegacy.config);
|
||||
setMapAppConfig(config);
|
||||
setKibanaVersion(kibanaVersion);
|
||||
};
|
||||
|
||||
export const bindStartCoreAndPlugins = (core: CoreStart, plugins: any) => {
|
||||
const { fileUpload, data, inspector, licensing } = plugins;
|
||||
if (licensing) {
|
||||
licensing.license$.subscribe((license: ILicense) => {
|
||||
const gold = license.check(APP_ID, 'gold');
|
||||
setIsGoldPlus(gold.state === 'valid');
|
||||
});
|
||||
}
|
||||
|
||||
setInspector(inspector);
|
||||
setFileUpload(fileUpload);
|
||||
setIndexPatternSelect(data.ui.IndexPatternSelect);
|
||||
setTimeFilter(data.query.timefilter.timefilter);
|
||||
setSearchService(data.search);
|
||||
setIndexPatternService(data.indexPatterns);
|
||||
setAutocompleteService(data.autocomplete);
|
||||
setCore(core);
|
||||
setSavedObjectsClient(core.savedObjects.client);
|
||||
setCoreChrome(core.chrome);
|
||||
setCoreOverlays(core.overlays);
|
||||
setMapsCapabilities(core.application.capabilities.maps);
|
||||
setDocLinks(core.docLinks);
|
||||
setData(plugins.data);
|
||||
setUiActions(plugins.uiActions);
|
||||
setNavigation(plugins.navigation);
|
||||
setCoreI18n(core.i18n);
|
||||
setEmbeddableService(plugins.embeddable);
|
||||
setNavigateToApp(core.application.navigateToApp);
|
||||
};
|
||||
export interface MapsPluginStartDependencies {
|
||||
data: DataPublicPluginStart;
|
||||
embeddable: EmbeddableStart;
|
||||
fileUpload: FileUploadStartContract;
|
||||
inspector: InspectorStartContract;
|
||||
licensing: LicensingPluginStart;
|
||||
navigation: NavigationPublicPluginStart;
|
||||
uiActions: UiActionsStart;
|
||||
}
|
||||
|
||||
/**
|
||||
* These are the interfaces with your public contracts. You should export these
|
||||
|
@ -144,14 +88,16 @@ export class MapsPlugin
|
|||
|
||||
public setup(core: CoreSetup, plugins: MapsPluginSetupDependencies) {
|
||||
const config = this._initializerContext.config.get<MapsConfigType>();
|
||||
const kibanaVersion = this._initializerContext.env.packageInfo.version;
|
||||
const { inspector, home, visualizations, embeddable } = plugins;
|
||||
bindSetupCoreAndPlugins(core, plugins, config, kibanaVersion);
|
||||
setKibanaCommonConfig(plugins.mapsLegacy.config);
|
||||
setMapAppConfig(config);
|
||||
setKibanaVersion(this._initializerContext.env.packageInfo.version);
|
||||
|
||||
inspector.registerView(MapView);
|
||||
home.featureCatalogue.register(featureCatalogueEntry);
|
||||
visualizations.registerAlias(getMapsVisTypeAlias());
|
||||
embeddable.registerEmbeddableFactory(MAP_SAVED_OBJECT_TYPE, new MapEmbeddableFactory());
|
||||
plugins.inspector.registerView(MapView);
|
||||
plugins.home.featureCatalogue.register(featureCatalogueEntry);
|
||||
plugins.visualizations.registerAlias(
|
||||
getMapsVisTypeAlias(plugins.visualizations, config.showMapVisualizationTypes)
|
||||
);
|
||||
plugins.embeddable.registerEmbeddableFactory(MAP_SAVED_OBJECT_TYPE, new MapEmbeddableFactory());
|
||||
|
||||
core.application.register({
|
||||
id: APP_ID,
|
||||
|
@ -162,16 +108,23 @@ export class MapsPlugin
|
|||
category: DEFAULT_APP_CATEGORIES.kibana,
|
||||
// @ts-expect-error
|
||||
async mount(context, params) {
|
||||
const [coreStart, startPlugins] = await core.getStartServices();
|
||||
bindStartCoreAndPlugins(coreStart, startPlugins);
|
||||
const { renderApp } = await lazyLoadMapModules();
|
||||
return renderApp(context, params);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
public start(core: CoreStart, plugins: any): MapsStartApi {
|
||||
bindStartCoreAndPlugins(core, plugins);
|
||||
public start(core: CoreStart, plugins: MapsPluginStartDependencies): MapsStartApi {
|
||||
if (plugins.licensing) {
|
||||
plugins.licensing.license$.subscribe((license: ILicense) => {
|
||||
const gold = license.check(APP_ID, 'gold');
|
||||
setIsGoldPlus(gold.state === 'valid');
|
||||
setLicenseId(license.uid);
|
||||
});
|
||||
}
|
||||
|
||||
setStartServices(core, plugins);
|
||||
|
||||
return {
|
||||
createSecurityLayerDescriptors,
|
||||
registerLayerWizard,
|
||||
|
|
|
@ -13,7 +13,7 @@ import {
|
|||
getInspector,
|
||||
getToasts,
|
||||
getCoreI18n,
|
||||
navigateToApp,
|
||||
getNavigateToApp,
|
||||
} from '../../../kibana_services';
|
||||
import {
|
||||
SavedObjectSaveModalOrigin,
|
||||
|
@ -117,7 +117,7 @@ export function getTopNavConfig({
|
|||
state: { id, type: MAP_SAVED_OBJECT_TYPE },
|
||||
});
|
||||
} else {
|
||||
navigateToApp(originatingApp);
|
||||
getNavigateToApp()(originatingApp);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue