Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@
* 2.0.
*/

import type { ObservabilityOnboardingLocatorParams } from '@kbn/deeplinks-observability';
import { i18n } from '@kbn/i18n';
import type { AddDataPanelProps } from '@kbn/observability-shared-plugin/public';
import type { LocatorPublic } from '@kbn/share-plugin/common';
import {
ApmOnboardingLocatorCategory,
ApmOnboardingLocatorParams,
} from '../../../locator/onboarding_locator';

export type AddAPMCalloutKeys =
| 'serviceOverview'
Expand All @@ -19,13 +22,11 @@ export type AddAPMCalloutKeys =
| 'metrics'
| 'errorGroupOverview';

const defaultActions = (
locator: LocatorPublic<ObservabilityOnboardingLocatorParams> | undefined
) => {
const defaultActions = (locator: LocatorPublic<ApmOnboardingLocatorParams> | undefined) => {
return {
actions: {
primary: {
href: locator?.getRedirectUrl({ category: 'application' }),
href: locator?.getRedirectUrl({ category: ApmOnboardingLocatorCategory.Apm }),
label: i18n.translate('xpack.apm.serviceTabEmptyState.defaultPrimaryActionLabel', {
defaultMessage: 'Add APM',
}),
Expand All @@ -42,7 +43,7 @@ const defaultActions = (

export const addAPMCalloutDefinitions = (
baseFolderPath: string,
locator: LocatorPublic<ObservabilityOnboardingLocatorParams> | undefined
locator: LocatorPublic<ApmOnboardingLocatorParams> | undefined
): Record<
AddAPMCalloutKeys,
Omit<AddDataPanelProps, 'onDismiss' | 'onAddData' | 'onLearnMore' | 'onTryIt'>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@
import React from 'react';
import { useKibana } from '@kbn/kibana-react-plugin/public';
import { AddDataPanel } from '@kbn/observability-shared-plugin/public';
import {
OBSERVABILITY_ONBOARDING_LOCATOR,
ObservabilityOnboardingLocatorParams,
} from '@kbn/deeplinks-observability';
import { OBSERVABILITY_ONBOARDING_LOCATOR } from '@kbn/deeplinks-observability';
import { ApmOnboardingLocatorParams } from '../../../locator/onboarding_locator';
import { useApmPluginContext } from '../../../context/apm_plugin/use_apm_plugin_context';
import { EmptyStateClickParams, EntityInventoryAddDataParams } from '../../../services/telemetry';
import { ApmPluginStartDeps, ApmServices } from '../../../plugin';
Expand Down Expand Up @@ -39,7 +37,7 @@ export function ServiceTabEmptyState({ id, onDismiss }: ServiceTabEmptyStateProp

const { share } = useApmPluginContext();

const onboardingLocator = share.url.locators.get<ObservabilityOnboardingLocatorParams>(
const onboardingLocator = share.url.locators.get<ApmOnboardingLocatorParams>(
OBSERVABILITY_ONBOARDING_LOCATOR
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import {
} from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import React, { useState } from 'react';
import { OBSERVABILITY_ONBOARDING_LOCATOR } from '@kbn/deeplinks-observability';
import { ApmOnboardingLocatorParams } from '../../../../locator/onboarding_locator';
import { useApmPluginContext } from '../../../../context/apm_plugin/use_apm_plugin_context';
import { useKibana } from '../../../../context/kibana_context/use_kibana';
import { ApmPluginStartDeps, ApmServices } from '../../../../plugin';
Expand All @@ -34,8 +36,17 @@ export function AddDataContextMenu() {
core: {
http: { basePath },
},
share: {
url: { locators },
},
} = useApmPluginContext();

const onboardingLocator = locators.get<ApmOnboardingLocatorParams>(
OBSERVABILITY_ONBOARDING_LOCATOR
);

const addApmButtonData = addApmData(onboardingLocator);

const button = (
<EuiHeaderLink
color="text"
Expand Down Expand Up @@ -77,15 +88,19 @@ export function AddDataContextMenu() {
reportButtonClick('collect_new_service_logs');
},
},
{
name: addApmData.name,
href: basePath.prepend(addApmData.link),
icon: 'plusInCircle',
'data-test-subj': 'apmAddDataApmAgent',
onClick: () => {
reportButtonClick('add_apm_agent');
},
},
...(addApmButtonData.link
? [
{
name: addApmButtonData.name,
href: addApmButtonData.link,
icon: 'plusInCircle',
'data-test-subj': 'apmAddDataApmAgent',
onClick: () => {
reportButtonClick('add_apm_agent');
},
},
]
: []),
],
},
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,21 @@
import { EuiButton, EuiButtonSize } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import React from 'react';
import { OBSERVABILITY_ONBOARDING_LOCATOR } from '@kbn/deeplinks-observability';
import { LocatorPublic } from '@kbn/share-plugin/common';
import { useApmPluginContext } from '../../../context/apm_plugin/use_apm_plugin_context';
import {
ApmOnboardingLocatorCategory,
ApmOnboardingLocatorParams,
} from '../../../locator/onboarding_locator';

export const addApmData = {
name: i18n.translate('xpack.apm.add.apm.agent.button.', {
defaultMessage: 'Add APM',
}),
link: '/app/observabilityOnboarding/?category=apm',
export const addApmData = (locator: LocatorPublic<ApmOnboardingLocatorParams> | undefined) => {
return {
name: i18n.translate('xpack.apm.add.apm.agent.button.', {
defaultMessage: 'Add APM',
}),
link: locator?.getRedirectUrl({ category: ApmOnboardingLocatorCategory.Apm }),
};
};

export const associateServiceLogs = {
Expand All @@ -42,19 +50,32 @@ interface AddApmDataProps {
}

export function AddApmData({ fill = false, size = 's', ...props }: AddApmDataProps) {
const { core } = useApmPluginContext();
const { basePath } = core.http;
const {
share: {
url: { locators },
},
} = useApmPluginContext();

const onboardingLocator = locators.get<ApmOnboardingLocatorParams>(
OBSERVABILITY_ONBOARDING_LOCATOR
);

const addApmButtonData = addApmData(onboardingLocator);

return (
<EuiButton
data-test-subj={props['data-test-subj']}
size={size}
onClick={props.onClick}
href={basePath.prepend(addApmData.link)}
fill={fill}
>
{addApmData.name}
</EuiButton>
<>
{addApmButtonData.link && (
<EuiButton
data-test-subj={props['data-test-subj']}
size={size}
onClick={props.onClick}
href={addApmButtonData?.link}
fill={fill}
>
{addApmButtonData.name}
</EuiButton>
)}
</>
);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { ObservabilityOnboardingLocatorParams } from '@kbn/deeplinks-observability';

export enum ApmOnboardingLocatorCategory {
Apm = 'application',
}

export interface ApmOnboardingLocatorParams extends ObservabilityOnboardingLocatorParams {
category: ApmOnboardingLocatorCategory;
}