Skip to content

Commit

Permalink
[7.x] [Maps] Move layers to np maps (#61877) (#62697)
Browse files Browse the repository at this point in the history
* Move layers to new location

* Update layer path refs

* Update np kibana services to cover all required services

* Init np kibana services in legacy plugin. Port init functions to np

* Path updates, supporting file moves, general clean up

* More moves of related files and clean-up of legacy refs

* Path updates. Typescript warning fixes

* Update test paths

* Clean up unused kibana services usage in legacy

* Remove unused http ref

* Test fixes and clean up

* Remove unused snapshots

* Add np service init to embeddables too

* Move validate color picker to NP
  • Loading branch information
Aaron Caldwell authored Apr 6, 2020
1 parent 8c6f0c2 commit 5c1c094
Show file tree
Hide file tree
Showing 261 changed files with 417 additions and 318 deletions.
57 changes: 1 addition & 56 deletions x-pack/legacy/plugins/maps/public/actions/map_actions.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,59 +5,4 @@
*/
/* eslint-disable @typescript-eslint/consistent-type-definitions */

import { Filter, Query, TimeRange } from 'src/plugins/data/public';
import { AnyAction } from 'redux';
import { LAYER_TYPE } from '../../common/constants';
import { DataMeta, MapFilters } from '../../common/descriptor_types';
import {
MapCenterAndZoom,
MapRefreshConfig,
} from '../../../../../plugins/maps/common/descriptor_types';

export type SyncContext = {
startLoading(dataId: string, requestToken: symbol, meta: DataMeta): void;
stopLoading(dataId: string, requestToken: symbol, data: unknown, meta: DataMeta): void;
onLoadError(dataId: string, requestToken: symbol, errorMessage: string): void;
updateSourceData(newData: unknown): void;
isRequestStillActive(dataId: string, requestToken: symbol): boolean;
registerCancelCallback(requestToken: symbol, callback: () => void): void;
dataFilters: MapFilters;
};

export function updateSourceProp(
layerId: string,
propName: string,
value: unknown,
newLayerType?: LAYER_TYPE
): void;

export function setGotoWithCenter(config: MapCenterAndZoom): AnyAction;

export function replaceLayerList(layerList: unknown[]): AnyAction;

export type QueryGroup = {
filters: Filter[];
query?: Query;
timeFilters?: TimeRange;
refresh?: boolean;
};

export function setQuery(query: QueryGroup): AnyAction;

export function setRefreshConfig(config: MapRefreshConfig): AnyAction;

export function disableScrollZoom(): AnyAction;

export function disableInteractive(): AnyAction;

export function disableTooltipControl(): AnyAction;

export function hideToolbarOverlay(): AnyAction;

export function hideLayerControl(): AnyAction;

export function hideViewControl(): AnyAction;

export function setHiddenLayers(hiddenLayerIds: string[]): AnyAction;

export function addLayerWithoutDataSync(layerDescriptor: unknown): AnyAction;
export * from '../../../../../plugins/maps/public/actions/map_actions';
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@
* you may not use this file except in compliance with the Elastic License.
*/
import _ from 'lodash';
import { KibanaTilemapSource } from '../layers/sources/kibana_tilemap_source';
import { EMSTMSSource } from '../layers/sources/ems_tms_source';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { KibanaTilemapSource } from '../../../../../plugins/maps/public/layers/sources/kibana_tilemap_source';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { EMSTMSSource } from '../../../../../plugins/maps/public/layers/sources/ems_tms_source';
import { getInjectedVarFunc } from '../kibana_services';
import { getKibanaTileMap } from '../meta';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { getKibanaTileMap } from '../../../../../plugins/maps/public/meta';

export function getInitialLayers(layerListJSON, initialLayers = []) {
if (layerListJSON) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

jest.mock('../meta', () => {
jest.mock('../../../../../plugins/maps/public/meta', () => {
return {};
});
jest.mock('../kibana_services');
Expand Down Expand Up @@ -32,7 +32,7 @@ describe('Saved object has layer list', () => {

describe('kibana.yml configured with map.tilemap.url', () => {
beforeAll(() => {
require('../meta').getKibanaTileMap = () => {
require('../../../../../plugins/maps/public/meta').getKibanaTileMap = () => {
return {
url: 'myTileUrl',
};
Expand Down Expand Up @@ -62,7 +62,7 @@ describe('kibana.yml configured with map.tilemap.url', () => {

describe('EMS is enabled', () => {
beforeAll(() => {
require('../meta').getKibanaTileMap = () => {
require('../../../../../plugins/maps/public/meta').getKibanaTileMap = () => {
return null;
};
require('../kibana_services').getInjectedVarFunc = () => key => {
Expand Down Expand Up @@ -106,7 +106,7 @@ describe('EMS is enabled', () => {

describe('EMS is not enabled', () => {
beforeAll(() => {
require('../meta').getKibanaTileMap = () => {
require('../../../../../plugins/maps/public/meta').getKibanaTileMap = () => {
return null;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ import {
getFilters,
} from '../../selectors/map_selectors';
import { getIsLayerTOCOpen, getOpenTOCDetails } from '../../selectors/ui_selectors';
import { convertMapExtentToPolygon } from '../../elasticsearch_geo_utils';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { convertMapExtentToPolygon } from '../../../../../../plugins/maps/public/elasticsearch_geo_utils';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { copyPersistentState } from '../../../../../../plugins/maps/public/reducers/util';
import { extractReferences, injectReferences } from '../../../common/migrations/references';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@

import React from 'react';
import { Filter } from 'src/plugins/data/public';
import { RenderToolTipContent } from '../../layers/tooltips/tooltip_property';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { RenderToolTipContent } from '../../../../../../plugins/maps/public/layers/tooltips/tooltip_property';

export const GisMap: React.ComponentType<{
addFilters: ((filters: Filter[]) => void) | null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import { LayerPanel } from '../layer_panel/index';
import { AddLayerPanel } from '../layer_addpanel/index';
import { EuiFlexGroup, EuiFlexItem, EuiCallOut } from '@elastic/eui';
import { ExitFullScreenButton } from 'ui/exit_full_screen';
import { getIndexPatternsFromIds } from '../../index_pattern_util';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { getIndexPatternsFromIds } from '../../../../../../plugins/maps/public/index_pattern_util';
import { ES_GEO_FIELD_TYPE } from '../../../common/constants';
import { indexPatterns as indexPatternsUtils } from '../../../../../../../src/plugins/data/public';
import { i18n } from '@kbn/i18n';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
import React, { Fragment } from 'react';
import { EuiSpacer, EuiPanel, EuiButtonEmpty } from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n/react';
import { uploadLayerWizardConfig } from '../../../layers/sources/client_file_source';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { uploadLayerWizardConfig } from '../../../../../../../plugins/maps/public/layers/sources/client_file_source';

export const ImportEditor = ({ clearSource, isIndexingTriggered, ...props }) => {
const editorProperties = getEditorProperties({ isIndexingTriggered, ...props });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
*/

import React, { Fragment } from 'react';
import { getLayerWizards } from '../../../layers/layer_wizard_registry';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { getLayerWizards } from '../../../../../../../plugins/maps/public/layers/layer_wizard_registry';
import { EuiTitle, EuiSpacer, EuiCard, EuiIcon } from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n/react';
import _ from 'lodash';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ import {
EuiFormHelpText,
} from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { SingleFieldSelect } from '../../../../components/single_field_select';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { SingleFieldSelect } from '../../../../../../../../plugins/maps/public/components/single_field_select';
import { FormattedMessage } from '@kbn/i18n/react';
import { getTermsFields } from '../../../../index_pattern_util';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { getTermsFields } from '../../../../../../../../plugins/maps/public/index_pattern_util';
import {
getIndexPatternService,
getIndexPatternSelectComponent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import {
EuiFormErrorText,
EuiFormHelpText,
} from '@elastic/eui';
import { MetricsEditor } from '../../../../components/metrics_editor';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { MetricsEditor } from '../../../../../../../../plugins/maps/public/components/metrics_editor';
import { FormattedMessage } from '@kbn/i18n/react';
import { AGG_TYPE } from '../../../../../common/constants';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

jest.mock('../../../../components/metrics_editor', () => ({
jest.mock('../../../../../../../../plugins/maps/public/components/metric_editor', () => ({
MetricsEditor: () => {
return <div>mockMetricsEditor</div>;
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import React, { Fragment } from 'react';

import { EuiTitle, EuiPanel, EuiFormRow, EuiFieldText, EuiSpacer } from '@elastic/eui';

import { ValidatedRange } from '../../../components/validated_range';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { ValidatedRange } from '../../../../../../../plugins/maps/public/components/validated_range';
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n/react';
import { ValidatedDualRange } from '../../../../../../../../src/plugins/kibana_react/public';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,4 @@
*/
/* eslint-disable @typescript-eslint/consistent-type-definitions */

import { LAYER_TYPE } from '../../../common/constants';

export type OnSourceChangeArgs = {
propName: string;
value: unknown;
newLayerType?: LAYER_TYPE;
};
export * from '../../../../../../plugins/maps/public/connected_components/layer_panel/view';
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import React, { Component, Fragment } from 'react';
import { EuiIcon } from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n/react';
import { i18n } from '@kbn/i18n';
import { createSpatialFilterWithGeometry } from '../../../elasticsearch_geo_utils';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { createSpatialFilterWithGeometry } from '../../../../../../../plugins/maps/public/elasticsearch_geo_utils';
import { GEO_JSON_TYPE } from '../../../../common/constants';
import { GeometryFilterForm } from '../../../components/geometry_filter_form';
import { UrlOverflowService } from 'ui/error_url_overflow';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ import {
createSpatialFilterWithGeometry,
getBoundingBoxGeometry,
roundCoordinates,
} from '../../../../elasticsearch_geo_utils';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
} from '../../../../../../../../plugins/maps/public/elasticsearch_geo_utils';
import { DrawTooltip } from './draw_tooltip';

const mbDrawModes = MapboxDraw.modes;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@
*/

import _ from 'lodash';
import { RGBAImage } from './image_utils';
import {
loadSpriteSheetImageData,
addSpriteSheetToMapFromImageData,
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
} from '../../../../../../../plugins/maps/public/connected_components/map/mb/utils';

export { loadSpriteSheetImageData, addSpriteSheetToMapFromImageData };

export function removeOrphanedSourcesAndLayers(mbMap, layerList) {
const mbStyle = mbMap.getStyle();
Expand Down Expand Up @@ -95,62 +101,7 @@ export function syncLayerOrderForSingleLayer(mbMap, layerList) {
});
}

function getImageData(img) {
const canvas = window.document.createElement('canvas');
const context = canvas.getContext('2d');
if (!context) {
throw new Error('failed to create canvas 2d context');
}
canvas.width = img.width;
canvas.height = img.height;
context.drawImage(img, 0, 0, img.width, img.height);
return context.getImageData(0, 0, img.width, img.height);
}

export async function loadSpriteSheetImageData(imgUrl) {
return new Promise((resolve, reject) => {
const image = new Image();
if (isCrossOriginUrl(imgUrl)) {
image.crossOrigin = 'Anonymous';
}
image.onload = el => {
const imgData = getImageData(el.currentTarget);
resolve(imgData);
};
image.onerror = e => {
reject(e);
};
image.src = imgUrl;
});
}

export function addSpriteSheetToMapFromImageData(json, imgData, mbMap) {
for (const imageId in json) {
if (!(json.hasOwnProperty(imageId) && !mbMap.hasImage(imageId))) {
continue;
}
const { width, height, x, y, sdf, pixelRatio } = json[imageId];
if (typeof width !== 'number' || typeof height !== 'number') {
continue;
}

const data = new RGBAImage({ width, height });
RGBAImage.copy(imgData, data, { x, y }, { x: 0, y: 0 }, { width, height });
mbMap.addImage(imageId, data, { pixelRatio, sdf });
}
}

export async function addSpritesheetToMap(json, imgUrl, mbMap) {
const imgData = await loadSpriteSheetImageData(imgUrl);
addSpriteSheetToMapFromImageData(json, imgData, mbMap);
}

function isCrossOriginUrl(url) {
const a = window.document.createElement('a');
a.href = url;
return (
a.protocol !== window.document.location.protocol ||
a.host !== window.document.location.host ||
a.port !== window.document.location.port
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import {
removeOrphanedSourcesAndLayers,
addSpritesheetToMap,
} from './utils';
import { getGlyphUrl, isRetina } from '../../../meta';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { getGlyphUrl, isRetina } from '../../../../../../../plugins/maps/public/meta';
import { DECIMAL_DEGREES_PRECISION, ZOOM_PRECISION } from '../../../../common/constants';
import mapboxgl from 'mapbox-gl/dist/mapbox-gl-csp';
import mbWorkerUrl from '!!file-loader!mapbox-gl/dist/mapbox-gl-csp-worker';
Expand All @@ -23,7 +24,11 @@ import sprites1 from '@elastic/maki/dist/[email protected]';
import sprites2 from '@elastic/maki/dist/[email protected]';
import { DrawControl } from './draw_control';
import { TooltipControl } from './tooltip_control';
import { clampToLatBounds, clampToLonBounds } from '../../../elasticsearch_geo_utils';
import {
clampToLatBounds,
clampToLonBounds,
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
} from '../../../../../../../plugins/maps/public/elasticsearch_geo_utils';

mapboxgl.workerUrl = mbWorkerUrl;
mapboxgl.setRTLTextPlugin(mbRtlPlugin);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ import {
} from '../../../../../plugins/maps/public/reducers/non_serializable_instances';
import { getMapCenter, getMapZoom, getHiddenLayerIds } from '../selectors/map_selectors';
import { MAP_SAVED_OBJECT_TYPE } from '../../common/constants';
import { RenderToolTipContent } from '../layers/tooltips/tooltip_property';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { RenderToolTipContent } from '../../../../../plugins/maps/public/layers/tooltips/tooltip_property';

interface MapEmbeddableConfig {
editUrl?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ import { getInitialLayers } from '../angular/get_initial_layers';
import { mergeInputWithSavedMap } from './merge_input_with_saved_map';
import '../angular/services/gis_map_saved_object_loader';
import { bindSetupCoreAndPlugins, bindStartCoreAndPlugins } from '../plugin';
// @ts-ignore
import {
bindSetupCoreAndPlugins as bindNpSetupCoreAndPlugins,
bindStartCoreAndPlugins as bindNpStartCoreAndPlugins,
} from '../../../../../plugins/maps/public/plugin'; // eslint-disable-line @kbn/eslint/no-restricted-paths

export class MapEmbeddableFactory implements EmbeddableFactoryDefinition {
type = MAP_SAVED_OBJECT_TYPE;
Expand All @@ -40,7 +45,9 @@ export class MapEmbeddableFactory implements EmbeddableFactoryDefinition {
constructor() {
// Init required services. Necessary while in legacy
bindSetupCoreAndPlugins(npSetup.core, npSetup.plugins);
bindNpSetupCoreAndPlugins(npSetup.core, npSetup.plugins);
bindStartCoreAndPlugins(npStart.core, npStart.plugins);
bindNpStartCoreAndPlugins(npStart.core, npStart.plugins);
}

async isEditable() {
Expand Down
2 changes: 1 addition & 1 deletion x-pack/legacy/plugins/maps/public/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
@import './mapbox_hacks';
@import './connected_components/index';
@import './components/index';
@import './layers/index';
@import '../../../../plugins/maps/public/layers/index';
6 changes: 5 additions & 1 deletion x-pack/legacy/plugins/maps/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,9 @@ export const plugin = (initializerContext: PluginInitializerContext) => {
return new MapsPlugin();
};

export { RenderTooltipContentParams, ITooltipProperty } from './layers/tooltips/tooltip_property';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
export {
RenderTooltipContentParams,
ITooltipProperty,
} from '../../../../plugins/maps/public/layers/tooltips/tooltip_property';
export { MapEmbeddable, MapEmbeddableInput } from './embeddable';
Loading

0 comments on commit 5c1c094

Please sign in to comment.