Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into chrome-navlinks
Browse files Browse the repository at this point in the history
  • Loading branch information
joshdover committed May 8, 2019
2 parents a0dfbcc + 95a3ceb commit 6b81939
Show file tree
Hide file tree
Showing 466 changed files with 14,946 additions and 4,661 deletions.
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) &gt; [kibana-plugin-public](./kibana-plugin-public.md) &gt; [InjectedMetadataSetup](./kibana-plugin-public.injectedmetadatasetup.md) &gt; [getKibanaBuildNumber](./kibana-plugin-public.injectedmetadatasetup.getkibanabuildnumber.md)

## InjectedMetadataSetup.getKibanaBuildNumber property

<b>Signature:</b>

```typescript
getKibanaBuildNumber: () => number;
```
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export interface InjectedMetadataSetup
| [getCspConfig](./kibana-plugin-public.injectedmetadatasetup.getcspconfig.md) | <code>() =&gt; {`<p/>` warnLegacyBrowsers: boolean;`<p/>` }</code> | |
| [getInjectedVar](./kibana-plugin-public.injectedmetadatasetup.getinjectedvar.md) | <code>(name: string, defaultValue?: any) =&gt; unknown</code> | |
| [getInjectedVars](./kibana-plugin-public.injectedmetadatasetup.getinjectedvars.md) | <code>() =&gt; {`<p/>` [key: string]: unknown;`<p/>` }</code> | |
| [getKibanaBuildNumber](./kibana-plugin-public.injectedmetadatasetup.getkibanabuildnumber.md) | <code>() =&gt; number</code> | |
| [getKibanaVersion](./kibana-plugin-public.injectedmetadatasetup.getkibanaversion.md) | <code>() =&gt; string</code> | |
| [getLegacyMetadata](./kibana-plugin-public.injectedmetadatasetup.getlegacymetadata.md) | <code>() =&gt; {`<p/>` app: unknown;`<p/>` translations: unknown;`<p/>` bundleId: string;`<p/>` nav: LegacyNavLink[];`<p/>` version: string;`<p/>` branch: string;`<p/>` buildNum: number;`<p/>` buildSha: string;`<p/>` basePath: string;`<p/>` serverName: string;`<p/>` devMode: boolean;`<p/>` uiSettings: {`<p/>` defaults: UiSettingsState;`<p/>` user?: UiSettingsState &#124; undefined;`<p/>` };`<p/>` }</code> | |
| [getPlugins](./kibana-plugin-public.injectedmetadatasetup.getplugins.md) | <code>() =&gt; Array&lt;{`<p/>` id: string;`<p/>` plugin: DiscoveredPlugin;`<p/>` }&gt;</code> | An array of frontend plugins in topological order. |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<b>Signature:</b>

```typescript
export declare class KibanaRequest<Params, Query, Body>
export declare class KibanaRequest<Params = unknown, Query = unknown, Body = unknown>
```

## Properties
Expand All @@ -27,4 +27,5 @@ export declare class KibanaRequest<Params, Query, Body>
| --- | --- | --- |
| [from(req, routeSchemas)](./kibana-plugin-server.kibanarequest.from.md) | <code>static</code> | Factory for creating requests. Validates the request before creating an instance of a KibanaRequest. |
| [getFilteredHeaders(headersToKeep)](./kibana-plugin-server.kibanarequest.getfilteredheaders.md) | | |
| [unstable\_getIncomingMessage()](./kibana-plugin-server.kibanarequest.unstable_getincomingmessage.md) | | |

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

[Home](./index) &gt; [kibana-plugin-server](./kibana-plugin-server.md) &gt; [KibanaRequest](./kibana-plugin-server.kibanarequest.md) &gt; [unstable\_getIncomingMessage](./kibana-plugin-server.kibanarequest.unstable_getincomingmessage.md)

## KibanaRequest.unstable\_getIncomingMessage() method

<b>Signature:</b>

```typescript
unstable_getIncomingMessage(): import("http").IncomingMessage;
```
<b>Returns:</b>

`import("http").IncomingMessage`

Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ export interface OnRequestToolkit
| [next](./kibana-plugin-server.onrequesttoolkit.next.md) | <code>() =&gt; OnRequestResult</code> | To pass request to the next handler |
| [redirected](./kibana-plugin-server.onrequesttoolkit.redirected.md) | <code>(url: string) =&gt; OnRequestResult</code> | To interrupt request handling and redirect to a configured url |
| [rejected](./kibana-plugin-server.onrequesttoolkit.rejected.md) | <code>(error: Error, options?: {`<p/>` statusCode?: number;`<p/>` }) =&gt; OnRequestResult</code> | Fail the request with specified error. |
| [setUrl](./kibana-plugin-server.onrequesttoolkit.seturl.md) | <code>(newUrl: string &#124; Url) =&gt; void</code> | Change url for an incoming request. |

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

[Home](./index) &gt; [kibana-plugin-server](./kibana-plugin-server.md) &gt; [OnRequestToolkit](./kibana-plugin-server.onrequesttoolkit.md) &gt; [setUrl](./kibana-plugin-server.onrequesttoolkit.seturl.md)

## OnRequestToolkit.setUrl property

Change url for an incoming request.

<b>Signature:</b>

```typescript
setUrl: (newUrl: string | Url) => void;
```
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,7 @@
http: {
registerAuth: HttpServiceSetup['registerAuth'];
registerOnRequest: HttpServiceSetup['registerOnRequest'];
getBasePathFor: HttpServiceSetup['getBasePathFor'];
setBasePathFor: HttpServiceSetup['setBasePathFor'];
};
```
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ export interface PluginSetupContext
| Property | Type | Description |
| --- | --- | --- |
| [elasticsearch](./kibana-plugin-server.pluginsetupcontext.elasticsearch.md) | <code>{`<p/>` adminClient$: Observable&lt;ClusterClient&gt;;`<p/>` dataClient$: Observable&lt;ClusterClient&gt;;`<p/>` }</code> | |
| [http](./kibana-plugin-server.pluginsetupcontext.http.md) | <code>{`<p/>` registerAuth: HttpServiceSetup['registerAuth'];`<p/>` registerOnRequest: HttpServiceSetup['registerOnRequest'];`<p/>` }</code> | |
| [http](./kibana-plugin-server.pluginsetupcontext.http.md) | <code>{`<p/>` registerAuth: HttpServiceSetup['registerAuth'];`<p/>` registerOnRequest: HttpServiceSetup['registerOnRequest'];`<p/>` getBasePathFor: HttpServiceSetup['getBasePathFor'];`<p/>` setBasePathFor: HttpServiceSetup['setBasePathFor'];`<p/>` }</code> | |
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
"@babel/core": "^7.3.4",
"@babel/polyfill": "^7.2.5",
"@babel/register": "^7.0.0",
"@elastic/charts": "^3.11.2",
"@elastic/datemath": "5.0.2",
"@elastic/eui": "10.4.0",
"@elastic/filesaver": "1.1.2",
Expand All @@ -124,7 +125,7 @@
"@types/recompose": "^0.30.5",
"JSONStream": "1.1.1",
"abortcontroller-polyfill": "^1.1.9",
"angular": "npm:@elastic/angular@1.6.9-kibana.0",
"angular": "1.6.9",
"angular-aria": "1.6.6",
"angular-elastic": "2.5.0",
"angular-recursion": "^1.0.5",
Expand Down
9 changes: 4 additions & 5 deletions src/core/public/core_system.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,12 @@ describe('constructor', () => {

expect(FatalErrorsServiceConstructor).toHaveBeenCalledTimes(1);

expect(FatalErrorsServiceConstructor).toHaveBeenLastCalledWith({
expect(FatalErrorsServiceConstructor).toHaveBeenLastCalledWith(
rootDomElement,
injectedMetadata: MockInjectedMetadataService,
stopCoreSystem: expect.any(Function),
});
expect.any(Function)
);

const [{ stopCoreSystem }] = FatalErrorsServiceConstructor.mock.calls[0];
const [, stopCoreSystem] = FatalErrorsServiceConstructor.mock.calls[0];

expect(coreSystem.stop).not.toHaveBeenCalled();
stopCoreSystem();
Expand Down
42 changes: 29 additions & 13 deletions src/core/public/core_system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import './core.css';
import { CoreSetup, CoreStart } from '.';
import { BasePathService } from './base_path';
import { ChromeService } from './chrome';
import { FatalErrorsService } from './fatal_errors';
import { FatalErrorsService, FatalErrorsSetup } from './fatal_errors';
import { HttpService } from './http';
import { I18nService } from './i18n';
import { InjectedMetadataParams, InjectedMetadataService } from './injected_metadata';
Expand Down Expand Up @@ -69,6 +69,7 @@ export class CoreSystem {

private readonly rootDomElement: HTMLElement;
private readonly overlayTargetDomElement: HTMLDivElement;
private fatalErrorsSetup: FatalErrorsSetup | null = null;

constructor(params: Params) {
const {
Expand All @@ -87,12 +88,9 @@ export class CoreSystem {
injectedMetadata,
});

this.fatalErrors = new FatalErrorsService({
rootDomElement,
injectedMetadata: this.injectedMetadata,
stopCoreSystem: () => {
this.stop();
},
this.fatalErrors = new FatalErrorsService(rootDomElement, () => {
// Stop Core before rendering any fatal errors into the DOM
this.stop();
});

this.notifications = new NotificationsService();
Expand All @@ -115,11 +113,17 @@ export class CoreSystem {

public async setup() {
try {
// Setup FatalErrorsService and it's dependencies first so that we're
// able to render any errors.
const i18n = this.i18n.setup();
const injectedMetadata = this.injectedMetadata.setup();
const fatalErrors = this.fatalErrors.setup({ i18n });
const http = this.http.setup({ fatalErrors });
this.fatalErrorsSetup = this.fatalErrors.setup({ injectedMetadata, i18n });
const basePath = this.basePath.setup({ injectedMetadata });
const http = this.http.setup({
basePath,
injectedMetadata,
fatalErrors: this.fatalErrorsSetup,
});
const uiSettings = this.uiSettings.setup({
http,
injectedMetadata,
Expand All @@ -136,7 +140,7 @@ export class CoreSystem {
application,
basePath,
chrome,
fatalErrors,
fatalErrors: this.fatalErrorsSetup,
http,
i18n,
injectedMetadata,
Expand All @@ -148,9 +152,15 @@ export class CoreSystem {
await this.plugins.setup(core);
await this.legacyPlatform.setup({ core });

return { fatalErrors };
return { fatalErrors: this.fatalErrorsSetup };
} catch (error) {
this.fatalErrors.add(error);
if (this.fatalErrorsSetup) {
this.fatalErrorsSetup.add(error);
} else {
// If the FatalErrorsService has not yet been setup, log error to console
// eslint-disable-next-line no-console
console.log(error);
}
}
}

Expand Down Expand Up @@ -191,7 +201,13 @@ export class CoreSystem {
await this.plugins.start(core);
await this.legacyPlatform.start({ core, targetDomElement: legacyPlatformTargetDomElement });
} catch (error) {
this.fatalErrors.add(error);
if (this.fatalErrorsSetup) {
this.fatalErrorsSetup.add(error);
} else {
// If the FatalErrorsService has not yet been setup, log error to console
// eslint-disable-next-line no-console
console.error(error);
}
}
}

Expand Down

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

1 change: 0 additions & 1 deletion src/core/public/fatal_errors/fatal_errors_service.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ type FatalErrorsServiceContract = PublicMethodsOf<FatalErrorsService>;
const createMock = () => {
const mocked: jest.Mocked<FatalErrorsServiceContract> = {
setup: jest.fn(),
add: jest.fn<never, any>(() => undefined as never),
};

mocked.setup.mockReturnValue(createSetupContractMock());
Expand Down
53 changes: 7 additions & 46 deletions src/core/public/fatal_errors/fatal_errors_service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,14 @@ expect.addSnapshotSerializer({
});

import { mockRender } from './fatal_errors_service.test.mocks';
import { injectedMetadataServiceMock } from '../injected_metadata/injected_metadata_service.mock';

import { FatalErrorsService } from './fatal_errors_service';

function setupService() {
const rootDomElement = document.createElement('div');

const injectedMetadata = {
getKibanaBuildNumber: jest.fn().mockReturnValue('kibanaBuildNumber'),
getKibanaVersion: jest.fn().mockReturnValue('kibanaVersion'),
};
const injectedMetadata = injectedMetadataServiceMock.createSetupContract();

const stopCoreSystem = jest.fn();

Expand All @@ -44,16 +42,13 @@ function setupService() {
},
};

const fatalErrorsService = new FatalErrorsService(rootDomElement, stopCoreSystem);

return {
rootDomElement,
injectedMetadata,
i18n,
stopCoreSystem,
fatalErrors: new FatalErrorsService({
injectedMetadata: injectedMetadata as any,
rootDomElement,
stopCoreSystem,
}),
fatalErrors: fatalErrorsService.setup({ injectedMetadata, i18n }),
};
}

Expand Down Expand Up @@ -91,46 +86,12 @@ describe('#add()', () => {
});
});

describe('setup.add()', () => {
it('exposes a function that passes its two arguments to fatalErrors.add()', () => {
const { fatalErrors, i18n } = setupService();

jest.spyOn(fatalErrors, 'add').mockImplementation(() => undefined as never);

expect(fatalErrors.add).not.toHaveBeenCalled();
const { add } = fatalErrors.setup({ i18n });
add('foo', 'bar');
expect(fatalErrors.add).toHaveBeenCalledTimes(1);
expect(fatalErrors.add).toHaveBeenCalledWith('foo', 'bar');
});

it('deletes all children of rootDomElement and renders <FatalErrorScreen /> into it', () => {
const { fatalErrors, i18n, rootDomElement } = setupService();

rootDomElement.innerHTML = `
<h1>Loading...</h1>
<div class="someSpinner"></div>
`;

expect(mockRender).not.toHaveBeenCalled();
expect(rootDomElement.children).toHaveLength(2);

const { add } = fatalErrors.setup({ i18n });

expect(() => add(new Error('foo'))).toThrowError();
expect(rootDomElement).toMatchSnapshot('fatal error screen container');
expect(mockRender.mock.calls).toMatchSnapshot('fatal error screen component');
});
});

describe('setup.get$()', () => {
it('provides info about the errors passed to fatalErrors.add()', () => {
const { fatalErrors, i18n } = setupService();

const setup = fatalErrors.setup({ i18n });
const { fatalErrors } = setupService();

const onError = jest.fn();
setup.get$().subscribe(onError);
fatalErrors.get$().subscribe(onError);

expect(onError).not.toHaveBeenCalled();
expect(() => {
Expand Down
Loading

0 comments on commit 6b81939

Please sign in to comment.