Skip to content

Commit 3184b4e

Browse files
timroesjoshdover
authored andcommitted
Add addError function to toastNotifications (#32187)
1 parent 1bbb8e3 commit 3184b4e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+658
-103
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
2+
3+
[Home](./index) &gt; [kibana-plugin-public](./kibana-plugin-public.md) &gt; [ErrorToastOptions](./kibana-plugin-public.errortoastoptions.md)
4+
5+
## ErrorToastOptions interface
6+
7+
<b>Signature:</b>
8+
9+
```typescript
10+
export interface ErrorToastOptions
11+
```
12+
13+
## Properties
14+
15+
| Property | Type | Description |
16+
| --- | --- | --- |
17+
| [title](./kibana-plugin-public.errortoastoptions.title.md) | <code>string</code> | The title of the toast and the dialog when expanding the message. |
18+
| [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. |
19+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
2+
3+
[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)
4+
5+
## ErrorToastOptions.title property
6+
7+
The title of the toast and the dialog when expanding the message.
8+
9+
<b>Signature:</b>
10+
11+
```typescript
12+
title: string;
13+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
2+
3+
[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)
4+
5+
## ErrorToastOptions.toastMessage property
6+
7+
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.
8+
9+
<b>Signature:</b>
10+
11+
```typescript
12+
toastMessage?: string;
13+
```

docs/development/core/public/kibana-plugin-public.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,15 @@ The plugin integrates with the core system via lifecycle events: `setup`<!-- -->
3030
| [ChromeNavLink](./kibana-plugin-public.chromenavlink.md) | |
3131
| [CoreSetup](./kibana-plugin-public.coresetup.md) | Core services exposed to the <code>Plugin</code> setup lifecycle |
3232
| [CoreStart](./kibana-plugin-public.corestart.md) | Core services exposed to the <code>Plugin</code> start lifecycle |
33+
| [ErrorToastOptions](./kibana-plugin-public.errortoastoptions.md) | |
3334
| [FatalErrorInfo](./kibana-plugin-public.fatalerrorinfo.md) | Represents the <code>message</code> and <code>stack</code> of a fatal Error |
3435
| [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. |
3536
| [HttpInterceptor](./kibana-plugin-public.httpinterceptor.md) | |
3637
| [HttpServiceBase](./kibana-plugin-public.httpservicebase.md) | |
3738
| [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. |
3839
| [LegacyNavLink](./kibana-plugin-public.legacynavlink.md) | |
3940
| [NotificationsSetup](./kibana-plugin-public.notificationssetup.md) | |
41+
| [NotificationsStart](./kibana-plugin-public.notificationsstart.md) | |
4042
| [OverlayRef](./kibana-plugin-public.overlayref.md) | |
4143
| [OverlayStart](./kibana-plugin-public.overlaystart.md) | |
4244
| [Plugin](./kibana-plugin-public.plugin.md) | The interface that should be returned by a <code>PluginInitializer</code>. |
@@ -53,7 +55,6 @@ The plugin integrates with the core system via lifecycle events: `setup`<!-- -->
5355
| [HttpSetup](./kibana-plugin-public.httpsetup.md) | |
5456
| [HttpStart](./kibana-plugin-public.httpstart.md) | |
5557
| [I18nStart](./kibana-plugin-public.i18nstart.md) | |
56-
| [NotificationsStart](./kibana-plugin-public.notificationsstart.md) | |
5758
| [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. |
5859
| [ToastInput](./kibana-plugin-public.toastinput.md) | |
5960
| [UiSettingsSetup](./kibana-plugin-public.uisettingssetup.md) | |

docs/development/core/public/kibana-plugin-public.notificationssetup.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ export interface NotificationsSetup
1515

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

docs/development/core/public/kibana-plugin-public.notificationssetup.toasts.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@
77
<b>Signature:</b>
88

99
```typescript
10-
toasts: ToastsApi;
10+
toasts: ToastsSetup;
1111
```

docs/development/core/public/kibana-plugin-public.notificationsstart.md

+9-2
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,18 @@
22

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

5-
## NotificationsStart type
5+
## NotificationsStart interface
66

77

88
<b>Signature:</b>
99

1010
```typescript
11-
export declare type NotificationsStart = NotificationsSetup;
11+
export interface NotificationsStart
1212
```
13+
14+
## Properties
15+
16+
| Property | Type | Description |
17+
| --- | --- | --- |
18+
| [toasts](./kibana-plugin-public.notificationsstart.toasts.md) | <code>ToastsStart</code> | |
19+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
2+
3+
[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)
4+
5+
## NotificationsStart.toasts property
6+
7+
<b>Signature:</b>
8+
9+
```typescript
10+
toasts: ToastsStart;
11+
```

docs/development/core/public/kibana-plugin-public.toastinput.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@
88
<b>Signature:</b>
99

1010
```typescript
11-
export declare type ToastInput = string | Pick<Toast, Exclude<keyof Toast, 'id'>>;
11+
export declare type ToastInput = string | ToastInputFields | Promise<ToastInputFields>;
1212
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
2+
3+
[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)
4+
5+
## ToastsApi.addError() method
6+
7+
<b>Signature:</b>
8+
9+
```typescript
10+
addError(error: Error, options: ErrorToastOptions): Toast;
11+
```
12+
13+
## Parameters
14+
15+
| Parameter | Type | Description |
16+
| --- | --- | --- |
17+
| error | <code>Error</code> | |
18+
| options | <code>ErrorToastOptions</code> | |
19+
20+
<b>Returns:</b>
21+
22+
`Toast`
23+

docs/development/core/public/kibana-plugin-public.toastsapi.md

+2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@ export declare class ToastsApi
1717
| --- | --- | --- |
1818
| [add(toastOrTitle)](./kibana-plugin-public.toastsapi.add.md) | | |
1919
| [addDanger(toastOrTitle)](./kibana-plugin-public.toastsapi.adddanger.md) | | |
20+
| [addError(error, options)](./kibana-plugin-public.toastsapi.adderror.md) | | |
2021
| [addSuccess(toastOrTitle)](./kibana-plugin-public.toastsapi.addsuccess.md) | | |
2122
| [addWarning(toastOrTitle)](./kibana-plugin-public.toastsapi.addwarning.md) | | |
2223
| [get$()](./kibana-plugin-public.toastsapi.get$.md) | | |
24+
| [registerOverlays(overlays)](./kibana-plugin-public.toastsapi.registeroverlays.md) | | |
2325
| [remove(toast)](./kibana-plugin-public.toastsapi.remove.md) | | |
2426

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
2+
3+
[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)
4+
5+
## ToastsApi.registerOverlays() method
6+
7+
<b>Signature:</b>
8+
9+
```typescript
10+
registerOverlays(overlays: OverlayStart): void;
11+
```
12+
13+
## Parameters
14+
15+
| Parameter | Type | Description |
16+
| --- | --- | --- |
17+
| overlays | <code>OverlayStart</code> | |
18+
19+
<b>Returns:</b>
20+
21+
`void`
22+

src/core/public/core_system.test.ts

+1
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ describe('#start()', () => {
235235
expect(MockNotificationsService.start).toHaveBeenCalledTimes(1);
236236
expect(MockNotificationsService.start).toHaveBeenCalledWith({
237237
i18n: expect.any(Object),
238+
overlays: expect.any(Object),
238239
targetDomElement: expect.any(HTMLElement),
239240
});
240241
});

src/core/public/core_system.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ export class CoreSystem {
116116
this.fatalErrorsSetup = this.fatalErrors.setup({ injectedMetadata, i18n });
117117
const http = this.http.setup({ injectedMetadata, fatalErrors: this.fatalErrorsSetup });
118118
const uiSettings = this.uiSettings.setup({ http, injectedMetadata });
119-
const notifications = this.notifications.setup({ uiSettings });
119+
const notifications = this.notifications.setup({ uiSettings, i18n });
120120
const application = this.application.setup();
121121
const chrome = this.chrome.setup({ injectedMetadata, notifications });
122122

@@ -166,11 +166,12 @@ export class CoreSystem {
166166
this.rootDomElement.appendChild(legacyPlatformTargetDomElement);
167167
this.rootDomElement.appendChild(overlayTargetDomElement);
168168

169+
const overlays = this.overlay.start({ i18n, targetDomElement: overlayTargetDomElement });
169170
const notifications = await this.notifications.start({
170171
i18n,
172+
overlays,
171173
targetDomElement: notificationsTargetDomElement,
172174
});
173-
const overlays = this.overlay.start({ i18n, targetDomElement: overlayTargetDomElement });
174175

175176
const core: InternalCoreStart = {
176177
application,

src/core/public/index.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,12 @@ import { HttpServiceBase, HttpSetup, HttpStart, HttpInterceptor } from './http';
4949
import { I18nSetup, I18nStart } from './i18n';
5050
import { InjectedMetadataSetup, InjectedMetadataStart, LegacyNavLink } from './injected_metadata';
5151
import {
52+
ErrorToastOptions,
5253
NotificationsSetup,
54+
NotificationsStart,
5355
Toast,
5456
ToastInput,
5557
ToastsApi,
56-
NotificationsStart,
5758
} from './notifications';
5859
import { OverlayRef, OverlayStart } from './overlays';
5960
import { Plugin, PluginInitializer, PluginInitializerContext } from './plugins';
@@ -130,6 +131,7 @@ export {
130131
HttpSetup,
131132
HttpStart,
132133
HttpInterceptor,
134+
ErrorToastOptions,
133135
FatalErrorsSetup,
134136
FatalErrorInfo,
135137
Capabilities,

src/core/public/notifications/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* under the License.
1818
*/
1919

20-
export { Toast, ToastInput, ToastsApi } from './toasts';
20+
export { ErrorToastOptions, Toast, ToastInput, ToastsApi } from './toasts';
2121
export {
2222
NotificationsService,
2323
NotificationsSetup,

src/core/public/notifications/notifications_service.ts

+13-9
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,19 @@
2020
import { i18n } from '@kbn/i18n';
2121

2222
import { Subscription } from 'rxjs';
23-
import { I18nStart } from '../i18n';
24-
import { ToastsService } from './toasts';
25-
import { ToastsApi } from './toasts/toasts_api';
23+
import { I18nStart, I18nSetup } from '../i18n';
24+
import { ToastsService, ToastsSetup, ToastsStart } from './toasts';
2625
import { UiSettingsSetup } from '../ui_settings';
26+
import { OverlayStart } from '../overlays';
2727

2828
interface SetupDeps {
29+
i18n: I18nSetup;
2930
uiSettings: UiSettingsSetup;
3031
}
3132

3233
interface StartDeps {
3334
i18n: I18nStart;
35+
overlays: OverlayStart;
3436
targetDomElement: HTMLElement;
3537
}
3638

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

47-
public setup({ uiSettings }: SetupDeps): NotificationsSetup {
48-
const notificationSetup = { toasts: this.toasts.setup() };
49+
public setup({ i18n: i18nSetup, uiSettings }: SetupDeps): NotificationsSetup {
50+
const notificationSetup = { toasts: this.toasts.setup({ i18n: i18nSetup, uiSettings }) };
4951

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

62-
public start({ i18n: i18nDep, targetDomElement }: StartDeps): NotificationsStart {
64+
public start({ i18n: i18nDep, overlays, targetDomElement }: StartDeps): NotificationsStart {
6365
this.targetDomElement = targetDomElement;
6466
const toastsContainer = document.createElement('div');
6567
targetDomElement.appendChild(toastsContainer);
6668

6769
return {
68-
toasts: this.toasts.start({ i18n: i18nDep, targetDomElement: toastsContainer }),
70+
toasts: this.toasts.start({ i18n: i18nDep, overlays, targetDomElement: toastsContainer }),
6971
};
7072
}
7173

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

8587
/** @public */
8688
export interface NotificationsSetup {
87-
toasts: ToastsApi;
89+
toasts: ToastsSetup;
8890
}
8991

9092
/** @public */
91-
export type NotificationsStart = NotificationsSetup;
93+
export interface NotificationsStart {
94+
toasts: ToastsStart;
95+
}

src/core/public/notifications/toasts/__snapshots__/error_toast.test.tsx.snap

+29
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/core/public/notifications/toasts/__snapshots__/global_toast_list.test.tsx.snap

+2-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)