Skip to content

Commit

Permalink
Use docLinks API for APM doc links (elastic#61880) (elastic#61909)
Browse files Browse the repository at this point in the history
* 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 elastic#56453
Fixes elastic#60945

Co-authored-by: Elastic Machine <[email protected]>
  • Loading branch information
smith and elasticmachine authored Apr 2, 2020
1 parent b7881fb commit 02565fc
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 23 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
) : (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}`
Expand All @@ -36,7 +40,6 @@ const mockConfig: ConfigSchema = {
export const mockApmPluginContextValue = {
config: mockConfig,
core: mockCore,
packageInfo: { version: '0' },
plugins: {}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@
*/

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'];

export interface ApmPluginContextValue {
config: ConfigSchema;
core: AppMountContext['core'];
packageInfo: PackageInfo;
plugins: ApmPluginSetupDeps;
}

Expand Down
11 changes: 0 additions & 11 deletions x-pack/legacy/plugins/apm/public/new-platform/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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);
Expand All @@ -139,7 +129,6 @@ export class ApmPlugin
const apmPluginContextValue = {
config,
core,
packageInfo,
plugins
};

Expand Down

0 comments on commit 02565fc

Please sign in to comment.