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

Add search deep links for APM, Metrics, Logs, and Dev Tools #96135

Merged
merged 5 commits into from
Apr 19, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 4 additions & 2 deletions src/plugins/dev_tools/public/dev_tool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* Side Public License, v 1.
*/

import { ReactNode } from 'react';
import { AppMount } from 'src/core/public';

/**
Expand All @@ -26,8 +27,9 @@ export class DevToolApp {
/**
* The human readable name of the dev tool. Should be internationalized.
* This will be used as a label in the tab above the actual tool.
* May also be a ReactNode.
*/
public readonly title: string;
public readonly title: ReactNode;
public readonly mount: AppMount;

/**
Expand Down Expand Up @@ -55,7 +57,7 @@ export class DevToolApp {

constructor(
id: string,
title: string,
title: ReactNode,
mount: AppMount,
enableRouting: boolean,
order: number,
Expand Down
16 changes: 15 additions & 1 deletion src/plugins/dev_tools/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import { BehaviorSubject } from 'rxjs';
import { Plugin, CoreSetup, AppMountParameters } from 'src/core/public';
import { Plugin, CoreSetup, AppMountParameters, AppSearchDeepLink } from 'src/core/public';
import { AppUpdater } from 'kibana/public';
import { i18n } from '@kbn/i18n';
import { sortBy } from 'lodash';
Expand Down Expand Up @@ -84,6 +84,20 @@ export class DevToolsPlugin implements Plugin<DevToolsSetup, void> {
public start() {
if (this.getSortedDevTools().length === 0) {
this.appStateUpdater.next(() => ({ navLinkStatus: AppNavLinkStatus.hidden }));
} else {
this.appStateUpdater.next(() => {
const deepLinks: AppSearchDeepLink[] = [...this.devTools.values()]
.filter(
// Some tools do not use a string title, so we filter those out
(tool) => !tool.enableRouting && !tool.isDisabled() && typeof tool.title === 'string'
)
.map((tool) => ({
id: tool.id,
title: tool.title as string,
path: `#/${tool.id}`,
Comment on lines +96 to +97
Copy link
Contributor

Choose a reason for hiding this comment

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

Why did you change DevToolApp.title from string to ReactNode to then forcecast it to string here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah that wasn't super clear was it. It's because there is a dev tool (Painless Lab) that is passing a component here to be rendered in the tabs UI. So I fixed the type on DevToolApp to be accurate and then filtered that dev tool out (for now) and casted this to a string.

}));
return { meta: { searchDeepLinks: deepLinks } };
});
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ export const routes: APMRouteDefinition[] = [
render: renderAsRedirectTo('/services'),
breadcrumb: 'APM',
},
// !! Need to be kept in sync with the searchDeepLinks in x-pack/plugins/apm/public/plugin.ts
{
exact: true,
path: '/services',
Expand All @@ -181,6 +182,7 @@ export const routes: APMRouteDefinition[] = [
defaultMessage: 'Services',
}),
},
// !! Need to be kept in sync with the searchDeepLinks in x-pack/plugins/apm/public/plugin.ts
{
exact: true,
path: '/traces',
Expand Down Expand Up @@ -326,6 +328,7 @@ export const routes: APMRouteDefinition[] = [
component: TraceLink,
breadcrumb: null,
},
// !! Need to be kept in sync with the searchDeepLinks in x-pack/plugins/apm/public/plugin.ts
sorenlouv marked this conversation as resolved.
Show resolved Hide resolved
{
exact: true,
path: '/service-map',
Expand Down
27 changes: 27 additions & 0 deletions x-pack/plugins/apm/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* 2.0.
*/

import { i18n } from '@kbn/i18n';
import type { ConfigSchema } from '.';
import {
AppMountParameters,
Expand Down Expand Up @@ -143,6 +144,32 @@ export class ApmPlugin implements Plugin<ApmPluginSetup, ApmPluginStart> {
appRoute: '/app/apm',
icon: 'plugins/apm/public/icon.svg',
category: DEFAULT_APP_CATEGORIES.observability,
meta: {
// !! Need to be kept in sync with the routes in x-pack/plugins/apm/public/components/app/Main/route_config/index.tsx
searchDeepLinks: [
{
id: 'services',
title: i18n.translate('xpack.apm.breadcrumb.servicesTitle', {
defaultMessage: 'Services',
}),
path: '/services',
},
{
id: 'traces',
title: i18n.translate('xpack.apm.breadcrumb.tracesTitle', {
defaultMessage: 'Traces',
}),
path: '/traces',
},
{
id: 'service-map',
title: i18n.translate('xpack.apm.breadcrumb.serviceMapTitle', {
defaultMessage: 'Service Map',
}),
path: '/service-map',
},
Comment on lines +150 to +170
Copy link
Member

Choose a reason for hiding this comment

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

If we implement a getDeepLink that pulls the necessary info from the routes obejct, we can probably replace this with something like:

Suggested change
{
id: 'services',
title: i18n.translate('xpack.apm.breadcrumb.servicesTitle', {
defaultMessage: 'Services',
}),
path: '/services',
},
{
id: 'traces',
title: i18n.translate('xpack.apm.breadcrumb.tracesTitle', {
defaultMessage: 'Traces',
}),
path: '/traces',
},
{
id: 'service-map',
title: i18n.translate('xpack.apm.breadcrumb.serviceMapTitle', {
defaultMessage: 'Service Map',
}),
path: '/service-map',
},
getDeepLink('services'),
getDeepLink('traces'),
getDeepLink('service-map'),

Not needed for this PR though.

],
},

async mount(params: AppMountParameters<unknown>) {
// Load application bundle and Get start services
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/infra/public/pages/logs/page_content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export const LogsPageContent: React.FunctionComponent = () => {
initialize();
});

// !! Need to be kept in sync with the searchDeepLinks in x-pack/plugins/infra/public/plugin.ts
const streamTab = {
app: 'logs',
title: streamTabTitle,
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/infra/public/pages/metrics/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ export const InfrastructurePage = ({ match }: RouteComponentProps) => {
>
<EuiFlexGroup gutterSize={'none'} alignItems={'center'}>
<EuiFlexItem>
{/** !! Need to be kept in sync with the searchDeepLinks in x-pack/plugins/infra/public/plugin.ts */}
<RoutedTabs
tabs={[
{
Expand Down
59 changes: 59 additions & 0 deletions x-pack/plugins/infra/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,39 @@ export class Plugin implements InfraClientPluginClass {
euiIconType: 'logoObservability',
order: 8100,
appRoute: '/app/logs',
meta: {
// !! Need to be kept in sync with the routes in x-pack/plugins/infra/public/pages/logs/page_content.tsx
searchDeepLinks: [
{
id: 'stream',
title: i18n.translate('xpack.infra.logs.index.streamTabTitle', {
defaultMessage: 'Stream',
}),
path: '/stream',
},
{
id: 'anomalies',
title: i18n.translate('xpack.infra.logs.index.anomaliesTabTitle', {
defaultMessage: 'Anomalies',
}),
path: '/anomalies',
},
{
id: 'log-categories',
title: i18n.translate('xpack.infra.logs.index.logCategoriesBetaBadgeTitle', {
defaultMessage: 'Categories',
}),
path: '/log-categories',
},
{
id: 'settings',
title: i18n.translate('xpack.infra.logs.index.settingsTabTitle', {
defaultMessage: 'Settings',
}),
path: '/settings',
},
],
},
category: DEFAULT_APP_CATEGORIES.observability,
mount: async (params: AppMountParameters) => {
// mount callback should not use setup dependencies, get start dependencies instead
Expand All @@ -82,6 +115,32 @@ export class Plugin implements InfraClientPluginClass {
order: 8200,
appRoute: '/app/metrics',
category: DEFAULT_APP_CATEGORIES.observability,
meta: {
// !! Need to be kept in sync with the routes in x-pack/plugins/infra/public/pages/metrics/index.tsx
searchDeepLinks: [
{
id: 'inventory',
title: i18n.translate('xpack.infra.homePage.inventoryTabTitle', {
defaultMessage: 'Inventory',
}),
path: '/inventory',
},
{
id: 'metrics-explorer',
title: i18n.translate('xpack.infra.homePage.metricsExplorerTabTitle', {
defaultMessage: 'Metrics Explorer',
}),
path: '/explorer',
},
{
id: 'settings',
title: i18n.translate('xpack.infra.homePage.settingsTabTitle', {
defaultMessage: 'Settings',
}),
path: '/settings',
},
],
},
mount: async (params: AppMountParameters) => {
// mount callback should not use setup dependencies, get start dependencies instead
const [coreStart, pluginsStart] = await core.getStartServices();
Expand Down