Skip to content

Commit

Permalink
expose DocLinks API from start only (#68745)
Browse files Browse the repository at this point in the history
* exose DocLinks API from start only

* update docs

* fix type errors

* update docs

Co-authored-by: Elastic Machine <[email protected]>
mshustov and elasticmachine authored Jun 24, 2020
1 parent d1a6fa2 commit 778136f
Showing 22 changed files with 62 additions and 133 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -18,7 +18,6 @@ export interface CoreSetup<TPluginsStart extends object = object, TStart = unkno
| --- | --- | --- |
| [application](./kibana-plugin-core-public.coresetup.application.md) | <code>ApplicationSetup</code> | [ApplicationSetup](./kibana-plugin-core-public.applicationsetup.md) |
| [context](./kibana-plugin-core-public.coresetup.context.md) | <code>ContextSetup</code> | [ContextSetup](./kibana-plugin-core-public.contextsetup.md) |
| [docLinks](./kibana-plugin-core-public.coresetup.doclinks.md) | <code>DocLinksSetup</code> | [DocLinksSetup](./kibana-plugin-core-public.doclinkssetup.md) |
| [fatalErrors](./kibana-plugin-core-public.coresetup.fatalerrors.md) | <code>FatalErrorsSetup</code> | [FatalErrorsSetup](./kibana-plugin-core-public.fatalerrorssetup.md) |
| [getStartServices](./kibana-plugin-core-public.coresetup.getstartservices.md) | <code>StartServicesAccessor&lt;TPluginsStart, TStart&gt;</code> | [StartServicesAccessor](./kibana-plugin-core-public.startservicesaccessor.md) |
| [http](./kibana-plugin-core-public.coresetup.http.md) | <code>HttpSetup</code> | [HttpSetup](./kibana-plugin-core-public.httpsetup.md) |

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-core-public](./kibana-plugin-core-public.md) &gt; [DocLinksStart](./kibana-plugin-core-public.doclinksstart.md) &gt; [DOC\_LINK\_VERSION](./kibana-plugin-core-public.doclinksstart.doc_link_version.md)

## DocLinksStart.DOC\_LINK\_VERSION property

<b>Signature:</b>

```typescript
readonly DOC_LINK_VERSION: string;
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-core-public](./kibana-plugin-core-public.md) &gt; [DocLinksStart](./kibana-plugin-core-public.doclinksstart.md) &gt; [ELASTIC\_WEBSITE\_URL](./kibana-plugin-core-public.doclinksstart.elastic_website_url.md)

## DocLinksStart.ELASTIC\_WEBSITE\_URL property

<b>Signature:</b>

```typescript
readonly ELASTIC_WEBSITE_URL: string;
```
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-core-public](./kibana-plugin-core-public.md) &gt; [DocLinksSetup](./kibana-plugin-core-public.doclinkssetup.md) &gt; [links](./kibana-plugin-core-public.doclinkssetup.links.md)
[Home](./index.md) &gt; [kibana-plugin-core-public](./kibana-plugin-core-public.md) &gt; [DocLinksStart](./kibana-plugin-core-public.doclinksstart.md) &gt; [links](./kibana-plugin-core-public.doclinksstart.links.md)

## DocLinksSetup.links property
## DocLinksStart.links property

<b>Signature:</b>

Original file line number Diff line number Diff line change
@@ -2,11 +2,20 @@

[Home](./index.md) &gt; [kibana-plugin-core-public](./kibana-plugin-core-public.md) &gt; [DocLinksStart](./kibana-plugin-core-public.doclinksstart.md)

## DocLinksStart type
## DocLinksStart interface


<b>Signature:</b>

```typescript
export declare type DocLinksStart = DocLinksSetup;
export interface DocLinksStart
```

## Properties

| Property | Type | Description |
| --- | --- | --- |
| [DOC\_LINK\_VERSION](./kibana-plugin-core-public.doclinksstart.doc_link_version.md) | <code>string</code> | |
| [ELASTIC\_WEBSITE\_URL](./kibana-plugin-core-public.doclinksstart.elastic_website_url.md) | <code>string</code> | |
| [links](./kibana-plugin-core-public.doclinksstart.links.md) | <code>{</code><br/><code> readonly dashboard: {</code><br/><code> readonly drilldowns: string;</code><br/><code> };</code><br/><code> readonly filebeat: {</code><br/><code> readonly base: string;</code><br/><code> readonly installation: string;</code><br/><code> readonly configuration: string;</code><br/><code> readonly elasticsearchOutput: string;</code><br/><code> readonly startup: string;</code><br/><code> readonly exportedFields: string;</code><br/><code> };</code><br/><code> readonly auditbeat: {</code><br/><code> readonly base: string;</code><br/><code> };</code><br/><code> readonly metricbeat: {</code><br/><code> readonly base: string;</code><br/><code> };</code><br/><code> readonly heartbeat: {</code><br/><code> readonly base: string;</code><br/><code> };</code><br/><code> readonly logstash: {</code><br/><code> readonly base: string;</code><br/><code> };</code><br/><code> readonly functionbeat: {</code><br/><code> readonly base: string;</code><br/><code> };</code><br/><code> readonly winlogbeat: {</code><br/><code> readonly base: string;</code><br/><code> };</code><br/><code> readonly aggs: {</code><br/><code> readonly date_histogram: string;</code><br/><code> readonly date_range: string;</code><br/><code> readonly filter: string;</code><br/><code> readonly filters: string;</code><br/><code> readonly geohash_grid: string;</code><br/><code> readonly histogram: string;</code><br/><code> readonly ip_range: string;</code><br/><code> readonly range: string;</code><br/><code> readonly significant_terms: string;</code><br/><code> readonly terms: string;</code><br/><code> readonly avg: string;</code><br/><code> readonly avg_bucket: string;</code><br/><code> readonly max_bucket: string;</code><br/><code> readonly min_bucket: string;</code><br/><code> readonly sum_bucket: string;</code><br/><code> readonly cardinality: string;</code><br/><code> readonly count: string;</code><br/><code> readonly cumulative_sum: string;</code><br/><code> readonly derivative: string;</code><br/><code> readonly geo_bounds: string;</code><br/><code> readonly geo_centroid: string;</code><br/><code> readonly max: string;</code><br/><code> readonly median: string;</code><br/><code> readonly min: string;</code><br/><code> readonly moving_avg: string;</code><br/><code> readonly percentile_ranks: string;</code><br/><code> readonly serial_diff: string;</code><br/><code> readonly std_dev: string;</code><br/><code> readonly sum: string;</code><br/><code> readonly top_hits: string;</code><br/><code> };</code><br/><code> readonly scriptedFields: {</code><br/><code> readonly scriptFields: string;</code><br/><code> readonly scriptAggs: string;</code><br/><code> readonly painless: string;</code><br/><code> readonly painlessApi: string;</code><br/><code> readonly painlessSyntax: string;</code><br/><code> readonly luceneExpressions: string;</code><br/><code> };</code><br/><code> readonly indexPatterns: {</code><br/><code> readonly loadingData: string;</code><br/><code> readonly introduction: string;</code><br/><code> };</code><br/><code> readonly kibana: string;</code><br/><code> readonly siem: {</code><br/><code> readonly guide: string;</code><br/><code> readonly gettingStarted: string;</code><br/><code> };</code><br/><code> readonly query: {</code><br/><code> readonly luceneQuerySyntax: string;</code><br/><code> readonly queryDsl: string;</code><br/><code> readonly kueryQuerySyntax: string;</code><br/><code> };</code><br/><code> readonly date: {</code><br/><code> readonly dateMath: string;</code><br/><code> };</code><br/><code> readonly management: Record&lt;string, string&gt;;</code><br/><code> }</code> | |

3 changes: 1 addition & 2 deletions docs/development/core/public/kibana-plugin-core-public.md
Original file line number Diff line number Diff line change
@@ -65,7 +65,7 @@ The plugin integrates with the core system via lifecycle events: `setup`<!-- -->
| [ContextSetup](./kibana-plugin-core-public.contextsetup.md) | An object that handles registration of context providers and configuring handlers with context. |
| [CoreSetup](./kibana-plugin-core-public.coresetup.md) | Core services exposed to the <code>Plugin</code> setup lifecycle |
| [CoreStart](./kibana-plugin-core-public.corestart.md) | Core services exposed to the <code>Plugin</code> start lifecycle |
| [DocLinksSetup](./kibana-plugin-core-public.doclinkssetup.md) | |
| [DocLinksStart](./kibana-plugin-core-public.doclinksstart.md) | |
| [EnvironmentMode](./kibana-plugin-core-public.environmentmode.md) | |
| [ErrorToastOptions](./kibana-plugin-core-public.errortoastoptions.md) | Options available for [IToasts](./kibana-plugin-core-public.itoasts.md) error APIs. |
| [FatalErrorInfo](./kibana-plugin-core-public.fatalerrorinfo.md) | Represents the <code>message</code> and <code>stack</code> of a fatal Error |
@@ -157,7 +157,6 @@ The plugin integrates with the core system via lifecycle events: `setup`<!-- -->
| [ChromeHelpExtensionMenuGitHubLink](./kibana-plugin-core-public.chromehelpextensionmenugithublink.md) | |
| [ChromeHelpExtensionMenuLink](./kibana-plugin-core-public.chromehelpextensionmenulink.md) | |
| [ChromeNavLinkUpdateableFields](./kibana-plugin-core-public.chromenavlinkupdateablefields.md) | |
| [DocLinksStart](./kibana-plugin-core-public.doclinksstart.md) | |
| [FatalErrorsStart](./kibana-plugin-core-public.fatalerrorsstart.md) | FatalErrors stop the Kibana Public Core and displays a fatal error screen with details about the Kibana build and the error. |
| [Freezable](./kibana-plugin-core-public.freezable.md) | |
| [HandlerContextType](./kibana-plugin-core-public.handlercontexttype.md) | Extracts the type of the first argument of a [HandlerFunction](./kibana-plugin-core-public.handlerfunction.md) to represent the type of the context. |
5 changes: 2 additions & 3 deletions src/core/public/core_system.ts
Original file line number Diff line number Diff line change
@@ -163,7 +163,7 @@ export class CoreSystem {
i18n: this.i18n.getContext(),
});
await this.integrations.setup();
const docLinks = this.docLinks.setup({ injectedMetadata });
this.docLinks.setup();
const http = this.http.setup({ injectedMetadata, fatalErrors: this.fatalErrorsSetup });
const uiSettings = this.uiSettings.setup({ http, injectedMetadata });
const notifications = this.notifications.setup({ uiSettings });
@@ -185,7 +185,6 @@ export class CoreSystem {
const core: InternalCoreSetup = {
application,
context,
docLinks,
fatalErrors: this.fatalErrorsSetup,
http,
injectedMetadata,
@@ -217,7 +216,7 @@ export class CoreSystem {
try {
const injectedMetadata = await this.injectedMetadata.start();
const uiSettings = await this.uiSettings.start();
const docLinks = this.docLinks.start();
const docLinks = this.docLinks.start({ injectedMetadata });
const http = await this.http.start();
const savedObjects = await this.savedObjects.start({ http });
const i18n = await this.i18n.start();
12 changes: 5 additions & 7 deletions src/core/public/doc_links/doc_links_service.mock.ts
Original file line number Diff line number Diff line change
@@ -18,25 +18,23 @@
*/

import { injectedMetadataServiceMock } from '../injected_metadata/injected_metadata_service.mock';
import { DocLinksService, DocLinksSetup, DocLinksStart } from './doc_links_service';
import { DocLinksService, DocLinksStart } from './doc_links_service';

const createSetupContractMock = (): DocLinksSetup => {
const createStartContractMock = (): DocLinksStart => {
// This service is so simple that we actually use the real implementation
const injectedMetadata = injectedMetadataServiceMock.createStartContract();
injectedMetadata.getKibanaBranch.mockReturnValue('mocked-test-branch');
return new DocLinksService().setup({ injectedMetadata });
return new DocLinksService().start({ injectedMetadata });
};

const createStartContractMock: () => DocLinksStart = createSetupContractMock;

type DocLinksServiceContract = PublicMethodsOf<DocLinksService>;
const createMock = (): jest.Mocked<DocLinksServiceContract> => ({
setup: jest.fn().mockReturnValue(createSetupContractMock()),
setup: jest.fn().mockReturnValue(undefined),
start: jest.fn().mockReturnValue(createStartContractMock()),
});

export const docLinksServiceMock = {
create: createMock,
createSetupContract: createSetupContractMock,
createSetupContract: () => jest.fn(),
createStartContract: createStartContractMock,
};
26 changes: 4 additions & 22 deletions src/core/public/doc_links/doc_links_service.test.ts
Original file line number Diff line number Diff line change
@@ -20,33 +20,15 @@
import { DocLinksService } from './doc_links_service';
import { injectedMetadataServiceMock } from '../injected_metadata/injected_metadata_service.mock';

describe('DocLinksService#setup()', () => {
describe('DocLinksService#start()', () => {
it('templates the doc links with the branch information from injectedMetadata', () => {
const injectedMetadata = injectedMetadataServiceMock.createStartContract();
injectedMetadata.getKibanaBranch.mockReturnValue('test-branch');
const service = new DocLinksService();
const setup = service.setup({ injectedMetadata });
expect(setup.DOC_LINK_VERSION).toEqual('test-branch');
expect(setup.links.kibana).toEqual(
const api = service.start({ injectedMetadata });
expect(api.DOC_LINK_VERSION).toEqual('test-branch');
expect(api.links.kibana).toEqual(
'https://www.elastic.co/guide/en/kibana/test-branch/index.html'
);
});
});

describe('DocLinksService#start()', () => {
it('returns the same data as setup', () => {
const injectedMetadata = injectedMetadataServiceMock.createStartContract();
injectedMetadata.getKibanaBranch.mockReturnValue('test-branch');
const service = new DocLinksService();
const setup = service.setup({ injectedMetadata });
const start = service.start();
expect(setup).toEqual(start);
});

it('must be called after setup', () => {
const service = new DocLinksService();
expect(() => {
service.start();
}).toThrowErrorMatchingInlineSnapshot(`"DocLinksService#setup() must be called first!"`);
});
});
24 changes: 5 additions & 19 deletions src/core/public/doc_links/doc_links_service.ts
Original file line number Diff line number Diff line change
@@ -20,20 +20,19 @@
import { InjectedMetadataSetup } from '../injected_metadata';
import { deepFreeze } from '../../utils';

interface SetupDeps {
interface StartDeps {
injectedMetadata: InjectedMetadataSetup;
}

/** @internal */
export class DocLinksService {
private service?: DocLinksSetup;

public setup({ injectedMetadata }: SetupDeps): DocLinksSetup {
public setup() {}
public start({ injectedMetadata }: StartDeps): DocLinksStart {
const DOC_LINK_VERSION = injectedMetadata.getKibanaBranch();
const ELASTIC_WEBSITE_URL = 'https://www.elastic.co/';
const ELASTICSEARCH_DOCS = `${ELASTIC_WEBSITE_URL}guide/en/elasticsearch/reference/${DOC_LINK_VERSION}/`;

this.service = deepFreeze({
return deepFreeze({
DOC_LINK_VERSION,
ELASTIC_WEBSITE_URL,
links: {
@@ -129,21 +128,11 @@ export class DocLinksService {
},
},
});

return this.service;
}

public start(): DocLinksStart {
if (!this.service) {
throw new Error(`DocLinksService#setup() must be called first!`);
}

return this.service;
}
}

/** @public */
export interface DocLinksSetup {
export interface DocLinksStart {
readonly DOC_LINK_VERSION: string;
readonly ELASTIC_WEBSITE_URL: string;
readonly links: {
@@ -236,6 +225,3 @@ export interface DocLinksSetup {
readonly management: Record<string, string>;
};
}

/** @public */
export type DocLinksStart = DocLinksSetup;
2 changes: 1 addition & 1 deletion src/core/public/doc_links/index.ts
Original file line number Diff line number Diff line change
@@ -17,4 +17,4 @@
* under the License.
*/

export { DocLinksService, DocLinksSetup, DocLinksStart } from './doc_links_service';
export { DocLinksService, DocLinksStart } from './doc_links_service';
5 changes: 1 addition & 4 deletions src/core/public/index.ts
Original file line number Diff line number Diff line change
@@ -67,7 +67,7 @@ import { OverlayStart } from './overlays';
import { Plugin, PluginInitializer, PluginInitializerContext, PluginOpaqueId } from './plugins';
import { UiSettingsState, IUiSettingsClient } from './ui_settings';
import { ApplicationSetup, Capabilities, ApplicationStart } from './application';
import { DocLinksSetup, DocLinksStart } from './doc_links';
import { DocLinksStart } from './doc_links';
import { SavedObjectsStart } from './saved_objects';
export { PackageInfo, EnvironmentMode } from '../server/types';
import {
@@ -216,8 +216,6 @@ export interface CoreSetup<TPluginsStart extends object = object, TStart = unkno
* @deprecated
*/
context: ContextSetup;
/** {@link DocLinksSetup} */
docLinks: DocLinksSetup;
/** {@link FatalErrorsSetup} */
fatalErrors: FatalErrorsSetup;
/** {@link HttpSetup} */
@@ -348,7 +346,6 @@ export {
HandlerParameters,
IContextProvider,
ContextSetup,
DocLinksSetup,
DocLinksStart,
FatalErrorInfo,
FatalErrorsSetup,
1 change: 0 additions & 1 deletion src/core/public/plugins/plugin_context.ts
Original file line number Diff line number Diff line change
@@ -101,7 +101,6 @@ export function createPluginSetupContext<
deps.application.registerMountContext(plugin.opaqueId, contextName, provider),
},
context: deps.context,
docLinks: deps.docLinks,
fatalErrors: deps.fatalErrors,
http: deps.http,
notifications: deps.notifications,
1 change: 0 additions & 1 deletion src/core/public/plugins/plugins_service.test.ts
Original file line number Diff line number Diff line change
@@ -89,7 +89,6 @@ describe('PluginsService', () => {
mockSetupDeps = {
application: applicationServiceMock.createInternalSetupContract(),
context: contextServiceMock.createSetupContract(),
docLinks: docLinksServiceMock.createSetupContract(),
fatalErrors: fatalErrorsServiceMock.createSetupContract(),
http: httpServiceMock.createSetupContract(),
injectedMetadata: pick(injectedMetadataServiceMock.createStartContract(), 'getInjectedVar'),
9 changes: 2 additions & 7 deletions src/core/public/public.api.md
Original file line number Diff line number Diff line change
@@ -508,8 +508,6 @@ export interface CoreSetup<TPluginsStart extends object = object, TStart = unkno
// @deprecated (undocumented)
context: ContextSetup;
// (undocumented)
docLinks: DocLinksSetup;
// (undocumented)
fatalErrors: FatalErrorsSetup;
// (undocumented)
getStartServices: StartServicesAccessor<TPluginsStart, TStart>;
@@ -600,7 +598,7 @@ export const DEFAULT_APP_CATEGORIES: Readonly<{
}>;

// @public (undocumented)
export interface DocLinksSetup {
export interface DocLinksStart {
// (undocumented)
readonly DOC_LINK_VERSION: string;
// (undocumented)
@@ -697,9 +695,6 @@ export interface DocLinksSetup {
};
}

// @public (undocumented)
export type DocLinksStart = DocLinksSetup;

// @public (undocumented)
export interface EnvironmentMode {
// (undocumented)
@@ -1594,6 +1589,6 @@ export interface UserProvidedValues<T = any> {

// Warnings were encountered during analysis:
//
// src/core/public/core_system.ts:216:21 - (ae-forgotten-export) The symbol "InternalApplicationStart" needs to be exported by the entry point index.d.ts
// src/core/public/core_system.ts:215:21 - (ae-forgotten-export) The symbol "InternalApplicationStart" needs to be exported by the entry point index.d.ts

```
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@
*/

import React, { createContext, useContext } from 'react';
import { HttpSetup, DocLinksSetup, NotificationsSetup } from 'src/core/public';
import { HttpSetup, DocLinksStart, NotificationsSetup } from 'src/core/public';

import { getApi, getUseRequest, getSendRequest, getDocumentation } from './lib';

@@ -15,7 +15,7 @@ interface Props {
httpClient: HttpSetup;
apiBasePath: string;
trackMetric: (type: 'loaded' | 'click' | 'count', eventName: string) => void;
docLinks: DocLinksSetup;
docLinks: DocLinksStart;
toasts: NotificationsSetup['toasts'];
}

Original file line number Diff line number Diff line change
@@ -4,9 +4,9 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { DocLinksSetup } from 'src/core/public';
import { DocLinksStart } from 'src/core/public';

export const getDocumentation = ({ ELASTIC_WEBSITE_URL, DOC_LINK_VERSION }: DocLinksSetup) => {
export const getDocumentation = ({ ELASTIC_WEBSITE_URL, DOC_LINK_VERSION }: DocLinksStart) => {
const docsBase = `${ELASTIC_WEBSITE_URL}guide/en`;
const esDocsBase = `${docsBase}/elasticsearch/reference/${DOC_LINK_VERSION}`;

Original file line number Diff line number Diff line change
@@ -27,6 +27,7 @@ describe('ExpressionChart', () => {
groupBy?: string
) {
const mocks = coreMock.createSetup();
const startMocks = coreMock.createStart();
const [
{
application: { capabilities },
@@ -38,7 +39,7 @@ describe('ExpressionChart', () => {
toastNotifications: mocks.notifications.toasts,
actionTypeRegistry: actionTypeRegistryMock.create() as any,
alertTypeRegistry: alertTypeRegistryMock.create() as any,
docLinks: mocks.docLinks,
docLinks: startMocks.docLinks,
capabilities: {
...capabilities,
actions: {

0 comments on commit 778136f

Please sign in to comment.