Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Maps] observability real user monitoring solution layer #64949

Merged
merged 27 commits into from
May 5, 2020
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions x-pack/plugins/maps/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export enum SOURCE_TYPES {
ES_GEO_GRID = 'ES_GEO_GRID',
ES_SEARCH = 'ES_SEARCH',
ES_PEW_PEW = 'ES_PEW_PEW',
ES_TERM_SOURCE = 'ES_TERM_SOURCE',
EMS_XYZ = 'EMS_XYZ', // identifies a custom TMS source. Name is a little unfortunate.
WMS = 'WMS',
KIBANA_TILEMAP = 'KIBANA_TILEMAP',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export type ESPewPewSourceDescriptor = AbstractESAggSourceDescriptor & {
export type ESTermSourceDescriptor = AbstractESAggSourceDescriptor & {
indexPatternTitle: string;
term: string; // term field name
whereQuery?: Query;
};

export type KibanaRegionmapSourceDescriptor = AbstractSourceDescriptor & {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { AGG_DELIMITER, AGG_TYPE, JOIN_FIELD_NAME_PREFIX } from './constants';
import { AGG_DELIMITER, AGG_TYPE, COUNT_PROP_NAME, JOIN_FIELD_NAME_PREFIX } from './constants';

// function in common since its needed by migration
export function getJoinAggKey({
aggType,
aggFieldName,
Expand All @@ -15,8 +14,18 @@ export function getJoinAggKey({
aggType: AGG_TYPE;
aggFieldName?: string;
rightSourceId: string;
}) {
}): string {
const metricKey =
aggType !== AGG_TYPE.COUNT ? `${aggType}${AGG_DELIMITER}${aggFieldName}` : aggType;
return `${JOIN_FIELD_NAME_PREFIX}${metricKey}__${rightSourceId}`;
}

export function getSourceAggKey({
aggType,
aggFieldName,
}: {
aggType: AGG_TYPE;
aggFieldName?: string;
}): string {
return aggType !== AGG_TYPE.COUNT ? `${aggType}${AGG_DELIMITER}${aggFieldName}` : COUNT_PROP_NAME;
}
2 changes: 1 addition & 1 deletion x-pack/plugins/maps/common/migrations/join_agg_key.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
LAYER_TYPE,
VECTOR_STYLES,
} from '../constants';
import { getJoinAggKey } from '../get_join_key';
import { getJoinAggKey } from '../get_agg_key';
import {
AggDescriptor,
JoinDescriptor,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@import 'gis_map/gis_map';
@import 'layer_addpanel/source_select/index';
@import 'layer_addpanel/index';
@import 'layer_panel/index';
@import 'widget_overlay/index';
@import 'toolbar_overlay/index';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* 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, Fragment } from 'react';
import { EuiSpacer, EuiCard, EuiIcon } from '@elastic/eui';
import { getLayerWizards, LayerWizard } from '../../layers/layer_wizard_registry';

interface Props {
onSelect: (layerWizard: LayerWizard) => void;
}

interface State {
layerWizards: LayerWizard[];
}

export class LayerWizardSelect extends Component<Props, State> {
private _isMounted: boolean = false;

state = {
layerWizards: [],
};

componentDidMount() {
this._isMounted = true;
this._loadLayerWizards();
}

componentWillUnmount() {
this._isMounted = false;
}

async _loadLayerWizards() {
const layerWizards = await getLayerWizards();
if (this._isMounted) {
this.setState({ layerWizards });
}
}

render() {
return this.state.layerWizards.map((layerWizard: LayerWizard) => {
const icon = layerWizard.icon ? <EuiIcon type={layerWizard.icon} size="l" /> : undefined;

const onClick = () => {
this.props.onSelect(layerWizard);
};

return (
<Fragment key={layerWizard.title}>
<EuiSpacer size="s" />
<EuiCard
className="mapLayerAddpanel__card"
title={layerWizard.title}
icon={icon}
onClick={onClick}
description={layerWizard.description}
layout="horizontal"
data-test-subj={_.camelCase(layerWizard.title)}
/>
</Fragment>
);
});
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

import React, { Component, Fragment } from 'react';
import { SourceSelect } from './source_select/source_select';
import { LayerWizardSelect } from './layer_wizard_select';
import { FlyoutFooter } from './flyout_footer';
import { ImportEditor } from './import_editor';
import { EuiButtonEmpty, EuiPanel, EuiTitle, EuiFlyoutHeader, EuiSpacer } from '@elastic/eui';
Expand Down Expand Up @@ -80,8 +80,8 @@ export class AddLayerPanel extends Component {
this.props.removeTransientLayer();
};

_onSourceSelectionChange = ({ layerWizard, isIndexingSource }) => {
this.setState({ layerWizard, importView: isIndexingSource });
_onWizardSelect = layerWizard => {
this.setState({ layerWizard, importView: !!layerWizard.isIndexingSource });
};

_layerAddHandler = () => {
Expand All @@ -100,7 +100,7 @@ export class AddLayerPanel extends Component {

_renderPanelBody() {
if (!this.state.layerWizard) {
return <SourceSelect updateSourceSelection={this._onSourceSelectionChange} />;
return <LayerWizardSelect onSelect={this._onWizardSelect} />;
}

const backButton = this.props.isIndexingTriggered ? null : (
Expand Down
22 changes: 17 additions & 5 deletions x-pack/plugins/maps/public/layers/layer_wizard_registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export type RenderWizardArguments = {
};

export type LayerWizard = {
checkVisibility?: () => boolean;
checkVisibility?: () => Promise<boolean>;
description: string;
icon: string;
isIndexingSource?: boolean;
Expand All @@ -31,11 +31,23 @@ export type LayerWizard = {
const registry: LayerWizard[] = [];

export function registerLayerWizard(layerWizard: LayerWizard) {
registry.push(layerWizard);
registry.push({
checkVisibility: async () => {
return true;
},
...layerWizard,
});
}

export function getLayerWizards(): LayerWizard[] {
return registry.filter(layerWizard => {
return layerWizard.checkVisibility ? layerWizard.checkVisibility() : true;
export async function getLayerWizards(): Promise<LayerWizard[]> {
const promises = registry.map(async layerWizard => {
return {
...layerWizard,
// @ts-ignore
isVisible: await layerWizard.checkVisibility(),
};
});
return (await Promise.all(promises)).filter(({ isVisible }) => {
return isVisible;
});
}
6 changes: 4 additions & 2 deletions x-pack/plugins/maps/public/layers/load_layer_wizards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,19 @@ import { tmsLayerWizardConfig } from './sources/xyz_tms_source';
// @ts-ignore
import { wmsLayerWizardConfig } from './sources/wms_source';
import { mvtVectorSourceWizardConfig } from './sources/mvt_single_layer_vector_source';
// @ts-ignore
import { ObservabilityLayerWizardConfig } from './solution_layers/observability';
import { getInjectedVarFunc } from '../kibana_services';

// Registration order determines display order
let registered = false;
export function registerLayerWizards() {
if (registered) {
return;
}

// Registration order determines display order
// @ts-ignore
registerLayerWizard(uploadLayerWizardConfig);
registerLayerWizard(ObservabilityLayerWizardConfig);
// @ts-ignore
registerLayerWizard(esDocumentsLayerWizardConfig);
// @ts-ignore
Expand Down
Loading