From 5de1a5fe6ec5128bb43b4128c0941d18846de7f9 Mon Sep 17 00:00:00 2001 From: Nathan L Smith Date: Mon, 30 Mar 2020 18:34:23 -0500 Subject: [PATCH] Use docLinks API for APM doc links (#61880) * Use docLinks API for APM doc links Remove `packageInfo` (from ui/metadata package from the legacy platform) and replace with `core.dockLinks` in the `ElasticDocsLink` component. Fixes #56453 Fixes #60945 --- .../app/Home/__snapshots__/Home.test.tsx.snap | 14 ++++++++------ .../components/shared/Links/ElasticDocsLink.tsx | 9 ++++++--- .../ApmPluginContext/MockApmPluginContext.tsx | 5 ++++- .../apm/public/context/ApmPluginContext/index.tsx | 3 +-- .../plugins/apm/public/new-platform/plugin.tsx | 11 ----------- 5 files changed, 19 insertions(+), 23 deletions(-) diff --git a/x-pack/legacy/plugins/apm/public/components/app/Home/__snapshots__/Home.test.tsx.snap b/x-pack/legacy/plugins/apm/public/components/app/Home/__snapshots__/Home.test.tsx.snap index 88d9d7864576f..2b1f835a14f4a 100644 --- a/x-pack/legacy/plugins/apm/public/components/app/Home/__snapshots__/Home.test.tsx.snap +++ b/x-pack/legacy/plugins/apm/public/components/app/Home/__snapshots__/Home.test.tsx.snap @@ -15,6 +15,10 @@ exports[`Home component should render services 1`] = ` "chrome": Object { "setBreadcrumbs": [Function], }, + "docLinks": Object { + "DOC_LINK_VERSION": "0", + "ELASTIC_WEBSITE_URL": "https://www.elastic.co/", + }, "http": Object { "basePath": Object { "prepend": [Function], @@ -27,9 +31,6 @@ exports[`Home component should render services 1`] = ` }, }, }, - "packageInfo": Object { - "version": "0", - }, "plugins": Object {}, } } @@ -55,6 +56,10 @@ exports[`Home component should render traces 1`] = ` "chrome": Object { "setBreadcrumbs": [Function], }, + "docLinks": Object { + "DOC_LINK_VERSION": "0", + "ELASTIC_WEBSITE_URL": "https://www.elastic.co/", + }, "http": Object { "basePath": Object { "prepend": [Function], @@ -67,9 +72,6 @@ exports[`Home component should render traces 1`] = ` }, }, }, - "packageInfo": Object { - "version": "0", - }, "plugins": Object {}, } } diff --git a/x-pack/legacy/plugins/apm/public/components/shared/Links/ElasticDocsLink.tsx b/x-pack/legacy/plugins/apm/public/components/shared/Links/ElasticDocsLink.tsx index 9fcab049e224f..8c2829a515f83 100644 --- a/x-pack/legacy/plugins/apm/public/components/shared/Links/ElasticDocsLink.tsx +++ b/x-pack/legacy/plugins/apm/public/components/shared/Links/ElasticDocsLink.tsx @@ -4,8 +4,8 @@ * you may not use this file except in compliance with the Elastic License. */ -import React from 'react'; import { EuiLink, EuiLinkAnchorProps } from '@elastic/eui'; +import React from 'react'; import { useApmPluginContext } from '../../../hooks/useApmPluginContext'; // union type constisting of valid guide sections that we link to @@ -17,8 +17,11 @@ interface Props extends EuiLinkAnchorProps { } export function ElasticDocsLink({ section, path, children, ...rest }: Props) { - const { version } = useApmPluginContext().packageInfo; - const href = `https://www.elastic.co/guide/en${section}/${version}${path}`; + const { docLinks } = useApmPluginContext().core; + const baseUrl = docLinks.ELASTIC_WEBSITE_URL; + const version = docLinks.DOC_LINK_VERSION; + const href = `${baseUrl}guide/en${section}/${version}${path}`; + return typeof children === 'function' ? ( children(href) ) : ( diff --git a/x-pack/legacy/plugins/apm/public/context/ApmPluginContext/MockApmPluginContext.tsx b/x-pack/legacy/plugins/apm/public/context/ApmPluginContext/MockApmPluginContext.tsx index 8775dc98c3e1a..cc2e382611628 100644 --- a/x-pack/legacy/plugins/apm/public/context/ApmPluginContext/MockApmPluginContext.tsx +++ b/x-pack/legacy/plugins/apm/public/context/ApmPluginContext/MockApmPluginContext.tsx @@ -12,6 +12,10 @@ const mockCore = { chrome: { setBreadcrumbs: () => {} }, + docLinks: { + DOC_LINK_VERSION: '0', + ELASTIC_WEBSITE_URL: 'https://www.elastic.co/' + }, http: { basePath: { prepend: (path: string) => `/basepath${path}` @@ -36,7 +40,6 @@ const mockConfig: ConfigSchema = { export const mockApmPluginContextValue = { config: mockConfig, core: mockCore, - packageInfo: { version: '0' }, plugins: {} }; diff --git a/x-pack/legacy/plugins/apm/public/context/ApmPluginContext/index.tsx b/x-pack/legacy/plugins/apm/public/context/ApmPluginContext/index.tsx index d8934ba4b0151..acc3886586889 100644 --- a/x-pack/legacy/plugins/apm/public/context/ApmPluginContext/index.tsx +++ b/x-pack/legacy/plugins/apm/public/context/ApmPluginContext/index.tsx @@ -5,7 +5,7 @@ */ import { createContext } from 'react'; -import { AppMountContext, PackageInfo } from 'kibana/public'; +import { AppMountContext } from 'kibana/public'; import { ApmPluginSetupDeps, ConfigSchema } from '../../new-platform/plugin'; export type AppMountContextBasePath = AppMountContext['core']['http']['basePath']; @@ -13,7 +13,6 @@ export type AppMountContextBasePath = AppMountContext['core']['http']['basePath' export interface ApmPluginContextValue { config: ConfigSchema; core: AppMountContext['core']; - packageInfo: PackageInfo; plugins: ApmPluginSetupDeps; } diff --git a/x-pack/legacy/plugins/apm/public/new-platform/plugin.tsx b/x-pack/legacy/plugins/apm/public/new-platform/plugin.tsx index 483e6078ea155..804d127bbd75b 100644 --- a/x-pack/legacy/plugins/apm/public/new-platform/plugin.tsx +++ b/x-pack/legacy/plugins/apm/public/new-platform/plugin.tsx @@ -8,13 +8,11 @@ import React from 'react'; import ReactDOM from 'react-dom'; import { Route, Router, Switch } from 'react-router-dom'; import styled from 'styled-components'; -import { metadata } from 'ui/metadata'; import { i18n } from '@kbn/i18n'; import { AlertType } from '../../../../../plugins/apm/common/alert_types'; import { CoreSetup, CoreStart, - PackageInfo, Plugin, PluginInitializerContext } from '../../../../../../src/core/public'; @@ -123,14 +121,6 @@ export class ApmPlugin // Until then we use a shim to get it from legacy injectedMetadata: const config = getConfigFromInjectedMetadata(); - // Once we're actually an NP plugin we'll get the package info from the - // initializerContext like: - // - // const packageInfo = this.initializerContext.env.packageInfo - // - // Until then we use a shim to get it from legacy metadata: - const packageInfo = metadata as PackageInfo; - // render APM feedback link in global help menu setHelpExtension(core); setReadonlyBadge(core); @@ -139,7 +129,6 @@ export class ApmPlugin const apmPluginContextValue = { config, core, - packageInfo, plugins };