From a809660cd780a4868167507e747ea2ac1808ab2e Mon Sep 17 00:00:00 2001 From: Stacey Gammon Date: Thu, 26 Mar 2020 09:52:02 -0400 Subject: [PATCH] Address code review comments and update some usages in SIEM and uptime to the new types --- .../maps/public/actions/map_actions.d.ts | 24 ++++----- .../maps/public/actions/ui_actions.d.ts | 2 +- .../public/angular/get_initial_layers.d.ts | 2 +- .../connected_components/gis_map/index.d.ts | 6 ++- .../plugins/maps/public/embeddable/index.ts | 8 +++ .../maps/public/embeddable/map_embeddable.tsx | 54 +++++++++---------- .../embeddable/map_embeddable_factory.ts | 14 +++-- .../merge_input_with_saved_map.d.ts | 7 ++- x-pack/legacy/plugins/maps/public/index.ts | 2 + .../maps/public/selectors/map_selectors.d.ts | 4 +- .../maps/public/selectors/ui_selectors.d.ts | 2 +- .../components/embeddables/embedded_map.tsx | 3 +- .../embeddables/embedded_map_helpers.tsx | 6 +-- .../public/components/embeddables/types.ts | 19 ------- .../location_map/embeddables/embedded_map.tsx | 10 ++-- .../location_map/embeddables/types.ts | 31 ----------- x-pack/plugins/maps/public/index.ts | 2 + 17 files changed, 85 insertions(+), 111 deletions(-) create mode 100644 x-pack/legacy/plugins/maps/public/embeddable/index.ts delete mode 100644 x-pack/legacy/plugins/uptime/public/components/functional/location_map/embeddables/types.ts diff --git a/x-pack/legacy/plugins/maps/public/actions/map_actions.d.ts b/x-pack/legacy/plugins/maps/public/actions/map_actions.d.ts index 73681c6577fbe..0d13d21f9abdb 100644 --- a/x-pack/legacy/plugins/maps/public/actions/map_actions.d.ts +++ b/x-pack/legacy/plugins/maps/public/actions/map_actions.d.ts @@ -28,14 +28,14 @@ export function updateSourceProp( ): void; export interface MapCenter { - lat: string; - lon: string; - zoom: unknown; + lat: number; + lon: number; + zoom: number; } export function setGotoWithCenter(config: MapCenter): AnyAction; -export function replaceLayerList(layerList: unknown): AnyAction; +export function replaceLayerList(layerList: unknown[]): AnyAction; export interface QueryGroup { filters: Filter[]; @@ -48,23 +48,23 @@ export function setQuery(query: QueryGroup): AnyAction; export interface RefreshConfig { isPaused: boolean; - interval: unknown; + interval: number; } export function setRefreshConfig(config: RefreshConfig): AnyAction; export function disableScrollZoom(): AnyAction; -export function disableInteractive(disable: boolean): AnyAction; +export function disableInteractive(): AnyAction; -export function disableTooltipControl(disable: boolean): AnyAction; +export function disableTooltipControl(): AnyAction; -export function hideToolbarOverlay(hide: boolean): AnyAction; +export function hideToolbarOverlay(): AnyAction; -export function hideLayerControl(hide: boolean): AnyAction; +export function hideLayerControl(): AnyAction; -export function hideViewControl(hide: boolean): AnyAction; +export function hideViewControl(): AnyAction; -export function setHiddenLayers(layer: unknown): AnyAction; +export function setHiddenLayers(hiddenLayerIds: string[]): AnyAction; -export function addLayerWithoutDataSync(layer: unknown): AnyAction; +export function addLayerWithoutDataSync(layerDescriptor: unknown): AnyAction; diff --git a/x-pack/legacy/plugins/maps/public/actions/ui_actions.d.ts b/x-pack/legacy/plugins/maps/public/actions/ui_actions.d.ts index ead09b5d10ca1..233918847de08 100644 --- a/x-pack/legacy/plugins/maps/public/actions/ui_actions.d.ts +++ b/x-pack/legacy/plugins/maps/public/actions/ui_actions.d.ts @@ -6,7 +6,7 @@ import { AnyAction } from 'redux'; -export function setOpenTOCDetails(details: unknown): AnyAction; +export function setOpenTOCDetails(layerIds?: string[]): AnyAction; export function setIsLayerTOCOpen(open: boolean): AnyAction; diff --git a/x-pack/legacy/plugins/maps/public/angular/get_initial_layers.d.ts b/x-pack/legacy/plugins/maps/public/angular/get_initial_layers.d.ts index 6fc24e601cd70..920888404b97d 100644 --- a/x-pack/legacy/plugins/maps/public/angular/get_initial_layers.d.ts +++ b/x-pack/legacy/plugins/maps/public/angular/get_initial_layers.d.ts @@ -4,4 +4,4 @@ * you may not use this file except in compliance with the Elastic License. */ -export function getInitialLayers(layers?: unknown): unknown[]; +export function getInitialLayers(layerListJSON?: string, initialLayers?: unknown[]): unknown[]; diff --git a/x-pack/legacy/plugins/maps/public/connected_components/gis_map/index.d.ts b/x-pack/legacy/plugins/maps/public/connected_components/gis_map/index.d.ts index 8079396162953..56b24cb6d2af0 100644 --- a/x-pack/legacy/plugins/maps/public/connected_components/gis_map/index.d.ts +++ b/x-pack/legacy/plugins/maps/public/connected_components/gis_map/index.d.ts @@ -5,5 +5,9 @@ */ import React from 'react'; +import { Filter } from 'src/plugins/data/public'; -export const GisMap: React.FC<{ addFilters: unknown; renderTooltipContent: unknown }>; +export const GisMap: React.ComponentType<{ + addFilters: ((filters: Filter[]) => void) | null; + renderTooltipContent?: (params: unknown) => React.ComponentType; +}>; diff --git a/x-pack/legacy/plugins/maps/public/embeddable/index.ts b/x-pack/legacy/plugins/maps/public/embeddable/index.ts new file mode 100644 index 0000000000000..a410a6699a01f --- /dev/null +++ b/x-pack/legacy/plugins/maps/public/embeddable/index.ts @@ -0,0 +1,8 @@ +/* + * 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 * from './map_embeddable'; +export * from './map_embeddable_factory'; diff --git a/x-pack/legacy/plugins/maps/public/embeddable/map_embeddable.tsx b/x-pack/legacy/plugins/maps/public/embeddable/map_embeddable.tsx index 25d059613f36b..f29674c8bab06 100644 --- a/x-pack/legacy/plugins/maps/public/embeddable/map_embeddable.tsx +++ b/x-pack/legacy/plugins/maps/public/embeddable/map_embeddable.tsx @@ -62,37 +62,37 @@ interface MapConfig { indexPatterns: IIndexPattern[]; editable: boolean; title?: string; - layerList: unknown; + layerList: unknown[]; } -export interface MapInput extends EmbeddableInput { +export interface MapEmbeddableInput extends EmbeddableInput { timeRange?: TimeRange; filters: Filter[]; query?: Query; - refresh: unknown; + refresh?: unknown; refreshConfig: RefreshInterval; isLayerTOCOpen: boolean; - openTOCDetails: unknown; - disableTooltipControl: boolean; - disableInteractive: boolean; - hideToolbarOverlay: boolean; - hideLayerControl: boolean; - hideViewControl: boolean; - mapCenter: MapCenter; - hiddenLayers: unknown; - hideFilterActions: boolean; + openTOCDetails?: string[]; + disableTooltipControl?: boolean; + disableInteractive?: boolean; + hideToolbarOverlay?: boolean; + hideLayerControl?: boolean; + hideViewControl?: boolean; + mapCenter?: MapCenter; + hiddenLayers?: string[]; + hideFilterActions?: boolean; } export interface MapOutput extends EmbeddableOutput { indexPatterns: IIndexPattern[]; } -export class MapEmbeddable extends Embeddable { +export class MapEmbeddable extends Embeddable { type = MAP_SAVED_OBJECT_TYPE; - private _renderTooltipContent?: unknown; + private _renderTooltipContent?: (params: unknown) => React.ComponentType; private _eventHandlers?: unknown; - private _layerList: unknown; + private _layerList: unknown[]; private _store: MapStore; private _subscription: Subscription; private _prevTimeRange?: TimeRange; @@ -104,9 +104,9 @@ export class MapEmbeddable extends Embeddable { constructor( config: MapConfig, - initialInput: MapInput, + initialInput: MapEmbeddableInput, parent?: IContainer, - renderTooltipContent?: unknown, + renderTooltipContent?: (params: unknown) => React.ComponentType, eventHandlers?: unknown ) { super( @@ -132,7 +132,7 @@ export class MapEmbeddable extends Embeddable { return getInspectorAdapters(this._store.getState()); } - onContainerStateChanged(containerState: MapInput) { + onContainerStateChanged(containerState: MapEmbeddableInput) { if ( !_.isEqual(containerState.timeRange, this._prevTimeRange) || !_.isEqual(containerState.query, this._prevQuery) || @@ -151,7 +151,7 @@ export class MapEmbeddable extends Embeddable { timeRange, filters, refresh, - }: Pick) { + }: Pick) { this._prevTimeRange = timeRange; this._prevQuery = query; this._prevFilters = filters; @@ -165,7 +165,7 @@ export class MapEmbeddable extends Embeddable { ); } - _dispatchSetRefreshConfig({ refreshConfig }: Pick) { + _dispatchSetRefreshConfig({ refreshConfig }: Pick) { this._prevRefreshConfig = refreshConfig; this._store.dispatch( setRefreshConfig({ @@ -194,22 +194,22 @@ export class MapEmbeddable extends Embeddable { } if (_.has(this.input, 'disableInteractive') && this.input.disableInteractive) { - this._store.dispatch(disableInteractive(this.input.disableInteractive)); + this._store.dispatch(disableInteractive()); } if (_.has(this.input, 'disableTooltipControl') && this.input.disableTooltipControl) { - this._store.dispatch(disableTooltipControl(this.input.disableTooltipControl)); + this._store.dispatch(disableTooltipControl()); } if (_.has(this.input, 'hideToolbarOverlay') && this.input.hideToolbarOverlay) { - this._store.dispatch(hideToolbarOverlay(this.input.hideToolbarOverlay)); + this._store.dispatch(hideToolbarOverlay()); } if (_.has(this.input, 'hideLayerControl') && this.input.hideLayerControl) { - this._store.dispatch(hideLayerControl(this.input.hideLayerControl)); + this._store.dispatch(hideLayerControl()); } if (_.has(this.input, 'hideViewControl') && this.input.hideViewControl) { - this._store.dispatch(hideViewControl(this.input.hideViewControl)); + this._store.dispatch(hideViewControl()); } if (this.input.mapCenter) { @@ -248,7 +248,7 @@ export class MapEmbeddable extends Embeddable { }); } - async setLayerList(layerList: unknown) { + async setLayerList(layerList: unknown[]) { this._layerList = layerList; return await this._store.dispatch(replaceLayerList(this._layerList)); } @@ -288,7 +288,7 @@ export class MapEmbeddable extends Embeddable { const center = getMapCenter(this._store.getState()); const zoom = getMapZoom(this._store.getState()); - const mapCenter = this.input.mapCenter || {}; + const mapCenter = this.input.mapCenter || undefined; if ( !mapCenter || mapCenter.lat !== center.lat || diff --git a/x-pack/legacy/plugins/maps/public/embeddable/map_embeddable_factory.ts b/x-pack/legacy/plugins/maps/public/embeddable/map_embeddable_factory.ts index d0d519d0d7e80..c65552851617f 100644 --- a/x-pack/legacy/plugins/maps/public/embeddable/map_embeddable_factory.ts +++ b/x-pack/legacy/plugins/maps/public/embeddable/map_embeddable_factory.ts @@ -17,7 +17,7 @@ import { IContainer, } 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, MapInput } from './map_embeddable'; +import { MapEmbeddable, MapEmbeddableInput } from './map_embeddable'; import { getIndexPatternService } from '../kibana_services'; import { createMapPath, MAP_SAVED_OBJECT_TYPE, APP_ICON } from '../../common/constants'; @@ -99,7 +99,11 @@ export class MapEmbeddableFactory extends EmbeddableFactory { return await savedObjectLoader.get(savedObjectId); } - async createFromSavedObject(savedObjectId: string, input: MapInput, parent?: IContainer) { + async createFromSavedObject( + savedObjectId: string, + input: MapEmbeddableInput, + parent?: IContainer + ) { const savedMap = await this._fetchSavedMap(savedObjectId); const layerList = getInitialLayers(savedMap.layerListJSON); const indexPatterns = await this._getIndexPatterns(layerList); @@ -131,9 +135,9 @@ export class MapEmbeddableFactory extends EmbeddableFactory { async createFromState( state: { title?: string; layerList?: unknown[] }, - input: MapInput, + input: MapEmbeddableInput, parent: IContainer, - renderTooltipContent: unknown, + renderTooltipContent: (params: unknown) => React.ComponentType, eventHandlers: unknown ) { const layerList = state && state.layerList ? state.layerList : getInitialLayers(); @@ -153,7 +157,7 @@ export class MapEmbeddableFactory extends EmbeddableFactory { ); } - async create(input: MapInput) { + async create(input: MapEmbeddableInput) { window.location.href = chrome.addBasePath(createMapPath('')); return new ErrorEmbeddable( 'Maps can only be created with createFromSavedObject or createFromState', diff --git a/x-pack/legacy/plugins/maps/public/embeddable/merge_input_with_saved_map.d.ts b/x-pack/legacy/plugins/maps/public/embeddable/merge_input_with_saved_map.d.ts index d7eff790b82a1..4ce4df02f6a39 100644 --- a/x-pack/legacy/plugins/maps/public/embeddable/merge_input_with_saved_map.d.ts +++ b/x-pack/legacy/plugins/maps/public/embeddable/merge_input_with_saved_map.d.ts @@ -4,6 +4,9 @@ * you may not use this file except in compliance with the Elastic License. */ -import { MapInput } from './map_embeddable'; +import { MapEmbeddableInput } from './map_embeddable'; -export function mergeInputWithSavedMap(input: MapInput, savedmap: unknown): Partial; +export function mergeInputWithSavedMap( + input: MapEmbeddableInput, + savedmap: unknown +): Partial; diff --git a/x-pack/legacy/plugins/maps/public/index.ts b/x-pack/legacy/plugins/maps/public/index.ts index 27cd64103eec9..fa33a1c1852d8 100644 --- a/x-pack/legacy/plugins/maps/public/index.ts +++ b/x-pack/legacy/plugins/maps/public/index.ts @@ -25,3 +25,5 @@ import { MapsPlugin } from './plugin'; export const plugin = (initializerContext: PluginInitializerContext) => { return new MapsPlugin(); }; + +export { MapEmbeddable, MapEmbeddableInput } from './embeddable'; diff --git a/x-pack/legacy/plugins/maps/public/selectors/map_selectors.d.ts b/x-pack/legacy/plugins/maps/public/selectors/map_selectors.d.ts index 86c819693a35c..c22c60853b75b 100644 --- a/x-pack/legacy/plugins/maps/public/selectors/map_selectors.d.ts +++ b/x-pack/legacy/plugins/maps/public/selectors/map_selectors.d.ts @@ -7,9 +7,9 @@ import { AnyAction } from 'redux'; import { MapCenter } from '../actions/map_actions'; -export function getHiddenLayerIds(config: unknown): AnyAction; +export function getHiddenLayerIds(config: unknown): string[]; -export function getMapZoom(config: unknown): unknown; +export function getMapZoom(config: unknown): number; export function getMapCenter(config: unknown): MapCenter; diff --git a/x-pack/legacy/plugins/maps/public/selectors/ui_selectors.d.ts b/x-pack/legacy/plugins/maps/public/selectors/ui_selectors.d.ts index 7d66e55602238..812e2082241bd 100644 --- a/x-pack/legacy/plugins/maps/public/selectors/ui_selectors.d.ts +++ b/x-pack/legacy/plugins/maps/public/selectors/ui_selectors.d.ts @@ -4,6 +4,6 @@ * you may not use this file except in compliance with the Elastic License. */ -export function getOpenTOCDetails(state: unknown): unknown; +export function getOpenTOCDetails(state: unknown): string[]; export function getIsLayerTOCOpen(state: unknown): boolean; diff --git a/x-pack/legacy/plugins/siem/public/components/embeddables/embedded_map.tsx b/x-pack/legacy/plugins/siem/public/components/embeddables/embedded_map.tsx index d0b1d8ffcb5ae..a3c4a655a4937 100644 --- a/x-pack/legacy/plugins/siem/public/components/embeddables/embedded_map.tsx +++ b/x-pack/legacy/plugins/siem/public/components/embeddables/embedded_map.tsx @@ -22,7 +22,8 @@ import { createEmbeddable, findMatchingIndexPatterns } from './embedded_map_help import { IndexPatternsMissingPrompt } from './index_patterns_missing_prompt'; import { MapToolTip } from './map_tool_tip/map_tool_tip'; import * as i18n from './translations'; -import { MapEmbeddable, SetQuery } from './types'; +import { SetQuery } from './types'; +import { MapEmbeddable } from '../../../../../plugins/maps/public'; import { Query, Filter } from '../../../../../../../src/plugins/data/public'; import { useKibana, useUiSetting$ } from '../../lib/kibana'; import { getSavedObjectFinder } from '../../../../../../../src/plugins/saved_objects/public'; diff --git a/x-pack/legacy/plugins/siem/public/components/embeddables/embedded_map_helpers.tsx b/x-pack/legacy/plugins/siem/public/components/embeddables/embedded_map_helpers.tsx index 888df8447a728..bf2f95a071d1f 100644 --- a/x-pack/legacy/plugins/siem/public/components/embeddables/embedded_map_helpers.tsx +++ b/x-pack/legacy/plugins/siem/public/components/embeddables/embedded_map_helpers.tsx @@ -9,10 +9,10 @@ import React from 'react'; import { OutPortal, PortalNode } from 'react-reverse-portal'; import minimatch from 'minimatch'; import { ViewMode } from '../../../../../../../src/legacy/core_plugins/embeddable_api/public/np_ready/public'; -import { IndexPatternMapping, MapEmbeddable, RenderTooltipContentParams, SetQuery } from './types'; +import { IndexPatternMapping, RenderTooltipContentParams, SetQuery } from './types'; import { getLayerList } from './map_config'; -// @ts-ignore Missing type defs as maps moves to Typescript -import { MAP_SAVED_OBJECT_TYPE } from '../../../../maps/common/constants'; +import { MAP_SAVED_OBJECT_TYPE } from '../../../../../../plugins/maps/public'; +import { MapEmbeddable } from '../../../../maps/public'; import * as i18n from './translations'; import { Query, Filter } from '../../../../../../../src/plugins/data/public'; import { EmbeddableStart } from '../../../../../../../src/plugins/embeddable/public'; diff --git a/x-pack/legacy/plugins/siem/public/components/embeddables/types.ts b/x-pack/legacy/plugins/siem/public/components/embeddables/types.ts index cc253beb08eae..cc1cbc5e0f6a0 100644 --- a/x-pack/legacy/plugins/siem/public/components/embeddables/types.ts +++ b/x-pack/legacy/plugins/siem/public/components/embeddables/types.ts @@ -4,26 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import { TimeRange } from 'src/plugins/data/public'; -import { - EmbeddableInput, - EmbeddableOutput, - IEmbeddable, -} from '../../../../../../../src/legacy/core_plugins/embeddable_api/public/np_ready/public'; import { inputsModel } from '../../store/inputs'; -import { Query, Filter } from '../../../../../../../src/plugins/data/public'; - -export interface MapEmbeddableInput extends EmbeddableInput { - filters: Filter[]; - query: Query; - refreshConfig: { - isPaused: boolean; - interval: number; - }; - timeRange?: TimeRange; -} - -export type MapEmbeddable = IEmbeddable; export interface IndexPatternMapping { title: string; diff --git a/x-pack/legacy/plugins/uptime/public/components/functional/location_map/embeddables/embedded_map.tsx b/x-pack/legacy/plugins/uptime/public/components/functional/location_map/embeddables/embedded_map.tsx index 11f6565734782..eba17a0bb21a8 100644 --- a/x-pack/legacy/plugins/uptime/public/components/functional/location_map/embeddables/embedded_map.tsx +++ b/x-pack/legacy/plugins/uptime/public/components/functional/location_map/embeddables/embedded_map.tsx @@ -8,13 +8,13 @@ import React, { useEffect, useState, useContext, useRef } from 'react'; import uuid from 'uuid'; import styled from 'styled-components'; +import { ViewMode } from 'src/plugins/embeddable/public'; import { start } from '../../../../../../../../../src/legacy/core_plugins/embeddable_api/public/np_ready/public/legacy'; import * as i18n from './translations'; -// @ts-ignore -import { MAP_SAVED_OBJECT_TYPE } from '../../../../../../maps/common/constants'; +import { MapEmbeddable, MapEmbeddableInput } from '../../../../../../maps/public'; +import { MAP_SAVED_OBJECT_TYPE } from '../../../../../../../../plugins/maps/public'; import { Location } from '../../../../../common/runtime_types'; -import { MapEmbeddable } from './types'; import { getLayerList } from './map_config'; import { UptimeThemeContext } from '../../../../contexts'; @@ -49,7 +49,7 @@ export const EmbeddedMap = React.memo(({ upPoints, downPoints }: EmbeddedMapProp const embeddableRoot: React.RefObject = useRef(null); const factory = start.getEmbeddableFactory(MAP_SAVED_OBJECT_TYPE); - const input = { + const input: MapEmbeddableInput = { id: uuid.v4(), filters: [], hidePanelTitles: true, @@ -57,7 +57,7 @@ export const EmbeddedMap = React.memo(({ upPoints, downPoints }: EmbeddedMapProp value: 0, pause: false, }, - viewMode: 'view', + viewMode: ViewMode.VIEW, isLayerTOCOpen: false, hideFilterActions: true, // Zoom Lat/Lon values are set to make sure map is in center in the panel diff --git a/x-pack/legacy/plugins/uptime/public/components/functional/location_map/embeddables/types.ts b/x-pack/legacy/plugins/uptime/public/components/functional/location_map/embeddables/types.ts deleted file mode 100644 index 03cb33c3459d2..0000000000000 --- a/x-pack/legacy/plugins/uptime/public/components/functional/location_map/embeddables/types.ts +++ /dev/null @@ -1,31 +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 { Query } from 'src/plugins/data/common'; -import { TimeRange } from 'src/plugins/data/public'; -import { - EmbeddableInput, - EmbeddableOutput, - IEmbeddable, -} from '../../../../../../../../../src/legacy/core_plugins/embeddable_api/public/np_ready/public'; - -import { Filter } from '../../../../../../../../../src/plugins/data/public'; - -export interface MapEmbeddableInput extends EmbeddableInput { - filters: Filter[]; - query: Query; - refreshConfig: { - isPaused: boolean; - interval: number; - }; - timeRange?: TimeRange; -} - -export interface CustomProps { - setLayerList: Function; -} - -export type MapEmbeddable = IEmbeddable & CustomProps; diff --git a/x-pack/plugins/maps/public/index.ts b/x-pack/plugins/maps/public/index.ts index c465700a4f9c5..e3feb47691877 100644 --- a/x-pack/plugins/maps/public/index.ts +++ b/x-pack/plugins/maps/public/index.ts @@ -10,3 +10,5 @@ import { MapsPlugin, MapsPluginSetup, MapsPluginStart } from './plugin'; export const plugin: PluginInitializer = () => { return new MapsPlugin(); }; + +export { MAP_SAVED_OBJECT_TYPE } from '../common/constants';