Skip to content

Commit

Permalink
Address code review comments and update some usages in SIEM and uptim…
Browse files Browse the repository at this point in the history
…e to the new types
  • Loading branch information
stacey-gammon committed Mar 26, 2020
1 parent ce18bb1 commit a809660
Show file tree
Hide file tree
Showing 17 changed files with 85 additions and 111 deletions.
24 changes: 12 additions & 12 deletions x-pack/legacy/plugins/maps/public/actions/map_actions.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
Expand All @@ -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;
2 changes: 1 addition & 1 deletion x-pack/legacy/plugins/maps/public/actions/ui_actions.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}>;
8 changes: 8 additions & 0 deletions x-pack/legacy/plugins/maps/public/embeddable/index.ts
Original file line number Diff line number Diff line change
@@ -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';
54 changes: 27 additions & 27 deletions x-pack/legacy/plugins/maps/public/embeddable/map_embeddable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<MapInput, MapOutput> {
export class MapEmbeddable extends Embeddable<MapEmbeddableInput, MapOutput> {
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;
Expand All @@ -104,9 +104,9 @@ export class MapEmbeddable extends Embeddable<MapInput, MapOutput> {

constructor(
config: MapConfig,
initialInput: MapInput,
initialInput: MapEmbeddableInput,
parent?: IContainer,
renderTooltipContent?: unknown,
renderTooltipContent?: (params: unknown) => React.ComponentType,
eventHandlers?: unknown
) {
super(
Expand All @@ -132,7 +132,7 @@ export class MapEmbeddable extends Embeddable<MapInput, MapOutput> {
return getInspectorAdapters(this._store.getState());
}

onContainerStateChanged(containerState: MapInput) {
onContainerStateChanged(containerState: MapEmbeddableInput) {
if (
!_.isEqual(containerState.timeRange, this._prevTimeRange) ||
!_.isEqual(containerState.query, this._prevQuery) ||
Expand All @@ -151,7 +151,7 @@ export class MapEmbeddable extends Embeddable<MapInput, MapOutput> {
timeRange,
filters,
refresh,
}: Pick<MapInput, 'query' | 'timeRange' | 'filters' | 'refresh'>) {
}: Pick<MapEmbeddableInput, 'query' | 'timeRange' | 'filters' | 'refresh'>) {
this._prevTimeRange = timeRange;
this._prevQuery = query;
this._prevFilters = filters;
Expand All @@ -165,7 +165,7 @@ export class MapEmbeddable extends Embeddable<MapInput, MapOutput> {
);
}

_dispatchSetRefreshConfig({ refreshConfig }: Pick<MapInput, 'refreshConfig'>) {
_dispatchSetRefreshConfig({ refreshConfig }: Pick<MapEmbeddableInput, 'refreshConfig'>) {
this._prevRefreshConfig = refreshConfig;
this._store.dispatch(
setRefreshConfig({
Expand Down Expand Up @@ -194,22 +194,22 @@ export class MapEmbeddable extends Embeddable<MapInput, MapOutput> {
}

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) {
Expand Down Expand Up @@ -248,7 +248,7 @@ export class MapEmbeddable extends Embeddable<MapInput, MapOutput> {
});
}

async setLayerList(layerList: unknown) {
async setLayerList(layerList: unknown[]) {
this._layerList = layerList;
return await this._store.dispatch(replaceLayerList(this._layerList));
}
Expand Down Expand Up @@ -288,7 +288,7 @@ export class MapEmbeddable extends Embeddable<MapInput, MapOutput> {
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 ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand All @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<MapInput>;
export function mergeInputWithSavedMap(
input: MapEmbeddableInput,
savedmap: unknown
): Partial<MapEmbeddableInput>;
2 changes: 2 additions & 0 deletions x-pack/legacy/plugins/maps/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,5 @@ import { MapsPlugin } from './plugin';
export const plugin = (initializerContext: PluginInitializerContext) => {
return new MapsPlugin();
};

export { MapEmbeddable, MapEmbeddableInput } from './embeddable';
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
19 changes: 0 additions & 19 deletions x-pack/legacy/plugins/siem/public/components/embeddables/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<MapEmbeddableInput, EmbeddableOutput>;

export interface IndexPatternMapping {
title: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -49,15 +49,15 @@ export const EmbeddedMap = React.memo(({ upPoints, downPoints }: EmbeddedMapProp
const embeddableRoot: React.RefObject<HTMLDivElement> = useRef<HTMLDivElement>(null);
const factory = start.getEmbeddableFactory(MAP_SAVED_OBJECT_TYPE);

const input = {
const input: MapEmbeddableInput = {
id: uuid.v4(),
filters: [],
hidePanelTitles: true,
refreshConfig: {
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
Expand Down
Loading

0 comments on commit a809660

Please sign in to comment.