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

[RUM Dashboard] Visitors by region map #77135

Merged
merged 26 commits into from
Sep 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
64bbd06
update
shahzad31 Sep 3, 2020
8b86367
Merge branch 'master' into visitor-breakdown-usability
shahzad31 Sep 4, 2020
e409714
update
shahzad31 Sep 4, 2020
48e3009
Merge branch 'master' into visitor-breakdown-usability
shahzad31 Sep 4, 2020
54e8176
update
shahzad31 Sep 4, 2020
caa2328
Merge branch 'master' into visitor-breakdown-usability
shahzad31 Sep 6, 2020
85549e0
update
shahzad31 Sep 6, 2020
5e41f85
Merge branch 'master' into visitor-breakdown-usability
shahzad31 Sep 7, 2020
e978f57
Merge branch 'master' into visitor-breakdown-usability
shahzad31 Sep 8, 2020
7f7025a
update
shahzad31 Sep 8, 2020
a9b56b8
Merge branch 'master' into visitor-breakdown-usability
shahzad31 Sep 8, 2020
31d7ca5
WIP
shahzad31 Sep 9, 2020
1ee8627
WIP
shahzad31 Sep 9, 2020
529a853
added filters to map
shahzad31 Sep 10, 2020
2edd2f2
added filters to map
shahzad31 Sep 10, 2020
fe90084
Merge branch 'master' into visitor-map
shahzad31 Sep 10, 2020
3b6a371
update
shahzad31 Sep 10, 2020
e103c08
added few tests
shahzad31 Sep 10, 2020
7d50ad9
added a simple story
shahzad31 Sep 10, 2020
e94d3cb
added snapshot
shahzad31 Sep 10, 2020
69687d4
added some constants
shahzad31 Sep 10, 2020
54a85be
remove extra type changes
shahzad31 Sep 10, 2020
abbd95b
hide filter action
shahzad31 Sep 10, 2020
ace12e5
Merge branch 'master' into visitor-map
elasticmachine Sep 14, 2020
5fa1e09
remove redundant file
shahzad31 Sep 14, 2020
92930d7
Merge branch 'visitor-map' of https://github.com/shahzad31/kibana int…
shahzad31 Sep 14, 2020
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
15 changes: 6 additions & 9 deletions x-pack/plugins/apm/kibana.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"apmOss",
"data",
"licensing",
"triggers_actions_ui"
"triggers_actions_ui",
"embeddable"
],
"optionalPlugins": [
"cloud",
Expand All @@ -22,17 +23,13 @@
],
"server": true,
"ui": true,
"configPath": [
"xpack",
"apm"
],
"extraPublicDirs": [
"public/style/variables"
],
"configPath": ["xpack", "apm"],
"extraPublicDirs": ["public/style/variables"],
"requiredBundles": [
"kibanaReact",
"kibanaUtils",
"observability",
"home"
"home",
"maps"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps add a comment that this is used by csm. This way we can remove it when csm is moved to a separate app.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JSON doesn't have comments.

]
}
17 changes: 13 additions & 4 deletions x-pack/plugins/apm/public/application/csmApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { LoadingIndicatorProvider } from '../context/LoadingIndicatorContext';
import { UrlParamsProvider } from '../context/UrlParamsContext';
import { useBreadcrumbs } from '../hooks/use_breadcrumbs';
import { ConfigSchema } from '../index';
import { ApmPluginSetupDeps } from '../plugin';
import { ApmPluginSetupDeps, ApmPluginStartDeps } from '../plugin';
import { createCallApmApi } from '../services/rest/createCallApmApi';
import { px, units } from '../style/variables';

Expand Down Expand Up @@ -70,11 +70,13 @@ export function CsmAppRoot({
deps,
history,
config,
corePlugins: { embeddable },
}: {
core: CoreStart;
deps: ApmPluginSetupDeps;
history: AppMountParameters['history'];
config: ConfigSchema;
corePlugins: ApmPluginStartDeps;
}) {
const i18nCore = core.i18n;
const plugins = deps;
Expand All @@ -86,7 +88,7 @@ export function CsmAppRoot({
return (
<RedirectAppLinks application={core.application}>
<ApmPluginContext.Provider value={apmPluginContextValue}>
<KibanaContextProvider services={{ ...core, ...plugins }}>
<KibanaContextProvider services={{ ...core, ...plugins, embeddable }}>
<i18nCore.Context>
<Router history={history}>
<UrlParamsProvider>
Expand All @@ -110,12 +112,19 @@ export const renderApp = (
core: CoreStart,
deps: ApmPluginSetupDeps,
{ element, history }: AppMountParameters,
config: ConfigSchema
config: ConfigSchema,
corePlugins: ApmPluginStartDeps
) => {
createCallApmApi(core.http);

ReactDOM.render(
<CsmAppRoot core={core} deps={deps} history={history} config={config} />,
<CsmAppRoot
core={core}
deps={deps}
history={history}
config={config}
corePlugins={corePlugins}
/>,
element
);
return () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ export function CoreVitalItem({
setInFocusInd(ind);
}}
/>
<EuiSpacer size="xl" />
</>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { PageLoadDistribution } from './PageLoadDistribution';
import { I18LABELS } from './translations';
import { VisitorBreakdown } from './VisitorBreakdown';
import { CoreVitals } from './CoreVitals';
import { VisitorBreakdownMap } from './VisitorBreakdownMap';

export function RumDashboard() {
return (
Expand Down Expand Up @@ -67,6 +68,9 @@ export function RumDashboard() {
<EuiFlexItem grow={3}>
<VisitorBreakdown />
</EuiFlexItem>
<EuiFlexItem grow={3}>
<VisitorBreakdownMap />
</EuiFlexItem>
</EuiFlexGroup>
</EuiPanel>
</EuiFlexItem>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
/*
* 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, { useEffect, useState, useRef } from 'react';
import uuid from 'uuid';
import styled from 'styled-components';

import {
MapEmbeddable,
MapEmbeddableInput,
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
} from '../../../../../../maps/public/embeddable';
import { MAP_SAVED_OBJECT_TYPE } from '../../../../../../maps/common/constants';
import { useKibana } from '../../../../../../../../src/plugins/kibana_react/public';
import {
ErrorEmbeddable,
ViewMode,
isErrorEmbeddable,
} from '../../../../../../../../src/plugins/embeddable/public';
import { getLayerList } from './LayerList';
import { useUrlParams } from '../../../../hooks/useUrlParams';
import { RenderTooltipContentParams } from '../../../../../../maps/public';
import { MapToolTip } from './MapToolTip';
import { useMapFilters } from './useMapFilters';
import { EmbeddableStart } from '../../../../../../../../src/plugins/embeddable/public';

const EmbeddedPanel = styled.div`
z-index: auto;
flex: 1;
display: flex;
flex-direction: column;
height: 100%;
position: relative;
.embPanel__content {
display: flex;
flex: 1 1 100%;
z-index: 1;
min-height: 0; // Absolute must for Firefox to scroll contents
}
&&& .mapboxgl-canvas {
animation: none !important;
}
`;

interface KibanaDeps {
embeddable: EmbeddableStart;
}
export function EmbeddedMapComponent() {
const { urlParams } = useUrlParams();

const { start, end, serviceName } = urlParams;

const mapFilters = useMapFilters();

const [embeddable, setEmbeddable] = useState<
MapEmbeddable | ErrorEmbeddable | undefined
>();

const embeddableRoot: React.RefObject<HTMLDivElement> = useRef<
HTMLDivElement
>(null);

const {
services: { embeddable: embeddablePlugin },
} = useKibana<KibanaDeps>();

if (!embeddablePlugin) {
throw new Error('Embeddable start plugin not found');
}
const factory: any = embeddablePlugin.getEmbeddableFactory(
MAP_SAVED_OBJECT_TYPE
);

const input: MapEmbeddableInput = {
id: uuid.v4(),
filters: mapFilters,
refreshConfig: {
value: 0,
pause: false,
},
viewMode: ViewMode.VIEW,
isLayerTOCOpen: false,
query: {
query: 'transaction.type : "page-load"',
language: 'kuery',
},
...(start && {
timeRange: {
from: new Date(start!).toISOString(),
to: new Date(end!).toISOString(),
},
}),
hideFilterActions: true,
};

function renderTooltipContent({
addFilters,
closeTooltip,
features,
isLocked,
getLayerName,
loadFeatureProperties,
loadFeatureGeometry,
}: RenderTooltipContentParams) {
const props = {
addFilters,
closeTooltip,
isLocked,
getLayerName,
loadFeatureProperties,
loadFeatureGeometry,
};

return <MapToolTip {...props} features={features} />;
}

useEffect(() => {
if (embeddable != null && serviceName) {
embeddable.updateInput({ filters: mapFilters });
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [mapFilters]);

// DateRange updated useEffect
useEffect(() => {
if (embeddable != null && start != null && end != null) {
const timeRange = {
from: new Date(start).toISOString(),
to: new Date(end).toISOString(),
};
embeddable.updateInput({ timeRange });
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [start, end]);

useEffect(() => {
async function setupEmbeddable() {
if (!factory) {
throw new Error('Map embeddable not found.');
}
const embeddableObject: any = await factory.create({
...input,
title: 'Visitors by region',
});

if (embeddableObject && !isErrorEmbeddable(embeddableObject)) {
embeddableObject.setRenderTooltipContent(renderTooltipContent);
await embeddableObject.setLayerList(getLayerList());
}

setEmbeddable(embeddableObject);
}

setupEmbeddable();

// we want this effect to execute exactly once after the component mounts
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

// We can only render after embeddable has already initialized
useEffect(() => {
if (embeddableRoot.current && embeddable) {
embeddable.render(embeddableRoot.current);
}
}, [embeddable, embeddableRoot]);

return (
<EmbeddedPanel>
<div
data-test-subj="xpack.apm.regionMap.embeddedPanel"
className="embPanel__content"
ref={embeddableRoot}
/>
</EmbeddedPanel>
);
}

EmbeddedMapComponent.displayName = 'EmbeddedMap';

export const EmbeddedMap = React.memo(EmbeddedMapComponent);
Loading