Skip to content

Commit

Permalink
Add addError function to toastNotifications (elastic#32187)
Browse files Browse the repository at this point in the history
  • Loading branch information
timroes authored and jkakavas committed May 30, 2019
1 parent ebb939b commit 8f48832
Show file tree
Hide file tree
Showing 44 changed files with 658 additions and 103 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index) &gt; [kibana-plugin-public](./kibana-plugin-public.md) &gt; [ErrorToastOptions](./kibana-plugin-public.errortoastoptions.md)

## ErrorToastOptions interface

<b>Signature:</b>

```typescript
export interface ErrorToastOptions
```

## Properties

| Property | Type | Description |
| --- | --- | --- |
| [title](./kibana-plugin-public.errortoastoptions.title.md) | <code>string</code> | The title of the toast and the dialog when expanding the message. |
| [toastMessage](./kibana-plugin-public.errortoastoptions.toastmessage.md) | <code>string</code> | The message to be shown in the toast. If this is not specified the error's message will be shown in the toast instead. Overwriting that message can be used to provide more user-friendly toasts. If you specify this, the error message will still be shown in the detailed error modal. |

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-public](./kibana-plugin-public.md) &gt; [ErrorToastOptions](./kibana-plugin-public.errortoastoptions.md) &gt; [title](./kibana-plugin-public.errortoastoptions.title.md)

## ErrorToastOptions.title property

The title of the toast and the dialog when expanding the message.

<b>Signature:</b>

```typescript
title: string;
```
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-public](./kibana-plugin-public.md) &gt; [ErrorToastOptions](./kibana-plugin-public.errortoastoptions.md) &gt; [toastMessage](./kibana-plugin-public.errortoastoptions.toastmessage.md)

## ErrorToastOptions.toastMessage property

The message to be shown in the toast. If this is not specified the error's message will be shown in the toast instead. Overwriting that message can be used to provide more user-friendly toasts. If you specify this, the error message will still be shown in the detailed error modal.

<b>Signature:</b>

```typescript
toastMessage?: string;
```
3 changes: 2 additions & 1 deletion docs/development/core/public/kibana-plugin-public.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,14 @@ The plugin integrates with the core system via lifecycle events: `setup`<!-- -->
| [ChromeNavLink](./kibana-plugin-public.chromenavlink.md) | |
| [CoreSetup](./kibana-plugin-public.coresetup.md) | Core services exposed to the <code>Plugin</code> setup lifecycle |
| [CoreStart](./kibana-plugin-public.corestart.md) | Core services exposed to the <code>Plugin</code> start lifecycle |
| [ErrorToastOptions](./kibana-plugin-public.errortoastoptions.md) | |
| [FatalErrorInfo](./kibana-plugin-public.fatalerrorinfo.md) | Represents the <code>message</code> and <code>stack</code> of a fatal Error |
| [FatalErrorsSetup](./kibana-plugin-public.fatalerrorssetup.md) | FatalErrors stop the Kibana Public Core and displays a fatal error screen with details about the Kibana build and the error. |
| [HttpServiceBase](./kibana-plugin-public.httpservicebase.md) | |
| [I18nSetup](./kibana-plugin-public.i18nsetup.md) | I18nSetup.Context is required by any localizable React component from @<!-- -->kbn/i18n and @<!-- -->elastic/eui packages and is supposed to be used as the topmost component for any i18n-compatible React tree. |
| [LegacyNavLink](./kibana-plugin-public.legacynavlink.md) | |
| [NotificationsSetup](./kibana-plugin-public.notificationssetup.md) | |
| [NotificationsStart](./kibana-plugin-public.notificationsstart.md) | |
| [OverlayRef](./kibana-plugin-public.overlayref.md) | |
| [OverlayStart](./kibana-plugin-public.overlaystart.md) | |
| [Plugin](./kibana-plugin-public.plugin.md) | The interface that should be returned by a <code>PluginInitializer</code>. |
Expand All @@ -52,7 +54,6 @@ The plugin integrates with the core system via lifecycle events: `setup`<!-- -->
| [HttpSetup](./kibana-plugin-public.httpsetup.md) | |
| [HttpStart](./kibana-plugin-public.httpstart.md) | |
| [I18nStart](./kibana-plugin-public.i18nstart.md) | |
| [NotificationsStart](./kibana-plugin-public.notificationsstart.md) | |
| [PluginInitializer](./kibana-plugin-public.plugininitializer.md) | The <code>plugin</code> export at the root of a plugin's <code>public</code> directory should conform to this interface. |
| [ToastInput](./kibana-plugin-public.toastinput.md) | |
| [UiSettingsSetup](./kibana-plugin-public.uisettingssetup.md) | |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ export interface NotificationsSetup

| Property | Type | Description |
| --- | --- | --- |
| [toasts](./kibana-plugin-public.notificationssetup.toasts.md) | <code>ToastsApi</code> | |
| [toasts](./kibana-plugin-public.notificationssetup.toasts.md) | <code>ToastsSetup</code> | |

Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
<b>Signature:</b>

```typescript
toasts: ToastsApi;
toasts: ToastsSetup;
```
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,18 @@

[Home](./index) &gt; [kibana-plugin-public](./kibana-plugin-public.md) &gt; [NotificationsStart](./kibana-plugin-public.notificationsstart.md)

## NotificationsStart type
## NotificationsStart interface


<b>Signature:</b>

```typescript
export declare type NotificationsStart = NotificationsSetup;
export interface NotificationsStart
```

## Properties

| Property | Type | Description |
| --- | --- | --- |
| [toasts](./kibana-plugin-public.notificationsstart.toasts.md) | <code>ToastsStart</code> | |

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; [NotificationsStart](./kibana-plugin-public.notificationsstart.md) &gt; [toasts](./kibana-plugin-public.notificationsstart.toasts.md)

## NotificationsStart.toasts property

<b>Signature:</b>

```typescript
toasts: ToastsStart;
```
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
<b>Signature:</b>

```typescript
export declare type ToastInput = string | Pick<Toast, Exclude<keyof Toast, 'id'>>;
export declare type ToastInput = string | ToastInputFields | Promise<ToastInputFields>;
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index) &gt; [kibana-plugin-public](./kibana-plugin-public.md) &gt; [ToastsApi](./kibana-plugin-public.toastsapi.md) &gt; [addError](./kibana-plugin-public.toastsapi.adderror.md)

## ToastsApi.addError() method

<b>Signature:</b>

```typescript
addError(error: Error, options: ErrorToastOptions): Toast;
```

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| error | <code>Error</code> | |
| options | <code>ErrorToastOptions</code> | |

<b>Returns:</b>

`Toast`

Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ export declare class ToastsApi
| --- | --- | --- |
| [add(toastOrTitle)](./kibana-plugin-public.toastsapi.add.md) | | |
| [addDanger(toastOrTitle)](./kibana-plugin-public.toastsapi.adddanger.md) | | |
| [addError(error, options)](./kibana-plugin-public.toastsapi.adderror.md) | | |
| [addSuccess(toastOrTitle)](./kibana-plugin-public.toastsapi.addsuccess.md) | | |
| [addWarning(toastOrTitle)](./kibana-plugin-public.toastsapi.addwarning.md) | | |
| [get$()](./kibana-plugin-public.toastsapi.get$.md) | | |
| [registerOverlays(overlays)](./kibana-plugin-public.toastsapi.registeroverlays.md) | | |
| [remove(toast)](./kibana-plugin-public.toastsapi.remove.md) | | |

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

[Home](./index) &gt; [kibana-plugin-public](./kibana-plugin-public.md) &gt; [ToastsApi](./kibana-plugin-public.toastsapi.md) &gt; [registerOverlays](./kibana-plugin-public.toastsapi.registeroverlays.md)

## ToastsApi.registerOverlays() method

<b>Signature:</b>

```typescript
registerOverlays(overlays: OverlayStart): void;
```

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| overlays | <code>OverlayStart</code> | |

<b>Returns:</b>

`void`

1 change: 1 addition & 0 deletions src/core/public/core_system.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ describe('#start()', () => {
expect(MockNotificationsService.start).toHaveBeenCalledTimes(1);
expect(MockNotificationsService.start).toHaveBeenCalledWith({
i18n: expect.any(Object),
overlays: expect.any(Object),
targetDomElement: expect.any(HTMLElement),
});
});
Expand Down
5 changes: 3 additions & 2 deletions src/core/public/core_system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export class CoreSystem {
this.fatalErrorsSetup = this.fatalErrors.setup({ injectedMetadata, i18n });
const http = this.http.setup({ injectedMetadata, fatalErrors: this.fatalErrorsSetup });
const uiSettings = this.uiSettings.setup({ http, injectedMetadata });
const notifications = this.notifications.setup({ uiSettings });
const notifications = this.notifications.setup({ uiSettings, i18n });
const application = this.application.setup();
const chrome = this.chrome.setup({ injectedMetadata, notifications });

Expand Down Expand Up @@ -166,11 +166,12 @@ export class CoreSystem {
this.rootDomElement.appendChild(legacyPlatformTargetDomElement);
this.rootDomElement.appendChild(overlayTargetDomElement);

const overlays = this.overlay.start({ i18n, targetDomElement: overlayTargetDomElement });
const notifications = await this.notifications.start({
i18n,
overlays,
targetDomElement: notificationsTargetDomElement,
});
const overlays = this.overlay.start({ i18n, targetDomElement: overlayTargetDomElement });

const core: InternalCoreStart = {
application,
Expand Down
4 changes: 3 additions & 1 deletion src/core/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,12 @@ import { HttpServiceBase, HttpSetup, HttpStart } from './http';
import { I18nSetup, I18nStart } from './i18n';
import { InjectedMetadataSetup, InjectedMetadataStart, LegacyNavLink } from './injected_metadata';
import {
ErrorToastOptions,
NotificationsSetup,
NotificationsStart,
Toast,
ToastInput,
ToastsApi,
NotificationsStart,
} from './notifications';
import { OverlayRef, OverlayStart } from './overlays';
import { Plugin, PluginInitializer, PluginInitializerContext } from './plugins';
Expand Down Expand Up @@ -128,6 +129,7 @@ export {
HttpServiceBase,
HttpSetup,
HttpStart,
ErrorToastOptions,
FatalErrorsSetup,
FatalErrorInfo,
Capabilities,
Expand Down
2 changes: 1 addition & 1 deletion src/core/public/notifications/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

export { Toast, ToastInput, ToastsApi } from './toasts';
export { ErrorToastOptions, Toast, ToastInput, ToastsApi } from './toasts';
export {
NotificationsService,
NotificationsSetup,
Expand Down
22 changes: 13 additions & 9 deletions src/core/public/notifications/notifications_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,19 @@
import { i18n } from '@kbn/i18n';

import { Subscription } from 'rxjs';
import { I18nStart } from '../i18n';
import { ToastsService } from './toasts';
import { ToastsApi } from './toasts/toasts_api';
import { I18nStart, I18nSetup } from '../i18n';
import { ToastsService, ToastsSetup, ToastsStart } from './toasts';
import { UiSettingsSetup } from '../ui_settings';
import { OverlayStart } from '../overlays';

interface SetupDeps {
i18n: I18nSetup;
uiSettings: UiSettingsSetup;
}

interface StartDeps {
i18n: I18nStart;
overlays: OverlayStart;
targetDomElement: HTMLElement;
}

Expand All @@ -44,8 +46,8 @@ export class NotificationsService {
this.toasts = new ToastsService();
}

public setup({ uiSettings }: SetupDeps): NotificationsSetup {
const notificationSetup = { toasts: this.toasts.setup() };
public setup({ i18n: i18nSetup, uiSettings }: SetupDeps): NotificationsSetup {
const notificationSetup = { toasts: this.toasts.setup({ i18n: i18nSetup, uiSettings }) };

this.uiSettingsErrorSubscription = uiSettings.getUpdateErrors$().subscribe(error => {
notificationSetup.toasts.addDanger({
Expand All @@ -59,13 +61,13 @@ export class NotificationsService {
return notificationSetup;
}

public start({ i18n: i18nDep, targetDomElement }: StartDeps): NotificationsStart {
public start({ i18n: i18nDep, overlays, targetDomElement }: StartDeps): NotificationsStart {
this.targetDomElement = targetDomElement;
const toastsContainer = document.createElement('div');
targetDomElement.appendChild(toastsContainer);

return {
toasts: this.toasts.start({ i18n: i18nDep, targetDomElement: toastsContainer }),
toasts: this.toasts.start({ i18n: i18nDep, overlays, targetDomElement: toastsContainer }),
};
}

Expand All @@ -84,8 +86,10 @@ export class NotificationsService {

/** @public */
export interface NotificationsSetup {
toasts: ToastsApi;
toasts: ToastsSetup;
}

/** @public */
export type NotificationsStart = NotificationsSetup;
export interface NotificationsStart {
toasts: ToastsStart;
}

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

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

Loading

0 comments on commit 8f48832

Please sign in to comment.