From 06dec30df45b5a91984c862ef8b650eea652c185 Mon Sep 17 00:00:00 2001 From: Aaron Caldwell Date: Tue, 11 Feb 2020 17:07:46 -0700 Subject: [PATCH 01/21] Plugin file and services in place. Some redux logic ported --- x-pack/plugins/maps/common/constants.js | 160 ++++++ x-pack/plugins/maps/common/i18n_getters.js | 50 ++ .../plugins/maps/common/parse_xml_string.js | 22 + .../maps/common/parse_xml_string.test.js | 16 + x-pack/plugins/maps/kibana.json | 8 + .../maps/public/actions/map_actions.js | 50 ++ .../plugins/maps/public/actions/ui_actions.js | 23 + .../maps/public/applications/maps/index.tsx | 78 +++ .../gis_map/_gis_map.scss | 19 + .../connected_components/gis_map/index.js | 45 ++ .../connected_components/gis_map/view.js | 222 +++++++ x-pack/plugins/maps/public/index.ts | 14 + x-pack/plugins/maps/public/kibana_services.js | 13 + x-pack/plugins/maps/public/plugin.ts | 79 +++ x-pack/plugins/maps/public/reducers/map.js | 543 ++++++++++++++++++ .../plugins/maps/public/reducers/map.test.js | 56 ++ .../reducers/non_serializable_instances.js | 107 ++++ x-pack/plugins/maps/public/reducers/store.js | 24 + x-pack/plugins/maps/public/reducers/ui.js | 81 +++ x-pack/plugins/maps/public/reducers/util.js | 21 + .../plugins/maps/public/reducers/util.test.js | 47 ++ .../maps/public/selectors/map_selectors.js | 85 +++ .../maps/public/selectors/ui_selectors.js | 13 + 23 files changed, 1776 insertions(+) create mode 100644 x-pack/plugins/maps/common/constants.js create mode 100644 x-pack/plugins/maps/common/i18n_getters.js create mode 100644 x-pack/plugins/maps/common/parse_xml_string.js create mode 100644 x-pack/plugins/maps/common/parse_xml_string.test.js create mode 100644 x-pack/plugins/maps/kibana.json create mode 100644 x-pack/plugins/maps/public/actions/map_actions.js create mode 100644 x-pack/plugins/maps/public/actions/ui_actions.js create mode 100644 x-pack/plugins/maps/public/applications/maps/index.tsx create mode 100644 x-pack/plugins/maps/public/connected_components/gis_map/_gis_map.scss create mode 100644 x-pack/plugins/maps/public/connected_components/gis_map/index.js create mode 100644 x-pack/plugins/maps/public/connected_components/gis_map/view.js create mode 100644 x-pack/plugins/maps/public/index.ts create mode 100644 x-pack/plugins/maps/public/kibana_services.js create mode 100644 x-pack/plugins/maps/public/plugin.ts create mode 100644 x-pack/plugins/maps/public/reducers/map.js create mode 100644 x-pack/plugins/maps/public/reducers/map.test.js create mode 100644 x-pack/plugins/maps/public/reducers/non_serializable_instances.js create mode 100644 x-pack/plugins/maps/public/reducers/store.js create mode 100644 x-pack/plugins/maps/public/reducers/ui.js create mode 100644 x-pack/plugins/maps/public/reducers/util.js create mode 100644 x-pack/plugins/maps/public/reducers/util.test.js create mode 100644 x-pack/plugins/maps/public/selectors/map_selectors.js create mode 100644 x-pack/plugins/maps/public/selectors/ui_selectors.js diff --git a/x-pack/plugins/maps/common/constants.js b/x-pack/plugins/maps/common/constants.js new file mode 100644 index 00000000000000..2570341aa5756e --- /dev/null +++ b/x-pack/plugins/maps/common/constants.js @@ -0,0 +1,160 @@ +/* + * 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 { i18n } from '@kbn/i18n'; + +export const EMS_CATALOGUE_PATH = 'ems/catalogue'; + +export const EMS_FILES_CATALOGUE_PATH = 'ems/files'; +export const EMS_FILES_API_PATH = 'ems/files'; +export const EMS_FILES_DEFAULT_JSON_PATH = 'file'; +export const EMS_GLYPHS_PATH = 'fonts'; +export const EMS_SPRITES_PATH = 'sprites'; + +export const EMS_TILES_CATALOGUE_PATH = 'ems/tiles'; +export const EMS_TILES_API_PATH = 'ems/tiles'; +export const EMS_TILES_RASTER_STYLE_PATH = 'raster/style'; +export const EMS_TILES_RASTER_TILE_PATH = 'raster/tile'; + +export const EMS_TILES_VECTOR_STYLE_PATH = 'vector/style'; +export const EMS_TILES_VECTOR_SOURCE_PATH = 'vector/source'; +export const EMS_TILES_VECTOR_TILE_PATH = 'vector/tile'; + +export const MAP_SAVED_OBJECT_TYPE = 'map'; +export const APP_ID = 'maps'; +export const APP_ICON = 'gisApp'; +export const TELEMETRY_TYPE = 'maps-telemetry'; + +export const MAP_APP_PATH = `app/${APP_ID}`; +export const GIS_API_PATH = `api/${APP_ID}`; +export const INDEX_SETTINGS_API_PATH = `${GIS_API_PATH}/indexSettings`; + +export const MAP_BASE_URL = `/${MAP_APP_PATH}#/${MAP_SAVED_OBJECT_TYPE}`; + +export function createMapPath(id) { + return `${MAP_BASE_URL}/${id}`; +} + +export const LAYER_TYPE = { + TILE: 'TILE', + VECTOR: 'VECTOR', + VECTOR_TILE: 'VECTOR_TILE', + HEATMAP: 'HEATMAP', +}; + +export const SORT_ORDER = { + ASC: 'asc', + DESC: 'desc', +}; + +export const EMS_TMS = 'EMS_TMS'; +export const EMS_FILE = 'EMS_FILE'; +export const ES_GEO_GRID = 'ES_GEO_GRID'; +export const ES_SEARCH = 'ES_SEARCH'; +export const ES_PEW_PEW = 'ES_PEW_PEW'; + +export const FIELD_ORIGIN = { + SOURCE: 'source', + JOIN: 'join', +}; + +export const SOURCE_DATA_ID_ORIGIN = 'source'; +export const META_ID_ORIGIN_SUFFIX = 'meta'; +export const SOURCE_META_ID_ORIGIN = `${SOURCE_DATA_ID_ORIGIN}_${META_ID_ORIGIN_SUFFIX}`; +export const FORMATTERS_ID_ORIGIN_SUFFIX = 'formatters'; +export const SOURCE_FORMATTERS_ID_ORIGIN = `${SOURCE_DATA_ID_ORIGIN}_${FORMATTERS_ID_ORIGIN_SUFFIX}`; + +export const GEOJSON_FILE = 'GEOJSON_FILE'; + +export const MIN_ZOOM = 0; +export const MAX_ZOOM = 24; + +export const DECIMAL_DEGREES_PRECISION = 5; // meters precision +export const ZOOM_PRECISION = 2; +export const DEFAULT_MAX_RESULT_WINDOW = 10000; +export const DEFAULT_MAX_INNER_RESULT_WINDOW = 100; +export const DEFAULT_MAX_BUCKETS_LIMIT = 10000; + +export const FEATURE_ID_PROPERTY_NAME = '__kbn__feature_id__'; +export const FEATURE_VISIBLE_PROPERTY_NAME = '__kbn_isvisibleduetojoin__'; + +export const MB_SOURCE_ID_LAYER_ID_PREFIX_DELIMITER = '_'; + +export const ES_GEO_FIELD_TYPE = { + GEO_POINT: 'geo_point', + GEO_SHAPE: 'geo_shape', +}; + +export const ES_SPATIAL_RELATIONS = { + INTERSECTS: 'INTERSECTS', + DISJOINT: 'DISJOINT', + WITHIN: 'WITHIN', +}; + +export const GEO_JSON_TYPE = { + POINT: 'Point', + MULTI_POINT: 'MultiPoint', + LINE_STRING: 'LineString', + MULTI_LINE_STRING: 'MultiLineString', + POLYGON: 'Polygon', + MULTI_POLYGON: 'MultiPolygon', + GEOMETRY_COLLECTION: 'GeometryCollection', +}; + +export const POLYGON_COORDINATES_EXTERIOR_INDEX = 0; +export const LON_INDEX = 0; +export const LAT_INDEX = 1; + +export const EMPTY_FEATURE_COLLECTION = { + type: 'FeatureCollection', + features: [], +}; + +export const DRAW_TYPE = { + BOUNDS: 'BOUNDS', + POLYGON: 'POLYGON', +}; + +export const METRIC_TYPE = { + AVG: 'avg', + COUNT: 'count', + MAX: 'max', + MIN: 'min', + SUM: 'sum', + UNIQUE_COUNT: 'cardinality', +}; + +export const COUNT_AGG_TYPE = METRIC_TYPE.COUNT; +export const COUNT_PROP_LABEL = i18n.translate('xpack.maps.aggs.defaultCountLabel', { + defaultMessage: 'count', +}); + +export const COUNT_PROP_NAME = 'doc_count'; + +export const STYLE_TYPE = { + STATIC: 'STATIC', + DYNAMIC: 'DYNAMIC', +}; + +export const LAYER_STYLE_TYPE = { + VECTOR: 'VECTOR', + HEATMAP: 'HEATMAP', +}; + +export const COLOR_MAP_TYPE = { + CATEGORICAL: 'CATEGORICAL', + ORDINAL: 'ORDINAL', +}; + +export const COLOR_PALETTE_MAX_SIZE = 10; + +export const CATEGORICAL_DATA_TYPES = ['string', 'ip', 'boolean']; + +export const SYMBOLIZE_AS_TYPES = { + CIRCLE: 'circle', + ICON: 'icon', +}; + +export const DEFAULT_ICON = 'airfield'; diff --git a/x-pack/plugins/maps/common/i18n_getters.js b/x-pack/plugins/maps/common/i18n_getters.js new file mode 100644 index 00000000000000..578d0cd4780e96 --- /dev/null +++ b/x-pack/plugins/maps/common/i18n_getters.js @@ -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; + * you may not use this file except in compliance with the Elastic License. + */ + +import { i18n } from '@kbn/i18n'; + +import { ES_SPATIAL_RELATIONS } from './constants'; + +export function getAppTitle() { + return i18n.translate('xpack.maps.appTitle', { + defaultMessage: 'Maps', + }); +} + +export function getDataSourceLabel() { + return i18n.translate('xpack.maps.source.dataSourceLabel', { + defaultMessage: 'Data source', + }); +} + +export function getUrlLabel() { + return i18n.translate('xpack.maps.source.urlLabel', { + defaultMessage: 'Url', + }); +} + +export function getEsSpatialRelationLabel(spatialRelation) { + switch (spatialRelation) { + case ES_SPATIAL_RELATIONS.INTERSECTS: + return i18n.translate('xpack.maps.common.esSpatialRelation.intersectsLabel', { + defaultMessage: 'intersects', + }); + case ES_SPATIAL_RELATIONS.DISJOINT: + return i18n.translate('xpack.maps.common.esSpatialRelation.disjointLabel', { + defaultMessage: 'disjoint', + }); + case ES_SPATIAL_RELATIONS.WITHIN: + return i18n.translate('xpack.maps.common.esSpatialRelation.withinLabel', { + defaultMessage: 'within', + }); + case ES_SPATIAL_RELATIONS.CONTAINS: + return i18n.translate('xpack.maps.common.esSpatialRelation.containsLabel', { + defaultMessage: 'contains', + }); + default: + return spatialRelation; + } +} diff --git a/x-pack/plugins/maps/common/parse_xml_string.js b/x-pack/plugins/maps/common/parse_xml_string.js new file mode 100644 index 00000000000000..9d95e0e78280d5 --- /dev/null +++ b/x-pack/plugins/maps/common/parse_xml_string.js @@ -0,0 +1,22 @@ +/* + * 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 { parseString } from 'xml2js'; + +// promise based wrapper around parseString +export async function parseXmlString(xmlString) { + const parsePromise = new Promise((resolve, reject) => { + parseString(xmlString, (error, result) => { + if (error) { + reject(error); + } else { + resolve(result); + } + }); + }); + + return await parsePromise; +} diff --git a/x-pack/plugins/maps/common/parse_xml_string.test.js b/x-pack/plugins/maps/common/parse_xml_string.test.js new file mode 100644 index 00000000000000..cfd6235667aae1 --- /dev/null +++ b/x-pack/plugins/maps/common/parse_xml_string.test.js @@ -0,0 +1,16 @@ +/* + * 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 { parseXmlString } from './parse_xml_string'; + +describe('parseXmlString', () => { + it('Should parse xml string into JS object', async () => { + const xmlAsObject = await parseXmlString('bar'); + expect(xmlAsObject).toEqual({ + foo: 'bar', + }); + }); +}); diff --git a/x-pack/plugins/maps/kibana.json b/x-pack/plugins/maps/kibana.json new file mode 100644 index 00000000000000..25a5efa9bc0dad --- /dev/null +++ b/x-pack/plugins/maps/kibana.json @@ -0,0 +1,8 @@ +{ + "id": "maps", + "version": "8.0.0", + "kibanaVersion": "kibana", + "configPath": ["xpack", "maps"], + "requiredPlugins": ["data"], + "ui": true +} diff --git a/x-pack/plugins/maps/public/actions/map_actions.js b/x-pack/plugins/maps/public/actions/map_actions.js new file mode 100644 index 00000000000000..5b99f277a16948 --- /dev/null +++ b/x-pack/plugins/maps/public/actions/map_actions.js @@ -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; + * you may not use this file except in compliance with the Elastic License. + */ + +import {getDataFilters} from "../../../../legacy/plugins/maps/public/selectors/map_selectors"; + +export const SET_SELECTED_LAYER = 'SET_SELECTED_LAYER'; +export const SET_TRANSIENT_LAYER = 'SET_TRANSIENT_LAYER'; +export const UPDATE_LAYER_ORDER = 'UPDATE_LAYER_ORDER'; +export const ADD_LAYER = 'ADD_LAYER'; +export const SET_LAYER_ERROR_STATUS = 'SET_LAYER_ERROR_STATUS'; +export const ADD_WAITING_FOR_MAP_READY_LAYER = 'ADD_WAITING_FOR_MAP_READY_LAYER'; +export const CLEAR_WAITING_FOR_MAP_READY_LAYER_LIST = 'CLEAR_WAITING_FOR_MAP_READY_LAYER_LIST'; +export const REMOVE_LAYER = 'REMOVE_LAYER'; +export const SET_LAYER_VISIBILITY = 'SET_LAYER_VISIBILITY'; +export const MAP_EXTENT_CHANGED = 'MAP_EXTENT_CHANGED'; +export const MAP_READY = 'MAP_READY'; +export const MAP_DESTROYED = 'MAP_DESTROYED'; +export const LAYER_DATA_LOAD_STARTED = 'LAYER_DATA_LOAD_STARTED'; +export const LAYER_DATA_LOAD_ENDED = 'LAYER_DATA_LOAD_ENDED'; +export const LAYER_DATA_LOAD_ERROR = 'LAYER_DATA_LOAD_ERROR'; +export const UPDATE_SOURCE_DATA_REQUEST = 'UPDATE_SOURCE_DATA_REQUEST'; +export const SET_JOINS = 'SET_JOINS'; +export const SET_QUERY = 'SET_QUERY'; +export const TRIGGER_REFRESH_TIMER = 'TRIGGER_REFRESH_TIMER'; +export const UPDATE_LAYER_PROP = 'UPDATE_LAYER_PROP'; +export const UPDATE_LAYER_STYLE = 'UPDATE_LAYER_STYLE'; +export const SET_LAYER_STYLE_META = 'SET_LAYER_STYLE_META'; +export const TOUCH_LAYER = 'TOUCH_LAYER'; +export const UPDATE_SOURCE_PROP = 'UPDATE_SOURCE_PROP'; +export const SET_REFRESH_CONFIG = 'SET_REFRESH_CONFIG'; +export const SET_MOUSE_COORDINATES = 'SET_MOUSE_COORDINATES'; +export const CLEAR_MOUSE_COORDINATES = 'CLEAR_MOUSE_COORDINATES'; +export const SET_GOTO = 'SET_GOTO'; +export const CLEAR_GOTO = 'CLEAR_GOTO'; +export const TRACK_CURRENT_LAYER_STATE = 'TRACK_CURRENT_LAYER_STATE'; +export const ROLLBACK_TO_TRACKED_LAYER_STATE = 'ROLLBACK_TO_TRACKED_LAYER_STATE'; +export const REMOVE_TRACKED_LAYER_STATE = 'REMOVE_TRACKED_LAYER_STATE'; +export const SET_TOOLTIP_STATE = 'SET_TOOLTIP_STATE'; +export const UPDATE_DRAW_STATE = 'UPDATE_DRAW_STATE'; +export const SET_SCROLL_ZOOM = 'SET_SCROLL_ZOOM'; +export const SET_MAP_INIT_ERROR = 'SET_MAP_INIT_ERROR'; +export const SET_INTERACTIVE = 'SET_INTERACTIVE'; +export const DISABLE_TOOLTIP_CONTROL = 'DISABLE_TOOLTIP_CONTROL'; +export const HIDE_TOOLBAR_OVERLAY = 'HIDE_TOOLBAR_OVERLAY'; +export const HIDE_LAYER_CONTROL = 'HIDE_LAYER_CONTROL'; +export const HIDE_VIEW_CONTROL = 'HIDE_VIEW_CONTROL'; +export const SET_WAITING_FOR_READY_HIDDEN_LAYERS = 'SET_WAITING_FOR_READY_HIDDEN_LAYERS'; diff --git a/x-pack/plugins/maps/public/actions/ui_actions.js b/x-pack/plugins/maps/public/actions/ui_actions.js new file mode 100644 index 00000000000000..fb6f1d97ac67f0 --- /dev/null +++ b/x-pack/plugins/maps/public/actions/ui_actions.js @@ -0,0 +1,23 @@ +/* + * 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. + */ + +export const UPDATE_FLYOUT = 'UPDATE_FLYOUT'; +export const CLOSE_SET_VIEW = 'CLOSE_SET_VIEW'; +export const OPEN_SET_VIEW = 'OPEN_SET_VIEW'; +export const SET_IS_LAYER_TOC_OPEN = 'SET_IS_LAYER_TOC_OPEN'; +export const SET_FULL_SCREEN = 'SET_FULL_SCREEN'; +export const SET_READ_ONLY = 'SET_READ_ONLY'; +export const SET_OPEN_TOC_DETAILS = 'SET_OPEN_TOC_DETAILS'; +export const SHOW_TOC_DETAILS = 'SHOW_TOC_DETAILS'; +export const HIDE_TOC_DETAILS = 'HIDE_TOC_DETAILS'; +export const UPDATE_INDEXING_STAGE = 'UPDATE_INDEXING_STAGE'; + +export function exitFullScreen() { + return { + type: SET_FULL_SCREEN, + isFullScreen: false, + }; +} diff --git a/x-pack/plugins/maps/public/applications/maps/index.tsx b/x-pack/plugins/maps/public/applications/maps/index.tsx new file mode 100644 index 00000000000000..9bea41126d2963 --- /dev/null +++ b/x-pack/plugins/maps/public/applications/maps/index.tsx @@ -0,0 +1,78 @@ +/* + * 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 * as React from 'react'; +import ReactDOM from 'react-dom'; +import { CoreStart, AppMountParameters } from 'kibana/public'; +import { I18nProvider, FormattedMessage } from '@kbn/i18n/react'; +import { Route, BrowserRouter, Switch } from 'react-router-dom'; +import { Provider } from 'react-redux'; +import { Store } from 'redux'; +import { appStoreFactory } from './store'; +import { AlertIndex } from './view/alerts'; + +/** + * This module will be loaded asynchronously to reduce the bundle size of your plugin's main bundle. + */ +export function renderApp(coreStart: CoreStart, { appBasePath, element }: AppMountParameters) { + coreStart.http.get('/api/endpoint/hello-world'); + + const [store, stopSagas] = appStoreFactory(coreStart); + + ReactDOM.render(, element); + + return () => { + ReactDOM.unmountComponentAtNode(element); + stopSagas(); + }; +} + +interface RouterProps { + basename: string; + store: Store; +} + +const AppRoot: React.FunctionComponent = React.memo(({ basename, store }) => ( + + + + + ( +

+ +

+ )} + /> + { + // FIXME: This is temporary. Will be removed in next PR for endpoint list + store.dispatch({ type: 'userEnteredEndpointListPage' }); + + return ( +

+ +

+ ); + }} + /> + + ( + + )} + /> +
+
+
+
+)); diff --git a/x-pack/plugins/maps/public/connected_components/gis_map/_gis_map.scss b/x-pack/plugins/maps/public/connected_components/gis_map/_gis_map.scss new file mode 100644 index 00000000000000..85168d970c6dec --- /dev/null +++ b/x-pack/plugins/maps/public/connected_components/gis_map/_gis_map.scss @@ -0,0 +1,19 @@ +.mapMapWrapper { + background-color: $euiColorEmptyShade; + position: relative; +} + +.mapMapLayerPanel { + background-color: $euiPageBackgroundColor; + width: 0; + overflow: hidden; + + > * { + width: $euiSizeXXL * 11; + } + + &-isVisible { + width: $euiSizeXXL * 11; + transition: width $euiAnimSpeedNormal $euiAnimSlightResistance; + } +} diff --git a/x-pack/plugins/maps/public/connected_components/gis_map/index.js b/x-pack/plugins/maps/public/connected_components/gis_map/index.js new file mode 100644 index 00000000000000..ceb0a6ea9f9225 --- /dev/null +++ b/x-pack/plugins/maps/public/connected_components/gis_map/index.js @@ -0,0 +1,45 @@ +/* + * 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 { connect } from 'react-redux'; +import { GisMap } from './view'; +import { FLYOUT_STATE } from '../../reducers/ui'; +import { exitFullScreen } from '../../actions/ui_actions'; +import { getFlyoutDisplay, getIsFullScreen } from '../../selectors/ui_selectors'; +import { triggerRefreshTimer, cancelAllInFlightRequests } from '../../actions/map_actions'; +import { + areLayersLoaded, + getRefreshConfig, + getMapInitError, + getQueryableUniqueIndexPatternIds, + isToolbarOverlayHidden, +} from '../../selectors/map_selectors'; + +function mapStateToProps(state = {}) { + const flyoutDisplay = getFlyoutDisplay(state); + return { + areLayersLoaded: areLayersLoaded(state), + layerDetailsVisible: flyoutDisplay === FLYOUT_STATE.LAYER_PANEL, + addLayerVisible: flyoutDisplay === FLYOUT_STATE.ADD_LAYER_WIZARD, + noFlyoutVisible: flyoutDisplay === FLYOUT_STATE.NONE, + isFullScreen: getIsFullScreen(state), + refreshConfig: getRefreshConfig(state), + mapInitError: getMapInitError(state), + indexPatternIds: getQueryableUniqueIndexPatternIds(state), + hideToolbarOverlay: isToolbarOverlayHidden(state), + }; +} + +function mapDispatchToProps(dispatch) { + return { + triggerRefreshTimer: () => dispatch(triggerRefreshTimer()), + exitFullScreen: () => dispatch(exitFullScreen()), + cancelAllInFlightRequests: () => dispatch(cancelAllInFlightRequests()), + }; +} + +const connectedGisMap = connect(mapStateToProps, mapDispatchToProps)(GisMap); +export { connectedGisMap as GisMap }; diff --git a/x-pack/plugins/maps/public/connected_components/gis_map/view.js b/x-pack/plugins/maps/public/connected_components/gis_map/view.js new file mode 100644 index 00000000000000..0c16cb9a0ae177 --- /dev/null +++ b/x-pack/plugins/maps/public/connected_components/gis_map/view.js @@ -0,0 +1,222 @@ +/* + * 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 React, { Component } from 'react'; +import { MBMapContainer } from '../map/mb'; +import { WidgetOverlay } from '../widget_overlay/index'; +import { ToolbarOverlay } from '../toolbar_overlay/index'; +import { LayerPanel } from '../layer_panel/index'; +import { AddLayerPanel } from '../layer_addpanel/index'; +import { EuiFlexGroup, EuiFlexItem, EuiCallOut } from '@elastic/eui'; +import { getIndexPatternsFromIds } from '../../index_pattern_util'; +import { ES_GEO_FIELD_TYPE } from '../../../common/constants'; +import { isNestedField } from '../../../../../../src/plugins/data/public'; +import { i18n } from '@kbn/i18n'; +import uuid from 'uuid/v4'; + +// TODO +import { ExitFullScreenButton } from 'ui/exit_full_screen'; + +const RENDER_COMPLETE_EVENT = 'renderComplete'; + +export class GisMap extends Component { + state = { + isInitialLoadRenderTimeoutComplete: false, + domId: uuid(), + geoFields: [], + }; + + componentDidMount() { + this._isMounted = true; + this._isInitalLoadRenderTimerStarted = false; + this._setRefreshTimer(); + } + + componentDidUpdate() { + this._setRefreshTimer(); + if (this.props.areLayersLoaded && !this._isInitalLoadRenderTimerStarted) { + this._isInitalLoadRenderTimerStarted = true; + this._startInitialLoadRenderTimer(); + } + + if (!!this.props.addFilters) { + this._loadGeoFields(this.props.indexPatternIds); + } + } + + componentWillUnmount() { + this._isMounted = false; + this._clearRefreshTimer(); + this.props.cancelAllInFlightRequests(); + } + + // Reporting uses both a `data-render-complete` attribute and a DOM event listener to determine + // if a visualization is done loading. The process roughly is: + // - See if the `data-render-complete` attribute is "true". If so we're done! + // - If it's not, then reporting injects a listener into the browser for a custom "renderComplete" event. + // - When that event is fired, we snapshot the viz and move on. + // Failure to not have the dom attribute, or custom event, will timeout the job. + // See x-pack/legacy/plugins/reporting/export_types/common/lib/screenshots/wait_for_render.ts for more. + _onInitialLoadRenderComplete = () => { + const el = document.querySelector(`[data-dom-id="${this.state.domId}"]`); + + if (el) { + el.dispatchEvent(new CustomEvent(RENDER_COMPLETE_EVENT, { bubbles: true })); + } + }; + + _loadGeoFields = async nextIndexPatternIds => { + if (_.isEqual(nextIndexPatternIds, this._prevIndexPatternIds)) { + // all ready loaded index pattern ids + return; + } + + this._prevIndexPatternIds = nextIndexPatternIds; + + const geoFields = []; + try { + const indexPatterns = await getIndexPatternsFromIds(nextIndexPatternIds); + indexPatterns.forEach(indexPattern => { + indexPattern.fields.forEach(field => { + if ( + !isNestedField(field) && + (field.type === ES_GEO_FIELD_TYPE.GEO_POINT || + field.type === ES_GEO_FIELD_TYPE.GEO_SHAPE) + ) { + geoFields.push({ + geoFieldName: field.name, + geoFieldType: field.type, + indexPatternTitle: indexPattern.title, + indexPatternId: indexPattern.id, + }); + } + }); + }); + } catch (e) { + // swallow errors. + // the Layer-TOC will indicate which layers are disfunctional on a per-layer basis + } + + if (!this._isMounted) { + return; + } + + this.setState({ geoFields }); + }; + + _setRefreshTimer = () => { + const { isPaused, interval } = this.props.refreshConfig; + + if (this.isPaused === isPaused && this.interval === interval) { + // refreshConfig is the same, nothing to do + return; + } + + this.isPaused = isPaused; + this.interval = interval; + + this._clearRefreshTimer(); + + if (!isPaused && interval > 0) { + this.refreshTimerId = setInterval(() => { + this.props.triggerRefreshTimer(); + }, interval); + } + }; + + _clearRefreshTimer = () => { + if (this.refreshTimerId) { + clearInterval(this.refreshTimerId); + } + }; + + // Mapbox does not provide any feedback when rendering is complete. + // Temporary solution is just to wait set period of time after data has loaded. + _startInitialLoadRenderTimer = () => { + setTimeout(() => { + if (this._isMounted) { + this.setState({ isInitialLoadRenderTimeoutComplete: true }); + this._onInitialLoadRenderComplete(); + } + }, 5000); + }; + + render() { + const { + addFilters, + layerDetailsVisible, + addLayerVisible, + noFlyoutVisible, + isFullScreen, + exitFullScreen, + mapInitError, + renderTooltipContent, + } = this.props; + + const { domId } = this.state; + + if (mapInitError) { + return ( +
+ +

{mapInitError}

+
+
+ ); + } + + let currentPanel; + let currentPanelClassName; + if (noFlyoutVisible) { + currentPanel = null; + } else if (addLayerVisible) { + currentPanelClassName = 'mapMapLayerPanel-isVisible'; + currentPanel = ; + } else if (layerDetailsVisible) { + currentPanelClassName = 'mapMapLayerPanel-isVisible'; + currentPanel = ; + } + + let exitFullScreenButton; + if (isFullScreen) { + exitFullScreenButton = ; + } + return ( + + + + {!this.props.hideToolbarOverlay && ( + + )} + + + + + {currentPanel} + + + {exitFullScreenButton} + + ); + } +} diff --git a/x-pack/plugins/maps/public/index.ts b/x-pack/plugins/maps/public/index.ts new file mode 100644 index 00000000000000..985da137eff359 --- /dev/null +++ b/x-pack/plugins/maps/public/index.ts @@ -0,0 +1,14 @@ +/* + * 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 { PluginInitializer, PluginInitializerContext } from 'kibana/public'; +import { MapsPlugin, MapsPluginSetup, MapsPluginStart } from './plugin'; + +export const plugin: PluginInitializer = ( + context: PluginInitializerContext +) => { + return new MapsPlugin(context); +}; diff --git a/x-pack/plugins/maps/public/kibana_services.js b/x-pack/plugins/maps/public/kibana_services.js new file mode 100644 index 00000000000000..a158ff21279001 --- /dev/null +++ b/x-pack/plugins/maps/public/kibana_services.js @@ -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; + * you may not use this file except in compliance with the Elastic License. + */ + +export let indexPatternService; +export let timeFilter; + +export const initKibanaServices = ({ data }) => { + indexPatternService = data.indexPatterns; + timeFilter: data.query.timefilter +}; diff --git a/x-pack/plugins/maps/public/plugin.ts b/x-pack/plugins/maps/public/plugin.ts new file mode 100644 index 00000000000000..9144ec2a924094 --- /dev/null +++ b/x-pack/plugins/maps/public/plugin.ts @@ -0,0 +1,79 @@ +/* + * 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 { + Plugin, + CoreSetup, + CoreStart, + PluginInitializerContext, + AppMountParameters +} from 'src/core/public'; +import { auto } from 'angular'; +import { IEmbeddableSetup } from '../../../../src/plugins/embeddable/public'; +// @ts-ignore +import { MapEmbeddableFactory } from './embeddable/map_embeddable_factory.js'; +// @ts-ignore +import { MAP_SAVED_OBJECT_TYPE } from '../common/constants'; +import { initKibanaServices } from './kibana_services'; +import {i18n} from "@kbn/i18n"; +import {createStore} from "../../../legacy/plugins/canvas/public/store"; + +export interface MapsPluginSetupDependencies { + embeddable: IEmbeddableSetup; +} +// eslint-disable-line @typescript-eslint/no-empty-interface +export interface MapsPluginStartDependencies {} + +/** + * These are the interfaces with your public contracts. You should export these + * for other plugins to use in _their_ `SetupDeps`/`StartDeps` interfaces. + * @public + */ +export type MapsPluginSetup = ReturnType; +export type MapsPluginStart = ReturnType; + +/** @internal */ +export class MapsPlugin + implements + Plugin< + MapsPluginSetup, + MapsPluginStart, + MapsPluginSetupDependencies, + MapsPluginStartDependencies + > { + private getEmbeddableInjector: (() => Promise) | null = null; + constructor(context: PluginInitializerContext) {} + + public setup(core: CoreSetup, plugins: MapsPluginSetupDependencies) { + core.application.register({ + id: 'maps', + title: i18n.translate('xpack.maps.pluginTitle', { + defaultMessage: 'Maps', + }), + async mount() { + }, + }); + + initKibanaServices(plugins); + // Set up embeddables + const isEditable = () => core.application.capabilities.get().maps.save as boolean; + if (!this.getEmbeddableInjector) { + throw Error('Maps plugin method getEmbeddableInjector is undefined'); + } + const addBasePath = core.http.basePath.prepend; + const factory = new MapEmbeddableFactory( + this.getEmbeddableInjector, + isEditable, + addBasePath + ); + plugins.embeddable.registerEmbeddableFactory(factory.type, factory); + plugins.embeddable.registerEmbeddableFactory(MAP_SAVED_OBJECT_TYPE, new MapEmbeddableFactory()); + } + + public start(core: CoreStart, plugins: any) { + // setInspector(plugins.np.inspector); + } +} diff --git a/x-pack/plugins/maps/public/reducers/map.js b/x-pack/plugins/maps/public/reducers/map.js new file mode 100644 index 00000000000000..234584d08a3114 --- /dev/null +++ b/x-pack/plugins/maps/public/reducers/map.js @@ -0,0 +1,543 @@ +/* + * 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 { + SET_SELECTED_LAYER, + SET_TRANSIENT_LAYER, + UPDATE_LAYER_ORDER, + LAYER_DATA_LOAD_STARTED, + LAYER_DATA_LOAD_ENDED, + LAYER_DATA_LOAD_ERROR, + ADD_LAYER, + SET_LAYER_ERROR_STATUS, + ADD_WAITING_FOR_MAP_READY_LAYER, + CLEAR_WAITING_FOR_MAP_READY_LAYER_LIST, + REMOVE_LAYER, + SET_LAYER_VISIBILITY, + MAP_EXTENT_CHANGED, + MAP_READY, + MAP_DESTROYED, + SET_QUERY, + UPDATE_LAYER_PROP, + UPDATE_LAYER_STYLE, + SET_LAYER_STYLE_META, + SET_JOINS, + TOUCH_LAYER, + UPDATE_SOURCE_PROP, + SET_REFRESH_CONFIG, + TRIGGER_REFRESH_TIMER, + SET_MOUSE_COORDINATES, + CLEAR_MOUSE_COORDINATES, + SET_GOTO, + CLEAR_GOTO, + TRACK_CURRENT_LAYER_STATE, + ROLLBACK_TO_TRACKED_LAYER_STATE, + REMOVE_TRACKED_LAYER_STATE, + UPDATE_SOURCE_DATA_REQUEST, + SET_TOOLTIP_STATE, + SET_SCROLL_ZOOM, + SET_MAP_INIT_ERROR, + UPDATE_DRAW_STATE, + SET_INTERACTIVE, + DISABLE_TOOLTIP_CONTROL, + HIDE_TOOLBAR_OVERLAY, + HIDE_LAYER_CONTROL, + HIDE_VIEW_CONTROL, + SET_WAITING_FOR_READY_HIDDEN_LAYERS, +} from '../actions/map_actions'; + +import { copyPersistentState, TRACKED_LAYER_DESCRIPTOR } from './util'; +import { SOURCE_DATA_ID_ORIGIN } from '../../common/constants'; + +const getLayerIndex = (list, layerId) => list.findIndex(({ id }) => layerId === id); + +const updateLayerInList = (state, layerId, attribute, newValue) => { + if (!layerId) { + return state; + } + const { layerList } = state; + const layerIdx = getLayerIndex(layerList, layerId); + const updatedLayer = { + ...layerList[layerIdx], + // Update layer w/ new value. If no value provided, toggle boolean value + // allow empty strings, 0-value + [attribute]: + newValue || newValue === '' || newValue === 0 ? newValue : !layerList[layerIdx][attribute], + }; + const updatedList = [ + ...layerList.slice(0, layerIdx), + updatedLayer, + ...layerList.slice(layerIdx + 1), + ]; + return { ...state, layerList: updatedList }; +}; + +const updateLayerSourceDescriptorProp = (state, layerId, propName, value) => { + const { layerList } = state; + const layerIdx = getLayerIndex(layerList, layerId); + const updatedLayer = { + ...layerList[layerIdx], + sourceDescriptor: { + ...layerList[layerIdx].sourceDescriptor, + [propName]: value, + }, + }; + const updatedList = [ + ...layerList.slice(0, layerIdx), + updatedLayer, + ...layerList.slice(layerIdx + 1), + ]; + return { ...state, layerList: updatedList }; +}; + +const INITIAL_STATE = { + ready: false, + mapInitError: null, + goto: null, + tooltipState: null, + mapState: { + zoom: null, // setting this value does not adjust map zoom, read only value used to store current map zoom for persisting between sessions + center: null, // setting this value does not adjust map view, read only value used to store current map center for persisting between sessions + scrollZoom: true, + extent: null, + mouseCoordinates: null, + timeFilters: null, + query: null, + filters: [], + refreshConfig: null, + refreshTimerLastTriggeredAt: null, + drawState: null, + disableInteractive: false, + disableTooltipControl: false, + hideToolbarOverlay: false, + hideLayerControl: false, + hideViewControl: false, + }, + selectedLayerId: null, + __transientLayerId: null, + layerList: [], + waitingForMapReadyLayerList: [], +}; + +export function map(state = INITIAL_STATE, action) { + switch (action.type) { + case UPDATE_DRAW_STATE: + return { + ...state, + mapState: { + ...state.mapState, + drawState: action.drawState, + }, + }; + case REMOVE_TRACKED_LAYER_STATE: + return removeTrackedLayerState(state, action.layerId); + case TRACK_CURRENT_LAYER_STATE: + return trackCurrentLayerState(state, action.layerId); + case ROLLBACK_TO_TRACKED_LAYER_STATE: + return rollbackTrackedLayerState(state, action.layerId); + case SET_TOOLTIP_STATE: + return { + ...state, + tooltipState: action.tooltipState, + }; + case SET_MOUSE_COORDINATES: + return { + ...state, + mapState: { + ...state.mapState, + mouseCoordinates: { + lat: action.lat, + lon: action.lon, + }, + }, + }; + case CLEAR_MOUSE_COORDINATES: + return { + ...state, + mapState: { + ...state.mapState, + mouseCoordinates: null, + }, + }; + case SET_GOTO: + return { + ...state, + goto: { + center: action.center, + bounds: action.bounds, + }, + }; + case CLEAR_GOTO: + return { + ...state, + goto: null, + }; + case SET_LAYER_ERROR_STATUS: + const { layerList } = state; + const layerIdx = getLayerIndex(layerList, action.layerId); + if (layerIdx === -1) { + return state; + } + + return { + ...state, + layerList: [ + ...layerList.slice(0, layerIdx), + { + ...layerList[layerIdx], + __isInErrorState: action.isInErrorState, + __errorMessage: action.errorMessage, + }, + ...layerList.slice(layerIdx + 1), + ], + }; + case UPDATE_SOURCE_DATA_REQUEST: + return updateSourceDataRequest(state, action); + case LAYER_DATA_LOAD_STARTED: + return updateWithDataRequest(state, action); + case LAYER_DATA_LOAD_ERROR: + return updateWithDataResponse(state, action); + case LAYER_DATA_LOAD_ENDED: + return updateWithDataResponse(state, action); + case TOUCH_LAYER: + //action to enforce a reflow of the styles + const layer = state.layerList.find(layer => layer.id === action.layerId); + if (!layer) { + return state; + } + const indexOfLayer = state.layerList.indexOf(layer); + const newLayer = { ...layer }; + const newLayerList = [...state.layerList]; + newLayerList[indexOfLayer] = newLayer; + return { ...state, layerList: newLayerList }; + case MAP_READY: + return { ...state, ready: true }; + case MAP_DESTROYED: + return { ...state, ready: false }; + case MAP_EXTENT_CHANGED: + const newMapState = { + center: action.mapState.center, + zoom: action.mapState.zoom, + extent: action.mapState.extent, + buffer: action.mapState.buffer, + }; + return { ...state, mapState: { ...state.mapState, ...newMapState } }; + case SET_QUERY: + const { query, timeFilters, filters } = action; + return { + ...state, + mapState: { + ...state.mapState, + query, + timeFilters, + filters, + }, + }; + case SET_REFRESH_CONFIG: + const { isPaused, interval } = action; + return { + ...state, + mapState: { + ...state.mapState, + refreshConfig: { + isPaused, + interval, + }, + }, + }; + case TRIGGER_REFRESH_TIMER: + return { + ...state, + mapState: { + ...state.mapState, + refreshTimerLastTriggeredAt: new Date().toISOString(), + }, + }; + case SET_SELECTED_LAYER: + const selectedMatch = state.layerList.find(layer => layer.id === action.selectedLayerId); + return { ...state, selectedLayerId: selectedMatch ? action.selectedLayerId : null }; + case SET_TRANSIENT_LAYER: + const transientMatch = state.layerList.find(layer => layer.id === action.transientLayerId); + return { ...state, __transientLayerId: transientMatch ? action.transientLayerId : null }; + case UPDATE_LAYER_ORDER: + return { + ...state, + layerList: action.newLayerOrder.map(layerNumber => state.layerList[layerNumber]), + }; + case UPDATE_LAYER_PROP: + return updateLayerInList(state, action.id, action.propName, action.newValue); + case UPDATE_SOURCE_PROP: + return updateLayerSourceDescriptorProp(state, action.layerId, action.propName, action.value); + case SET_JOINS: + const layerDescriptor = state.layerList.find( + descriptor => descriptor.id === action.layer.getId() + ); + if (layerDescriptor) { + const newLayerDescriptor = { ...layerDescriptor, joins: action.joins.slice() }; + const index = state.layerList.findIndex( + descriptor => descriptor.id === action.layer.getId() + ); + const newLayerList = state.layerList.slice(); + newLayerList[index] = newLayerDescriptor; + return { ...state, layerList: newLayerList }; + } + return state; + case ADD_LAYER: + return { + ...state, + layerList: [...state.layerList, action.layer], + }; + case REMOVE_LAYER: + return { + ...state, + layerList: [...state.layerList.filter(({ id }) => id !== action.id)], + }; + case ADD_WAITING_FOR_MAP_READY_LAYER: + return { + ...state, + waitingForMapReadyLayerList: [...state.waitingForMapReadyLayerList, action.layer], + }; + case CLEAR_WAITING_FOR_MAP_READY_LAYER_LIST: + return { + ...state, + waitingForMapReadyLayerList: [], + }; + case SET_LAYER_VISIBILITY: + return updateLayerInList(state, action.layerId, 'visible', action.visibility); + case UPDATE_LAYER_STYLE: + const styleLayerId = action.layerId; + return updateLayerInList(state, styleLayerId, 'style', { ...action.style }); + case SET_LAYER_STYLE_META: + const { layerId, styleMeta } = action; + const index = getLayerIndex(state.layerList, layerId); + if (index === -1) { + return state; + } + + return updateLayerInList(state, layerId, 'style', { + ...state.layerList[index].style, + __styleMeta: styleMeta, + }); + case SET_SCROLL_ZOOM: + return { + ...state, + mapState: { + ...state.mapState, + scrollZoom: action.scrollZoom, + }, + }; + case SET_MAP_INIT_ERROR: + return { + ...state, + mapInitError: action.errorMessage, + }; + case SET_INTERACTIVE: + return { + ...state, + mapState: { + ...state.mapState, + disableInteractive: action.disableInteractive, + }, + }; + case DISABLE_TOOLTIP_CONTROL: + return { + ...state, + mapState: { + ...state.mapState, + disableTooltipControl: action.disableTooltipControl, + }, + }; + case HIDE_TOOLBAR_OVERLAY: + return { + ...state, + mapState: { + ...state.mapState, + hideToolbarOverlay: action.hideToolbarOverlay, + }, + }; + case HIDE_LAYER_CONTROL: + return { + ...state, + mapState: { + ...state.mapState, + hideLayerControl: action.hideLayerControl, + }, + }; + case HIDE_VIEW_CONTROL: + return { + ...state, + mapState: { + ...state.mapState, + hideViewControl: action.hideViewControl, + }, + }; + case SET_WAITING_FOR_READY_HIDDEN_LAYERS: + return { + ...state, + waitingForMapReadyLayerList: state.waitingForMapReadyLayerList.map(layer => ({ + ...layer, + visible: !action.hiddenLayerIds.includes(layer.id), + })), + }; + default: + return state; + } +} + +function findDataRequest(layerDescriptor, dataRequestAction) { + if (!layerDescriptor.__dataRequests) { + return; + } + + return layerDescriptor.__dataRequests.find(dataRequest => { + return dataRequest.dataId === dataRequestAction.dataId; + }); +} + +function updateWithDataRequest(state, action) { + let dataRequest = getValidDataRequest(state, action, false); + const layerRequestingData = findLayerById(state, action.layerId); + + if (!dataRequest) { + dataRequest = { + dataId: action.dataId, + }; + layerRequestingData.__dataRequests = [ + ...(layerRequestingData.__dataRequests ? layerRequestingData.__dataRequests : []), + dataRequest, + ]; + } + dataRequest.dataMetaAtStart = action.meta; + dataRequest.dataRequestToken = action.requestToken; + const layerList = [...state.layerList]; + return { ...state, layerList }; +} + +function updateSourceDataRequest(state, action) { + const layerDescriptor = findLayerById(state, action.layerId); + if (!layerDescriptor) { + return state; + } + const dataRequest = layerDescriptor.__dataRequests.find(dataRequest => { + return dataRequest.dataId === SOURCE_DATA_ID_ORIGIN; + }); + if (!dataRequest) { + return state; + } + + dataRequest.data = action.newData; + return resetDataRequest(state, action, dataRequest); +} + +function updateWithDataResponse(state, action) { + const dataRequest = getValidDataRequest(state, action); + if (!dataRequest) { + return state; + } + + dataRequest.data = action.data; + dataRequest.dataMeta = { ...dataRequest.dataMetaAtStart, ...action.meta }; + dataRequest.dataMetaAtStart = null; + return resetDataRequest(state, action, dataRequest); +} + +export function resetDataRequest(state, action, request) { + const dataRequest = request || getValidDataRequest(state, action); + if (!dataRequest) { + return state; + } + + const layer = findLayerById(state, action.layerId); + const dataRequestIndex = layer.__dataRequests.indexOf(dataRequest); + + const newDataRequests = [...layer.__dataRequests]; + newDataRequests[dataRequestIndex] = { + ...dataRequest, + dataRequestToken: null, + }; + + const layerIndex = state.layerList.indexOf(layer); + const newLayerList = [...state.layerList]; + newLayerList[layerIndex] = { + ...layer, + __dataRequests: newDataRequests, + }; + return { ...state, layerList: newLayerList }; +} + +function getValidDataRequest(state, action, checkRequestToken = true) { + const layer = findLayerById(state, action.layerId); + if (!layer) { + return; + } + + const dataRequest = findDataRequest(layer, action); + if (!dataRequest) { + return; + } + + if ( + checkRequestToken && + dataRequest.dataRequestToken && + dataRequest.dataRequestToken !== action.requestToken + ) { + // ignore responses to outdated requests + return; + } + return dataRequest; +} + +function findLayerById(state, id) { + return state.layerList.find(layer => layer.id === id); +} + +function trackCurrentLayerState(state, layerId) { + const layer = findLayerById(state, layerId); + const layerCopy = copyPersistentState(layer); + return updateLayerInList(state, layerId, TRACKED_LAYER_DESCRIPTOR, layerCopy); +} + +function removeTrackedLayerState(state, layerId) { + const layer = findLayerById(state, layerId); + if (!layer) { + return state; + } + + const copyLayer = { ...layer }; + delete copyLayer[TRACKED_LAYER_DESCRIPTOR]; + + return { + ...state, + layerList: replaceInLayerList(state.layerList, layerId, copyLayer), + }; +} + +function rollbackTrackedLayerState(state, layerId) { + const layer = findLayerById(state, layerId); + if (!layer) { + return state; + } + + const trackedLayerDescriptor = layer[TRACKED_LAYER_DESCRIPTOR]; + + //this assumes that any nested temp-state in the layer-descriptor (e.g. of styles), is not relevant and can be recovered easily (e.g. this is not the case for __dataRequests) + //That assumption is true in the context of this app, but not generalizable. + //consider rewriting copyPersistentState to only strip the first level of temp state. + const rolledbackLayer = { ...layer, ...trackedLayerDescriptor }; + delete rolledbackLayer[TRACKED_LAYER_DESCRIPTOR]; + + return { + ...state, + layerList: replaceInLayerList(state.layerList, layerId, rolledbackLayer), + }; +} + +function replaceInLayerList(layerList, layerId, newLayerDescriptor) { + const layerIndex = getLayerIndex(layerList, layerId); + const newLayerList = [...layerList]; + newLayerList[layerIndex] = newLayerDescriptor; + return newLayerList; +} diff --git a/x-pack/plugins/maps/public/reducers/map.test.js b/x-pack/plugins/maps/public/reducers/map.test.js new file mode 100644 index 00000000000000..089dec952fc777 --- /dev/null +++ b/x-pack/plugins/maps/public/reducers/map.test.js @@ -0,0 +1,56 @@ +/* + * 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. + */ + +jest.mock('../actions/map_actions', () => ({})); + +import { resetDataRequest } from './map'; +import _ from 'lodash'; + +describe('reducers/map', () => { + it('Should clear datarequest without mutation store state', async () => { + const layerId = 'foobar'; + const requestToken = 'tokenId'; + const dataId = 'dataId'; + + const preState = { + layerList: [ + { + id: `not_${layerId}`, + }, + { + id: layerId, + __dataRequests: [ + { + dataRequestToken: `not_${requestToken}`, + dataId: `not_${dataId}`, + }, + { + dataRequestToken: requestToken, + dataId: dataId, + }, + ], + }, + ], + }; + + const preStateCopy = _.cloneDeep(preState); + + const action = { + layerId, + requestToken, + dataId, + }; + + const postState = resetDataRequest(preState, action); + + //Ensure previous state is not mutated. + expect(_.isEqual(preState, preStateCopy)).toEqual(true); + + //Ensure new state is set correctly. + expect(postState.layerList[1].__dataRequests[1].dataId).toEqual(dataId); + expect(postState.layerList[1].__dataRequests[1].dataRequestToken).toEqual(null); + }); +}); diff --git a/x-pack/plugins/maps/public/reducers/non_serializable_instances.js b/x-pack/plugins/maps/public/reducers/non_serializable_instances.js new file mode 100644 index 00000000000000..fcd583a91ca8a5 --- /dev/null +++ b/x-pack/plugins/maps/public/reducers/non_serializable_instances.js @@ -0,0 +1,107 @@ +/* + * 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 { RequestAdapter} from '../../../../../src/plugins/inspector/public/adapters/request'; +import { MapAdapter } from '../inspector/adapters/map_adapter'; + +// TODO +import chrome from 'ui/chrome'; + +const REGISTER_CANCEL_CALLBACK = 'REGISTER_CANCEL_CALLBACK'; +const UNREGISTER_CANCEL_CALLBACK = 'UNREGISTER_CANCEL_CALLBACK'; +const SET_EVENT_HANDLERS = 'SET_EVENT_HANDLERS'; + +function createInspectorAdapters() { + const inspectorAdapters = { + requests: new RequestAdapter(), + }; + if (chrome.getInjected('showMapsInspectorAdapter', false)) { + inspectorAdapters.map = new MapAdapter(); + } + return inspectorAdapters; +} + +// Reducer +export function nonSerializableInstances(state, action = {}) { + if (!state) { + return { + inspectorAdapters: createInspectorAdapters(), + cancelRequestCallbacks: new Map(), // key is request token, value is cancel callback + eventHandlers: {}, + }; + } + + switch (action.type) { + case REGISTER_CANCEL_CALLBACK: + state.cancelRequestCallbacks.set(action.requestToken, action.callback); + return { + ...state, + }; + case UNREGISTER_CANCEL_CALLBACK: + state.cancelRequestCallbacks.delete(action.requestToken); + return { + ...state, + }; + case SET_EVENT_HANDLERS: { + return { + ...state, + eventHandlers: action.eventHandlers, + }; + } + default: + return state; + } +} + +// Selectors +export const getInspectorAdapters = ({ nonSerializableInstances }) => { + return nonSerializableInstances.inspectorAdapters; +}; + +export const getCancelRequestCallbacks = ({ nonSerializableInstances }) => { + return nonSerializableInstances.cancelRequestCallbacks; +}; + +export const getEventHandlers = ({ nonSerializableInstances }) => { + return nonSerializableInstances.eventHandlers; +}; + +// Actions +export const registerCancelCallback = (requestToken, callback) => { + return { + type: REGISTER_CANCEL_CALLBACK, + requestToken, + callback, + }; +}; + +export const unregisterCancelCallback = requestToken => { + return { + type: UNREGISTER_CANCEL_CALLBACK, + requestToken, + }; +}; + +export const cancelRequest = requestToken => { + return (dispatch, getState) => { + if (!requestToken) { + return; + } + + const cancelCallback = getCancelRequestCallbacks(getState()).get(requestToken); + if (cancelCallback) { + cancelCallback(); + dispatch(unregisterCancelCallback(requestToken)); + } + }; +}; + +export const setEventHandlers = (eventHandlers = {}) => { + return { + type: SET_EVENT_HANDLERS, + eventHandlers, + }; +}; diff --git a/x-pack/plugins/maps/public/reducers/store.js b/x-pack/plugins/maps/public/reducers/store.js new file mode 100644 index 00000000000000..40b769f11b5292 --- /dev/null +++ b/x-pack/plugins/maps/public/reducers/store.js @@ -0,0 +1,24 @@ +/* + * 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 { combineReducers, applyMiddleware, createStore, compose } from 'redux'; +import thunk from 'redux-thunk'; +import { ui } from './ui'; +import { map } from './map'; +import { nonSerializableInstances } from './non_serializable_instances'; + +const rootReducer = combineReducers({ + map, + ui, + nonSerializableInstances, +}); + +const enhancers = [applyMiddleware(thunk)]; + +export function createMapStore() { + const storeConfig = {}; + return createStore(rootReducer, storeConfig, compose(...enhancers)); +} diff --git a/x-pack/plugins/maps/public/reducers/ui.js b/x-pack/plugins/maps/public/reducers/ui.js new file mode 100644 index 00000000000000..287e1f8dd3ddad --- /dev/null +++ b/x-pack/plugins/maps/public/reducers/ui.js @@ -0,0 +1,81 @@ +/* + * 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 { + UPDATE_FLYOUT, + CLOSE_SET_VIEW, + OPEN_SET_VIEW, + SET_IS_LAYER_TOC_OPEN, + SET_FULL_SCREEN, + SET_READ_ONLY, + SET_OPEN_TOC_DETAILS, + SHOW_TOC_DETAILS, + HIDE_TOC_DETAILS, + UPDATE_INDEXING_STAGE, +} from '../actions/ui_actions'; + +export const FLYOUT_STATE = { + NONE: 'NONE', + LAYER_PANEL: 'LAYER_PANEL', + ADD_LAYER_WIZARD: 'ADD_LAYER_WIZARD', +}; + +export const INDEXING_STAGE = { + READY: 'READY', + TRIGGERED: 'TRIGGERED', + SUCCESS: 'SUCCESS', + ERROR: 'ERROR', +}; + +export const DEFAULT_IS_LAYER_TOC_OPEN = true; + +const INITIAL_STATE = { + flyoutDisplay: FLYOUT_STATE.NONE, + isFullScreen: false, + isReadOnly: false, + isLayerTOCOpen: DEFAULT_IS_LAYER_TOC_OPEN, + isSetViewOpen: false, + // storing TOC detail visibility outside of map.layerList because its UI state and not map rendering state. + // This also makes for easy read/write access for embeddables. + openTOCDetails: [], + importIndexingStage: null, +}; + +// Reducer +export function ui(state = INITIAL_STATE, action) { + switch (action.type) { + case UPDATE_FLYOUT: + return { ...state, flyoutDisplay: action.display }; + case CLOSE_SET_VIEW: + return { ...state, isSetViewOpen: false }; + case OPEN_SET_VIEW: + return { ...state, isSetViewOpen: true }; + case SET_IS_LAYER_TOC_OPEN: + return { ...state, isLayerTOCOpen: action.isLayerTOCOpen }; + case SET_FULL_SCREEN: + return { ...state, isFullScreen: action.isFullScreen }; + case SET_READ_ONLY: + return { ...state, isReadOnly: action.isReadOnly }; + case SET_OPEN_TOC_DETAILS: + return { ...state, openTOCDetails: action.layerIds }; + case SHOW_TOC_DETAILS: + return { + ...state, + openTOCDetails: [...state.openTOCDetails, action.layerId], + }; + case HIDE_TOC_DETAILS: + return { + ...state, + openTOCDetails: state.openTOCDetails.filter(layerId => { + return layerId !== action.layerId; + }), + }; + case UPDATE_INDEXING_STAGE: + return { ...state, importIndexingStage: action.stage }; + default: + return state; + } +} diff --git a/x-pack/plugins/maps/public/reducers/util.js b/x-pack/plugins/maps/public/reducers/util.js new file mode 100644 index 00000000000000..e93eedbaebf50f --- /dev/null +++ b/x-pack/plugins/maps/public/reducers/util.js @@ -0,0 +1,21 @@ +/* + * 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. + */ + +export const TRACKED_LAYER_DESCRIPTOR = '__trackedLayerDescriptor'; + +export function copyPersistentState(input) { + if (typeof input !== 'object' || input === null) { + //primitive + return input; + } + const copyInput = Array.isArray(input) ? [] : {}; + for (const key in input) { + if (!key.startsWith('__')) { + copyInput[key] = copyPersistentState(input[key]); + } + } + return copyInput; +} diff --git a/x-pack/plugins/maps/public/reducers/util.test.js b/x-pack/plugins/maps/public/reducers/util.test.js new file mode 100644 index 00000000000000..2829c9410724e3 --- /dev/null +++ b/x-pack/plugins/maps/public/reducers/util.test.js @@ -0,0 +1,47 @@ +/* + * 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 { copyPersistentState } from './util'; + +describe('reducers/util', () => { + describe('copyPersistentState', () => { + it('should ignore state preceded by double underscores', async () => { + const copy = copyPersistentState({ + foo: 'bar', + nested: { + bar: 'foo', + __bar: 'foo__', + }, + }); + + expect(copy).toEqual({ + foo: 'bar', + nested: { + bar: 'foo', + }, + }); + }); + + it('should copy null value correctly', async () => { + const copy = copyPersistentState({ + foo: 'bar', + nested: { + nullval: null, + bar: 'foo', + __bar: 'foo__', + }, + }); + + expect(copy).toEqual({ + foo: 'bar', + nested: { + nullval: null, + bar: 'foo', + }, + }); + }); + }); +}); diff --git a/x-pack/plugins/maps/public/selectors/map_selectors.js b/x-pack/plugins/maps/public/selectors/map_selectors.js new file mode 100644 index 00000000000000..0e7c91df5e4bac --- /dev/null +++ b/x-pack/plugins/maps/public/selectors/map_selectors.js @@ -0,0 +1,85 @@ +/* + * 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 { timeFilter } from '../kibana_services'; + +export const getTooltipState = ({ map }) => { + return map.tooltipState; +}; + +export const getMapReady = ({ map }) => map && map.ready; + +export const getMapInitError = ({ map }) => map.mapInitError; + +export const getGoto = ({ map }) => map && map.goto; + +export const getSelectedLayerId = ({ map }) => { + return !map.selectedLayerId || !map.layerList ? null : map.selectedLayerId; +}; + +export const getTransientLayerId = ({ map }) => map.__transientLayerId; + +export const getLayerListRaw = ({ map }) => (map.layerList ? map.layerList : []); + +export const getWaitingForMapReadyLayerListRaw = ({ map }) => + map.waitingForMapReadyLayerList ? map.waitingForMapReadyLayerList : []; + +export const getScrollZoom = ({ map }) => map.mapState.scrollZoom; + +export const isInteractiveDisabled = ({ map }) => map.mapState.disableInteractive; + +export const isTooltipControlDisabled = ({ map }) => map.mapState.disableTooltipControl; + +export const isToolbarOverlayHidden = ({ map }) => map.mapState.hideToolbarOverlay; + +export const isLayerControlHidden = ({ map }) => map.mapState.hideLayerControl; + +export const isViewControlHidden = ({ map }) => map.mapState.hideViewControl; + +export const getMapExtent = ({ map }) => (map.mapState.extent ? map.mapState.extent : {}); + +export const getMapBuffer = ({ map }) => (map.mapState.buffer ? map.mapState.buffer : {}); + +export const getMapZoom = ({ map }) => (map.mapState.zoom ? map.mapState.zoom : 0); + +export const getMapCenter = ({ map }) => + map.mapState.center ? map.mapState.center : { lat: 0, lon: 0 }; + +export const getMouseCoordinates = ({ map }) => map.mapState.mouseCoordinates; + +export const getTimeFilters = ({ map }) => + map.mapState.timeFilters ? map.mapState.timeFilters : timeFilter.getTime(); + +export const getQuery = ({ map }) => map.mapState.query; + +export const getFilters = ({ map }) => map.mapState.filters; + +export const isUsingSearch = state => { + const filters = getFilters(state).filter(filter => !filter.meta.disabled); + const queryString = _.get(getQuery(state), 'query', ''); + return filters.length || queryString.length; +}; + +export const getDrawState = ({ map }) => map.mapState.drawState; + +export const isDrawingFilter = ({ map }) => { + return !!map.mapState.drawState; +}; + +export const getRefreshConfig = ({ map }) => { + if (map.mapState.refreshConfig) { + return map.mapState.refreshConfig; + } + + const refreshInterval = timefilter.getRefreshInterval(); + return { + isPaused: refreshInterval.pause, + interval: refreshInterval.value, + }; +}; + +export const getRefreshTimerLastTriggeredAt = ({ map }) => map.mapState.refreshTimerLastTriggeredAt; diff --git a/x-pack/plugins/maps/public/selectors/ui_selectors.js b/x-pack/plugins/maps/public/selectors/ui_selectors.js new file mode 100644 index 00000000000000..912ee083962126 --- /dev/null +++ b/x-pack/plugins/maps/public/selectors/ui_selectors.js @@ -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; + * you may not use this file except in compliance with the Elastic License. + */ + +export const getFlyoutDisplay = ({ ui }) => ui.flyoutDisplay; +export const getIsSetViewOpen = ({ ui }) => ui.isSetViewOpen; +export const getIsLayerTOCOpen = ({ ui }) => ui.isLayerTOCOpen; +export const getOpenTOCDetails = ({ ui }) => ui.openTOCDetails; +export const getIsFullScreen = ({ ui }) => ui.isFullScreen; +export const getIsReadOnly = ({ ui }) => ui.isReadOnly; +export const getIndexingStage = ({ ui }) => ui.importIndexingStage; From a84f38a6e946b7f8b89ece4905711ffaf55ea61f Mon Sep 17 00:00:00 2001 From: Aaron Caldwell Date: Wed, 12 Feb 2020 09:05:53 -0700 Subject: [PATCH 02/21] Port and update index pattern util --- .../plugins/maps/public/index_pattern_util.js | 52 +++++++++++++++++++ .../maps/public/index_pattern_util.test.js | 29 +++++++++++ 2 files changed, 81 insertions(+) create mode 100644 x-pack/plugins/maps/public/index_pattern_util.js create mode 100644 x-pack/plugins/maps/public/index_pattern_util.test.js diff --git a/x-pack/plugins/maps/public/index_pattern_util.js b/x-pack/plugins/maps/public/index_pattern_util.js new file mode 100644 index 00000000000000..48251b858cc9d2 --- /dev/null +++ b/x-pack/plugins/maps/public/index_pattern_util.js @@ -0,0 +1,52 @@ +/* + * 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 { indexPatternService } from './kibana_services'; +import { isNestedField } from '../../../../src/plugins/data/public'; +import { ES_GEO_FIELD_TYPE } from '../common/constants'; + +export async function getIndexPatternsFromIds(indexPatternIds = []) { + const promises = []; + indexPatternIds.forEach(id => { + const indexPatternPromise = indexPatternService.get(id); + if (indexPatternPromise) { + promises.push(indexPatternPromise); + } + }); + + return await Promise.all(promises); +} + +export function getTermsFields(fields) { + return fields.filter(field => { + return ( + field.aggregatable && + !isNestedField(field) && + ['number', 'boolean', 'date', 'ip', 'string'].includes(field.type) + ); + }); +} + +export const AGGREGATABLE_GEO_FIELD_TYPES = [ES_GEO_FIELD_TYPE.GEO_POINT]; + +export function getAggregatableGeoFields(fields) { + return fields.filter(field => { + return ( + field.aggregatable && + !isNestedField(field) && + AGGREGATABLE_GEO_FIELD_TYPES.includes(field.type) + ); + }); +} + +// Returns filtered fields list containing only fields that exist in _source. +export function getSourceFields(fields) { + return fields.filter(field => { + // Multi fields are not stored in _source and only exist in index. + const isMultiField = field.subType && field.subType.multi; + return !isMultiField && !isNestedField(field); + }); +} diff --git a/x-pack/plugins/maps/public/index_pattern_util.test.js b/x-pack/plugins/maps/public/index_pattern_util.test.js new file mode 100644 index 00000000000000..7f8f1c175cf152 --- /dev/null +++ b/x-pack/plugins/maps/public/index_pattern_util.test.js @@ -0,0 +1,29 @@ +/* + * 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. + */ + +jest.mock('./kibana_services', () => ({})); + +import { getSourceFields } from './index_pattern_util'; + +describe('getSourceFields', () => { + test('Should remove multi fields from field list', () => { + const fields = [ + { + name: 'agent', + }, + { + name: 'agent.keyword', + subType: { + multi: { + parent: 'agent', + }, + }, + }, + ]; + const sourceFields = getSourceFields(fields); + expect(sourceFields).toEqual([{ name: 'agent' }]); + }); +}); From 86e499f18617383c17168061134bc22207e3bf04 Mon Sep 17 00:00:00 2001 From: Aaron Caldwell Date: Fri, 14 Feb 2020 13:15:28 -0700 Subject: [PATCH 03/21] Move reducers over to NP. Update refs in legacy --- .../maps/public/actions/map_actions.js | 4 +- .../maps/public/angular/map_controller.js | 8 +- .../public/angular/services/saved_gis_map.js | 2 +- .../connected_components/gis_map/index.js | 2 +- .../layer_addpanel/import_editor/index.js | 4 +- .../layer_addpanel/index.js | 4 +- .../layer_addpanel/source_editor/index.js | 2 +- .../layer_panel/flyout_footer/index.js | 2 +- .../connected_components/map/mb/index.js | 2 +- .../widget_overlay/layer_control/index.js | 2 +- .../layer_toc/toc_entry/index.js | 2 +- .../maps/public/embeddable/map_embeddable.js | 4 +- .../embeddable/map_embeddable_factory.js | 2 +- .../embeddable/merge_input_with_saved_map.js | 2 +- .../plugins/maps/public/layers/layer.js | 2 +- .../maps/public/layers/sources/es_source.js | 2 +- .../maps/public/layers/sources/source.js | 2 +- .../plugins/maps/public/reducers/map.js | 543 ------------------ .../plugins/maps/public/reducers/map.test.js | 56 -- .../reducers/non_serializable_instances.js | 105 ---- .../plugins/maps/public/reducers/store.js | 24 - .../legacy/plugins/maps/public/reducers/ui.js | 81 --- .../plugins/maps/public/reducers/util.js | 21 - .../plugins/maps/public/reducers/util.test.js | 47 -- .../maps/public/selectors/map_selectors.js | 4 +- .../public/selectors/map_selectors.test.js | 2 +- x-pack/plugins/maps/public/plugin.ts | 60 +- 27 files changed, 48 insertions(+), 943 deletions(-) delete mode 100644 x-pack/legacy/plugins/maps/public/reducers/map.js delete mode 100644 x-pack/legacy/plugins/maps/public/reducers/map.test.js delete mode 100644 x-pack/legacy/plugins/maps/public/reducers/non_serializable_instances.js delete mode 100644 x-pack/legacy/plugins/maps/public/reducers/store.js delete mode 100644 x-pack/legacy/plugins/maps/public/reducers/ui.js delete mode 100644 x-pack/legacy/plugins/maps/public/reducers/util.js delete mode 100644 x-pack/legacy/plugins/maps/public/reducers/util.test.js diff --git a/x-pack/legacy/plugins/maps/public/actions/map_actions.js b/x-pack/legacy/plugins/maps/public/actions/map_actions.js index 2c6c60db9a0124..03ed474a777e46 100644 --- a/x-pack/legacy/plugins/maps/public/actions/map_actions.js +++ b/x-pack/legacy/plugins/maps/public/actions/map_actions.js @@ -19,13 +19,13 @@ import { getOpenTooltips, getQuery, } from '../selectors/map_selectors'; -import { FLYOUT_STATE } from '../reducers/ui'; +import { FLYOUT_STATE } from '../../../../../plugins/maps/public/reducers/ui'; import { cancelRequest, registerCancelCallback, unregisterCancelCallback, getEventHandlers, -} from '../reducers/non_serializable_instances'; +} from '../../../../../plugins/maps/public/reducers/non_serializable_instances'; import { updateFlyout } from '../actions/ui_actions'; import { FEATURE_ID_PROPERTY_NAME, diff --git a/x-pack/legacy/plugins/maps/public/angular/map_controller.js b/x-pack/legacy/plugins/maps/public/angular/map_controller.js index c90560a4fcfdfd..461e2b33bc27ab 100644 --- a/x-pack/legacy/plugins/maps/public/angular/map_controller.js +++ b/x-pack/legacy/plugins/maps/public/angular/map_controller.js @@ -16,7 +16,7 @@ import { render, unmountComponentAtNode } from 'react-dom'; import { uiModules } from 'ui/modules'; import { timefilter } from 'ui/timefilter'; import { Provider } from 'react-redux'; -import { createMapStore } from '../reducers/store'; +import { createMapStore } from '../../../../../plugins/maps/public/reducers/store'; import { GisMap } from '../connected_components/gis_map'; import { addHelpMenuToAppChrome } from '../help_menu_util'; import { @@ -27,7 +27,7 @@ import { setQuery, clearTransientLayerStateAndCloseFlyout, } from '../actions/map_actions'; -import { DEFAULT_IS_LAYER_TOC_OPEN, FLYOUT_STATE } from '../reducers/ui'; +import { DEFAULT_IS_LAYER_TOC_OPEN, FLYOUT_STATE } from '../../../../../plugins/maps/public/reducers/ui'; import { enableFullScreen, updateFlyout, @@ -36,13 +36,13 @@ import { setOpenTOCDetails, } from '../actions/ui_actions'; import { getIsFullScreen } from '../selectors/ui_selectors'; -import { copyPersistentState } from '../reducers/util'; +import { copyPersistentState } from '../../../../../plugins/maps/public/reducers/util'; import { getQueryableUniqueIndexPatternIds, hasDirtyState, getLayerListRaw, } from '../selectors/map_selectors'; -import { getInspectorAdapters } from '../reducers/non_serializable_instances'; +import { getInspectorAdapters } from '../../../../../plugins/maps/public/reducers/non_serializable_instances'; import { docTitle } from 'ui/doc_title'; import { indexPatternService, getInspector } from '../kibana_services'; import { toastNotifications } from 'ui/notify'; diff --git a/x-pack/legacy/plugins/maps/public/angular/services/saved_gis_map.js b/x-pack/legacy/plugins/maps/public/angular/services/saved_gis_map.js index 490ab16a1799c0..12590de17c2063 100644 --- a/x-pack/legacy/plugins/maps/public/angular/services/saved_gis_map.js +++ b/x-pack/legacy/plugins/maps/public/angular/services/saved_gis_map.js @@ -18,7 +18,7 @@ import { } from '../../selectors/map_selectors'; import { getIsLayerTOCOpen, getOpenTOCDetails } from '../../selectors/ui_selectors'; import { convertMapExtentToPolygon } from '../../elasticsearch_geo_utils'; -import { copyPersistentState } from '../../reducers/util'; +import { copyPersistentState } from '../../../../../../plugins/maps/public/reducers/util'; import { extractReferences, injectReferences } from '../../../common/migrations/references'; import { MAP_SAVED_OBJECT_TYPE } from '../../../common/constants'; diff --git a/x-pack/legacy/plugins/maps/public/connected_components/gis_map/index.js b/x-pack/legacy/plugins/maps/public/connected_components/gis_map/index.js index ceb0a6ea9f9225..6385edb1b096d1 100644 --- a/x-pack/legacy/plugins/maps/public/connected_components/gis_map/index.js +++ b/x-pack/legacy/plugins/maps/public/connected_components/gis_map/index.js @@ -6,7 +6,7 @@ import { connect } from 'react-redux'; import { GisMap } from './view'; -import { FLYOUT_STATE } from '../../reducers/ui'; +import { FLYOUT_STATE } from '../../../../../../plugins/maps/public/reducers/ui'; import { exitFullScreen } from '../../actions/ui_actions'; import { getFlyoutDisplay, getIsFullScreen } from '../../selectors/ui_selectors'; import { triggerRefreshTimer, cancelAllInFlightRequests } from '../../actions/map_actions'; diff --git a/x-pack/legacy/plugins/maps/public/connected_components/layer_addpanel/import_editor/index.js b/x-pack/legacy/plugins/maps/public/connected_components/layer_addpanel/import_editor/index.js index 8d0dd0c266f28e..963cd1c2e60e3c 100644 --- a/x-pack/legacy/plugins/maps/public/connected_components/layer_addpanel/import_editor/index.js +++ b/x-pack/legacy/plugins/maps/public/connected_components/layer_addpanel/import_editor/index.js @@ -6,8 +6,8 @@ import { connect } from 'react-redux'; import { ImportEditor } from './view'; -import { getInspectorAdapters } from '../../../reducers/non_serializable_instances'; -import { INDEXING_STAGE } from '../../../reducers/ui'; +import { getInspectorAdapters } from '../../../../../../../plugins/maps/public/reducers/non_serializable_instances'; +import { INDEXING_STAGE } from '../../../../../../../plugins/maps/public/reducers/ui'; import { updateIndexingStage } from '../../../actions/ui_actions'; import { getIndexingStage } from '../../../selectors/ui_selectors'; diff --git a/x-pack/legacy/plugins/maps/public/connected_components/layer_addpanel/index.js b/x-pack/legacy/plugins/maps/public/connected_components/layer_addpanel/index.js index d2b43775c5a492..abd67760a8c4f8 100644 --- a/x-pack/legacy/plugins/maps/public/connected_components/layer_addpanel/index.js +++ b/x-pack/legacy/plugins/maps/public/connected_components/layer_addpanel/index.js @@ -6,11 +6,11 @@ import { connect } from 'react-redux'; import { AddLayerPanel } from './view'; -import { FLYOUT_STATE, INDEXING_STAGE } from '../../reducers/ui'; +import { FLYOUT_STATE, INDEXING_STAGE } from '../../../../../../plugins/maps/public/reducers/ui'; import { updateFlyout, updateIndexingStage } from '../../actions/ui_actions'; import { getFlyoutDisplay, getIndexingStage } from '../../selectors/ui_selectors'; import { getMapColors } from '../../selectors/map_selectors'; -import { getInspectorAdapters } from '../../reducers/non_serializable_instances'; +import { getInspectorAdapters } from '../../../../../../plugins/maps/public/reducers/non_serializable_instances'; import { setTransientLayer, addLayer, diff --git a/x-pack/legacy/plugins/maps/public/connected_components/layer_addpanel/source_editor/index.js b/x-pack/legacy/plugins/maps/public/connected_components/layer_addpanel/source_editor/index.js index 51ed19d1c77d1f..967b454060e1a6 100644 --- a/x-pack/legacy/plugins/maps/public/connected_components/layer_addpanel/source_editor/index.js +++ b/x-pack/legacy/plugins/maps/public/connected_components/layer_addpanel/source_editor/index.js @@ -6,7 +6,7 @@ import { connect } from 'react-redux'; import { SourceEditor } from './view'; -import { getInspectorAdapters } from '../../../reducers/non_serializable_instances'; +import { getInspectorAdapters } from '../../../../../../../plugins/maps/public/reducers/non_serializable_instances'; function mapStateToProps(state = {}) { return { diff --git a/x-pack/legacy/plugins/maps/public/connected_components/layer_panel/flyout_footer/index.js b/x-pack/legacy/plugins/maps/public/connected_components/layer_panel/flyout_footer/index.js index 76e650cad97eb5..cc036bdcf02e66 100644 --- a/x-pack/legacy/plugins/maps/public/connected_components/layer_panel/flyout_footer/index.js +++ b/x-pack/legacy/plugins/maps/public/connected_components/layer_panel/flyout_footer/index.js @@ -6,7 +6,7 @@ import { connect } from 'react-redux'; import { FlyoutFooter } from './view'; -import { FLYOUT_STATE } from '../../../reducers/ui'; +import { FLYOUT_STATE } from '../../../../../../../plugins/maps/public/reducers/ui'; import { updateFlyout } from '../../../actions/ui_actions'; import { hasDirtyState } from '../../../selectors/map_selectors'; import { diff --git a/x-pack/legacy/plugins/maps/public/connected_components/map/mb/index.js b/x-pack/legacy/plugins/maps/public/connected_components/map/mb/index.js index a2f121a9377fef..095bb338e122b7 100644 --- a/x-pack/legacy/plugins/maps/public/connected_components/map/mb/index.js +++ b/x-pack/legacy/plugins/maps/public/connected_components/map/mb/index.js @@ -24,7 +24,7 @@ import { isTooltipControlDisabled, isViewControlHidden, } from '../../../selectors/map_selectors'; -import { getInspectorAdapters } from '../../../reducers/non_serializable_instances'; +import { getInspectorAdapters } from '../../../../../../../plugins/maps/public/reducers/non_serializable_instances'; function mapStateToProps(state = {}) { return { diff --git a/x-pack/legacy/plugins/maps/public/connected_components/widget_overlay/layer_control/index.js b/x-pack/legacy/plugins/maps/public/connected_components/widget_overlay/layer_control/index.js index 0b090a639edb2b..c9cceb6b23651c 100644 --- a/x-pack/legacy/plugins/maps/public/connected_components/widget_overlay/layer_control/index.js +++ b/x-pack/legacy/plugins/maps/public/connected_components/widget_overlay/layer_control/index.js @@ -6,7 +6,7 @@ import { connect } from 'react-redux'; import { LayerControl } from './view'; -import { FLYOUT_STATE } from '../../../reducers/ui'; +import { FLYOUT_STATE } from '../../../../../../../plugins/maps/public/reducers/ui.js' import { updateFlyout, setIsLayerTOCOpen } from '../../../actions/ui_actions'; import { setSelectedLayer } from '../../../actions/map_actions'; import { diff --git a/x-pack/legacy/plugins/maps/public/connected_components/widget_overlay/layer_control/layer_toc/toc_entry/index.js b/x-pack/legacy/plugins/maps/public/connected_components/widget_overlay/layer_control/layer_toc/toc_entry/index.js index e9debdba7b9148..479173f0d36958 100644 --- a/x-pack/legacy/plugins/maps/public/connected_components/widget_overlay/layer_control/layer_toc/toc_entry/index.js +++ b/x-pack/legacy/plugins/maps/public/connected_components/widget_overlay/layer_control/layer_toc/toc_entry/index.js @@ -7,7 +7,7 @@ import _ from 'lodash'; import { connect } from 'react-redux'; import { TOCEntry } from './view'; -import { FLYOUT_STATE } from '../../../../../reducers/ui'; +import { FLYOUT_STATE } from '../../../../../../../../../plugins/maps/public/reducers/ui.js'; import { updateFlyout, hideTOCDetails, showTOCDetails } from '../../../../../actions/ui_actions'; import { getIsReadOnly, getOpenTOCDetails } from '../../../../../selectors/ui_selectors'; import { diff --git a/x-pack/legacy/plugins/maps/public/embeddable/map_embeddable.js b/x-pack/legacy/plugins/maps/public/embeddable/map_embeddable.js index 5988a128232d60..5a42dc65ea226e 100644 --- a/x-pack/legacy/plugins/maps/public/embeddable/map_embeddable.js +++ b/x-pack/legacy/plugins/maps/public/embeddable/map_embeddable.js @@ -19,7 +19,7 @@ import { esFilters } from '../../../../../../src/plugins/data/public'; import { I18nContext } from 'ui/i18n'; import { GisMap } from '../connected_components/gis_map'; -import { createMapStore } from '../reducers/store'; +import { createMapStore } from '../../../../../plugins/maps/public/reducers/store'; import { npStart } from 'ui/new_platform'; import { setGotoWithCenter, @@ -36,7 +36,7 @@ import { } from '../actions/map_actions'; import { setReadOnly, setIsLayerTOCOpen, setOpenTOCDetails } from '../actions/ui_actions'; import { getIsLayerTOCOpen, getOpenTOCDetails } from '../selectors/ui_selectors'; -import { getInspectorAdapters, setEventHandlers } from '../reducers/non_serializable_instances'; +import { getInspectorAdapters, setEventHandlers } from '../../../../../plugins/maps/public/reducers/non_serializable_instances'; import { getMapCenter, getMapZoom, getHiddenLayerIds } from '../selectors/map_selectors'; import { MAP_SAVED_OBJECT_TYPE } from '../../common/constants'; diff --git a/x-pack/legacy/plugins/maps/public/embeddable/map_embeddable_factory.js b/x-pack/legacy/plugins/maps/public/embeddable/map_embeddable_factory.js index ec3a588d3627f7..4f45a15fd65135 100644 --- a/x-pack/legacy/plugins/maps/public/embeddable/map_embeddable_factory.js +++ b/x-pack/legacy/plugins/maps/public/embeddable/map_embeddable_factory.js @@ -17,7 +17,7 @@ import { MapEmbeddable } from './map_embeddable'; import { indexPatternService } from '../kibana_services'; import { createMapPath, MAP_SAVED_OBJECT_TYPE, APP_ICON } from '../../common/constants'; -import { createMapStore } from '../reducers/store'; +import { createMapStore } from '../../../../../plugins/maps/public/reducers/store'; import { addLayerWithoutDataSync } from '../actions/map_actions'; import { getQueryableUniqueIndexPatternIds } from '../selectors/map_selectors'; import { getInitialLayers } from '../angular/get_initial_layers'; diff --git a/x-pack/legacy/plugins/maps/public/embeddable/merge_input_with_saved_map.js b/x-pack/legacy/plugins/maps/public/embeddable/merge_input_with_saved_map.js index 935747da936870..26ab1f95a94c0e 100644 --- a/x-pack/legacy/plugins/maps/public/embeddable/merge_input_with_saved_map.js +++ b/x-pack/legacy/plugins/maps/public/embeddable/merge_input_with_saved_map.js @@ -5,7 +5,7 @@ */ import _ from 'lodash'; -import { DEFAULT_IS_LAYER_TOC_OPEN } from '../reducers/ui'; +import { DEFAULT_IS_LAYER_TOC_OPEN } from '../../../../../plugins/maps/public/reducers/ui'; const MAP_EMBEDDABLE_INPUT_KEYS = [ 'hideFilterActions', diff --git a/x-pack/legacy/plugins/maps/public/layers/layer.js b/x-pack/legacy/plugins/maps/public/layers/layer.js index b76f1ebce15d21..7fceaf2ff33912 100644 --- a/x-pack/legacy/plugins/maps/public/layers/layer.js +++ b/x-pack/legacy/plugins/maps/public/layers/layer.js @@ -14,7 +14,7 @@ import { SOURCE_DATA_ID_ORIGIN, } from '../../common/constants'; import uuid from 'uuid/v4'; -import { copyPersistentState } from '../reducers/util'; +import { copyPersistentState } from '../../../../../plugins/maps/public/reducers/util.js' import { i18n } from '@kbn/i18n'; export class AbstractLayer { diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_source.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_source.js index d78d3038f870d9..de4b3e63768346 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_source.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_source.js @@ -17,7 +17,7 @@ import _ from 'lodash'; import { AggConfigs } from 'ui/agg_types'; import { i18n } from '@kbn/i18n'; import uuid from 'uuid/v4'; -import { copyPersistentState } from '../../reducers/util'; +import { copyPersistentState } from '../../../../../../plugins/maps/public/reducers/util'; import { ES_GEO_FIELD_TYPE, METRIC_TYPE } from '../../../common/constants'; import { DataRequestAbortError } from '../util/data_request'; import { expandToTileBoundaries } from './es_geo_grid_source/geo_tile_utils'; diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/source.js b/x-pack/legacy/plugins/maps/public/layers/sources/source.js index 3c6ddb74bedeba..a09c6d03032f15 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/source.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/source.js @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import { copyPersistentState } from '../../reducers/util'; +import { copyPersistentState } from '../../../../../../plugins/maps/public/reducers'; export class AbstractSource { static isIndexingSource = false; diff --git a/x-pack/legacy/plugins/maps/public/reducers/map.js b/x-pack/legacy/plugins/maps/public/reducers/map.js deleted file mode 100644 index 7e81fb03dd85be..00000000000000 --- a/x-pack/legacy/plugins/maps/public/reducers/map.js +++ /dev/null @@ -1,543 +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 { - SET_SELECTED_LAYER, - SET_TRANSIENT_LAYER, - UPDATE_LAYER_ORDER, - LAYER_DATA_LOAD_STARTED, - LAYER_DATA_LOAD_ENDED, - LAYER_DATA_LOAD_ERROR, - ADD_LAYER, - SET_LAYER_ERROR_STATUS, - ADD_WAITING_FOR_MAP_READY_LAYER, - CLEAR_WAITING_FOR_MAP_READY_LAYER_LIST, - REMOVE_LAYER, - SET_LAYER_VISIBILITY, - MAP_EXTENT_CHANGED, - MAP_READY, - MAP_DESTROYED, - SET_QUERY, - UPDATE_LAYER_PROP, - UPDATE_LAYER_STYLE, - SET_LAYER_STYLE_META, - SET_JOINS, - TOUCH_LAYER, - UPDATE_SOURCE_PROP, - SET_REFRESH_CONFIG, - TRIGGER_REFRESH_TIMER, - SET_MOUSE_COORDINATES, - CLEAR_MOUSE_COORDINATES, - SET_GOTO, - CLEAR_GOTO, - TRACK_CURRENT_LAYER_STATE, - ROLLBACK_TO_TRACKED_LAYER_STATE, - REMOVE_TRACKED_LAYER_STATE, - UPDATE_SOURCE_DATA_REQUEST, - SET_OPEN_TOOLTIPS, - SET_SCROLL_ZOOM, - SET_MAP_INIT_ERROR, - UPDATE_DRAW_STATE, - SET_INTERACTIVE, - DISABLE_TOOLTIP_CONTROL, - HIDE_TOOLBAR_OVERLAY, - HIDE_LAYER_CONTROL, - HIDE_VIEW_CONTROL, - SET_WAITING_FOR_READY_HIDDEN_LAYERS, -} from '../actions/map_actions'; - -import { copyPersistentState, TRACKED_LAYER_DESCRIPTOR } from './util'; -import { SOURCE_DATA_ID_ORIGIN } from '../../common/constants'; - -const getLayerIndex = (list, layerId) => list.findIndex(({ id }) => layerId === id); - -const updateLayerInList = (state, layerId, attribute, newValue) => { - if (!layerId) { - return state; - } - const { layerList } = state; - const layerIdx = getLayerIndex(layerList, layerId); - const updatedLayer = { - ...layerList[layerIdx], - // Update layer w/ new value. If no value provided, toggle boolean value - // allow empty strings, 0-value - [attribute]: - newValue || newValue === '' || newValue === 0 ? newValue : !layerList[layerIdx][attribute], - }; - const updatedList = [ - ...layerList.slice(0, layerIdx), - updatedLayer, - ...layerList.slice(layerIdx + 1), - ]; - return { ...state, layerList: updatedList }; -}; - -const updateLayerSourceDescriptorProp = (state, layerId, propName, value) => { - const { layerList } = state; - const layerIdx = getLayerIndex(layerList, layerId); - const updatedLayer = { - ...layerList[layerIdx], - sourceDescriptor: { - ...layerList[layerIdx].sourceDescriptor, - [propName]: value, - }, - }; - const updatedList = [ - ...layerList.slice(0, layerIdx), - updatedLayer, - ...layerList.slice(layerIdx + 1), - ]; - return { ...state, layerList: updatedList }; -}; - -const INITIAL_STATE = { - ready: false, - mapInitError: null, - goto: null, - openTooltips: [], - mapState: { - zoom: null, // setting this value does not adjust map zoom, read only value used to store current map zoom for persisting between sessions - center: null, // setting this value does not adjust map view, read only value used to store current map center for persisting between sessions - scrollZoom: true, - extent: null, - mouseCoordinates: null, - timeFilters: null, - query: null, - filters: [], - refreshConfig: null, - refreshTimerLastTriggeredAt: null, - drawState: null, - disableInteractive: false, - disableTooltipControl: false, - hideToolbarOverlay: false, - hideLayerControl: false, - hideViewControl: false, - }, - selectedLayerId: null, - __transientLayerId: null, - layerList: [], - waitingForMapReadyLayerList: [], -}; - -export function map(state = INITIAL_STATE, action) { - switch (action.type) { - case UPDATE_DRAW_STATE: - return { - ...state, - mapState: { - ...state.mapState, - drawState: action.drawState, - }, - }; - case REMOVE_TRACKED_LAYER_STATE: - return removeTrackedLayerState(state, action.layerId); - case TRACK_CURRENT_LAYER_STATE: - return trackCurrentLayerState(state, action.layerId); - case ROLLBACK_TO_TRACKED_LAYER_STATE: - return rollbackTrackedLayerState(state, action.layerId); - case SET_OPEN_TOOLTIPS: - return { - ...state, - openTooltips: action.openTooltips, - }; - case SET_MOUSE_COORDINATES: - return { - ...state, - mapState: { - ...state.mapState, - mouseCoordinates: { - lat: action.lat, - lon: action.lon, - }, - }, - }; - case CLEAR_MOUSE_COORDINATES: - return { - ...state, - mapState: { - ...state.mapState, - mouseCoordinates: null, - }, - }; - case SET_GOTO: - return { - ...state, - goto: { - center: action.center, - bounds: action.bounds, - }, - }; - case CLEAR_GOTO: - return { - ...state, - goto: null, - }; - case SET_LAYER_ERROR_STATUS: - const { layerList } = state; - const layerIdx = getLayerIndex(layerList, action.layerId); - if (layerIdx === -1) { - return state; - } - - return { - ...state, - layerList: [ - ...layerList.slice(0, layerIdx), - { - ...layerList[layerIdx], - __isInErrorState: action.isInErrorState, - __errorMessage: action.errorMessage, - }, - ...layerList.slice(layerIdx + 1), - ], - }; - case UPDATE_SOURCE_DATA_REQUEST: - return updateSourceDataRequest(state, action); - case LAYER_DATA_LOAD_STARTED: - return updateWithDataRequest(state, action); - case LAYER_DATA_LOAD_ERROR: - return updateWithDataResponse(state, action); - case LAYER_DATA_LOAD_ENDED: - return updateWithDataResponse(state, action); - case TOUCH_LAYER: - //action to enforce a reflow of the styles - const layer = state.layerList.find(layer => layer.id === action.layerId); - if (!layer) { - return state; - } - const indexOfLayer = state.layerList.indexOf(layer); - const newLayer = { ...layer }; - const newLayerList = [...state.layerList]; - newLayerList[indexOfLayer] = newLayer; - return { ...state, layerList: newLayerList }; - case MAP_READY: - return { ...state, ready: true }; - case MAP_DESTROYED: - return { ...state, ready: false }; - case MAP_EXTENT_CHANGED: - const newMapState = { - center: action.mapState.center, - zoom: action.mapState.zoom, - extent: action.mapState.extent, - buffer: action.mapState.buffer, - }; - return { ...state, mapState: { ...state.mapState, ...newMapState } }; - case SET_QUERY: - const { query, timeFilters, filters } = action; - return { - ...state, - mapState: { - ...state.mapState, - query, - timeFilters, - filters, - }, - }; - case SET_REFRESH_CONFIG: - const { isPaused, interval } = action; - return { - ...state, - mapState: { - ...state.mapState, - refreshConfig: { - isPaused, - interval, - }, - }, - }; - case TRIGGER_REFRESH_TIMER: - return { - ...state, - mapState: { - ...state.mapState, - refreshTimerLastTriggeredAt: new Date().toISOString(), - }, - }; - case SET_SELECTED_LAYER: - const selectedMatch = state.layerList.find(layer => layer.id === action.selectedLayerId); - return { ...state, selectedLayerId: selectedMatch ? action.selectedLayerId : null }; - case SET_TRANSIENT_LAYER: - const transientMatch = state.layerList.find(layer => layer.id === action.transientLayerId); - return { ...state, __transientLayerId: transientMatch ? action.transientLayerId : null }; - case UPDATE_LAYER_ORDER: - return { - ...state, - layerList: action.newLayerOrder.map(layerNumber => state.layerList[layerNumber]), - }; - case UPDATE_LAYER_PROP: - return updateLayerInList(state, action.id, action.propName, action.newValue); - case UPDATE_SOURCE_PROP: - return updateLayerSourceDescriptorProp(state, action.layerId, action.propName, action.value); - case SET_JOINS: - const layerDescriptor = state.layerList.find( - descriptor => descriptor.id === action.layer.getId() - ); - if (layerDescriptor) { - const newLayerDescriptor = { ...layerDescriptor, joins: action.joins.slice() }; - const index = state.layerList.findIndex( - descriptor => descriptor.id === action.layer.getId() - ); - const newLayerList = state.layerList.slice(); - newLayerList[index] = newLayerDescriptor; - return { ...state, layerList: newLayerList }; - } - return state; - case ADD_LAYER: - return { - ...state, - layerList: [...state.layerList, action.layer], - }; - case REMOVE_LAYER: - return { - ...state, - layerList: [...state.layerList.filter(({ id }) => id !== action.id)], - }; - case ADD_WAITING_FOR_MAP_READY_LAYER: - return { - ...state, - waitingForMapReadyLayerList: [...state.waitingForMapReadyLayerList, action.layer], - }; - case CLEAR_WAITING_FOR_MAP_READY_LAYER_LIST: - return { - ...state, - waitingForMapReadyLayerList: [], - }; - case SET_LAYER_VISIBILITY: - return updateLayerInList(state, action.layerId, 'visible', action.visibility); - case UPDATE_LAYER_STYLE: - const styleLayerId = action.layerId; - return updateLayerInList(state, styleLayerId, 'style', { ...action.style }); - case SET_LAYER_STYLE_META: - const { layerId, styleMeta } = action; - const index = getLayerIndex(state.layerList, layerId); - if (index === -1) { - return state; - } - - return updateLayerInList(state, layerId, 'style', { - ...state.layerList[index].style, - __styleMeta: styleMeta, - }); - case SET_SCROLL_ZOOM: - return { - ...state, - mapState: { - ...state.mapState, - scrollZoom: action.scrollZoom, - }, - }; - case SET_MAP_INIT_ERROR: - return { - ...state, - mapInitError: action.errorMessage, - }; - case SET_INTERACTIVE: - return { - ...state, - mapState: { - ...state.mapState, - disableInteractive: action.disableInteractive, - }, - }; - case DISABLE_TOOLTIP_CONTROL: - return { - ...state, - mapState: { - ...state.mapState, - disableTooltipControl: action.disableTooltipControl, - }, - }; - case HIDE_TOOLBAR_OVERLAY: - return { - ...state, - mapState: { - ...state.mapState, - hideToolbarOverlay: action.hideToolbarOverlay, - }, - }; - case HIDE_LAYER_CONTROL: - return { - ...state, - mapState: { - ...state.mapState, - hideLayerControl: action.hideLayerControl, - }, - }; - case HIDE_VIEW_CONTROL: - return { - ...state, - mapState: { - ...state.mapState, - hideViewControl: action.hideViewControl, - }, - }; - case SET_WAITING_FOR_READY_HIDDEN_LAYERS: - return { - ...state, - waitingForMapReadyLayerList: state.waitingForMapReadyLayerList.map(layer => ({ - ...layer, - visible: !action.hiddenLayerIds.includes(layer.id), - })), - }; - default: - return state; - } -} - -function findDataRequest(layerDescriptor, dataRequestAction) { - if (!layerDescriptor.__dataRequests) { - return; - } - - return layerDescriptor.__dataRequests.find(dataRequest => { - return dataRequest.dataId === dataRequestAction.dataId; - }); -} - -function updateWithDataRequest(state, action) { - let dataRequest = getValidDataRequest(state, action, false); - const layerRequestingData = findLayerById(state, action.layerId); - - if (!dataRequest) { - dataRequest = { - dataId: action.dataId, - }; - layerRequestingData.__dataRequests = [ - ...(layerRequestingData.__dataRequests ? layerRequestingData.__dataRequests : []), - dataRequest, - ]; - } - dataRequest.dataMetaAtStart = action.meta; - dataRequest.dataRequestToken = action.requestToken; - const layerList = [...state.layerList]; - return { ...state, layerList }; -} - -function updateSourceDataRequest(state, action) { - const layerDescriptor = findLayerById(state, action.layerId); - if (!layerDescriptor) { - return state; - } - const dataRequest = layerDescriptor.__dataRequests.find(dataRequest => { - return dataRequest.dataId === SOURCE_DATA_ID_ORIGIN; - }); - if (!dataRequest) { - return state; - } - - dataRequest.data = action.newData; - return resetDataRequest(state, action, dataRequest); -} - -function updateWithDataResponse(state, action) { - const dataRequest = getValidDataRequest(state, action); - if (!dataRequest) { - return state; - } - - dataRequest.data = action.data; - dataRequest.dataMeta = { ...dataRequest.dataMetaAtStart, ...action.meta }; - dataRequest.dataMetaAtStart = null; - return resetDataRequest(state, action, dataRequest); -} - -export function resetDataRequest(state, action, request) { - const dataRequest = request || getValidDataRequest(state, action); - if (!dataRequest) { - return state; - } - - const layer = findLayerById(state, action.layerId); - const dataRequestIndex = layer.__dataRequests.indexOf(dataRequest); - - const newDataRequests = [...layer.__dataRequests]; - newDataRequests[dataRequestIndex] = { - ...dataRequest, - dataRequestToken: null, - }; - - const layerIndex = state.layerList.indexOf(layer); - const newLayerList = [...state.layerList]; - newLayerList[layerIndex] = { - ...layer, - __dataRequests: newDataRequests, - }; - return { ...state, layerList: newLayerList }; -} - -function getValidDataRequest(state, action, checkRequestToken = true) { - const layer = findLayerById(state, action.layerId); - if (!layer) { - return; - } - - const dataRequest = findDataRequest(layer, action); - if (!dataRequest) { - return; - } - - if ( - checkRequestToken && - dataRequest.dataRequestToken && - dataRequest.dataRequestToken !== action.requestToken - ) { - // ignore responses to outdated requests - return; - } - return dataRequest; -} - -function findLayerById(state, id) { - return state.layerList.find(layer => layer.id === id); -} - -function trackCurrentLayerState(state, layerId) { - const layer = findLayerById(state, layerId); - const layerCopy = copyPersistentState(layer); - return updateLayerInList(state, layerId, TRACKED_LAYER_DESCRIPTOR, layerCopy); -} - -function removeTrackedLayerState(state, layerId) { - const layer = findLayerById(state, layerId); - if (!layer) { - return state; - } - - const copyLayer = { ...layer }; - delete copyLayer[TRACKED_LAYER_DESCRIPTOR]; - - return { - ...state, - layerList: replaceInLayerList(state.layerList, layerId, copyLayer), - }; -} - -function rollbackTrackedLayerState(state, layerId) { - const layer = findLayerById(state, layerId); - if (!layer) { - return state; - } - - const trackedLayerDescriptor = layer[TRACKED_LAYER_DESCRIPTOR]; - - //this assumes that any nested temp-state in the layer-descriptor (e.g. of styles), is not relevant and can be recovered easily (e.g. this is not the case for __dataRequests) - //That assumption is true in the context of this app, but not generalizable. - //consider rewriting copyPersistentState to only strip the first level of temp state. - const rolledbackLayer = { ...layer, ...trackedLayerDescriptor }; - delete rolledbackLayer[TRACKED_LAYER_DESCRIPTOR]; - - return { - ...state, - layerList: replaceInLayerList(state.layerList, layerId, rolledbackLayer), - }; -} - -function replaceInLayerList(layerList, layerId, newLayerDescriptor) { - const layerIndex = getLayerIndex(layerList, layerId); - const newLayerList = [...layerList]; - newLayerList[layerIndex] = newLayerDescriptor; - return newLayerList; -} diff --git a/x-pack/legacy/plugins/maps/public/reducers/map.test.js b/x-pack/legacy/plugins/maps/public/reducers/map.test.js deleted file mode 100644 index 089dec952fc777..00000000000000 --- a/x-pack/legacy/plugins/maps/public/reducers/map.test.js +++ /dev/null @@ -1,56 +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. - */ - -jest.mock('../actions/map_actions', () => ({})); - -import { resetDataRequest } from './map'; -import _ from 'lodash'; - -describe('reducers/map', () => { - it('Should clear datarequest without mutation store state', async () => { - const layerId = 'foobar'; - const requestToken = 'tokenId'; - const dataId = 'dataId'; - - const preState = { - layerList: [ - { - id: `not_${layerId}`, - }, - { - id: layerId, - __dataRequests: [ - { - dataRequestToken: `not_${requestToken}`, - dataId: `not_${dataId}`, - }, - { - dataRequestToken: requestToken, - dataId: dataId, - }, - ], - }, - ], - }; - - const preStateCopy = _.cloneDeep(preState); - - const action = { - layerId, - requestToken, - dataId, - }; - - const postState = resetDataRequest(preState, action); - - //Ensure previous state is not mutated. - expect(_.isEqual(preState, preStateCopy)).toEqual(true); - - //Ensure new state is set correctly. - expect(postState.layerList[1].__dataRequests[1].dataId).toEqual(dataId); - expect(postState.layerList[1].__dataRequests[1].dataRequestToken).toEqual(null); - }); -}); diff --git a/x-pack/legacy/plugins/maps/public/reducers/non_serializable_instances.js b/x-pack/legacy/plugins/maps/public/reducers/non_serializable_instances.js deleted file mode 100644 index c7de2beff0cf6a..00000000000000 --- a/x-pack/legacy/plugins/maps/public/reducers/non_serializable_instances.js +++ /dev/null @@ -1,105 +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 chrome from 'ui/chrome'; -import { RequestAdapter } from '../../../../../../src/plugins/inspector/public'; -import { MapAdapter } from '../inspector/adapters/map_adapter'; - -const REGISTER_CANCEL_CALLBACK = 'REGISTER_CANCEL_CALLBACK'; -const UNREGISTER_CANCEL_CALLBACK = 'UNREGISTER_CANCEL_CALLBACK'; -const SET_EVENT_HANDLERS = 'SET_EVENT_HANDLERS'; - -function createInspectorAdapters() { - const inspectorAdapters = { - requests: new RequestAdapter(), - }; - if (chrome.getInjected('showMapsInspectorAdapter', false)) { - inspectorAdapters.map = new MapAdapter(); - } - return inspectorAdapters; -} - -// Reducer -export function nonSerializableInstances(state, action = {}) { - if (!state) { - return { - inspectorAdapters: createInspectorAdapters(), - cancelRequestCallbacks: new Map(), // key is request token, value is cancel callback - eventHandlers: {}, - }; - } - - switch (action.type) { - case REGISTER_CANCEL_CALLBACK: - state.cancelRequestCallbacks.set(action.requestToken, action.callback); - return { - ...state, - }; - case UNREGISTER_CANCEL_CALLBACK: - state.cancelRequestCallbacks.delete(action.requestToken); - return { - ...state, - }; - case SET_EVENT_HANDLERS: { - return { - ...state, - eventHandlers: action.eventHandlers, - }; - } - default: - return state; - } -} - -// Selectors -export const getInspectorAdapters = ({ nonSerializableInstances }) => { - return nonSerializableInstances.inspectorAdapters; -}; - -export const getCancelRequestCallbacks = ({ nonSerializableInstances }) => { - return nonSerializableInstances.cancelRequestCallbacks; -}; - -export const getEventHandlers = ({ nonSerializableInstances }) => { - return nonSerializableInstances.eventHandlers; -}; - -// Actions -export const registerCancelCallback = (requestToken, callback) => { - return { - type: REGISTER_CANCEL_CALLBACK, - requestToken, - callback, - }; -}; - -export const unregisterCancelCallback = requestToken => { - return { - type: UNREGISTER_CANCEL_CALLBACK, - requestToken, - }; -}; - -export const cancelRequest = requestToken => { - return (dispatch, getState) => { - if (!requestToken) { - return; - } - - const cancelCallback = getCancelRequestCallbacks(getState()).get(requestToken); - if (cancelCallback) { - cancelCallback(); - dispatch(unregisterCancelCallback(requestToken)); - } - }; -}; - -export const setEventHandlers = (eventHandlers = {}) => { - return { - type: SET_EVENT_HANDLERS, - eventHandlers, - }; -}; diff --git a/x-pack/legacy/plugins/maps/public/reducers/store.js b/x-pack/legacy/plugins/maps/public/reducers/store.js deleted file mode 100644 index 40b769f11b5292..00000000000000 --- a/x-pack/legacy/plugins/maps/public/reducers/store.js +++ /dev/null @@ -1,24 +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 { combineReducers, applyMiddleware, createStore, compose } from 'redux'; -import thunk from 'redux-thunk'; -import { ui } from './ui'; -import { map } from './map'; -import { nonSerializableInstances } from './non_serializable_instances'; - -const rootReducer = combineReducers({ - map, - ui, - nonSerializableInstances, -}); - -const enhancers = [applyMiddleware(thunk)]; - -export function createMapStore() { - const storeConfig = {}; - return createStore(rootReducer, storeConfig, compose(...enhancers)); -} diff --git a/x-pack/legacy/plugins/maps/public/reducers/ui.js b/x-pack/legacy/plugins/maps/public/reducers/ui.js deleted file mode 100644 index 287e1f8dd3ddad..00000000000000 --- a/x-pack/legacy/plugins/maps/public/reducers/ui.js +++ /dev/null @@ -1,81 +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 { - UPDATE_FLYOUT, - CLOSE_SET_VIEW, - OPEN_SET_VIEW, - SET_IS_LAYER_TOC_OPEN, - SET_FULL_SCREEN, - SET_READ_ONLY, - SET_OPEN_TOC_DETAILS, - SHOW_TOC_DETAILS, - HIDE_TOC_DETAILS, - UPDATE_INDEXING_STAGE, -} from '../actions/ui_actions'; - -export const FLYOUT_STATE = { - NONE: 'NONE', - LAYER_PANEL: 'LAYER_PANEL', - ADD_LAYER_WIZARD: 'ADD_LAYER_WIZARD', -}; - -export const INDEXING_STAGE = { - READY: 'READY', - TRIGGERED: 'TRIGGERED', - SUCCESS: 'SUCCESS', - ERROR: 'ERROR', -}; - -export const DEFAULT_IS_LAYER_TOC_OPEN = true; - -const INITIAL_STATE = { - flyoutDisplay: FLYOUT_STATE.NONE, - isFullScreen: false, - isReadOnly: false, - isLayerTOCOpen: DEFAULT_IS_LAYER_TOC_OPEN, - isSetViewOpen: false, - // storing TOC detail visibility outside of map.layerList because its UI state and not map rendering state. - // This also makes for easy read/write access for embeddables. - openTOCDetails: [], - importIndexingStage: null, -}; - -// Reducer -export function ui(state = INITIAL_STATE, action) { - switch (action.type) { - case UPDATE_FLYOUT: - return { ...state, flyoutDisplay: action.display }; - case CLOSE_SET_VIEW: - return { ...state, isSetViewOpen: false }; - case OPEN_SET_VIEW: - return { ...state, isSetViewOpen: true }; - case SET_IS_LAYER_TOC_OPEN: - return { ...state, isLayerTOCOpen: action.isLayerTOCOpen }; - case SET_FULL_SCREEN: - return { ...state, isFullScreen: action.isFullScreen }; - case SET_READ_ONLY: - return { ...state, isReadOnly: action.isReadOnly }; - case SET_OPEN_TOC_DETAILS: - return { ...state, openTOCDetails: action.layerIds }; - case SHOW_TOC_DETAILS: - return { - ...state, - openTOCDetails: [...state.openTOCDetails, action.layerId], - }; - case HIDE_TOC_DETAILS: - return { - ...state, - openTOCDetails: state.openTOCDetails.filter(layerId => { - return layerId !== action.layerId; - }), - }; - case UPDATE_INDEXING_STAGE: - return { ...state, importIndexingStage: action.stage }; - default: - return state; - } -} diff --git a/x-pack/legacy/plugins/maps/public/reducers/util.js b/x-pack/legacy/plugins/maps/public/reducers/util.js deleted file mode 100644 index e93eedbaebf50f..00000000000000 --- a/x-pack/legacy/plugins/maps/public/reducers/util.js +++ /dev/null @@ -1,21 +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. - */ - -export const TRACKED_LAYER_DESCRIPTOR = '__trackedLayerDescriptor'; - -export function copyPersistentState(input) { - if (typeof input !== 'object' || input === null) { - //primitive - return input; - } - const copyInput = Array.isArray(input) ? [] : {}; - for (const key in input) { - if (!key.startsWith('__')) { - copyInput[key] = copyPersistentState(input[key]); - } - } - return copyInput; -} diff --git a/x-pack/legacy/plugins/maps/public/reducers/util.test.js b/x-pack/legacy/plugins/maps/public/reducers/util.test.js deleted file mode 100644 index 2829c9410724e3..00000000000000 --- a/x-pack/legacy/plugins/maps/public/reducers/util.test.js +++ /dev/null @@ -1,47 +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 { copyPersistentState } from './util'; - -describe('reducers/util', () => { - describe('copyPersistentState', () => { - it('should ignore state preceded by double underscores', async () => { - const copy = copyPersistentState({ - foo: 'bar', - nested: { - bar: 'foo', - __bar: 'foo__', - }, - }); - - expect(copy).toEqual({ - foo: 'bar', - nested: { - bar: 'foo', - }, - }); - }); - - it('should copy null value correctly', async () => { - const copy = copyPersistentState({ - foo: 'bar', - nested: { - nullval: null, - bar: 'foo', - __bar: 'foo__', - }, - }); - - expect(copy).toEqual({ - foo: 'bar', - nested: { - nullval: null, - bar: 'foo', - }, - }); - }); - }); -}); diff --git a/x-pack/legacy/plugins/maps/public/selectors/map_selectors.js b/x-pack/legacy/plugins/maps/public/selectors/map_selectors.js index d1048a759beca0..b407a5e76317bc 100644 --- a/x-pack/legacy/plugins/maps/public/selectors/map_selectors.js +++ b/x-pack/legacy/plugins/maps/public/selectors/map_selectors.js @@ -12,8 +12,8 @@ import { VectorLayer } from '../layers/vector_layer'; import { HeatmapLayer } from '../layers/heatmap_layer'; import { ALL_SOURCES } from '../layers/sources/all_sources'; import { timefilter } from 'ui/timefilter'; -import { getInspectorAdapters } from '../reducers/non_serializable_instances'; -import { copyPersistentState, TRACKED_LAYER_DESCRIPTOR } from '../reducers/util'; +import { getInspectorAdapters } from '../../../../../plugins/maps/public/reducers/non_serializable_instances'; +import { copyPersistentState, TRACKED_LAYER_DESCRIPTOR } from '../../../../../plugins/maps/public/reducers/util'; function createLayerInstance(layerDescriptor, inspectorAdapters) { const source = createSourceInstance(layerDescriptor.sourceDescriptor, inspectorAdapters); diff --git a/x-pack/legacy/plugins/maps/public/selectors/map_selectors.test.js b/x-pack/legacy/plugins/maps/public/selectors/map_selectors.test.js index da45047d3a5671..655aa96a90ec88 100644 --- a/x-pack/legacy/plugins/maps/public/selectors/map_selectors.test.js +++ b/x-pack/legacy/plugins/maps/public/selectors/map_selectors.test.js @@ -8,7 +8,7 @@ jest.mock('../layers/vector_layer', () => {}); jest.mock('../layers/heatmap_layer', () => {}); jest.mock('../layers/vector_tile_layer', () => {}); jest.mock('../layers/sources/all_sources', () => {}); -jest.mock('../reducers/non_serializable_instances', () => ({ +jest.mock('../../../../../plugins/maps/public/reducers/non_serializable_instances', () => ({ getInspectorAdapters: () => { return {}; }, diff --git a/x-pack/plugins/maps/public/plugin.ts b/x-pack/plugins/maps/public/plugin.ts index 9144ec2a924094..4d79728944efd1 100644 --- a/x-pack/plugins/maps/public/plugin.ts +++ b/x-pack/plugins/maps/public/plugin.ts @@ -7,22 +7,15 @@ import { Plugin, CoreSetup, - CoreStart, - PluginInitializerContext, - AppMountParameters + CoreStart, AppMountParameters, } from 'src/core/public'; -import { auto } from 'angular'; -import { IEmbeddableSetup } from '../../../../src/plugins/embeddable/public'; -// @ts-ignore -import { MapEmbeddableFactory } from './embeddable/map_embeddable_factory.js'; -// @ts-ignore -import { MAP_SAVED_OBJECT_TYPE } from '../common/constants'; +import { DataPublicPluginSetup } from '../../../../src/plugins/data/public'; import { initKibanaServices } from './kibana_services'; -import {i18n} from "@kbn/i18n"; -import {createStore} from "../../../legacy/plugins/canvas/public/store"; +import { i18n } from '@kbn/i18n'; +// eslint-disable-line @typescript-eslint/no-empty-interface export interface MapsPluginSetupDependencies { - embeddable: IEmbeddableSetup; + data: DataPublicPluginSetup } // eslint-disable-line @typescript-eslint/no-empty-interface export interface MapsPluginStartDependencies {} @@ -44,36 +37,25 @@ export class MapsPlugin MapsPluginSetupDependencies, MapsPluginStartDependencies > { - private getEmbeddableInjector: (() => Promise) | null = null; - constructor(context: PluginInitializerContext) {} public setup(core: CoreSetup, plugins: MapsPluginSetupDependencies) { - core.application.register({ - id: 'maps', - title: i18n.translate('xpack.maps.pluginTitle', { - defaultMessage: 'Maps', - }), - async mount() { - }, - }); - - initKibanaServices(plugins); - // Set up embeddables - const isEditable = () => core.application.capabilities.get().maps.save as boolean; - if (!this.getEmbeddableInjector) { - throw Error('Maps plugin method getEmbeddableInjector is undefined'); + initKibanaServices(core, plugins); + // core.application.register({ + // id: 'maps', + // title: i18n.translate('xpack.maps.pluginTitle', { + // defaultMessage: 'Maps', + // }), + // async mount(params: AppMountParameters) { + // const [coreStart] = await core.getStartServices(); + // const { renderApp } = await import('./applications/maps'); + // return renderApp(coreStart, params); + // }, + // }); + return { + maps: 'testing' } - const addBasePath = core.http.basePath.prepend; - const factory = new MapEmbeddableFactory( - this.getEmbeddableInjector, - isEditable, - addBasePath - ); - plugins.embeddable.registerEmbeddableFactory(factory.type, factory); - plugins.embeddable.registerEmbeddableFactory(MAP_SAVED_OBJECT_TYPE, new MapEmbeddableFactory()); - } - public start(core: CoreStart, plugins: any) { - // setInspector(plugins.np.inspector); } + + public start(core: CoreStart, plugins: any) {} } From bbcf6b6f7822c3bbd7cdced9d14002297f737c76 Mon Sep 17 00:00:00 2001 From: Aaron Caldwell Date: Fri, 14 Feb 2020 13:16:25 -0700 Subject: [PATCH 04/21] Port inspector to NP --- .../public/inspector/adapters/map_adapter.js | 24 ++++ .../public/inspector/views/map_details.js | 128 ++++++++++++++++++ .../maps/public/inspector/views/map_view.js | 66 +++++++++ .../public/inspector/views/register_views.ts | 12 ++ 4 files changed, 230 insertions(+) create mode 100644 x-pack/plugins/maps/public/inspector/adapters/map_adapter.js create mode 100644 x-pack/plugins/maps/public/inspector/views/map_details.js create mode 100644 x-pack/plugins/maps/public/inspector/views/map_view.js create mode 100644 x-pack/plugins/maps/public/inspector/views/register_views.ts diff --git a/x-pack/plugins/maps/public/inspector/adapters/map_adapter.js b/x-pack/plugins/maps/public/inspector/adapters/map_adapter.js new file mode 100644 index 00000000000000..60a6cab7df3d1e --- /dev/null +++ b/x-pack/plugins/maps/public/inspector/adapters/map_adapter.js @@ -0,0 +1,24 @@ +/* + * 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 { EventEmitter } from 'events'; + +class MapAdapter extends EventEmitter { + setMapState({ stats, style }) { + this.stats = stats; + this.style = style; + this._onChange(); + } + + getMapState() { + return { stats: this.stats, style: this.style }; + } + + _onChange() { + this.emit('change'); + } +} + +export { MapAdapter }; diff --git a/x-pack/plugins/maps/public/inspector/views/map_details.js b/x-pack/plugins/maps/public/inspector/views/map_details.js new file mode 100644 index 00000000000000..e84cf51ed34c1c --- /dev/null +++ b/x-pack/plugins/maps/public/inspector/views/map_details.js @@ -0,0 +1,128 @@ +/* + * 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, { Component } from 'react'; +import PropTypes from 'prop-types'; +import { + EuiTab, + EuiTabs, + EuiCodeBlock, + EuiTable, + EuiTableBody, + EuiTableRow, + EuiTableRowCell, +} from '@elastic/eui'; +import { i18n } from '@kbn/i18n'; +import { FormattedMessage } from '@kbn/i18n/react'; + +const DETAILS_TAB_ID = 'details'; +const STYLE_TAB_ID = 'mapStyle'; + +class MapDetails extends Component { + tabs = [ + { + id: DETAILS_TAB_ID, + name: i18n.translate('xpack.maps.inspector.mapDetailsTitle', { + defaultMessage: 'Map details', + }), + dataTestSubj: 'mapDetailsTab', + }, + { + id: STYLE_TAB_ID, + name: i18n.translate('xpack.maps.inspector.mapboxStyleTitle', { + defaultMessage: 'Mapbox style', + }), + dataTestSubj: 'mapboxStyleTab', + }, + ]; + + state = { + selectedTabId: DETAILS_TAB_ID, + }; + + onSelectedTabChanged = id => { + this.setState({ + selectedTabId: id, + }); + }; + + renderTab = () => { + if (STYLE_TAB_ID === this.state.selectedTabId) { + return ( +
+ + {JSON.stringify(this.props.mapStyle, null, 2)} + +
+ ); + } + + return ( + + + + + + + {this.props.centerLon} + + + + + + + {this.props.centerLat} + + + + + + + {this.props.zoom} + + + + ); + }; + + renderTabs() { + return this.tabs.map((tab, index) => ( + this.onSelectedTabChanged(tab.id)} + isSelected={tab.id === this.state.selectedTabId} + key={index} + data-test-subj={tab.dataTestSubj} + > + {tab.name} + + )); + } + + render() { + return ( +
+ {this.renderTabs()} + + {this.renderTab()} +
+ ); + } +} + +MapDetails.propTypes = { + centerLon: PropTypes.number.isRequired, + centerLat: PropTypes.number.isRequired, + zoom: PropTypes.number.isRequired, + mapStyle: PropTypes.object.isRequired, +}; + +export { MapDetails }; diff --git a/x-pack/plugins/maps/public/inspector/views/map_view.js b/x-pack/plugins/maps/public/inspector/views/map_view.js new file mode 100644 index 00000000000000..db96e77c93984c --- /dev/null +++ b/x-pack/plugins/maps/public/inspector/views/map_view.js @@ -0,0 +1,66 @@ +/* + * 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, { Component } from 'react'; +import PropTypes from 'prop-types'; +import { MapDetails } from './map_details'; +import { i18n } from '@kbn/i18n'; + +class MapViewComponent extends Component { + constructor(props) { + super(props); + props.adapters.map.on('change', this._onMapChange); + + const { stats, style } = props.adapters.map.getMapState(); + this.state = { + stats, + mapStyle: style, + }; + } + + _onMapChange = () => { + const { stats, style } = this.props.adapters.map.getMapState(); + this.setState({ + stats, + mapStyle: style, + }); + }; + + componentWillUnmount() { + this.props.adapters.map.removeListener('change', this._onMapChange); + } + + render() { + return ( + + ); + } +} + +MapViewComponent.propTypes = { + adapters: PropTypes.object.isRequired, +}; + +const MapView = { + title: i18n.translate('xpack.maps.inspector.mapDetailsViewTitle', { + defaultMessage: 'Map details', + }), + order: 30, + help: i18n.translate('xpack.maps.inspector.mapDetailsViewHelpText', { + defaultMessage: 'View the map state', + }), + shouldShow(adapters) { + return Boolean(adapters.map); + }, + component: MapViewComponent, +}; + +export { MapView }; diff --git a/x-pack/plugins/maps/public/inspector/views/register_views.ts b/x-pack/plugins/maps/public/inspector/views/register_views.ts new file mode 100644 index 00000000000000..59c05956683007 --- /dev/null +++ b/x-pack/plugins/maps/public/inspector/views/register_views.ts @@ -0,0 +1,12 @@ +/* + * 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 { npSetup } from 'ui/new_platform'; + +// @ts-ignore +import { MapView } from './map_view'; + +npSetup.plugins.inspector.registerView(MapView); From 2fd29f3bbabd01008f1ea78a62da5bbc8df63568 Mon Sep 17 00:00:00 2001 From: Aaron Caldwell Date: Fri, 14 Feb 2020 13:18:19 -0700 Subject: [PATCH 05/21] Move some kibana services init to NP. Some cleaning --- .../maps/public/angular/map_controller.js | 5 ++++- .../widget_overlay/layer_control/index.js | 2 +- .../maps/public/embeddable/map_embeddable.js | 5 ++++- .../plugins/maps/public/kibana_services.js | 12 ---------- .../plugins/maps/public/layers/layer.js | 2 +- .../maps/public/layers/sources/source.js | 2 +- x-pack/legacy/plugins/maps/public/meta.js | 2 +- x-pack/legacy/plugins/maps/public/plugin.ts | 3 ++- .../maps/public/selectors/map_selectors.js | 5 ++++- x-pack/plugins/maps/public/kibana_services.js | 20 +++++++++++++++-- x-pack/plugins/maps/public/plugin.ts | 22 +++++++++---------- .../reducers/non_serializable_instances.js | 8 +++---- x-pack/plugins/maps/public/reducers/store.js | 14 +++++------- 13 files changed, 55 insertions(+), 47 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/angular/map_controller.js b/x-pack/legacy/plugins/maps/public/angular/map_controller.js index 461e2b33bc27ab..ad9d5c1c1ec0f6 100644 --- a/x-pack/legacy/plugins/maps/public/angular/map_controller.js +++ b/x-pack/legacy/plugins/maps/public/angular/map_controller.js @@ -27,7 +27,10 @@ import { setQuery, clearTransientLayerStateAndCloseFlyout, } from '../actions/map_actions'; -import { DEFAULT_IS_LAYER_TOC_OPEN, FLYOUT_STATE } from '../../../../../plugins/maps/public/reducers/ui'; +import { + DEFAULT_IS_LAYER_TOC_OPEN, + FLYOUT_STATE, +} from '../../../../../plugins/maps/public/reducers/ui'; import { enableFullScreen, updateFlyout, diff --git a/x-pack/legacy/plugins/maps/public/connected_components/widget_overlay/layer_control/index.js b/x-pack/legacy/plugins/maps/public/connected_components/widget_overlay/layer_control/index.js index c9cceb6b23651c..8dc89ac6f06c16 100644 --- a/x-pack/legacy/plugins/maps/public/connected_components/widget_overlay/layer_control/index.js +++ b/x-pack/legacy/plugins/maps/public/connected_components/widget_overlay/layer_control/index.js @@ -6,7 +6,7 @@ import { connect } from 'react-redux'; import { LayerControl } from './view'; -import { FLYOUT_STATE } from '../../../../../../../plugins/maps/public/reducers/ui.js' +import { FLYOUT_STATE } from '../../../../../../../plugins/maps/public/reducers/ui.js'; import { updateFlyout, setIsLayerTOCOpen } from '../../../actions/ui_actions'; import { setSelectedLayer } from '../../../actions/map_actions'; import { diff --git a/x-pack/legacy/plugins/maps/public/embeddable/map_embeddable.js b/x-pack/legacy/plugins/maps/public/embeddable/map_embeddable.js index 5a42dc65ea226e..8528232da1ddb9 100644 --- a/x-pack/legacy/plugins/maps/public/embeddable/map_embeddable.js +++ b/x-pack/legacy/plugins/maps/public/embeddable/map_embeddable.js @@ -36,7 +36,10 @@ import { } from '../actions/map_actions'; import { setReadOnly, setIsLayerTOCOpen, setOpenTOCDetails } from '../actions/ui_actions'; import { getIsLayerTOCOpen, getOpenTOCDetails } from '../selectors/ui_selectors'; -import { getInspectorAdapters, setEventHandlers } from '../../../../../plugins/maps/public/reducers/non_serializable_instances'; +import { + getInspectorAdapters, + setEventHandlers, +} from '../../../../../plugins/maps/public/reducers/non_serializable_instances'; import { getMapCenter, getMapZoom, getHiddenLayerIds } from '../selectors/map_selectors'; import { MAP_SAVED_OBJECT_TYPE } from '../../common/constants'; diff --git a/x-pack/legacy/plugins/maps/public/kibana_services.js b/x-pack/legacy/plugins/maps/public/kibana_services.js index a1b1c9ec1518e6..0e7e4324c39241 100644 --- a/x-pack/legacy/plugins/maps/public/kibana_services.js +++ b/x-pack/legacy/plugins/maps/public/kibana_services.js @@ -16,18 +16,6 @@ export { SearchSource } from '../../../../../src/plugins/data/public'; export const indexPatternService = npStart.plugins.data.indexPatterns; export const autocompleteService = npStart.plugins.data.autocomplete; -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; -}; - export async function fetchSearchSourceAndRecordWithInspector({ searchSource, requestId, diff --git a/x-pack/legacy/plugins/maps/public/layers/layer.js b/x-pack/legacy/plugins/maps/public/layers/layer.js index 7fceaf2ff33912..d4bfd114c2665f 100644 --- a/x-pack/legacy/plugins/maps/public/layers/layer.js +++ b/x-pack/legacy/plugins/maps/public/layers/layer.js @@ -14,7 +14,7 @@ import { SOURCE_DATA_ID_ORIGIN, } from '../../common/constants'; import uuid from 'uuid/v4'; -import { copyPersistentState } from '../../../../../plugins/maps/public/reducers/util.js' +import { copyPersistentState } from '../../../../../plugins/maps/public/reducers/util.js'; import { i18n } from '@kbn/i18n'; export class AbstractLayer { diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/source.js b/x-pack/legacy/plugins/maps/public/layers/sources/source.js index a09c6d03032f15..d6c7ff4e14c438 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/source.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/source.js @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import { copyPersistentState } from '../../../../../../plugins/maps/public/reducers'; +import { copyPersistentState } from '../../../../../../plugins/maps/public/reducers/util'; export class AbstractSource { static isIndexingSource = false; diff --git a/x-pack/legacy/plugins/maps/public/meta.js b/x-pack/legacy/plugins/maps/public/meta.js index c5cfb582976c1c..1ab0abacd28379 100644 --- a/x-pack/legacy/plugins/maps/public/meta.js +++ b/x-pack/legacy/plugins/maps/public/meta.js @@ -13,7 +13,7 @@ import { import chrome from 'ui/chrome'; import { i18n } from '@kbn/i18n'; import { EMSClient } from '@elastic/ems-client'; -import { getLicenseId } from './kibana_services'; +import { getLicenseId } from '../../../../plugins/maps/public/kibana_services'; import fetch from 'node-fetch'; const GIS_API_RELATIVE = `../${GIS_API_PATH}`; diff --git a/x-pack/legacy/plugins/maps/public/plugin.ts b/x-pack/legacy/plugins/maps/public/plugin.ts index e2af53d59671fe..f631fc3b3400de 100644 --- a/x-pack/legacy/plugins/maps/public/plugin.ts +++ b/x-pack/legacy/plugins/maps/public/plugin.ts @@ -10,7 +10,7 @@ import { wrapInI18nContext } from 'ui/i18n'; // @ts-ignore import { MapListing } from './components/map_listing'; // @ts-ignore -import { setLicenseId, setInspector } from './kibana_services'; +import { setLicenseId, setInspector, setInjectedVarFunc } from '../../../../plugins/maps/public/kibana_services'; import { HomePublicPluginSetup } from '../../../../../src/plugins/home/public'; import { LicensingPluginSetup } from '../../../../plugins/licensing/public'; import { featureCatalogueEntry } from './feature_catalogue_entry'; @@ -43,6 +43,7 @@ export class MapsPlugin implements Plugin { return reactDirective(wrapInI18nContext(MapListing)); }); + setInjectedVarFunc(core.injectedMetadata.getInjectedVar); if (licensing) { licensing.license$.subscribe(({ uid }) => setLicenseId(uid)); } diff --git a/x-pack/legacy/plugins/maps/public/selectors/map_selectors.js b/x-pack/legacy/plugins/maps/public/selectors/map_selectors.js index b407a5e76317bc..b0b8b90d23d57d 100644 --- a/x-pack/legacy/plugins/maps/public/selectors/map_selectors.js +++ b/x-pack/legacy/plugins/maps/public/selectors/map_selectors.js @@ -13,7 +13,10 @@ import { HeatmapLayer } from '../layers/heatmap_layer'; import { ALL_SOURCES } from '../layers/sources/all_sources'; import { timefilter } from 'ui/timefilter'; import { getInspectorAdapters } from '../../../../../plugins/maps/public/reducers/non_serializable_instances'; -import { copyPersistentState, TRACKED_LAYER_DESCRIPTOR } from '../../../../../plugins/maps/public/reducers/util'; +import { + copyPersistentState, + TRACKED_LAYER_DESCRIPTOR, +} from '../../../../../plugins/maps/public/reducers/util'; function createLayerInstance(layerDescriptor, inspectorAdapters) { const source = createSourceInstance(layerDescriptor.sourceDescriptor, inspectorAdapters); diff --git a/x-pack/plugins/maps/public/kibana_services.js b/x-pack/plugins/maps/public/kibana_services.js index a158ff21279001..4008d30e4765fe 100644 --- a/x-pack/plugins/maps/public/kibana_services.js +++ b/x-pack/plugins/maps/public/kibana_services.js @@ -7,7 +7,23 @@ export let indexPatternService; export let timeFilter; -export const initKibanaServices = ({ data }) => { +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 getInjectedVar; +export const setInjectedVarFunc = getInjectedVarFunc => (getInjectedVar = getInjectedVarFunc); +export const getInjectedVarFunc = () => getInjectedVar; + +export const initKibanaServices = ({ injectedMetadata }, { data }) => { indexPatternService = data.indexPatterns; - timeFilter: data.query.timefilter + timeFilter = data.query.timefilter; }; diff --git a/x-pack/plugins/maps/public/plugin.ts b/x-pack/plugins/maps/public/plugin.ts index 4d79728944efd1..f44a56065df0e7 100644 --- a/x-pack/plugins/maps/public/plugin.ts +++ b/x-pack/plugins/maps/public/plugin.ts @@ -4,18 +4,16 @@ * you may not use this file except in compliance with the Elastic License. */ -import { - Plugin, - CoreSetup, - CoreStart, AppMountParameters, -} from 'src/core/public'; +import { Plugin, CoreSetup, CoreStart } from 'src/core/public'; +import { Setup as InspectorSetupContract } from 'src/plugins/inspector/public'; import { DataPublicPluginSetup } from '../../../../src/plugins/data/public'; -import { initKibanaServices } from './kibana_services'; -import { i18n } from '@kbn/i18n'; +// @ts-ignore +import { initKibanaServices, setInspector, setInjectedVarFunc } from './kibana_services'; // eslint-disable-line @typescript-eslint/no-empty-interface export interface MapsPluginSetupDependencies { - data: DataPublicPluginSetup + data: DataPublicPluginSetup; + inspector: InspectorSetupContract; } // eslint-disable-line @typescript-eslint/no-empty-interface export interface MapsPluginStartDependencies {} @@ -37,9 +35,10 @@ export class MapsPlugin MapsPluginSetupDependencies, MapsPluginStartDependencies > { - public setup(core: CoreSetup, plugins: MapsPluginSetupDependencies) { initKibanaServices(core, plugins); + setInspector(plugins.inspector); + setInjectedVarFunc(core.injectedMetadata.getInjectedVar); // core.application.register({ // id: 'maps', // title: i18n.translate('xpack.maps.pluginTitle', { @@ -52,9 +51,8 @@ export class MapsPlugin // }, // }); return { - maps: 'testing' - } - + maps: 'testing', + }; } public start(core: CoreStart, plugins: any) {} diff --git a/x-pack/plugins/maps/public/reducers/non_serializable_instances.js b/x-pack/plugins/maps/public/reducers/non_serializable_instances.js index fcd583a91ca8a5..afc77d561ce212 100644 --- a/x-pack/plugins/maps/public/reducers/non_serializable_instances.js +++ b/x-pack/plugins/maps/public/reducers/non_serializable_instances.js @@ -4,11 +4,9 @@ * you may not use this file except in compliance with the Elastic License. */ -import { RequestAdapter} from '../../../../../src/plugins/inspector/public/adapters/request'; +import { RequestAdapter } from '../../../../../src/plugins/inspector/common/adapters/request'; import { MapAdapter } from '../inspector/adapters/map_adapter'; - -// TODO -import chrome from 'ui/chrome'; +import { getInjectedVarFunc } from '../kibana_services'; const REGISTER_CANCEL_CALLBACK = 'REGISTER_CANCEL_CALLBACK'; const UNREGISTER_CANCEL_CALLBACK = 'UNREGISTER_CANCEL_CALLBACK'; @@ -18,7 +16,7 @@ function createInspectorAdapters() { const inspectorAdapters = { requests: new RequestAdapter(), }; - if (chrome.getInjected('showMapsInspectorAdapter', false)) { + if (getInjectedVarFunc()('showMapsInspectorAdapter', false)) { inspectorAdapters.map = new MapAdapter(); } return inspectorAdapters; diff --git a/x-pack/plugins/maps/public/reducers/store.js b/x-pack/plugins/maps/public/reducers/store.js index 40b769f11b5292..b5c4bb435e7256 100644 --- a/x-pack/plugins/maps/public/reducers/store.js +++ b/x-pack/plugins/maps/public/reducers/store.js @@ -10,15 +10,13 @@ import { ui } from './ui'; import { map } from './map'; import { nonSerializableInstances } from './non_serializable_instances'; -const rootReducer = combineReducers({ - map, - ui, - nonSerializableInstances, -}); - -const enhancers = [applyMiddleware(thunk)]; - export function createMapStore() { + const enhancers = [applyMiddleware(thunk)]; + const rootReducer = combineReducers({ + map, + ui, + nonSerializableInstances, + }); const storeConfig = {}; return createStore(rootReducer, storeConfig, compose(...enhancers)); } From aa1a8a0fd4817ce9e52873f1806d84c4b3af967c Mon Sep 17 00:00:00 2001 From: Aaron Caldwell Date: Fri, 21 Feb 2020 16:27:05 -0700 Subject: [PATCH 06/21] Clean up work not related to reducers/store --- .../plugins/maps/public/kibana_services.js | 12 +++ x-pack/legacy/plugins/maps/public/meta.js | 2 +- x-pack/legacy/plugins/maps/public/plugin.ts | 26 +++--- x-pack/plugins/maps/public/kibana_services.js | 20 ----- x-pack/plugins/maps/public/plugin.ts | 21 +---- .../maps/public/selectors/map_selectors.js | 85 ------------------- .../maps/public/selectors/ui_selectors.js | 13 --- 7 files changed, 29 insertions(+), 150 deletions(-) delete mode 100644 x-pack/plugins/maps/public/selectors/map_selectors.js delete mode 100644 x-pack/plugins/maps/public/selectors/ui_selectors.js diff --git a/x-pack/legacy/plugins/maps/public/kibana_services.js b/x-pack/legacy/plugins/maps/public/kibana_services.js index 0e7e4324c39241..a1b1c9ec1518e6 100644 --- a/x-pack/legacy/plugins/maps/public/kibana_services.js +++ b/x-pack/legacy/plugins/maps/public/kibana_services.js @@ -16,6 +16,18 @@ export { SearchSource } from '../../../../../src/plugins/data/public'; export const indexPatternService = npStart.plugins.data.indexPatterns; export const autocompleteService = npStart.plugins.data.autocomplete; +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; +}; + export async function fetchSearchSourceAndRecordWithInspector({ searchSource, requestId, diff --git a/x-pack/legacy/plugins/maps/public/meta.js b/x-pack/legacy/plugins/maps/public/meta.js index 1ab0abacd28379..c5cfb582976c1c 100644 --- a/x-pack/legacy/plugins/maps/public/meta.js +++ b/x-pack/legacy/plugins/maps/public/meta.js @@ -13,7 +13,7 @@ import { import chrome from 'ui/chrome'; import { i18n } from '@kbn/i18n'; import { EMSClient } from '@elastic/ems-client'; -import { getLicenseId } from '../../../../plugins/maps/public/kibana_services'; +import { getLicenseId } from './kibana_services'; import fetch from 'node-fetch'; const GIS_API_RELATIVE = `../${GIS_API_PATH}`; diff --git a/x-pack/legacy/plugins/maps/public/plugin.ts b/x-pack/legacy/plugins/maps/public/plugin.ts index f631fc3b3400de..40402af88998b8 100644 --- a/x-pack/legacy/plugins/maps/public/plugin.ts +++ b/x-pack/legacy/plugins/maps/public/plugin.ts @@ -4,13 +4,13 @@ * you may not use this file except in compliance with the Elastic License. */ +// @ts-nocheck import { Plugin, CoreStart } from 'src/core/public'; -// @ts-ignore import { wrapInI18nContext } from 'ui/i18n'; -// @ts-ignore import { MapListing } from './components/map_listing'; -// @ts-ignore -import { setLicenseId, setInspector, setInjectedVarFunc } from '../../../../plugins/maps/public/kibana_services'; +// eslint-disable-next-line @kbn/eslint/no-restricted-paths +import { setInjectedVarFunc } from '../../../../plugins/maps/public/kibana_services'; +import { setLicenseId, setInspector } from './kibana_services'; import { HomePublicPluginSetup } from '../../../../../src/plugins/home/public'; import { LicensingPluginSetup } from '../../../../plugins/licensing/public'; import { featureCatalogueEntry } from './feature_catalogue_entry'; @@ -31,24 +31,26 @@ interface MapsPluginSetupDependencies { }; } +// This function will grow as more pieces are migrated to NP +function initializeNewPlatformCode(getInjectedVar: any) { + setInjectedVarFunc(getInjectedVar); +} + /** @internal */ export class MapsPlugin implements Plugin { - public setup( - core: any, - { __LEGACY: { uiModules }, np: { licensing, home } }: MapsPluginSetupDependencies - ) { + public setup(core: any, { __LEGACY: { uiModules }, np }: MapsPluginSetupDependencies) { uiModules .get('app/maps', ['ngRoute', 'react']) .directive('mapListing', function(reactDirective: any) { return reactDirective(wrapInI18nContext(MapListing)); }); - setInjectedVarFunc(core.injectedMetadata.getInjectedVar); - if (licensing) { - licensing.license$.subscribe(({ uid }) => setLicenseId(uid)); + if (np.licensing) { + np.licensing.license$.subscribe(({ uid }) => setLicenseId(uid)); } + np.home.featureCatalogue.register(featureCatalogueEntry); - home.featureCatalogue.register(featureCatalogueEntry); + initializeNewPlatformCode(core.injectedMetadata.getInjectedVar); } public start(core: CoreStart, plugins: any) { diff --git a/x-pack/plugins/maps/public/kibana_services.js b/x-pack/plugins/maps/public/kibana_services.js index 4008d30e4765fe..1073e44fa711e7 100644 --- a/x-pack/plugins/maps/public/kibana_services.js +++ b/x-pack/plugins/maps/public/kibana_services.js @@ -4,26 +4,6 @@ * you may not use this file except in compliance with the Elastic License. */ -export let indexPatternService; -export let timeFilter; - -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 getInjectedVar; export const setInjectedVarFunc = getInjectedVarFunc => (getInjectedVar = getInjectedVarFunc); export const getInjectedVarFunc = () => getInjectedVar; - -export const initKibanaServices = ({ injectedMetadata }, { data }) => { - indexPatternService = data.indexPatterns; - timeFilter = data.query.timefilter; -}; diff --git a/x-pack/plugins/maps/public/plugin.ts b/x-pack/plugins/maps/public/plugin.ts index f44a56065df0e7..bcc764537351ec 100644 --- a/x-pack/plugins/maps/public/plugin.ts +++ b/x-pack/plugins/maps/public/plugin.ts @@ -8,14 +8,13 @@ import { Plugin, CoreSetup, CoreStart } from 'src/core/public'; import { Setup as InspectorSetupContract } from 'src/plugins/inspector/public'; import { DataPublicPluginSetup } from '../../../../src/plugins/data/public'; // @ts-ignore -import { initKibanaServices, setInspector, setInjectedVarFunc } from './kibana_services'; +import { setInjectedVarFunc } from './kibana_services'; -// eslint-disable-line @typescript-eslint/no-empty-interface export interface MapsPluginSetupDependencies { data: DataPublicPluginSetup; inspector: InspectorSetupContract; } -// eslint-disable-line @typescript-eslint/no-empty-interface +// eslint-disable-next-line @typescript-eslint/no-empty-interface export interface MapsPluginStartDependencies {} /** @@ -36,23 +35,7 @@ export class MapsPlugin MapsPluginStartDependencies > { public setup(core: CoreSetup, plugins: MapsPluginSetupDependencies) { - initKibanaServices(core, plugins); - setInspector(plugins.inspector); setInjectedVarFunc(core.injectedMetadata.getInjectedVar); - // core.application.register({ - // id: 'maps', - // title: i18n.translate('xpack.maps.pluginTitle', { - // defaultMessage: 'Maps', - // }), - // async mount(params: AppMountParameters) { - // const [coreStart] = await core.getStartServices(); - // const { renderApp } = await import('./applications/maps'); - // return renderApp(coreStart, params); - // }, - // }); - return { - maps: 'testing', - }; } public start(core: CoreStart, plugins: any) {} diff --git a/x-pack/plugins/maps/public/selectors/map_selectors.js b/x-pack/plugins/maps/public/selectors/map_selectors.js deleted file mode 100644 index 0e7c91df5e4bac..00000000000000 --- a/x-pack/plugins/maps/public/selectors/map_selectors.js +++ /dev/null @@ -1,85 +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 _ from 'lodash'; -import { timeFilter } from '../kibana_services'; - -export const getTooltipState = ({ map }) => { - return map.tooltipState; -}; - -export const getMapReady = ({ map }) => map && map.ready; - -export const getMapInitError = ({ map }) => map.mapInitError; - -export const getGoto = ({ map }) => map && map.goto; - -export const getSelectedLayerId = ({ map }) => { - return !map.selectedLayerId || !map.layerList ? null : map.selectedLayerId; -}; - -export const getTransientLayerId = ({ map }) => map.__transientLayerId; - -export const getLayerListRaw = ({ map }) => (map.layerList ? map.layerList : []); - -export const getWaitingForMapReadyLayerListRaw = ({ map }) => - map.waitingForMapReadyLayerList ? map.waitingForMapReadyLayerList : []; - -export const getScrollZoom = ({ map }) => map.mapState.scrollZoom; - -export const isInteractiveDisabled = ({ map }) => map.mapState.disableInteractive; - -export const isTooltipControlDisabled = ({ map }) => map.mapState.disableTooltipControl; - -export const isToolbarOverlayHidden = ({ map }) => map.mapState.hideToolbarOverlay; - -export const isLayerControlHidden = ({ map }) => map.mapState.hideLayerControl; - -export const isViewControlHidden = ({ map }) => map.mapState.hideViewControl; - -export const getMapExtent = ({ map }) => (map.mapState.extent ? map.mapState.extent : {}); - -export const getMapBuffer = ({ map }) => (map.mapState.buffer ? map.mapState.buffer : {}); - -export const getMapZoom = ({ map }) => (map.mapState.zoom ? map.mapState.zoom : 0); - -export const getMapCenter = ({ map }) => - map.mapState.center ? map.mapState.center : { lat: 0, lon: 0 }; - -export const getMouseCoordinates = ({ map }) => map.mapState.mouseCoordinates; - -export const getTimeFilters = ({ map }) => - map.mapState.timeFilters ? map.mapState.timeFilters : timeFilter.getTime(); - -export const getQuery = ({ map }) => map.mapState.query; - -export const getFilters = ({ map }) => map.mapState.filters; - -export const isUsingSearch = state => { - const filters = getFilters(state).filter(filter => !filter.meta.disabled); - const queryString = _.get(getQuery(state), 'query', ''); - return filters.length || queryString.length; -}; - -export const getDrawState = ({ map }) => map.mapState.drawState; - -export const isDrawingFilter = ({ map }) => { - return !!map.mapState.drawState; -}; - -export const getRefreshConfig = ({ map }) => { - if (map.mapState.refreshConfig) { - return map.mapState.refreshConfig; - } - - const refreshInterval = timefilter.getRefreshInterval(); - return { - isPaused: refreshInterval.pause, - interval: refreshInterval.value, - }; -}; - -export const getRefreshTimerLastTriggeredAt = ({ map }) => map.mapState.refreshTimerLastTriggeredAt; diff --git a/x-pack/plugins/maps/public/selectors/ui_selectors.js b/x-pack/plugins/maps/public/selectors/ui_selectors.js deleted file mode 100644 index 912ee083962126..00000000000000 --- a/x-pack/plugins/maps/public/selectors/ui_selectors.js +++ /dev/null @@ -1,13 +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. - */ - -export const getFlyoutDisplay = ({ ui }) => ui.flyoutDisplay; -export const getIsSetViewOpen = ({ ui }) => ui.isSetViewOpen; -export const getIsLayerTOCOpen = ({ ui }) => ui.isLayerTOCOpen; -export const getOpenTOCDetails = ({ ui }) => ui.openTOCDetails; -export const getIsFullScreen = ({ ui }) => ui.isFullScreen; -export const getIsReadOnly = ({ ui }) => ui.isReadOnly; -export const getIndexingStage = ({ ui }) => ui.importIndexingStage; From e127a90034e75da4f4cb9c78a8c3845a6ead5a42 Mon Sep 17 00:00:00 2001 From: Aaron Caldwell Date: Mon, 24 Feb 2020 12:41:34 -0700 Subject: [PATCH 07/21] Ignore temp imports from NP. Clean up of changes unrelated to this PR --- x-pack/legacy/plugins/maps/index.js | 1 - .../maps/public/actions/map_actions.js | 2 + .../maps/public/angular/map_controller.js | 4 + .../public/angular/services/saved_gis_map.js | 1 + .../connected_components/gis_map/index.js | 1 + .../layer_addpanel/import_editor/index.js | 2 + .../layer_addpanel/index.js | 2 + .../layer_addpanel/source_editor/index.js | 1 + .../layer_panel/flyout_footer/index.js | 1 + .../connected_components/map/mb/index.js | 1 + .../widget_overlay/layer_control/index.js | 1 + .../layer_toc/toc_entry/index.js | 1 + .../maps/public/embeddable/map_embeddable.js | 2 + .../embeddable/map_embeddable_factory.js | 1 + .../embeddable/merge_input_with_saved_map.js | 1 + .../plugins/maps/public/layers/layer.js | 1 + .../maps/public/layers/sources/es_source.js | 1 + .../maps/public/layers/sources/source.js | 1 + x-pack/legacy/plugins/maps/public/plugin.ts | 11 +- .../maps/public/selectors/map_selectors.js | 2 + .../maps/public/actions/map_actions.js | 2 - .../gis_map/_gis_map.scss | 19 -- .../connected_components/gis_map/index.js | 45 ---- .../connected_components/gis_map/view.js | 222 ------------------ .../plugins/maps/public/index_pattern_util.js | 52 ---- .../maps/public/index_pattern_util.test.js | 29 --- .../public/inspector/views/register_views.ts | 12 - 27 files changed, 31 insertions(+), 388 deletions(-) delete mode 100644 x-pack/plugins/maps/public/connected_components/gis_map/_gis_map.scss delete mode 100644 x-pack/plugins/maps/public/connected_components/gis_map/index.js delete mode 100644 x-pack/plugins/maps/public/connected_components/gis_map/view.js delete mode 100644 x-pack/plugins/maps/public/index_pattern_util.js delete mode 100644 x-pack/plugins/maps/public/index_pattern_util.test.js delete mode 100644 x-pack/plugins/maps/public/inspector/views/register_views.ts diff --git a/x-pack/legacy/plugins/maps/index.js b/x-pack/legacy/plugins/maps/index.js index 5cd5a8731a7033..5660b29d7b67dc 100644 --- a/x-pack/legacy/plugins/maps/index.js +++ b/x-pack/legacy/plugins/maps/index.js @@ -52,7 +52,6 @@ export function maps(kibana) { }; }, embeddableFactories: ['plugins/maps/embeddable/map_embeddable_factory'], - inspectorViews: ['plugins/maps/inspector/views/register_views'], home: ['plugins/maps/legacy_register_feature'], styleSheetPaths: `${__dirname}/public/index.scss`, savedObjectSchemas: { diff --git a/x-pack/legacy/plugins/maps/public/actions/map_actions.js b/x-pack/legacy/plugins/maps/public/actions/map_actions.js index 03ed474a777e46..e019f0a2380347 100644 --- a/x-pack/legacy/plugins/maps/public/actions/map_actions.js +++ b/x-pack/legacy/plugins/maps/public/actions/map_actions.js @@ -19,12 +19,14 @@ import { getOpenTooltips, getQuery, } from '../selectors/map_selectors'; +// eslint-disable-next-line @kbn/eslint/no-restricted-paths import { FLYOUT_STATE } from '../../../../../plugins/maps/public/reducers/ui'; import { cancelRequest, registerCancelCallback, unregisterCancelCallback, getEventHandlers, + // eslint-disable-next-line @kbn/eslint/no-restricted-paths } from '../../../../../plugins/maps/public/reducers/non_serializable_instances'; import { updateFlyout } from '../actions/ui_actions'; import { diff --git a/x-pack/legacy/plugins/maps/public/angular/map_controller.js b/x-pack/legacy/plugins/maps/public/angular/map_controller.js index ad9d5c1c1ec0f6..33a3dd75c0fe7a 100644 --- a/x-pack/legacy/plugins/maps/public/angular/map_controller.js +++ b/x-pack/legacy/plugins/maps/public/angular/map_controller.js @@ -16,6 +16,7 @@ import { render, unmountComponentAtNode } from 'react-dom'; import { uiModules } from 'ui/modules'; import { timefilter } from 'ui/timefilter'; import { Provider } from 'react-redux'; +// eslint-disable-next-line @kbn/eslint/no-restricted-paths import { createMapStore } from '../../../../../plugins/maps/public/reducers/store'; import { GisMap } from '../connected_components/gis_map'; import { addHelpMenuToAppChrome } from '../help_menu_util'; @@ -30,6 +31,7 @@ import { import { DEFAULT_IS_LAYER_TOC_OPEN, FLYOUT_STATE, + // eslint-disable-next-line @kbn/eslint/no-restricted-paths } from '../../../../../plugins/maps/public/reducers/ui'; import { enableFullScreen, @@ -39,12 +41,14 @@ import { setOpenTOCDetails, } from '../actions/ui_actions'; import { getIsFullScreen } from '../selectors/ui_selectors'; +// eslint-disable-next-line @kbn/eslint/no-restricted-paths import { copyPersistentState } from '../../../../../plugins/maps/public/reducers/util'; import { getQueryableUniqueIndexPatternIds, hasDirtyState, getLayerListRaw, } from '../selectors/map_selectors'; +// eslint-disable-next-line @kbn/eslint/no-restricted-paths import { getInspectorAdapters } from '../../../../../plugins/maps/public/reducers/non_serializable_instances'; import { docTitle } from 'ui/doc_title'; import { indexPatternService, getInspector } from '../kibana_services'; diff --git a/x-pack/legacy/plugins/maps/public/angular/services/saved_gis_map.js b/x-pack/legacy/plugins/maps/public/angular/services/saved_gis_map.js index 12590de17c2063..f846d3d4a617f0 100644 --- a/x-pack/legacy/plugins/maps/public/angular/services/saved_gis_map.js +++ b/x-pack/legacy/plugins/maps/public/angular/services/saved_gis_map.js @@ -18,6 +18,7 @@ import { } 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 { copyPersistentState } from '../../../../../../plugins/maps/public/reducers/util'; import { extractReferences, injectReferences } from '../../../common/migrations/references'; import { MAP_SAVED_OBJECT_TYPE } from '../../../common/constants'; diff --git a/x-pack/legacy/plugins/maps/public/connected_components/gis_map/index.js b/x-pack/legacy/plugins/maps/public/connected_components/gis_map/index.js index 6385edb1b096d1..39cb2c469e0544 100644 --- a/x-pack/legacy/plugins/maps/public/connected_components/gis_map/index.js +++ b/x-pack/legacy/plugins/maps/public/connected_components/gis_map/index.js @@ -6,6 +6,7 @@ import { connect } from 'react-redux'; import { GisMap } from './view'; +// eslint-disable-next-line @kbn/eslint/no-restricted-paths import { FLYOUT_STATE } from '../../../../../../plugins/maps/public/reducers/ui'; import { exitFullScreen } from '../../actions/ui_actions'; import { getFlyoutDisplay, getIsFullScreen } from '../../selectors/ui_selectors'; diff --git a/x-pack/legacy/plugins/maps/public/connected_components/layer_addpanel/import_editor/index.js b/x-pack/legacy/plugins/maps/public/connected_components/layer_addpanel/import_editor/index.js index 963cd1c2e60e3c..e8192795f98aef 100644 --- a/x-pack/legacy/plugins/maps/public/connected_components/layer_addpanel/import_editor/index.js +++ b/x-pack/legacy/plugins/maps/public/connected_components/layer_addpanel/import_editor/index.js @@ -6,7 +6,9 @@ import { connect } from 'react-redux'; import { ImportEditor } from './view'; +// eslint-disable-next-line @kbn/eslint/no-restricted-paths import { getInspectorAdapters } from '../../../../../../../plugins/maps/public/reducers/non_serializable_instances'; +// eslint-disable-next-line @kbn/eslint/no-restricted-paths import { INDEXING_STAGE } from '../../../../../../../plugins/maps/public/reducers/ui'; import { updateIndexingStage } from '../../../actions/ui_actions'; import { getIndexingStage } from '../../../selectors/ui_selectors'; diff --git a/x-pack/legacy/plugins/maps/public/connected_components/layer_addpanel/index.js b/x-pack/legacy/plugins/maps/public/connected_components/layer_addpanel/index.js index abd67760a8c4f8..c4e2fa5169b0fa 100644 --- a/x-pack/legacy/plugins/maps/public/connected_components/layer_addpanel/index.js +++ b/x-pack/legacy/plugins/maps/public/connected_components/layer_addpanel/index.js @@ -6,10 +6,12 @@ import { connect } from 'react-redux'; import { AddLayerPanel } from './view'; +// eslint-disable-next-line @kbn/eslint/no-restricted-paths import { FLYOUT_STATE, INDEXING_STAGE } from '../../../../../../plugins/maps/public/reducers/ui'; import { updateFlyout, updateIndexingStage } from '../../actions/ui_actions'; import { getFlyoutDisplay, getIndexingStage } from '../../selectors/ui_selectors'; import { getMapColors } from '../../selectors/map_selectors'; +// eslint-disable-next-line @kbn/eslint/no-restricted-paths import { getInspectorAdapters } from '../../../../../../plugins/maps/public/reducers/non_serializable_instances'; import { setTransientLayer, diff --git a/x-pack/legacy/plugins/maps/public/connected_components/layer_addpanel/source_editor/index.js b/x-pack/legacy/plugins/maps/public/connected_components/layer_addpanel/source_editor/index.js index 967b454060e1a6..553e54ee897665 100644 --- a/x-pack/legacy/plugins/maps/public/connected_components/layer_addpanel/source_editor/index.js +++ b/x-pack/legacy/plugins/maps/public/connected_components/layer_addpanel/source_editor/index.js @@ -6,6 +6,7 @@ import { connect } from 'react-redux'; import { SourceEditor } from './view'; +// eslint-disable-next-line @kbn/eslint/no-restricted-paths import { getInspectorAdapters } from '../../../../../../../plugins/maps/public/reducers/non_serializable_instances'; function mapStateToProps(state = {}) { diff --git a/x-pack/legacy/plugins/maps/public/connected_components/layer_panel/flyout_footer/index.js b/x-pack/legacy/plugins/maps/public/connected_components/layer_panel/flyout_footer/index.js index cc036bdcf02e66..287f0019f18ecd 100644 --- a/x-pack/legacy/plugins/maps/public/connected_components/layer_panel/flyout_footer/index.js +++ b/x-pack/legacy/plugins/maps/public/connected_components/layer_panel/flyout_footer/index.js @@ -6,6 +6,7 @@ import { connect } from 'react-redux'; import { FlyoutFooter } from './view'; +// eslint-disable-next-line @kbn/eslint/no-restricted-paths import { FLYOUT_STATE } from '../../../../../../../plugins/maps/public/reducers/ui'; import { updateFlyout } from '../../../actions/ui_actions'; import { hasDirtyState } from '../../../selectors/map_selectors'; diff --git a/x-pack/legacy/plugins/maps/public/connected_components/map/mb/index.js b/x-pack/legacy/plugins/maps/public/connected_components/map/mb/index.js index 095bb338e122b7..350cb7028abee2 100644 --- a/x-pack/legacy/plugins/maps/public/connected_components/map/mb/index.js +++ b/x-pack/legacy/plugins/maps/public/connected_components/map/mb/index.js @@ -24,6 +24,7 @@ import { isTooltipControlDisabled, isViewControlHidden, } from '../../../selectors/map_selectors'; +// eslint-disable-next-line @kbn/eslint/no-restricted-paths import { getInspectorAdapters } from '../../../../../../../plugins/maps/public/reducers/non_serializable_instances'; function mapStateToProps(state = {}) { diff --git a/x-pack/legacy/plugins/maps/public/connected_components/widget_overlay/layer_control/index.js b/x-pack/legacy/plugins/maps/public/connected_components/widget_overlay/layer_control/index.js index 8dc89ac6f06c16..e51e59ec41e18e 100644 --- a/x-pack/legacy/plugins/maps/public/connected_components/widget_overlay/layer_control/index.js +++ b/x-pack/legacy/plugins/maps/public/connected_components/widget_overlay/layer_control/index.js @@ -6,6 +6,7 @@ import { connect } from 'react-redux'; import { LayerControl } from './view'; +// eslint-disable-next-line @kbn/eslint/no-restricted-paths import { FLYOUT_STATE } from '../../../../../../../plugins/maps/public/reducers/ui.js'; import { updateFlyout, setIsLayerTOCOpen } from '../../../actions/ui_actions'; import { setSelectedLayer } from '../../../actions/map_actions'; diff --git a/x-pack/legacy/plugins/maps/public/connected_components/widget_overlay/layer_control/layer_toc/toc_entry/index.js b/x-pack/legacy/plugins/maps/public/connected_components/widget_overlay/layer_control/layer_toc/toc_entry/index.js index 479173f0d36958..ececc5a90ab89b 100644 --- a/x-pack/legacy/plugins/maps/public/connected_components/widget_overlay/layer_control/layer_toc/toc_entry/index.js +++ b/x-pack/legacy/plugins/maps/public/connected_components/widget_overlay/layer_control/layer_toc/toc_entry/index.js @@ -7,6 +7,7 @@ import _ from 'lodash'; import { connect } from 'react-redux'; import { TOCEntry } from './view'; +// eslint-disable-next-line @kbn/eslint/no-restricted-paths import { FLYOUT_STATE } from '../../../../../../../../../plugins/maps/public/reducers/ui.js'; import { updateFlyout, hideTOCDetails, showTOCDetails } from '../../../../../actions/ui_actions'; import { getIsReadOnly, getOpenTOCDetails } from '../../../../../selectors/ui_selectors'; diff --git a/x-pack/legacy/plugins/maps/public/embeddable/map_embeddable.js b/x-pack/legacy/plugins/maps/public/embeddable/map_embeddable.js index 8528232da1ddb9..650e827cc16562 100644 --- a/x-pack/legacy/plugins/maps/public/embeddable/map_embeddable.js +++ b/x-pack/legacy/plugins/maps/public/embeddable/map_embeddable.js @@ -19,6 +19,7 @@ import { esFilters } from '../../../../../../src/plugins/data/public'; import { I18nContext } from 'ui/i18n'; import { GisMap } from '../connected_components/gis_map'; +// eslint-disable-next-line @kbn/eslint/no-restricted-paths import { createMapStore } from '../../../../../plugins/maps/public/reducers/store'; import { npStart } from 'ui/new_platform'; import { @@ -39,6 +40,7 @@ import { getIsLayerTOCOpen, getOpenTOCDetails } from '../selectors/ui_selectors' import { getInspectorAdapters, setEventHandlers, + // eslint-disable-next-line @kbn/eslint/no-restricted-paths } from '../../../../../plugins/maps/public/reducers/non_serializable_instances'; import { getMapCenter, getMapZoom, getHiddenLayerIds } from '../selectors/map_selectors'; import { MAP_SAVED_OBJECT_TYPE } from '../../common/constants'; diff --git a/x-pack/legacy/plugins/maps/public/embeddable/map_embeddable_factory.js b/x-pack/legacy/plugins/maps/public/embeddable/map_embeddable_factory.js index 4f45a15fd65135..5df99866a8d88a 100644 --- a/x-pack/legacy/plugins/maps/public/embeddable/map_embeddable_factory.js +++ b/x-pack/legacy/plugins/maps/public/embeddable/map_embeddable_factory.js @@ -17,6 +17,7 @@ import { MapEmbeddable } from './map_embeddable'; import { indexPatternService } from '../kibana_services'; import { createMapPath, MAP_SAVED_OBJECT_TYPE, APP_ICON } from '../../common/constants'; +// eslint-disable-next-line @kbn/eslint/no-restricted-paths import { createMapStore } from '../../../../../plugins/maps/public/reducers/store'; import { addLayerWithoutDataSync } from '../actions/map_actions'; import { getQueryableUniqueIndexPatternIds } from '../selectors/map_selectors'; diff --git a/x-pack/legacy/plugins/maps/public/embeddable/merge_input_with_saved_map.js b/x-pack/legacy/plugins/maps/public/embeddable/merge_input_with_saved_map.js index 26ab1f95a94c0e..8e3e0a9168e30e 100644 --- a/x-pack/legacy/plugins/maps/public/embeddable/merge_input_with_saved_map.js +++ b/x-pack/legacy/plugins/maps/public/embeddable/merge_input_with_saved_map.js @@ -5,6 +5,7 @@ */ import _ from 'lodash'; +// eslint-disable-next-line @kbn/eslint/no-restricted-paths import { DEFAULT_IS_LAYER_TOC_OPEN } from '../../../../../plugins/maps/public/reducers/ui'; const MAP_EMBEDDABLE_INPUT_KEYS = [ diff --git a/x-pack/legacy/plugins/maps/public/layers/layer.js b/x-pack/legacy/plugins/maps/public/layers/layer.js index d4bfd114c2665f..bafdeb62fcb06a 100644 --- a/x-pack/legacy/plugins/maps/public/layers/layer.js +++ b/x-pack/legacy/plugins/maps/public/layers/layer.js @@ -14,6 +14,7 @@ import { SOURCE_DATA_ID_ORIGIN, } from '../../common/constants'; import uuid from 'uuid/v4'; +// eslint-disable-next-line @kbn/eslint/no-restricted-paths import { copyPersistentState } from '../../../../../plugins/maps/public/reducers/util.js'; import { i18n } from '@kbn/i18n'; diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_source.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_source.js index de4b3e63768346..2d3e5e693a775a 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_source.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_source.js @@ -17,6 +17,7 @@ import _ from 'lodash'; import { AggConfigs } from 'ui/agg_types'; import { i18n } from '@kbn/i18n'; import uuid from 'uuid/v4'; +// eslint-disable-next-line @kbn/eslint/no-restricted-paths import { copyPersistentState } from '../../../../../../plugins/maps/public/reducers/util'; import { ES_GEO_FIELD_TYPE, METRIC_TYPE } from '../../../common/constants'; import { DataRequestAbortError } from '../util/data_request'; diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/source.js b/x-pack/legacy/plugins/maps/public/layers/sources/source.js index d6c7ff4e14c438..b8c91e97c4a237 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/source.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/source.js @@ -4,6 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ +// eslint-disable-next-line @kbn/eslint/no-restricted-paths import { copyPersistentState } from '../../../../../../plugins/maps/public/reducers/util'; export class AbstractSource { diff --git a/x-pack/legacy/plugins/maps/public/plugin.ts b/x-pack/legacy/plugins/maps/public/plugin.ts index 40402af88998b8..ffc1b1938860ac 100644 --- a/x-pack/legacy/plugins/maps/public/plugin.ts +++ b/x-pack/legacy/plugins/maps/public/plugin.ts @@ -10,6 +10,8 @@ import { wrapInI18nContext } from 'ui/i18n'; import { MapListing } from './components/map_listing'; // eslint-disable-next-line @kbn/eslint/no-restricted-paths import { setInjectedVarFunc } from '../../../../plugins/maps/public/kibana_services'; +// eslint-disable-next-line @kbn/eslint/no-restricted-paths +import { MapView } from '../../../../plugins/maps/public/inspector/views/map_view'; import { setLicenseId, setInspector } from './kibana_services'; import { HomePublicPluginSetup } from '../../../../../src/plugins/home/public'; import { LicensingPluginSetup } from '../../../../plugins/licensing/public'; @@ -31,11 +33,6 @@ interface MapsPluginSetupDependencies { }; } -// This function will grow as more pieces are migrated to NP -function initializeNewPlatformCode(getInjectedVar: any) { - setInjectedVarFunc(getInjectedVar); -} - /** @internal */ export class MapsPlugin implements Plugin { public setup(core: any, { __LEGACY: { uiModules }, np }: MapsPluginSetupDependencies) { @@ -50,7 +47,9 @@ export class MapsPlugin implements Plugin { } np.home.featureCatalogue.register(featureCatalogueEntry); - initializeNewPlatformCode(core.injectedMetadata.getInjectedVar); + // NP setup + setInjectedVarFunc(core.injectedMetadata.getInjectedVar); + np.inspector.registerView(MapView); } public start(core: CoreStart, plugins: any) { diff --git a/x-pack/legacy/plugins/maps/public/selectors/map_selectors.js b/x-pack/legacy/plugins/maps/public/selectors/map_selectors.js index b0b8b90d23d57d..75327e88148248 100644 --- a/x-pack/legacy/plugins/maps/public/selectors/map_selectors.js +++ b/x-pack/legacy/plugins/maps/public/selectors/map_selectors.js @@ -12,10 +12,12 @@ import { VectorLayer } from '../layers/vector_layer'; import { HeatmapLayer } from '../layers/heatmap_layer'; import { ALL_SOURCES } from '../layers/sources/all_sources'; import { timefilter } from 'ui/timefilter'; +// eslint-disable-next-line @kbn/eslint/no-restricted-paths import { getInspectorAdapters } from '../../../../../plugins/maps/public/reducers/non_serializable_instances'; import { copyPersistentState, TRACKED_LAYER_DESCRIPTOR, + // eslint-disable-next-line @kbn/eslint/no-restricted-paths } from '../../../../../plugins/maps/public/reducers/util'; function createLayerInstance(layerDescriptor, inspectorAdapters) { diff --git a/x-pack/plugins/maps/public/actions/map_actions.js b/x-pack/plugins/maps/public/actions/map_actions.js index 5b99f277a16948..3be2b4fea3aa3d 100644 --- a/x-pack/plugins/maps/public/actions/map_actions.js +++ b/x-pack/plugins/maps/public/actions/map_actions.js @@ -4,8 +4,6 @@ * you may not use this file except in compliance with the Elastic License. */ -import {getDataFilters} from "../../../../legacy/plugins/maps/public/selectors/map_selectors"; - export const SET_SELECTED_LAYER = 'SET_SELECTED_LAYER'; export const SET_TRANSIENT_LAYER = 'SET_TRANSIENT_LAYER'; export const UPDATE_LAYER_ORDER = 'UPDATE_LAYER_ORDER'; diff --git a/x-pack/plugins/maps/public/connected_components/gis_map/_gis_map.scss b/x-pack/plugins/maps/public/connected_components/gis_map/_gis_map.scss deleted file mode 100644 index 85168d970c6dec..00000000000000 --- a/x-pack/plugins/maps/public/connected_components/gis_map/_gis_map.scss +++ /dev/null @@ -1,19 +0,0 @@ -.mapMapWrapper { - background-color: $euiColorEmptyShade; - position: relative; -} - -.mapMapLayerPanel { - background-color: $euiPageBackgroundColor; - width: 0; - overflow: hidden; - - > * { - width: $euiSizeXXL * 11; - } - - &-isVisible { - width: $euiSizeXXL * 11; - transition: width $euiAnimSpeedNormal $euiAnimSlightResistance; - } -} diff --git a/x-pack/plugins/maps/public/connected_components/gis_map/index.js b/x-pack/plugins/maps/public/connected_components/gis_map/index.js deleted file mode 100644 index ceb0a6ea9f9225..00000000000000 --- a/x-pack/plugins/maps/public/connected_components/gis_map/index.js +++ /dev/null @@ -1,45 +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 { connect } from 'react-redux'; -import { GisMap } from './view'; -import { FLYOUT_STATE } from '../../reducers/ui'; -import { exitFullScreen } from '../../actions/ui_actions'; -import { getFlyoutDisplay, getIsFullScreen } from '../../selectors/ui_selectors'; -import { triggerRefreshTimer, cancelAllInFlightRequests } from '../../actions/map_actions'; -import { - areLayersLoaded, - getRefreshConfig, - getMapInitError, - getQueryableUniqueIndexPatternIds, - isToolbarOverlayHidden, -} from '../../selectors/map_selectors'; - -function mapStateToProps(state = {}) { - const flyoutDisplay = getFlyoutDisplay(state); - return { - areLayersLoaded: areLayersLoaded(state), - layerDetailsVisible: flyoutDisplay === FLYOUT_STATE.LAYER_PANEL, - addLayerVisible: flyoutDisplay === FLYOUT_STATE.ADD_LAYER_WIZARD, - noFlyoutVisible: flyoutDisplay === FLYOUT_STATE.NONE, - isFullScreen: getIsFullScreen(state), - refreshConfig: getRefreshConfig(state), - mapInitError: getMapInitError(state), - indexPatternIds: getQueryableUniqueIndexPatternIds(state), - hideToolbarOverlay: isToolbarOverlayHidden(state), - }; -} - -function mapDispatchToProps(dispatch) { - return { - triggerRefreshTimer: () => dispatch(triggerRefreshTimer()), - exitFullScreen: () => dispatch(exitFullScreen()), - cancelAllInFlightRequests: () => dispatch(cancelAllInFlightRequests()), - }; -} - -const connectedGisMap = connect(mapStateToProps, mapDispatchToProps)(GisMap); -export { connectedGisMap as GisMap }; diff --git a/x-pack/plugins/maps/public/connected_components/gis_map/view.js b/x-pack/plugins/maps/public/connected_components/gis_map/view.js deleted file mode 100644 index 0c16cb9a0ae177..00000000000000 --- a/x-pack/plugins/maps/public/connected_components/gis_map/view.js +++ /dev/null @@ -1,222 +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 _ from 'lodash'; -import React, { Component } from 'react'; -import { MBMapContainer } from '../map/mb'; -import { WidgetOverlay } from '../widget_overlay/index'; -import { ToolbarOverlay } from '../toolbar_overlay/index'; -import { LayerPanel } from '../layer_panel/index'; -import { AddLayerPanel } from '../layer_addpanel/index'; -import { EuiFlexGroup, EuiFlexItem, EuiCallOut } from '@elastic/eui'; -import { getIndexPatternsFromIds } from '../../index_pattern_util'; -import { ES_GEO_FIELD_TYPE } from '../../../common/constants'; -import { isNestedField } from '../../../../../../src/plugins/data/public'; -import { i18n } from '@kbn/i18n'; -import uuid from 'uuid/v4'; - -// TODO -import { ExitFullScreenButton } from 'ui/exit_full_screen'; - -const RENDER_COMPLETE_EVENT = 'renderComplete'; - -export class GisMap extends Component { - state = { - isInitialLoadRenderTimeoutComplete: false, - domId: uuid(), - geoFields: [], - }; - - componentDidMount() { - this._isMounted = true; - this._isInitalLoadRenderTimerStarted = false; - this._setRefreshTimer(); - } - - componentDidUpdate() { - this._setRefreshTimer(); - if (this.props.areLayersLoaded && !this._isInitalLoadRenderTimerStarted) { - this._isInitalLoadRenderTimerStarted = true; - this._startInitialLoadRenderTimer(); - } - - if (!!this.props.addFilters) { - this._loadGeoFields(this.props.indexPatternIds); - } - } - - componentWillUnmount() { - this._isMounted = false; - this._clearRefreshTimer(); - this.props.cancelAllInFlightRequests(); - } - - // Reporting uses both a `data-render-complete` attribute and a DOM event listener to determine - // if a visualization is done loading. The process roughly is: - // - See if the `data-render-complete` attribute is "true". If so we're done! - // - If it's not, then reporting injects a listener into the browser for a custom "renderComplete" event. - // - When that event is fired, we snapshot the viz and move on. - // Failure to not have the dom attribute, or custom event, will timeout the job. - // See x-pack/legacy/plugins/reporting/export_types/common/lib/screenshots/wait_for_render.ts for more. - _onInitialLoadRenderComplete = () => { - const el = document.querySelector(`[data-dom-id="${this.state.domId}"]`); - - if (el) { - el.dispatchEvent(new CustomEvent(RENDER_COMPLETE_EVENT, { bubbles: true })); - } - }; - - _loadGeoFields = async nextIndexPatternIds => { - if (_.isEqual(nextIndexPatternIds, this._prevIndexPatternIds)) { - // all ready loaded index pattern ids - return; - } - - this._prevIndexPatternIds = nextIndexPatternIds; - - const geoFields = []; - try { - const indexPatterns = await getIndexPatternsFromIds(nextIndexPatternIds); - indexPatterns.forEach(indexPattern => { - indexPattern.fields.forEach(field => { - if ( - !isNestedField(field) && - (field.type === ES_GEO_FIELD_TYPE.GEO_POINT || - field.type === ES_GEO_FIELD_TYPE.GEO_SHAPE) - ) { - geoFields.push({ - geoFieldName: field.name, - geoFieldType: field.type, - indexPatternTitle: indexPattern.title, - indexPatternId: indexPattern.id, - }); - } - }); - }); - } catch (e) { - // swallow errors. - // the Layer-TOC will indicate which layers are disfunctional on a per-layer basis - } - - if (!this._isMounted) { - return; - } - - this.setState({ geoFields }); - }; - - _setRefreshTimer = () => { - const { isPaused, interval } = this.props.refreshConfig; - - if (this.isPaused === isPaused && this.interval === interval) { - // refreshConfig is the same, nothing to do - return; - } - - this.isPaused = isPaused; - this.interval = interval; - - this._clearRefreshTimer(); - - if (!isPaused && interval > 0) { - this.refreshTimerId = setInterval(() => { - this.props.triggerRefreshTimer(); - }, interval); - } - }; - - _clearRefreshTimer = () => { - if (this.refreshTimerId) { - clearInterval(this.refreshTimerId); - } - }; - - // Mapbox does not provide any feedback when rendering is complete. - // Temporary solution is just to wait set period of time after data has loaded. - _startInitialLoadRenderTimer = () => { - setTimeout(() => { - if (this._isMounted) { - this.setState({ isInitialLoadRenderTimeoutComplete: true }); - this._onInitialLoadRenderComplete(); - } - }, 5000); - }; - - render() { - const { - addFilters, - layerDetailsVisible, - addLayerVisible, - noFlyoutVisible, - isFullScreen, - exitFullScreen, - mapInitError, - renderTooltipContent, - } = this.props; - - const { domId } = this.state; - - if (mapInitError) { - return ( -
- -

{mapInitError}

-
-
- ); - } - - let currentPanel; - let currentPanelClassName; - if (noFlyoutVisible) { - currentPanel = null; - } else if (addLayerVisible) { - currentPanelClassName = 'mapMapLayerPanel-isVisible'; - currentPanel = ; - } else if (layerDetailsVisible) { - currentPanelClassName = 'mapMapLayerPanel-isVisible'; - currentPanel = ; - } - - let exitFullScreenButton; - if (isFullScreen) { - exitFullScreenButton = ; - } - return ( - - - - {!this.props.hideToolbarOverlay && ( - - )} - - - - - {currentPanel} - - - {exitFullScreenButton} - - ); - } -} diff --git a/x-pack/plugins/maps/public/index_pattern_util.js b/x-pack/plugins/maps/public/index_pattern_util.js deleted file mode 100644 index 48251b858cc9d2..00000000000000 --- a/x-pack/plugins/maps/public/index_pattern_util.js +++ /dev/null @@ -1,52 +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 { indexPatternService } from './kibana_services'; -import { isNestedField } from '../../../../src/plugins/data/public'; -import { ES_GEO_FIELD_TYPE } from '../common/constants'; - -export async function getIndexPatternsFromIds(indexPatternIds = []) { - const promises = []; - indexPatternIds.forEach(id => { - const indexPatternPromise = indexPatternService.get(id); - if (indexPatternPromise) { - promises.push(indexPatternPromise); - } - }); - - return await Promise.all(promises); -} - -export function getTermsFields(fields) { - return fields.filter(field => { - return ( - field.aggregatable && - !isNestedField(field) && - ['number', 'boolean', 'date', 'ip', 'string'].includes(field.type) - ); - }); -} - -export const AGGREGATABLE_GEO_FIELD_TYPES = [ES_GEO_FIELD_TYPE.GEO_POINT]; - -export function getAggregatableGeoFields(fields) { - return fields.filter(field => { - return ( - field.aggregatable && - !isNestedField(field) && - AGGREGATABLE_GEO_FIELD_TYPES.includes(field.type) - ); - }); -} - -// Returns filtered fields list containing only fields that exist in _source. -export function getSourceFields(fields) { - return fields.filter(field => { - // Multi fields are not stored in _source and only exist in index. - const isMultiField = field.subType && field.subType.multi; - return !isMultiField && !isNestedField(field); - }); -} diff --git a/x-pack/plugins/maps/public/index_pattern_util.test.js b/x-pack/plugins/maps/public/index_pattern_util.test.js deleted file mode 100644 index 7f8f1c175cf152..00000000000000 --- a/x-pack/plugins/maps/public/index_pattern_util.test.js +++ /dev/null @@ -1,29 +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. - */ - -jest.mock('./kibana_services', () => ({})); - -import { getSourceFields } from './index_pattern_util'; - -describe('getSourceFields', () => { - test('Should remove multi fields from field list', () => { - const fields = [ - { - name: 'agent', - }, - { - name: 'agent.keyword', - subType: { - multi: { - parent: 'agent', - }, - }, - }, - ]; - const sourceFields = getSourceFields(fields); - expect(sourceFields).toEqual([{ name: 'agent' }]); - }); -}); diff --git a/x-pack/plugins/maps/public/inspector/views/register_views.ts b/x-pack/plugins/maps/public/inspector/views/register_views.ts deleted file mode 100644 index 59c05956683007..00000000000000 --- a/x-pack/plugins/maps/public/inspector/views/register_views.ts +++ /dev/null @@ -1,12 +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 { npSetup } from 'ui/new_platform'; - -// @ts-ignore -import { MapView } from './map_view'; - -npSetup.plugins.inspector.registerView(MapView); From 6942fc2c98125bfbcdbb6c15a071ad2aeb420cc6 Mon Sep 17 00:00:00 2001 From: Aaron Caldwell Date: Mon, 24 Feb 2020 16:09:49 -0700 Subject: [PATCH 08/21] More cleanup. Check injected vars avab. before calling to handle dashboard case --- x-pack/plugins/maps/public/applications/maps/index.tsx | 2 ++ x-pack/plugins/maps/public/index.ts | 8 +++----- .../maps/public/reducers/non_serializable_instances.js | 3 ++- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/x-pack/plugins/maps/public/applications/maps/index.tsx b/x-pack/plugins/maps/public/applications/maps/index.tsx index 9bea41126d2963..d0973dc08013d1 100644 --- a/x-pack/plugins/maps/public/applications/maps/index.tsx +++ b/x-pack/plugins/maps/public/applications/maps/index.tsx @@ -11,7 +11,9 @@ import { I18nProvider, FormattedMessage } from '@kbn/i18n/react'; import { Route, BrowserRouter, Switch } from 'react-router-dom'; import { Provider } from 'react-redux'; import { Store } from 'redux'; +// @ts-ignore import { appStoreFactory } from './store'; +// @ts-ignore import { AlertIndex } from './view/alerts'; /** diff --git a/x-pack/plugins/maps/public/index.ts b/x-pack/plugins/maps/public/index.ts index 985da137eff359..c465700a4f9c56 100644 --- a/x-pack/plugins/maps/public/index.ts +++ b/x-pack/plugins/maps/public/index.ts @@ -4,11 +4,9 @@ * you may not use this file except in compliance with the Elastic License. */ -import { PluginInitializer, PluginInitializerContext } from 'kibana/public'; +import { PluginInitializer } from 'kibana/public'; import { MapsPlugin, MapsPluginSetup, MapsPluginStart } from './plugin'; -export const plugin: PluginInitializer = ( - context: PluginInitializerContext -) => { - return new MapsPlugin(context); +export const plugin: PluginInitializer = () => { + return new MapsPlugin(); }; diff --git a/x-pack/plugins/maps/public/reducers/non_serializable_instances.js b/x-pack/plugins/maps/public/reducers/non_serializable_instances.js index afc77d561ce212..8265c70ae18001 100644 --- a/x-pack/plugins/maps/public/reducers/non_serializable_instances.js +++ b/x-pack/plugins/maps/public/reducers/non_serializable_instances.js @@ -16,7 +16,8 @@ function createInspectorAdapters() { const inspectorAdapters = { requests: new RequestAdapter(), }; - if (getInjectedVarFunc()('showMapsInspectorAdapter', false)) { + const getInjectedVar = getInjectedVarFunc(); + if (getInjectedVar && getInjectedVar('showMapsInspectorAdapter', false)) { inspectorAdapters.map = new MapAdapter(); } return inspectorAdapters; From 9c2e7482f37d216ff6f9226a130fb886815b504e Mon Sep 17 00:00:00 2001 From: Aaron Caldwell Date: Mon, 2 Mar 2020 08:46:16 -0700 Subject: [PATCH 09/21] Bind embeddables services the same way Maps app services bound. Create function for eventual init in NP --- .../maps/public/embeddable/map_embeddable_factory.js | 12 ++++++++++-- x-pack/legacy/plugins/maps/public/plugin.ts | 12 ++++++++---- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/embeddable/map_embeddable_factory.js b/x-pack/legacy/plugins/maps/public/embeddable/map_embeddable_factory.js index 5df99866a8d88a..7f435540b82f51 100644 --- a/x-pack/legacy/plugins/maps/public/embeddable/map_embeddable_factory.js +++ b/x-pack/legacy/plugins/maps/public/embeddable/map_embeddable_factory.js @@ -12,7 +12,6 @@ import { EmbeddableFactory, ErrorEmbeddable, } from '../../../../../../src/legacy/core_plugins/embeddable_api/public/np_ready/public'; -import { setup } from '../../../../../../src/legacy/core_plugins/embeddable_api/public/np_ready/public/legacy'; import { MapEmbeddable } from './map_embeddable'; import { indexPatternService } from '../kibana_services'; @@ -24,6 +23,9 @@ import { getQueryableUniqueIndexPatternIds } from '../selectors/map_selectors'; import { getInitialLayers } from '../angular/get_initial_layers'; import { mergeInputWithSavedMap } from './merge_input_with_saved_map'; import '../angular/services/gis_map_saved_object_loader'; +import { bindCoreAndPlugins } from '../plugin'; +import { npStart } from '../../../../../../src/legacy/ui/public/new_platform'; +import { setup as embeddableSetup } from '../../../../../../src/legacy/core_plugins/embeddable_api/public/np_ready/public/legacy'; export class MapEmbeddableFactory extends EmbeddableFactory { type = MAP_SAVED_OBJECT_TYPE; @@ -39,6 +41,7 @@ export class MapEmbeddableFactory extends EmbeddableFactory { }, }); } + isEditable() { return capabilities.get().maps.save; } @@ -148,4 +151,9 @@ export class MapEmbeddableFactory extends EmbeddableFactory { } } -setup.registerEmbeddableFactory(MAP_SAVED_OBJECT_TYPE, new MapEmbeddableFactory()); +// Will be called from setup/start in NP after migration +((core, plugins) => { + bindCoreAndPlugins(core, plugins); + const mapEmbeddableFactory = new MapEmbeddableFactory(); + embeddableSetup.registerEmbeddableFactory(mapEmbeddableFactory.type, mapEmbeddableFactory); +})(npStart.core, { np: npStart.plugins }); diff --git a/x-pack/legacy/plugins/maps/public/plugin.ts b/x-pack/legacy/plugins/maps/public/plugin.ts index ffc1b1938860ac..16ca5a2766ccdb 100644 --- a/x-pack/legacy/plugins/maps/public/plugin.ts +++ b/x-pack/legacy/plugins/maps/public/plugin.ts @@ -33,6 +33,11 @@ interface MapsPluginSetupDependencies { }; } +export const bindCoreAndPlugins = ({ injectedMetadata }, { inspector }) => { + setInspector(inspector); + setInjectedVarFunc(injectedMetadata.getInjectedVar); +}; + /** @internal */ export class MapsPlugin implements Plugin { public setup(core: any, { __LEGACY: { uiModules }, np }: MapsPluginSetupDependencies) { @@ -48,11 +53,10 @@ export class MapsPlugin implements Plugin { np.home.featureCatalogue.register(featureCatalogueEntry); // NP setup - setInjectedVarFunc(core.injectedMetadata.getInjectedVar); np.inspector.registerView(MapView); - } - public start(core: CoreStart, plugins: any) { - setInspector(plugins.np.inspector); + bindCoreAndPlugins(core, np); } + + public start(core: CoreStart, plugins: any) {} } From fd96c7067cc7af2a92572bd4a7193d31f5ec988d Mon Sep 17 00:00:00 2001 From: Aaron Caldwell Date: Tue, 3 Mar 2020 08:13:29 -0700 Subject: [PATCH 10/21] Call binding from constructor. Fix npStart plugins arg --- .../maps/public/embeddable/map_embeddable_factory.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/embeddable/map_embeddable_factory.js b/x-pack/legacy/plugins/maps/public/embeddable/map_embeddable_factory.js index 7f435540b82f51..e404443988a703 100644 --- a/x-pack/legacy/plugins/maps/public/embeddable/map_embeddable_factory.js +++ b/x-pack/legacy/plugins/maps/public/embeddable/map_embeddable_factory.js @@ -40,6 +40,8 @@ export class MapEmbeddableFactory extends EmbeddableFactory { getIconForSavedObject: () => APP_ICON, }, }); + // Will be called from setup/start in NP after migration + bindCoreAndPlugins(npStart.core, npStart.plugins); } isEditable() { @@ -151,9 +153,5 @@ export class MapEmbeddableFactory extends EmbeddableFactory { } } -// Will be called from setup/start in NP after migration -((core, plugins) => { - bindCoreAndPlugins(core, plugins); - const mapEmbeddableFactory = new MapEmbeddableFactory(); - embeddableSetup.registerEmbeddableFactory(mapEmbeddableFactory.type, mapEmbeddableFactory); -})(npStart.core, { np: npStart.plugins }); +const mapEmbeddableFactory = new MapEmbeddableFactory(); +embeddableSetup.registerEmbeddableFactory(mapEmbeddableFactory.type, mapEmbeddableFactory); From eec53c51afdf9771d3431194a74fe2ed9d758219 Mon Sep 17 00:00:00 2001 From: Aaron Caldwell Date: Wed, 4 Mar 2020 09:50:32 -0700 Subject: [PATCH 11/21] Adapt changes from master --- .../embeddable/map_embeddable_factory.js | 13 ++++----- x-pack/legacy/plugins/maps/public/plugin.ts | 28 ++++++++++--------- 2 files changed, 20 insertions(+), 21 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/embeddable/map_embeddable_factory.js b/x-pack/legacy/plugins/maps/public/embeddable/map_embeddable_factory.js index e404443988a703..710b7f737e8610 100644 --- a/x-pack/legacy/plugins/maps/public/embeddable/map_embeddable_factory.js +++ b/x-pack/legacy/plugins/maps/public/embeddable/map_embeddable_factory.js @@ -12,6 +12,7 @@ import { EmbeddableFactory, ErrorEmbeddable, } from '../../../../../../src/legacy/core_plugins/embeddable_api/public/np_ready/public'; +import { setup } from '../../../../../../src/legacy/core_plugins/embeddable_api/public/np_ready/public/legacy'; import { MapEmbeddable } from './map_embeddable'; import { indexPatternService } from '../kibana_services'; @@ -23,9 +24,8 @@ import { getQueryableUniqueIndexPatternIds } from '../selectors/map_selectors'; import { getInitialLayers } from '../angular/get_initial_layers'; import { mergeInputWithSavedMap } from './merge_input_with_saved_map'; import '../angular/services/gis_map_saved_object_loader'; -import { bindCoreAndPlugins } from '../plugin'; -import { npStart } from '../../../../../../src/legacy/ui/public/new_platform'; -import { setup as embeddableSetup } from '../../../../../../src/legacy/core_plugins/embeddable_api/public/np_ready/public/legacy'; +import { bindSetupCoreAndPlugins } from '../plugin'; +import { npSetup } from 'ui/new_platform'; export class MapEmbeddableFactory extends EmbeddableFactory { type = MAP_SAVED_OBJECT_TYPE; @@ -40,10 +40,8 @@ export class MapEmbeddableFactory extends EmbeddableFactory { getIconForSavedObject: () => APP_ICON, }, }); - // Will be called from setup/start in NP after migration - bindCoreAndPlugins(npStart.core, npStart.plugins); + bindSetupCoreAndPlugins(npSetup.core, npSetup.plugins); } - isEditable() { return capabilities.get().maps.save; } @@ -153,5 +151,4 @@ export class MapEmbeddableFactory extends EmbeddableFactory { } } -const mapEmbeddableFactory = new MapEmbeddableFactory(); -embeddableSetup.registerEmbeddableFactory(mapEmbeddableFactory.type, mapEmbeddableFactory); +setup.registerEmbeddableFactory(MAP_SAVED_OBJECT_TYPE, new MapEmbeddableFactory()); diff --git a/x-pack/legacy/plugins/maps/public/plugin.ts b/x-pack/legacy/plugins/maps/public/plugin.ts index 16ca5a2766ccdb..80f525fb7b859f 100644 --- a/x-pack/legacy/plugins/maps/public/plugin.ts +++ b/x-pack/legacy/plugins/maps/public/plugin.ts @@ -5,7 +5,7 @@ */ // @ts-nocheck -import { Plugin, CoreStart } from 'src/core/public'; +import { Plugin, CoreStart, CoreSetup } from 'src/core/public'; import { wrapInI18nContext } from 'ui/i18n'; import { MapListing } from './components/map_listing'; // eslint-disable-next-line @kbn/eslint/no-restricted-paths @@ -33,30 +33,32 @@ interface MapsPluginSetupDependencies { }; } -export const bindCoreAndPlugins = ({ injectedMetadata }, { inspector }) => { - setInspector(inspector); +export const bindSetupCoreAndPlugins = (core: CoreSetup, plugins: any) => { + const { licensing } = plugins; + const { injectedMetadata } = core; + if (licensing) { + licensing.license$.subscribe(({ uid }: { uid: string }) => setLicenseId(uid)); + } setInjectedVarFunc(injectedMetadata.getInjectedVar); }; /** @internal */ export class MapsPlugin implements Plugin { - public setup(core: any, { __LEGACY: { uiModules }, np }: MapsPluginSetupDependencies) { + public setup(core: CoreSetup, { __LEGACY: { uiModules }, np }: MapsPluginSetupDependencies) { uiModules .get('app/maps', ['ngRoute', 'react']) .directive('mapListing', function(reactDirective: any) { return reactDirective(wrapInI18nContext(MapListing)); }); - if (np.licensing) { - np.licensing.license$.subscribe(({ uid }) => setLicenseId(uid)); - } - np.home.featureCatalogue.register(featureCatalogueEntry); - - // NP setup - np.inspector.registerView(MapView); + bindSetupCoreAndPlugins(core, np); - bindCoreAndPlugins(core, np); + np.home.featureCatalogue.register(featureCatalogueEntry); } - public start(core: CoreStart, plugins: any) {} + public start(core: CoreStart, plugins: any) { + const { inspector } = np.plugins; + setInspector(inspector); + inspector.registerView(MapView); + } } From b2ad8a20cf1726d890c27c2c68ac0152cbe906cd Mon Sep 17 00:00:00 2001 From: Aaron Caldwell Date: Wed, 4 Mar 2020 14:50:38 -0700 Subject: [PATCH 12/21] Register inspector views for embeddable. Add NP folder to i18n --- x-pack/.i18nrc.json | 2 +- x-pack/legacy/plugins/maps/public/plugin.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/x-pack/.i18nrc.json b/x-pack/.i18nrc.json index 824bb764345f3a..01d1f1d577a87a 100644 --- a/x-pack/.i18nrc.json +++ b/x-pack/.i18nrc.json @@ -26,7 +26,7 @@ "xpack.licensing": "plugins/licensing", "xpack.logstash": "legacy/plugins/logstash", "xpack.main": "legacy/plugins/xpack_main", - "xpack.maps": "legacy/plugins/maps", + "xpack.maps": ["plugins/maps", "legacy/plugins/maps"], "xpack.ml": ["plugins/ml", "legacy/plugins/ml"], "xpack.monitoring": "legacy/plugins/monitoring", "xpack.remoteClusters": "plugins/remote_clusters", diff --git a/x-pack/legacy/plugins/maps/public/plugin.ts b/x-pack/legacy/plugins/maps/public/plugin.ts index b09180583f3840..fdedbf0588cb1f 100644 --- a/x-pack/legacy/plugins/maps/public/plugin.ts +++ b/x-pack/legacy/plugins/maps/public/plugin.ts @@ -34,12 +34,13 @@ interface MapsPluginSetupDependencies { } export const bindSetupCoreAndPlugins = (core: CoreSetup, plugins: any) => { - const { licensing } = plugins; + const { licensing, inspector } = plugins; const { injectedMetadata } = core; if (licensing) { licensing.license$.subscribe(({ uid }: { uid: string }) => setLicenseId(uid)); } setInjectedVarFunc(injectedMetadata.getInjectedVar); + inspector.registerView(MapView); }; /** @internal */ @@ -54,7 +55,6 @@ export class MapsPlugin implements Plugin { bindSetupCoreAndPlugins(core, np); np.home.featureCatalogue.register(featureCatalogueEntry); - np.inspector.registerView(MapView); } public start(core: CoreStart, plugins: any) { From a4b34d36afb5fe235da22e3ece8c4e0658ff2016 Mon Sep 17 00:00:00 2001 From: Aaron Caldwell Date: Wed, 4 Mar 2020 16:18:39 -0700 Subject: [PATCH 13/21] Clean up. Add comments. Move inspector map view registration to NP --- .../maps/public/actions/map_actions.js | 3 + .../plugins/maps/public/actions/ui_actions.js | 9 +-- .../public/inspector/adapters/map_adapter.js | 24 ------ .../public/inspector/views/register_views.ts | 12 --- x-pack/legacy/plugins/maps/public/plugin.ts | 5 +- x-pack/plugins/maps/kibana.json | 2 +- .../maps/public/actions/map_actions.js | 3 + .../plugins/maps/public/actions/ui_actions.js | 3 + .../maps/public/applications/maps/index.tsx | 80 ------------------- x-pack/plugins/maps/public/plugin.ts | 6 +- 10 files changed, 16 insertions(+), 131 deletions(-) delete mode 100644 x-pack/legacy/plugins/maps/public/inspector/adapters/map_adapter.js delete mode 100644 x-pack/legacy/plugins/maps/public/inspector/views/register_views.ts delete mode 100644 x-pack/plugins/maps/public/applications/maps/index.tsx diff --git a/x-pack/legacy/plugins/maps/public/actions/map_actions.js b/x-pack/legacy/plugins/maps/public/actions/map_actions.js index 162f7802cfd2de..2c420a69c486af 100644 --- a/x-pack/legacy/plugins/maps/public/actions/map_actions.js +++ b/x-pack/legacy/plugins/maps/public/actions/map_actions.js @@ -36,6 +36,8 @@ import { SOURCE_DATA_ID_ORIGIN, } from '../../common/constants'; +// NP Migration +// Temporarily redundant with x-pack/plugins/maps/public/actions/map_actions.js export const SET_SELECTED_LAYER = 'SET_SELECTED_LAYER'; export const SET_TRANSIENT_LAYER = 'SET_TRANSIENT_LAYER'; export const UPDATE_LAYER_ORDER = 'UPDATE_LAYER_ORDER'; @@ -78,6 +80,7 @@ export const HIDE_TOOLBAR_OVERLAY = 'HIDE_TOOLBAR_OVERLAY'; export const HIDE_LAYER_CONTROL = 'HIDE_LAYER_CONTROL'; export const HIDE_VIEW_CONTROL = 'HIDE_VIEW_CONTROL'; export const SET_WAITING_FOR_READY_HIDDEN_LAYERS = 'SET_WAITING_FOR_READY_HIDDEN_LAYERS'; +// End temporary redundancy function getLayerLoadingCallbacks(dispatch, getState, layerId) { return { diff --git a/x-pack/legacy/plugins/maps/public/actions/ui_actions.js b/x-pack/legacy/plugins/maps/public/actions/ui_actions.js index 2b687516f3e5ac..14cd80825e6dc3 100644 --- a/x-pack/legacy/plugins/maps/public/actions/ui_actions.js +++ b/x-pack/legacy/plugins/maps/public/actions/ui_actions.js @@ -4,6 +4,8 @@ * you may not use this file except in compliance with the Elastic License. */ +// NP Migration +// Temporarily redundant with x-pack/plugins/maps/public/actions/ui_actions.js export const UPDATE_FLYOUT = 'UPDATE_FLYOUT'; export const CLOSE_SET_VIEW = 'CLOSE_SET_VIEW'; export const OPEN_SET_VIEW = 'OPEN_SET_VIEW'; @@ -14,6 +16,7 @@ export const SET_OPEN_TOC_DETAILS = 'SET_OPEN_TOC_DETAILS'; export const SHOW_TOC_DETAILS = 'SHOW_TOC_DETAILS'; export const HIDE_TOC_DETAILS = 'HIDE_TOC_DETAILS'; export const UPDATE_INDEXING_STAGE = 'UPDATE_INDEXING_STAGE'; +// End temporary redundancy export function updateFlyout(display) { return { @@ -37,12 +40,6 @@ export function setIsLayerTOCOpen(isLayerTOCOpen) { isLayerTOCOpen, }; } -export function exitFullScreen() { - return { - type: SET_FULL_SCREEN, - isFullScreen: false, - }; -} export function enableFullScreen() { return { type: SET_FULL_SCREEN, diff --git a/x-pack/legacy/plugins/maps/public/inspector/adapters/map_adapter.js b/x-pack/legacy/plugins/maps/public/inspector/adapters/map_adapter.js deleted file mode 100644 index 60a6cab7df3d1e..00000000000000 --- a/x-pack/legacy/plugins/maps/public/inspector/adapters/map_adapter.js +++ /dev/null @@ -1,24 +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 { EventEmitter } from 'events'; - -class MapAdapter extends EventEmitter { - setMapState({ stats, style }) { - this.stats = stats; - this.style = style; - this._onChange(); - } - - getMapState() { - return { stats: this.stats, style: this.style }; - } - - _onChange() { - this.emit('change'); - } -} - -export { MapAdapter }; diff --git a/x-pack/legacy/plugins/maps/public/inspector/views/register_views.ts b/x-pack/legacy/plugins/maps/public/inspector/views/register_views.ts deleted file mode 100644 index 59c05956683007..00000000000000 --- a/x-pack/legacy/plugins/maps/public/inspector/views/register_views.ts +++ /dev/null @@ -1,12 +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 { npSetup } from 'ui/new_platform'; - -// @ts-ignore -import { MapView } from './map_view'; - -npSetup.plugins.inspector.registerView(MapView); diff --git a/x-pack/legacy/plugins/maps/public/plugin.ts b/x-pack/legacy/plugins/maps/public/plugin.ts index fdedbf0588cb1f..d923854ab1e350 100644 --- a/x-pack/legacy/plugins/maps/public/plugin.ts +++ b/x-pack/legacy/plugins/maps/public/plugin.ts @@ -10,8 +10,6 @@ import { wrapInI18nContext } from 'ui/i18n'; import { MapListing } from './components/map_listing'; // eslint-disable-next-line @kbn/eslint/no-restricted-paths import { setInjectedVarFunc } from '../../../../plugins/maps/public/kibana_services'; -// eslint-disable-next-line @kbn/eslint/no-restricted-paths -import { MapView } from '../../../../plugins/maps/public/inspector/views/map_view'; import { setLicenseId, setInspector, setFileUpload } from './kibana_services'; import { HomePublicPluginSetup } from '../../../../../src/plugins/home/public'; import { LicensingPluginSetup } from '../../../../plugins/licensing/public'; @@ -34,13 +32,12 @@ interface MapsPluginSetupDependencies { } export const bindSetupCoreAndPlugins = (core: CoreSetup, plugins: any) => { - const { licensing, inspector } = plugins; + const { licensing } = plugins; const { injectedMetadata } = core; if (licensing) { licensing.license$.subscribe(({ uid }: { uid: string }) => setLicenseId(uid)); } setInjectedVarFunc(injectedMetadata.getInjectedVar); - inspector.registerView(MapView); }; /** @internal */ diff --git a/x-pack/plugins/maps/kibana.json b/x-pack/plugins/maps/kibana.json index 25a5efa9bc0dad..b2aec30c113eb6 100644 --- a/x-pack/plugins/maps/kibana.json +++ b/x-pack/plugins/maps/kibana.json @@ -3,6 +3,6 @@ "version": "8.0.0", "kibanaVersion": "kibana", "configPath": ["xpack", "maps"], - "requiredPlugins": ["data"], + "requiredPlugins": ["inspector"], "ui": true } diff --git a/x-pack/plugins/maps/public/actions/map_actions.js b/x-pack/plugins/maps/public/actions/map_actions.js index 3be2b4fea3aa3d..3c01aece88ba60 100644 --- a/x-pack/plugins/maps/public/actions/map_actions.js +++ b/x-pack/plugins/maps/public/actions/map_actions.js @@ -4,6 +4,8 @@ * you may not use this file except in compliance with the Elastic License. */ +// NP Migration +// Temporarily redundant with x-pack/legacy/plugins/maps/public/actions/map_actions.js export const SET_SELECTED_LAYER = 'SET_SELECTED_LAYER'; export const SET_TRANSIENT_LAYER = 'SET_TRANSIENT_LAYER'; export const UPDATE_LAYER_ORDER = 'UPDATE_LAYER_ORDER'; @@ -46,3 +48,4 @@ export const HIDE_TOOLBAR_OVERLAY = 'HIDE_TOOLBAR_OVERLAY'; export const HIDE_LAYER_CONTROL = 'HIDE_LAYER_CONTROL'; export const HIDE_VIEW_CONTROL = 'HIDE_VIEW_CONTROL'; export const SET_WAITING_FOR_READY_HIDDEN_LAYERS = 'SET_WAITING_FOR_READY_HIDDEN_LAYERS'; +// End temporary redundancy diff --git a/x-pack/plugins/maps/public/actions/ui_actions.js b/x-pack/plugins/maps/public/actions/ui_actions.js index fb6f1d97ac67f0..d488d434858ba4 100644 --- a/x-pack/plugins/maps/public/actions/ui_actions.js +++ b/x-pack/plugins/maps/public/actions/ui_actions.js @@ -4,6 +4,8 @@ * you may not use this file except in compliance with the Elastic License. */ +// NP Migration +// Temporarily redundant with x-pack/legacy/plugins/maps/public/actions/ui_actions.js export const UPDATE_FLYOUT = 'UPDATE_FLYOUT'; export const CLOSE_SET_VIEW = 'CLOSE_SET_VIEW'; export const OPEN_SET_VIEW = 'OPEN_SET_VIEW'; @@ -14,6 +16,7 @@ export const SET_OPEN_TOC_DETAILS = 'SET_OPEN_TOC_DETAILS'; export const SHOW_TOC_DETAILS = 'SHOW_TOC_DETAILS'; export const HIDE_TOC_DETAILS = 'HIDE_TOC_DETAILS'; export const UPDATE_INDEXING_STAGE = 'UPDATE_INDEXING_STAGE'; +// End temporary redundancy export function exitFullScreen() { return { diff --git a/x-pack/plugins/maps/public/applications/maps/index.tsx b/x-pack/plugins/maps/public/applications/maps/index.tsx deleted file mode 100644 index d0973dc08013d1..00000000000000 --- a/x-pack/plugins/maps/public/applications/maps/index.tsx +++ /dev/null @@ -1,80 +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 * as React from 'react'; -import ReactDOM from 'react-dom'; -import { CoreStart, AppMountParameters } from 'kibana/public'; -import { I18nProvider, FormattedMessage } from '@kbn/i18n/react'; -import { Route, BrowserRouter, Switch } from 'react-router-dom'; -import { Provider } from 'react-redux'; -import { Store } from 'redux'; -// @ts-ignore -import { appStoreFactory } from './store'; -// @ts-ignore -import { AlertIndex } from './view/alerts'; - -/** - * This module will be loaded asynchronously to reduce the bundle size of your plugin's main bundle. - */ -export function renderApp(coreStart: CoreStart, { appBasePath, element }: AppMountParameters) { - coreStart.http.get('/api/endpoint/hello-world'); - - const [store, stopSagas] = appStoreFactory(coreStart); - - ReactDOM.render(, element); - - return () => { - ReactDOM.unmountComponentAtNode(element); - stopSagas(); - }; -} - -interface RouterProps { - basename: string; - store: Store; -} - -const AppRoot: React.FunctionComponent = React.memo(({ basename, store }) => ( - - - - - ( -

- -

- )} - /> - { - // FIXME: This is temporary. Will be removed in next PR for endpoint list - store.dispatch({ type: 'userEnteredEndpointListPage' }); - - return ( -

- -

- ); - }} - /> - - ( - - )} - /> -
-
-
-
-)); diff --git a/x-pack/plugins/maps/public/plugin.ts b/x-pack/plugins/maps/public/plugin.ts index bcc764537351ec..506b0c426f0fae 100644 --- a/x-pack/plugins/maps/public/plugin.ts +++ b/x-pack/plugins/maps/public/plugin.ts @@ -6,12 +6,10 @@ import { Plugin, CoreSetup, CoreStart } from 'src/core/public'; import { Setup as InspectorSetupContract } from 'src/plugins/inspector/public'; -import { DataPublicPluginSetup } from '../../../../src/plugins/data/public'; // @ts-ignore -import { setInjectedVarFunc } from './kibana_services'; +import { MapView } from './inspector/views/map_view'; export interface MapsPluginSetupDependencies { - data: DataPublicPluginSetup; inspector: InspectorSetupContract; } // eslint-disable-next-line @typescript-eslint/no-empty-interface @@ -35,7 +33,7 @@ export class MapsPlugin MapsPluginStartDependencies > { public setup(core: CoreSetup, plugins: MapsPluginSetupDependencies) { - setInjectedVarFunc(core.injectedMetadata.getInjectedVar); + plugins.inspector.registerView(MapView); } public start(core: CoreStart, plugins: any) {} From 2151af4b854ad98ce46238da27f26ff464cf801c Mon Sep 17 00:00:00 2001 From: Aaron Caldwell Date: Wed, 4 Mar 2020 16:52:20 -0700 Subject: [PATCH 14/21] Remove unused inspector files in legacy --- .../public/inspector/views/map_details.js | 128 ------------------ .../maps/public/inspector/views/map_view.js | 66 --------- 2 files changed, 194 deletions(-) delete mode 100644 x-pack/legacy/plugins/maps/public/inspector/views/map_details.js delete mode 100644 x-pack/legacy/plugins/maps/public/inspector/views/map_view.js diff --git a/x-pack/legacy/plugins/maps/public/inspector/views/map_details.js b/x-pack/legacy/plugins/maps/public/inspector/views/map_details.js deleted file mode 100644 index e84cf51ed34c1c..00000000000000 --- a/x-pack/legacy/plugins/maps/public/inspector/views/map_details.js +++ /dev/null @@ -1,128 +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, { Component } from 'react'; -import PropTypes from 'prop-types'; -import { - EuiTab, - EuiTabs, - EuiCodeBlock, - EuiTable, - EuiTableBody, - EuiTableRow, - EuiTableRowCell, -} from '@elastic/eui'; -import { i18n } from '@kbn/i18n'; -import { FormattedMessage } from '@kbn/i18n/react'; - -const DETAILS_TAB_ID = 'details'; -const STYLE_TAB_ID = 'mapStyle'; - -class MapDetails extends Component { - tabs = [ - { - id: DETAILS_TAB_ID, - name: i18n.translate('xpack.maps.inspector.mapDetailsTitle', { - defaultMessage: 'Map details', - }), - dataTestSubj: 'mapDetailsTab', - }, - { - id: STYLE_TAB_ID, - name: i18n.translate('xpack.maps.inspector.mapboxStyleTitle', { - defaultMessage: 'Mapbox style', - }), - dataTestSubj: 'mapboxStyleTab', - }, - ]; - - state = { - selectedTabId: DETAILS_TAB_ID, - }; - - onSelectedTabChanged = id => { - this.setState({ - selectedTabId: id, - }); - }; - - renderTab = () => { - if (STYLE_TAB_ID === this.state.selectedTabId) { - return ( -
- - {JSON.stringify(this.props.mapStyle, null, 2)} - -
- ); - } - - return ( - - - - - - - {this.props.centerLon} - - - - - - - {this.props.centerLat} - - - - - - - {this.props.zoom} - - - - ); - }; - - renderTabs() { - return this.tabs.map((tab, index) => ( - this.onSelectedTabChanged(tab.id)} - isSelected={tab.id === this.state.selectedTabId} - key={index} - data-test-subj={tab.dataTestSubj} - > - {tab.name} - - )); - } - - render() { - return ( -
- {this.renderTabs()} - - {this.renderTab()} -
- ); - } -} - -MapDetails.propTypes = { - centerLon: PropTypes.number.isRequired, - centerLat: PropTypes.number.isRequired, - zoom: PropTypes.number.isRequired, - mapStyle: PropTypes.object.isRequired, -}; - -export { MapDetails }; diff --git a/x-pack/legacy/plugins/maps/public/inspector/views/map_view.js b/x-pack/legacy/plugins/maps/public/inspector/views/map_view.js deleted file mode 100644 index db96e77c93984c..00000000000000 --- a/x-pack/legacy/plugins/maps/public/inspector/views/map_view.js +++ /dev/null @@ -1,66 +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, { Component } from 'react'; -import PropTypes from 'prop-types'; -import { MapDetails } from './map_details'; -import { i18n } from '@kbn/i18n'; - -class MapViewComponent extends Component { - constructor(props) { - super(props); - props.adapters.map.on('change', this._onMapChange); - - const { stats, style } = props.adapters.map.getMapState(); - this.state = { - stats, - mapStyle: style, - }; - } - - _onMapChange = () => { - const { stats, style } = this.props.adapters.map.getMapState(); - this.setState({ - stats, - mapStyle: style, - }); - }; - - componentWillUnmount() { - this.props.adapters.map.removeListener('change', this._onMapChange); - } - - render() { - return ( - - ); - } -} - -MapViewComponent.propTypes = { - adapters: PropTypes.object.isRequired, -}; - -const MapView = { - title: i18n.translate('xpack.maps.inspector.mapDetailsViewTitle', { - defaultMessage: 'Map details', - }), - order: 30, - help: i18n.translate('xpack.maps.inspector.mapDetailsViewHelpText', { - defaultMessage: 'View the map state', - }), - shouldShow(adapters) { - return Boolean(adapters.map); - }, - component: MapViewComponent, -}; - -export { MapView }; From 0db88eeab044a33705bf37dbaa740d347345c194 Mon Sep 17 00:00:00 2001 From: Aaron Caldwell Date: Thu, 5 Mar 2020 08:15:29 -0700 Subject: [PATCH 15/21] Move full screen action to legacy --- x-pack/legacy/plugins/maps/public/actions/ui_actions.js | 7 +++++++ x-pack/plugins/maps/public/actions/ui_actions.js | 7 ------- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/actions/ui_actions.js b/x-pack/legacy/plugins/maps/public/actions/ui_actions.js index 14cd80825e6dc3..9a6003be1d8900 100644 --- a/x-pack/legacy/plugins/maps/public/actions/ui_actions.js +++ b/x-pack/legacy/plugins/maps/public/actions/ui_actions.js @@ -18,6 +18,13 @@ export const HIDE_TOC_DETAILS = 'HIDE_TOC_DETAILS'; export const UPDATE_INDEXING_STAGE = 'UPDATE_INDEXING_STAGE'; // End temporary redundancy +export function exitFullScreen() { + return { + type: SET_FULL_SCREEN, + isFullScreen: false, + }; +} + export function updateFlyout(display) { return { type: UPDATE_FLYOUT, diff --git a/x-pack/plugins/maps/public/actions/ui_actions.js b/x-pack/plugins/maps/public/actions/ui_actions.js index d488d434858ba4..b5caf4d75d6b18 100644 --- a/x-pack/plugins/maps/public/actions/ui_actions.js +++ b/x-pack/plugins/maps/public/actions/ui_actions.js @@ -17,10 +17,3 @@ export const SHOW_TOC_DETAILS = 'SHOW_TOC_DETAILS'; export const HIDE_TOC_DETAILS = 'HIDE_TOC_DETAILS'; export const UPDATE_INDEXING_STAGE = 'UPDATE_INDEXING_STAGE'; // End temporary redundancy - -export function exitFullScreen() { - return { - type: SET_FULL_SCREEN, - isFullScreen: false, - }; -} From bd06f6681d789fc8dc6e1d6019039e637e84c885 Mon Sep 17 00:00:00 2001 From: Aaron Caldwell Date: Thu, 5 Mar 2020 15:18:11 -0700 Subject: [PATCH 16/21] Add in missing tooltip updates --- x-pack/plugins/maps/public/actions/map_actions.js | 2 +- x-pack/plugins/maps/public/reducers/map.js | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/x-pack/plugins/maps/public/actions/map_actions.js b/x-pack/plugins/maps/public/actions/map_actions.js index 3c01aece88ba60..eddc5fcf924b97 100644 --- a/x-pack/plugins/maps/public/actions/map_actions.js +++ b/x-pack/plugins/maps/public/actions/map_actions.js @@ -38,7 +38,7 @@ export const CLEAR_GOTO = 'CLEAR_GOTO'; export const TRACK_CURRENT_LAYER_STATE = 'TRACK_CURRENT_LAYER_STATE'; export const ROLLBACK_TO_TRACKED_LAYER_STATE = 'ROLLBACK_TO_TRACKED_LAYER_STATE'; export const REMOVE_TRACKED_LAYER_STATE = 'REMOVE_TRACKED_LAYER_STATE'; -export const SET_TOOLTIP_STATE = 'SET_TOOLTIP_STATE'; +export const SET_OPEN_TOOLTIPS = 'SET_OPEN_TOOLTIPS'; export const UPDATE_DRAW_STATE = 'UPDATE_DRAW_STATE'; export const SET_SCROLL_ZOOM = 'SET_SCROLL_ZOOM'; export const SET_MAP_INIT_ERROR = 'SET_MAP_INIT_ERROR'; diff --git a/x-pack/plugins/maps/public/reducers/map.js b/x-pack/plugins/maps/public/reducers/map.js index 234584d08a3114..7e81fb03dd85be 100644 --- a/x-pack/plugins/maps/public/reducers/map.js +++ b/x-pack/plugins/maps/public/reducers/map.js @@ -37,7 +37,7 @@ import { ROLLBACK_TO_TRACKED_LAYER_STATE, REMOVE_TRACKED_LAYER_STATE, UPDATE_SOURCE_DATA_REQUEST, - SET_TOOLTIP_STATE, + SET_OPEN_TOOLTIPS, SET_SCROLL_ZOOM, SET_MAP_INIT_ERROR, UPDATE_DRAW_STATE, @@ -97,7 +97,7 @@ const INITIAL_STATE = { ready: false, mapInitError: null, goto: null, - tooltipState: null, + openTooltips: [], mapState: { zoom: null, // setting this value does not adjust map zoom, read only value used to store current map zoom for persisting between sessions center: null, // setting this value does not adjust map view, read only value used to store current map center for persisting between sessions @@ -138,10 +138,10 @@ export function map(state = INITIAL_STATE, action) { return trackCurrentLayerState(state, action.layerId); case ROLLBACK_TO_TRACKED_LAYER_STATE: return rollbackTrackedLayerState(state, action.layerId); - case SET_TOOLTIP_STATE: + case SET_OPEN_TOOLTIPS: return { ...state, - tooltipState: action.tooltipState, + openTooltips: action.openTooltips, }; case SET_MOUSE_COORDINATES: return { From 6c815d9e5766b8a7d10072f1ec64ef21600535d0 Mon Sep 17 00:00:00 2001 From: Aaron Caldwell Date: Fri, 6 Mar 2020 08:37:55 -0700 Subject: [PATCH 17/21] Review feedback. Update constants and i18n_getters to latest in NP --- .../common/{constants.js => constants.ts} | 42 ++++++++++++------- .../{i18n_getters.js => i18n_getters.ts} | 4 +- 2 files changed, 30 insertions(+), 16 deletions(-) rename x-pack/plugins/maps/common/{constants.js => constants.ts} (88%) rename x-pack/plugins/maps/common/{i18n_getters.js => i18n_getters.ts} (90%) diff --git a/x-pack/plugins/maps/common/constants.js b/x-pack/plugins/maps/common/constants.ts similarity index 88% rename from x-pack/plugins/maps/common/constants.js rename to x-pack/plugins/maps/common/constants.ts index 2570341aa5756e..4f1b3223967a58 100644 --- a/x-pack/plugins/maps/common/constants.js +++ b/x-pack/plugins/maps/common/constants.ts @@ -4,7 +4,6 @@ * you may not use this file except in compliance with the Elastic License. */ import { i18n } from '@kbn/i18n'; - export const EMS_CATALOGUE_PATH = 'ems/catalogue'; export const EMS_FILES_CATALOGUE_PATH = 'ems/files'; @@ -33,7 +32,7 @@ export const INDEX_SETTINGS_API_PATH = `${GIS_API_PATH}/indexSettings`; export const MAP_BASE_URL = `/${MAP_APP_PATH}#/${MAP_SAVED_OBJECT_TYPE}`; -export function createMapPath(id) { +export function createMapPath(id: string) { return `${MAP_BASE_URL}/${id}`; } @@ -44,16 +43,17 @@ export const LAYER_TYPE = { HEATMAP: 'HEATMAP', }; -export const SORT_ORDER = { - ASC: 'asc', - DESC: 'desc', -}; +export enum SORT_ORDER { + ASC = 'asc', + DESC = 'desc', +} export const EMS_TMS = 'EMS_TMS'; export const EMS_FILE = 'EMS_FILE'; export const ES_GEO_GRID = 'ES_GEO_GRID'; export const ES_SEARCH = 'ES_SEARCH'; export const ES_PEW_PEW = 'ES_PEW_PEW'; +export const EMS_XYZ = 'EMS_XYZ'; // identifies a custom TMS source. Name is a little unfortunate. export const FIELD_ORIGIN = { SOURCE: 'source', @@ -117,16 +117,28 @@ export const DRAW_TYPE = { POLYGON: 'POLYGON', }; -export const METRIC_TYPE = { - AVG: 'avg', - COUNT: 'count', - MAX: 'max', - MIN: 'min', - SUM: 'sum', - UNIQUE_COUNT: 'cardinality', -}; +export enum AGG_TYPE { + AVG = 'avg', + COUNT = 'count', + MAX = 'max', + MIN = 'min', + SUM = 'sum', + TERMS = 'terms', + UNIQUE_COUNT = 'cardinality', +} + +export enum RENDER_AS { + HEATMAP = 'heatmap', + POINT = 'point', + GRID = 'grid', +} + +export enum GRID_RESOLUTION { + COARSE = 'COARSE', + FINE = 'FINE', + MOST_FINE = 'MOST_FINE', +} -export const COUNT_AGG_TYPE = METRIC_TYPE.COUNT; export const COUNT_PROP_LABEL = i18n.translate('xpack.maps.aggs.defaultCountLabel', { defaultMessage: 'count', }); diff --git a/x-pack/plugins/maps/common/i18n_getters.js b/x-pack/plugins/maps/common/i18n_getters.ts similarity index 90% rename from x-pack/plugins/maps/common/i18n_getters.js rename to x-pack/plugins/maps/common/i18n_getters.ts index 578d0cd4780e96..0008a119f1c7cc 100644 --- a/x-pack/plugins/maps/common/i18n_getters.js +++ b/x-pack/plugins/maps/common/i18n_getters.ts @@ -6,6 +6,7 @@ import { i18n } from '@kbn/i18n'; +import { $Values } from '@kbn/utility-types'; import { ES_SPATIAL_RELATIONS } from './constants'; export function getAppTitle() { @@ -26,7 +27,7 @@ export function getUrlLabel() { }); } -export function getEsSpatialRelationLabel(spatialRelation) { +export function getEsSpatialRelationLabel(spatialRelation: $Values) { switch (spatialRelation) { case ES_SPATIAL_RELATIONS.INTERSECTS: return i18n.translate('xpack.maps.common.esSpatialRelation.intersectsLabel', { @@ -40,6 +41,7 @@ export function getEsSpatialRelationLabel(spatialRelation) { return i18n.translate('xpack.maps.common.esSpatialRelation.withinLabel', { defaultMessage: 'within', }); + // @ts-ignore case ES_SPATIAL_RELATIONS.CONTAINS: return i18n.translate('xpack.maps.common.esSpatialRelation.containsLabel', { defaultMessage: 'contains', From 13d78b767b8d49c27f623d6e2ac24b6823a97017 Mon Sep 17 00:00:00 2001 From: Aaron Caldwell Date: Fri, 6 Mar 2020 09:01:56 -0700 Subject: [PATCH 18/21] Review feedback. Add redundancy comments to common files redundant in legacy and NP --- x-pack/legacy/plugins/maps/common/constants.ts | 4 ++++ x-pack/legacy/plugins/maps/common/i18n_getters.ts | 3 +++ x-pack/legacy/plugins/maps/common/parse_xml_string.js | 3 +++ x-pack/legacy/plugins/maps/common/parse_xml_string.test.js | 3 +++ x-pack/plugins/maps/common/constants.ts | 4 ++++ x-pack/plugins/maps/common/i18n_getters.ts | 3 +++ x-pack/plugins/maps/common/parse_xml_string.js | 3 +++ x-pack/plugins/maps/common/parse_xml_string.test.js | 3 +++ 8 files changed, 26 insertions(+) diff --git a/x-pack/legacy/plugins/maps/common/constants.ts b/x-pack/legacy/plugins/maps/common/constants.ts index 53289fbbc9005a..8fe9619f641eba 100644 --- a/x-pack/legacy/plugins/maps/common/constants.ts +++ b/x-pack/legacy/plugins/maps/common/constants.ts @@ -3,6 +3,9 @@ * or more contributor license agreements. Licensed under the Elastic License; * you may not use this file except in compliance with the Elastic License. */ + +// NP Migration +// Temporarily redundant with x-pack/plugins/maps/common/constants.ts import { i18n } from '@kbn/i18n'; export const EMS_CATALOGUE_PATH = 'ems/catalogue'; @@ -172,3 +175,4 @@ export const SYMBOLIZE_AS_TYPES = { }; export const DEFAULT_ICON = 'airfield'; +// End temporary redundancy diff --git a/x-pack/legacy/plugins/maps/common/i18n_getters.ts b/x-pack/legacy/plugins/maps/common/i18n_getters.ts index 0008a119f1c7cc..6a7d53b8c82fac 100644 --- a/x-pack/legacy/plugins/maps/common/i18n_getters.ts +++ b/x-pack/legacy/plugins/maps/common/i18n_getters.ts @@ -9,6 +9,8 @@ import { i18n } from '@kbn/i18n'; import { $Values } from '@kbn/utility-types'; import { ES_SPATIAL_RELATIONS } from './constants'; +// NP Migration +// Temporarily redundant with x-pack/plugins/maps/common/i18n_getters.ts export function getAppTitle() { return i18n.translate('xpack.maps.appTitle', { defaultMessage: 'Maps', @@ -50,3 +52,4 @@ export function getEsSpatialRelationLabel(spatialRelation: $Values { @@ -20,3 +22,4 @@ export async function parseXmlString(xmlString) { return await parsePromise; } +// End temporary redundancy diff --git a/x-pack/legacy/plugins/maps/common/parse_xml_string.test.js b/x-pack/legacy/plugins/maps/common/parse_xml_string.test.js index cfd6235667aae1..cf7cda227dee46 100644 --- a/x-pack/legacy/plugins/maps/common/parse_xml_string.test.js +++ b/x-pack/legacy/plugins/maps/common/parse_xml_string.test.js @@ -6,6 +6,8 @@ import { parseXmlString } from './parse_xml_string'; +// NP Migration +// Temporarily redundant with x-pack/plugins/maps/common/parse_xml_string.test.js describe('parseXmlString', () => { it('Should parse xml string into JS object', async () => { const xmlAsObject = await parseXmlString('bar'); @@ -14,3 +16,4 @@ describe('parseXmlString', () => { }); }); }); +// End temporary redundancy diff --git a/x-pack/plugins/maps/common/constants.ts b/x-pack/plugins/maps/common/constants.ts index 4f1b3223967a58..a51bbd3b938f21 100644 --- a/x-pack/plugins/maps/common/constants.ts +++ b/x-pack/plugins/maps/common/constants.ts @@ -3,6 +3,9 @@ * or more contributor license agreements. Licensed under the Elastic License; * you may not use this file except in compliance with the Elastic License. */ + +// NP Migration +// Temporarily redundant with x-pack/legacy/plugins/maps/common/constants.ts import { i18n } from '@kbn/i18n'; export const EMS_CATALOGUE_PATH = 'ems/catalogue'; @@ -170,3 +173,4 @@ export const SYMBOLIZE_AS_TYPES = { }; export const DEFAULT_ICON = 'airfield'; +// End temporary redundancy diff --git a/x-pack/plugins/maps/common/i18n_getters.ts b/x-pack/plugins/maps/common/i18n_getters.ts index 0008a119f1c7cc..e7296c807b0652 100644 --- a/x-pack/plugins/maps/common/i18n_getters.ts +++ b/x-pack/plugins/maps/common/i18n_getters.ts @@ -9,6 +9,8 @@ import { i18n } from '@kbn/i18n'; import { $Values } from '@kbn/utility-types'; import { ES_SPATIAL_RELATIONS } from './constants'; +// NP Migration +// Temporarily redundant with x-pack/legacy/plugins/maps/common/i18n_getters.ts export function getAppTitle() { return i18n.translate('xpack.maps.appTitle', { defaultMessage: 'Maps', @@ -50,3 +52,4 @@ export function getEsSpatialRelationLabel(spatialRelation: $Values { @@ -20,3 +22,4 @@ export async function parseXmlString(xmlString) { return await parsePromise; } +// End temporary redundancy diff --git a/x-pack/plugins/maps/common/parse_xml_string.test.js b/x-pack/plugins/maps/common/parse_xml_string.test.js index cfd6235667aae1..bee8625f1aeac2 100644 --- a/x-pack/plugins/maps/common/parse_xml_string.test.js +++ b/x-pack/plugins/maps/common/parse_xml_string.test.js @@ -6,6 +6,8 @@ import { parseXmlString } from './parse_xml_string'; +// NP Migration +// Temporarily redundant with x-pack/legacy/plugins/maps/common/parse_xml_string.test.js describe('parseXmlString', () => { it('Should parse xml string into JS object', async () => { const xmlAsObject = await parseXmlString('bar'); @@ -14,3 +16,4 @@ describe('parseXmlString', () => { }); }); }); +// End temporary redundancy From 02f396ab531be8259bbe0ef6060ba0a34cdb926f Mon Sep 17 00:00:00 2001 From: Aaron Caldwell Date: Wed, 11 Mar 2020 12:20:05 -0600 Subject: [PATCH 19/21] Remove unneeded copy of parse xml string test in legacy --- .../maps/common/parse_xml_string.test.js | 19 ------------------- 1 file changed, 19 deletions(-) delete mode 100644 x-pack/legacy/plugins/maps/common/parse_xml_string.test.js diff --git a/x-pack/legacy/plugins/maps/common/parse_xml_string.test.js b/x-pack/legacy/plugins/maps/common/parse_xml_string.test.js deleted file mode 100644 index cf7cda227dee46..00000000000000 --- a/x-pack/legacy/plugins/maps/common/parse_xml_string.test.js +++ /dev/null @@ -1,19 +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 { parseXmlString } from './parse_xml_string'; - -// NP Migration -// Temporarily redundant with x-pack/plugins/maps/common/parse_xml_string.test.js -describe('parseXmlString', () => { - it('Should parse xml string into JS object', async () => { - const xmlAsObject = await parseXmlString('bar'); - expect(xmlAsObject).toEqual({ - foo: 'bar', - }); - }); -}); -// End temporary redundancy From 25ec8f18d06e101b9144172d2e350fbf0ed7b636 Mon Sep 17 00:00:00 2001 From: Aaron Caldwell Date: Wed, 11 Mar 2020 12:33:27 -0600 Subject: [PATCH 20/21] Review feedback. Remove redundant portions. Export from NP where possible. General clean up --- .../legacy/plugins/maps/common/constants.ts | 182 +----------------- .../plugins/maps/common/i18n_getters.ts | 51 +---- .../plugins/maps/common/parse_xml_string.js | 21 +- .../maps/public/actions/map_actions.js | 91 ++++----- .../plugins/maps/public/actions/ui_actions.js | 28 +-- x-pack/legacy/plugins/maps/public/plugin.ts | 8 +- x-pack/plugins/maps/common/constants.ts | 34 ++-- x-pack/plugins/maps/common/i18n_getters.ts | 3 - .../plugins/maps/common/parse_xml_string.js | 3 - .../maps/common/parse_xml_string.test.js | 3 - .../maps/public/actions/map_actions.js | 4 - .../plugins/maps/public/actions/ui_actions.js | 3 - 12 files changed, 95 insertions(+), 336 deletions(-) diff --git a/x-pack/legacy/plugins/maps/common/constants.ts b/x-pack/legacy/plugins/maps/common/constants.ts index c9e73b2d685455..98945653c25dc8 100644 --- a/x-pack/legacy/plugins/maps/common/constants.ts +++ b/x-pack/legacy/plugins/maps/common/constants.ts @@ -4,183 +4,5 @@ * you may not use this file except in compliance with the Elastic License. */ -// NP Migration -// Temporarily redundant with x-pack/plugins/maps/common/constants.ts -import { i18n } from '@kbn/i18n'; -export const EMS_CATALOGUE_PATH = 'ems/catalogue'; - -export const EMS_FILES_CATALOGUE_PATH = 'ems/files'; -export const EMS_FILES_API_PATH = 'ems/files'; -export const EMS_FILES_DEFAULT_JSON_PATH = 'file'; -export const EMS_GLYPHS_PATH = 'fonts'; -export const EMS_SPRITES_PATH = 'sprites'; - -export const EMS_TILES_CATALOGUE_PATH = 'ems/tiles'; -export const EMS_TILES_API_PATH = 'ems/tiles'; -export const EMS_TILES_RASTER_STYLE_PATH = 'raster/style'; -export const EMS_TILES_RASTER_TILE_PATH = 'raster/tile'; - -export const EMS_TILES_VECTOR_STYLE_PATH = 'vector/style'; -export const EMS_TILES_VECTOR_SOURCE_PATH = 'vector/source'; -export const EMS_TILES_VECTOR_TILE_PATH = 'vector/tile'; - -export const MAP_SAVED_OBJECT_TYPE = 'map'; -export const APP_ID = 'maps'; -export const APP_ICON = 'gisApp'; -export const TELEMETRY_TYPE = 'maps-telemetry'; - -export const MAP_APP_PATH = `app/${APP_ID}`; -export const GIS_API_PATH = `api/${APP_ID}`; -export const INDEX_SETTINGS_API_PATH = `${GIS_API_PATH}/indexSettings`; - -export const MAP_BASE_URL = `/${MAP_APP_PATH}#/${MAP_SAVED_OBJECT_TYPE}`; - -export function createMapPath(id: string) { - return `${MAP_BASE_URL}/${id}`; -} - -export const LAYER_TYPE = { - TILE: 'TILE', - VECTOR: 'VECTOR', - VECTOR_TILE: 'VECTOR_TILE', - HEATMAP: 'HEATMAP', -}; - -export enum SORT_ORDER { - ASC = 'asc', - DESC = 'desc', -} - -export const EMS_TMS = 'EMS_TMS'; -export const EMS_FILE = 'EMS_FILE'; -export const ES_GEO_GRID = 'ES_GEO_GRID'; -export const ES_SEARCH = 'ES_SEARCH'; -export const ES_PEW_PEW = 'ES_PEW_PEW'; -export const EMS_XYZ = 'EMS_XYZ'; // identifies a custom TMS source. Name is a little unfortunate. - -export enum FIELD_ORIGIN { - SOURCE = 'source', - JOIN = 'join', -} - -export const SOURCE_DATA_ID_ORIGIN = 'source'; -export const META_ID_ORIGIN_SUFFIX = 'meta'; -export const SOURCE_META_ID_ORIGIN = `${SOURCE_DATA_ID_ORIGIN}_${META_ID_ORIGIN_SUFFIX}`; -export const FORMATTERS_ID_ORIGIN_SUFFIX = 'formatters'; -export const SOURCE_FORMATTERS_ID_ORIGIN = `${SOURCE_DATA_ID_ORIGIN}_${FORMATTERS_ID_ORIGIN_SUFFIX}`; - -export const GEOJSON_FILE = 'GEOJSON_FILE'; - -export const MIN_ZOOM = 0; -export const MAX_ZOOM = 24; - -export const DECIMAL_DEGREES_PRECISION = 5; // meters precision -export const ZOOM_PRECISION = 2; -export const DEFAULT_MAX_RESULT_WINDOW = 10000; -export const DEFAULT_MAX_INNER_RESULT_WINDOW = 100; -export const DEFAULT_MAX_BUCKETS_LIMIT = 10000; - -export const FEATURE_ID_PROPERTY_NAME = '__kbn__feature_id__'; -export const FEATURE_VISIBLE_PROPERTY_NAME = '__kbn_isvisibleduetojoin__'; - -export const MB_SOURCE_ID_LAYER_ID_PREFIX_DELIMITER = '_'; - -export const ES_GEO_FIELD_TYPE = { - GEO_POINT: 'geo_point', - GEO_SHAPE: 'geo_shape', -}; - -export const ES_SPATIAL_RELATIONS = { - INTERSECTS: 'INTERSECTS', - DISJOINT: 'DISJOINT', - WITHIN: 'WITHIN', -}; - -export const GEO_JSON_TYPE = { - POINT: 'Point', - MULTI_POINT: 'MultiPoint', - LINE_STRING: 'LineString', - MULTI_LINE_STRING: 'MultiLineString', - POLYGON: 'Polygon', - MULTI_POLYGON: 'MultiPolygon', - GEOMETRY_COLLECTION: 'GeometryCollection', -}; - -export const POLYGON_COORDINATES_EXTERIOR_INDEX = 0; -export const LON_INDEX = 0; -export const LAT_INDEX = 1; - -export const EMPTY_FEATURE_COLLECTION = { - type: 'FeatureCollection', - features: [], -}; - -export const DRAW_TYPE = { - BOUNDS: 'BOUNDS', - POLYGON: 'POLYGON', -}; - -export enum AGG_TYPE { - AVG = 'avg', - COUNT = 'count', - MAX = 'max', - MIN = 'min', - SUM = 'sum', - TERMS = 'terms', - UNIQUE_COUNT = 'cardinality', -} - -export enum RENDER_AS { - HEATMAP = 'heatmap', - POINT = 'point', - GRID = 'grid', -} - -export enum GRID_RESOLUTION { - COARSE = 'COARSE', - FINE = 'FINE', - MOST_FINE = 'MOST_FINE', -} - -export const TOP_TERM_PERCENTAGE_SUFFIX = '__percentage'; - -export const COUNT_PROP_LABEL = i18n.translate('xpack.maps.aggs.defaultCountLabel', { - defaultMessage: 'count', -}); - -export const COUNT_PROP_NAME = 'doc_count'; - -export const STYLE_TYPE = { - STATIC: 'STATIC', - DYNAMIC: 'DYNAMIC', -}; - -export const LAYER_STYLE_TYPE = { - VECTOR: 'VECTOR', - HEATMAP: 'HEATMAP', -}; - -export const COLOR_MAP_TYPE = { - CATEGORICAL: 'CATEGORICAL', - ORDINAL: 'ORDINAL', -}; - -export const COLOR_PALETTE_MAX_SIZE = 10; - -export const CATEGORICAL_DATA_TYPES = ['string', 'ip', 'boolean']; -export const ORDINAL_DATA_TYPES = ['number', 'date']; - -export enum SYMBOLIZE_AS_TYPES { - CIRCLE = 'circle', - ICON = 'icon', -} - -export enum LABEL_BORDER_SIZES { - NONE = 'NONE', - SMALL = 'SMALL', - MEDIUM = 'MEDIUM', - LARGE = 'LARGE', -} - -export const DEFAULT_ICON = 'airfield'; -// End temporary redundancy +// eslint-disable-next-line @kbn/eslint/no-restricted-paths +export * from '../../../../plugins/maps/common/constants'; diff --git a/x-pack/legacy/plugins/maps/common/i18n_getters.ts b/x-pack/legacy/plugins/maps/common/i18n_getters.ts index 6a7d53b8c82fac..f9d186dea2e2b9 100644 --- a/x-pack/legacy/plugins/maps/common/i18n_getters.ts +++ b/x-pack/legacy/plugins/maps/common/i18n_getters.ts @@ -4,52 +4,5 @@ * you may not use this file except in compliance with the Elastic License. */ -import { i18n } from '@kbn/i18n'; - -import { $Values } from '@kbn/utility-types'; -import { ES_SPATIAL_RELATIONS } from './constants'; - -// NP Migration -// Temporarily redundant with x-pack/plugins/maps/common/i18n_getters.ts -export function getAppTitle() { - return i18n.translate('xpack.maps.appTitle', { - defaultMessage: 'Maps', - }); -} - -export function getDataSourceLabel() { - return i18n.translate('xpack.maps.source.dataSourceLabel', { - defaultMessage: 'Data source', - }); -} - -export function getUrlLabel() { - return i18n.translate('xpack.maps.source.urlLabel', { - defaultMessage: 'Url', - }); -} - -export function getEsSpatialRelationLabel(spatialRelation: $Values) { - switch (spatialRelation) { - case ES_SPATIAL_RELATIONS.INTERSECTS: - return i18n.translate('xpack.maps.common.esSpatialRelation.intersectsLabel', { - defaultMessage: 'intersects', - }); - case ES_SPATIAL_RELATIONS.DISJOINT: - return i18n.translate('xpack.maps.common.esSpatialRelation.disjointLabel', { - defaultMessage: 'disjoint', - }); - case ES_SPATIAL_RELATIONS.WITHIN: - return i18n.translate('xpack.maps.common.esSpatialRelation.withinLabel', { - defaultMessage: 'within', - }); - // @ts-ignore - case ES_SPATIAL_RELATIONS.CONTAINS: - return i18n.translate('xpack.maps.common.esSpatialRelation.containsLabel', { - defaultMessage: 'contains', - }); - default: - return spatialRelation; - } -} -// End temporary redundancy +// eslint-disable-next-line @kbn/eslint/no-restricted-paths +export * from '../../../../plugins/maps/common/i18n_getters'; diff --git a/x-pack/legacy/plugins/maps/common/parse_xml_string.js b/x-pack/legacy/plugins/maps/common/parse_xml_string.js index 62a2f2a4c1d6b7..34ec1444728281 100644 --- a/x-pack/legacy/plugins/maps/common/parse_xml_string.js +++ b/x-pack/legacy/plugins/maps/common/parse_xml_string.js @@ -4,22 +4,5 @@ * you may not use this file except in compliance with the Elastic License. */ -import { parseString } from 'xml2js'; - -// NP Migration -// Temporarily redundant with x-pack/plugins/maps/common/parse_xml_string.js -// promise based wrapper around parseString -export async function parseXmlString(xmlString) { - const parsePromise = new Promise((resolve, reject) => { - parseString(xmlString, (error, result) => { - if (error) { - reject(error); - } else { - resolve(result); - } - }); - }); - - return await parsePromise; -} -// End temporary redundancy +// eslint-disable-next-line @kbn/eslint/no-restricted-paths +export * from '../../../../plugins/maps/common/parse_xml_string'; diff --git a/x-pack/legacy/plugins/maps/public/actions/map_actions.js b/x-pack/legacy/plugins/maps/public/actions/map_actions.js index 2c420a69c486af..7a1e5e5266246d 100644 --- a/x-pack/legacy/plugins/maps/public/actions/map_actions.js +++ b/x-pack/legacy/plugins/maps/public/actions/map_actions.js @@ -36,51 +36,52 @@ import { SOURCE_DATA_ID_ORIGIN, } from '../../common/constants'; -// NP Migration -// Temporarily redundant with x-pack/plugins/maps/public/actions/map_actions.js -export const SET_SELECTED_LAYER = 'SET_SELECTED_LAYER'; -export const SET_TRANSIENT_LAYER = 'SET_TRANSIENT_LAYER'; -export const UPDATE_LAYER_ORDER = 'UPDATE_LAYER_ORDER'; -export const ADD_LAYER = 'ADD_LAYER'; -export const SET_LAYER_ERROR_STATUS = 'SET_LAYER_ERROR_STATUS'; -export const ADD_WAITING_FOR_MAP_READY_LAYER = 'ADD_WAITING_FOR_MAP_READY_LAYER'; -export const CLEAR_WAITING_FOR_MAP_READY_LAYER_LIST = 'CLEAR_WAITING_FOR_MAP_READY_LAYER_LIST'; -export const REMOVE_LAYER = 'REMOVE_LAYER'; -export const SET_LAYER_VISIBILITY = 'SET_LAYER_VISIBILITY'; -export const MAP_EXTENT_CHANGED = 'MAP_EXTENT_CHANGED'; -export const MAP_READY = 'MAP_READY'; -export const MAP_DESTROYED = 'MAP_DESTROYED'; -export const LAYER_DATA_LOAD_STARTED = 'LAYER_DATA_LOAD_STARTED'; -export const LAYER_DATA_LOAD_ENDED = 'LAYER_DATA_LOAD_ENDED'; -export const LAYER_DATA_LOAD_ERROR = 'LAYER_DATA_LOAD_ERROR'; -export const UPDATE_SOURCE_DATA_REQUEST = 'UPDATE_SOURCE_DATA_REQUEST'; -export const SET_JOINS = 'SET_JOINS'; -export const SET_QUERY = 'SET_QUERY'; -export const TRIGGER_REFRESH_TIMER = 'TRIGGER_REFRESH_TIMER'; -export const UPDATE_LAYER_PROP = 'UPDATE_LAYER_PROP'; -export const UPDATE_LAYER_STYLE = 'UPDATE_LAYER_STYLE'; -export const SET_LAYER_STYLE_META = 'SET_LAYER_STYLE_META'; -export const TOUCH_LAYER = 'TOUCH_LAYER'; -export const UPDATE_SOURCE_PROP = 'UPDATE_SOURCE_PROP'; -export const SET_REFRESH_CONFIG = 'SET_REFRESH_CONFIG'; -export const SET_MOUSE_COORDINATES = 'SET_MOUSE_COORDINATES'; -export const CLEAR_MOUSE_COORDINATES = 'CLEAR_MOUSE_COORDINATES'; -export const SET_GOTO = 'SET_GOTO'; -export const CLEAR_GOTO = 'CLEAR_GOTO'; -export const TRACK_CURRENT_LAYER_STATE = 'TRACK_CURRENT_LAYER_STATE'; -export const ROLLBACK_TO_TRACKED_LAYER_STATE = 'ROLLBACK_TO_TRACKED_LAYER_STATE'; -export const REMOVE_TRACKED_LAYER_STATE = 'REMOVE_TRACKED_LAYER_STATE'; -export const SET_OPEN_TOOLTIPS = 'SET_OPEN_TOOLTIPS'; -export const UPDATE_DRAW_STATE = 'UPDATE_DRAW_STATE'; -export const SET_SCROLL_ZOOM = 'SET_SCROLL_ZOOM'; -export const SET_MAP_INIT_ERROR = 'SET_MAP_INIT_ERROR'; -export const SET_INTERACTIVE = 'SET_INTERACTIVE'; -export const DISABLE_TOOLTIP_CONTROL = 'DISABLE_TOOLTIP_CONTROL'; -export const HIDE_TOOLBAR_OVERLAY = 'HIDE_TOOLBAR_OVERLAY'; -export const HIDE_LAYER_CONTROL = 'HIDE_LAYER_CONTROL'; -export const HIDE_VIEW_CONTROL = 'HIDE_VIEW_CONTROL'; -export const SET_WAITING_FOR_READY_HIDDEN_LAYERS = 'SET_WAITING_FOR_READY_HIDDEN_LAYERS'; -// End temporary redundancy +import { + SET_SELECTED_LAYER, + SET_TRANSIENT_LAYER, + UPDATE_LAYER_ORDER, + ADD_LAYER, + SET_LAYER_ERROR_STATUS, + ADD_WAITING_FOR_MAP_READY_LAYER, + CLEAR_WAITING_FOR_MAP_READY_LAYER_LIST, + REMOVE_LAYER, + SET_LAYER_VISIBILITY, + MAP_EXTENT_CHANGED, + MAP_READY, + MAP_DESTROYED, + LAYER_DATA_LOAD_STARTED, + LAYER_DATA_LOAD_ENDED, + LAYER_DATA_LOAD_ERROR, + UPDATE_SOURCE_DATA_REQUEST, + SET_JOINS, + SET_QUERY, + TRIGGER_REFRESH_TIMER, + UPDATE_LAYER_PROP, + UPDATE_LAYER_STYLE, + SET_LAYER_STYLE_META, + UPDATE_SOURCE_PROP, + SET_REFRESH_CONFIG, + SET_MOUSE_COORDINATES, + CLEAR_MOUSE_COORDINATES, + SET_GOTO, + CLEAR_GOTO, + TRACK_CURRENT_LAYER_STATE, + ROLLBACK_TO_TRACKED_LAYER_STATE, + REMOVE_TRACKED_LAYER_STATE, + SET_OPEN_TOOLTIPS, + UPDATE_DRAW_STATE, + SET_SCROLL_ZOOM, + SET_MAP_INIT_ERROR, + SET_INTERACTIVE, + DISABLE_TOOLTIP_CONTROL, + HIDE_TOOLBAR_OVERLAY, + HIDE_LAYER_CONTROL, + HIDE_VIEW_CONTROL, + SET_WAITING_FOR_READY_HIDDEN_LAYERS, + // eslint-disable-next-line @kbn/eslint/no-restricted-paths +} from '../../../../../plugins/maps/public/actions/map_actions'; +// eslint-disable-next-line @kbn/eslint/no-restricted-paths +export * from '../../../../../plugins/maps/public/actions/map_actions'; function getLayerLoadingCallbacks(dispatch, getState, layerId) { return { diff --git a/x-pack/legacy/plugins/maps/public/actions/ui_actions.js b/x-pack/legacy/plugins/maps/public/actions/ui_actions.js index 9a6003be1d8900..33ab2fd74122a6 100644 --- a/x-pack/legacy/plugins/maps/public/actions/ui_actions.js +++ b/x-pack/legacy/plugins/maps/public/actions/ui_actions.js @@ -4,19 +4,21 @@ * you may not use this file except in compliance with the Elastic License. */ -// NP Migration -// Temporarily redundant with x-pack/plugins/maps/public/actions/ui_actions.js -export const UPDATE_FLYOUT = 'UPDATE_FLYOUT'; -export const CLOSE_SET_VIEW = 'CLOSE_SET_VIEW'; -export const OPEN_SET_VIEW = 'OPEN_SET_VIEW'; -export const SET_IS_LAYER_TOC_OPEN = 'SET_IS_LAYER_TOC_OPEN'; -export const SET_FULL_SCREEN = 'SET_FULL_SCREEN'; -export const SET_READ_ONLY = 'SET_READ_ONLY'; -export const SET_OPEN_TOC_DETAILS = 'SET_OPEN_TOC_DETAILS'; -export const SHOW_TOC_DETAILS = 'SHOW_TOC_DETAILS'; -export const HIDE_TOC_DETAILS = 'HIDE_TOC_DETAILS'; -export const UPDATE_INDEXING_STAGE = 'UPDATE_INDEXING_STAGE'; -// End temporary redundancy +import { + UPDATE_FLYOUT, + CLOSE_SET_VIEW, + OPEN_SET_VIEW, + SET_IS_LAYER_TOC_OPEN, + SET_FULL_SCREEN, + SET_READ_ONLY, + SET_OPEN_TOC_DETAILS, + SHOW_TOC_DETAILS, + HIDE_TOC_DETAILS, + UPDATE_INDEXING_STAGE, + // eslint-disable-next-line @kbn/eslint/no-restricted-paths +} from '../../../../../plugins/maps/public/actions/ui_actions'; +// eslint-disable-next-line @kbn/eslint/no-restricted-paths +export * from '../../../../../plugins/maps/public/actions/ui_actions'; export function exitFullScreen() { return { diff --git a/x-pack/legacy/plugins/maps/public/plugin.ts b/x-pack/legacy/plugins/maps/public/plugin.ts index d923854ab1e350..e2d1d432956466 100644 --- a/x-pack/legacy/plugins/maps/public/plugin.ts +++ b/x-pack/legacy/plugins/maps/public/plugin.ts @@ -4,12 +4,14 @@ * you may not use this file except in compliance with the Elastic License. */ -// @ts-nocheck import { Plugin, CoreStart, CoreSetup } from 'src/core/public'; +// @ts-ignore import { wrapInI18nContext } from 'ui/i18n'; +// @ts-ignore import { MapListing } from './components/map_listing'; -// eslint-disable-next-line @kbn/eslint/no-restricted-paths -import { setInjectedVarFunc } from '../../../../plugins/maps/public/kibana_services'; +// @ts-ignore +import { setInjectedVarFunc } from '../../../../plugins/maps/public/kibana_services'; // eslint-disable-line @kbn/eslint/no-restricted-paths +// @ts-ignore import { setLicenseId, setInspector, setFileUpload } from './kibana_services'; import { HomePublicPluginSetup } from '../../../../../src/plugins/home/public'; import { LicensingPluginSetup } from '../../../../plugins/licensing/public'; diff --git a/x-pack/plugins/maps/common/constants.ts b/x-pack/plugins/maps/common/constants.ts index a51bbd3b938f21..ae3e164ffb2bc1 100644 --- a/x-pack/plugins/maps/common/constants.ts +++ b/x-pack/plugins/maps/common/constants.ts @@ -4,8 +4,11 @@ * you may not use this file except in compliance with the Elastic License. */ -// NP Migration -// Temporarily redundant with x-pack/legacy/plugins/maps/common/constants.ts +/* + * 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 { i18n } from '@kbn/i18n'; export const EMS_CATALOGUE_PATH = 'ems/catalogue'; @@ -58,10 +61,10 @@ export const ES_SEARCH = 'ES_SEARCH'; export const ES_PEW_PEW = 'ES_PEW_PEW'; export const EMS_XYZ = 'EMS_XYZ'; // identifies a custom TMS source. Name is a little unfortunate. -export const FIELD_ORIGIN = { - SOURCE: 'source', - JOIN: 'join', -}; +export enum FIELD_ORIGIN { + SOURCE = 'source', + JOIN = 'join', +} export const SOURCE_DATA_ID_ORIGIN = 'source'; export const META_ID_ORIGIN_SUFFIX = 'meta'; @@ -142,6 +145,8 @@ export enum GRID_RESOLUTION { MOST_FINE = 'MOST_FINE', } +export const TOP_TERM_PERCENTAGE_SUFFIX = '__percentage'; + export const COUNT_PROP_LABEL = i18n.translate('xpack.maps.aggs.defaultCountLabel', { defaultMessage: 'count', }); @@ -166,11 +171,18 @@ export const COLOR_MAP_TYPE = { export const COLOR_PALETTE_MAX_SIZE = 10; export const CATEGORICAL_DATA_TYPES = ['string', 'ip', 'boolean']; +export const ORDINAL_DATA_TYPES = ['number', 'date']; -export const SYMBOLIZE_AS_TYPES = { - CIRCLE: 'circle', - ICON: 'icon', -}; +export enum SYMBOLIZE_AS_TYPES { + CIRCLE = 'circle', + ICON = 'icon', +} + +export enum LABEL_BORDER_SIZES { + NONE = 'NONE', + SMALL = 'SMALL', + MEDIUM = 'MEDIUM', + LARGE = 'LARGE', +} export const DEFAULT_ICON = 'airfield'; -// End temporary redundancy diff --git a/x-pack/plugins/maps/common/i18n_getters.ts b/x-pack/plugins/maps/common/i18n_getters.ts index e7296c807b0652..0008a119f1c7cc 100644 --- a/x-pack/plugins/maps/common/i18n_getters.ts +++ b/x-pack/plugins/maps/common/i18n_getters.ts @@ -9,8 +9,6 @@ import { i18n } from '@kbn/i18n'; import { $Values } from '@kbn/utility-types'; import { ES_SPATIAL_RELATIONS } from './constants'; -// NP Migration -// Temporarily redundant with x-pack/legacy/plugins/maps/common/i18n_getters.ts export function getAppTitle() { return i18n.translate('xpack.maps.appTitle', { defaultMessage: 'Maps', @@ -52,4 +50,3 @@ export function getEsSpatialRelationLabel(spatialRelation: $Values { @@ -22,4 +20,3 @@ export async function parseXmlString(xmlString) { return await parsePromise; } -// End temporary redundancy diff --git a/x-pack/plugins/maps/common/parse_xml_string.test.js b/x-pack/plugins/maps/common/parse_xml_string.test.js index bee8625f1aeac2..cfd6235667aae1 100644 --- a/x-pack/plugins/maps/common/parse_xml_string.test.js +++ b/x-pack/plugins/maps/common/parse_xml_string.test.js @@ -6,8 +6,6 @@ import { parseXmlString } from './parse_xml_string'; -// NP Migration -// Temporarily redundant with x-pack/legacy/plugins/maps/common/parse_xml_string.test.js describe('parseXmlString', () => { it('Should parse xml string into JS object', async () => { const xmlAsObject = await parseXmlString('bar'); @@ -16,4 +14,3 @@ describe('parseXmlString', () => { }); }); }); -// End temporary redundancy diff --git a/x-pack/plugins/maps/public/actions/map_actions.js b/x-pack/plugins/maps/public/actions/map_actions.js index eddc5fcf924b97..13cb3d5f898601 100644 --- a/x-pack/plugins/maps/public/actions/map_actions.js +++ b/x-pack/plugins/maps/public/actions/map_actions.js @@ -4,8 +4,6 @@ * you may not use this file except in compliance with the Elastic License. */ -// NP Migration -// Temporarily redundant with x-pack/legacy/plugins/maps/public/actions/map_actions.js export const SET_SELECTED_LAYER = 'SET_SELECTED_LAYER'; export const SET_TRANSIENT_LAYER = 'SET_TRANSIENT_LAYER'; export const UPDATE_LAYER_ORDER = 'UPDATE_LAYER_ORDER'; @@ -28,7 +26,6 @@ export const TRIGGER_REFRESH_TIMER = 'TRIGGER_REFRESH_TIMER'; export const UPDATE_LAYER_PROP = 'UPDATE_LAYER_PROP'; export const UPDATE_LAYER_STYLE = 'UPDATE_LAYER_STYLE'; export const SET_LAYER_STYLE_META = 'SET_LAYER_STYLE_META'; -export const TOUCH_LAYER = 'TOUCH_LAYER'; export const UPDATE_SOURCE_PROP = 'UPDATE_SOURCE_PROP'; export const SET_REFRESH_CONFIG = 'SET_REFRESH_CONFIG'; export const SET_MOUSE_COORDINATES = 'SET_MOUSE_COORDINATES'; @@ -48,4 +45,3 @@ export const HIDE_TOOLBAR_OVERLAY = 'HIDE_TOOLBAR_OVERLAY'; export const HIDE_LAYER_CONTROL = 'HIDE_LAYER_CONTROL'; export const HIDE_VIEW_CONTROL = 'HIDE_VIEW_CONTROL'; export const SET_WAITING_FOR_READY_HIDDEN_LAYERS = 'SET_WAITING_FOR_READY_HIDDEN_LAYERS'; -// End temporary redundancy diff --git a/x-pack/plugins/maps/public/actions/ui_actions.js b/x-pack/plugins/maps/public/actions/ui_actions.js index b5caf4d75d6b18..59ae56c15056a0 100644 --- a/x-pack/plugins/maps/public/actions/ui_actions.js +++ b/x-pack/plugins/maps/public/actions/ui_actions.js @@ -4,8 +4,6 @@ * you may not use this file except in compliance with the Elastic License. */ -// NP Migration -// Temporarily redundant with x-pack/legacy/plugins/maps/public/actions/ui_actions.js export const UPDATE_FLYOUT = 'UPDATE_FLYOUT'; export const CLOSE_SET_VIEW = 'CLOSE_SET_VIEW'; export const OPEN_SET_VIEW = 'OPEN_SET_VIEW'; @@ -16,4 +14,3 @@ export const SET_OPEN_TOC_DETAILS = 'SET_OPEN_TOC_DETAILS'; export const SHOW_TOC_DETAILS = 'SHOW_TOC_DETAILS'; export const HIDE_TOC_DETAILS = 'HIDE_TOC_DETAILS'; export const UPDATE_INDEXING_STAGE = 'UPDATE_INDEXING_STAGE'; -// End temporary redundancy From 86d9b410ebd521a732bc8804178e21f65720e778 Mon Sep 17 00:00:00 2001 From: Aaron Caldwell Date: Wed, 11 Mar 2020 14:06:31 -0600 Subject: [PATCH 21/21] Remove remaining refernce and case for 'TOUCH_LAYER'. It's never used --- x-pack/plugins/maps/public/reducers/map.js | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/x-pack/plugins/maps/public/reducers/map.js b/x-pack/plugins/maps/public/reducers/map.js index 7e81fb03dd85be..7e07569b44b830 100644 --- a/x-pack/plugins/maps/public/reducers/map.js +++ b/x-pack/plugins/maps/public/reducers/map.js @@ -25,7 +25,6 @@ import { UPDATE_LAYER_STYLE, SET_LAYER_STYLE_META, SET_JOINS, - TOUCH_LAYER, UPDATE_SOURCE_PROP, SET_REFRESH_CONFIG, TRIGGER_REFRESH_TIMER, @@ -202,17 +201,6 @@ export function map(state = INITIAL_STATE, action) { return updateWithDataResponse(state, action); case LAYER_DATA_LOAD_ENDED: return updateWithDataResponse(state, action); - case TOUCH_LAYER: - //action to enforce a reflow of the styles - const layer = state.layerList.find(layer => layer.id === action.layerId); - if (!layer) { - return state; - } - const indexOfLayer = state.layerList.indexOf(layer); - const newLayer = { ...layer }; - const newLayerList = [...state.layerList]; - newLayerList[indexOfLayer] = newLayer; - return { ...state, layerList: newLayerList }; case MAP_READY: return { ...state, ready: true }; case MAP_DESTROYED: