Skip to content

Commit 1b94a7c

Browse files
committed
beautiful toasts
1 parent 366408d commit 1b94a7c

File tree

8 files changed

+72
-22
lines changed

8 files changed

+72
-22
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
import React, { Fragment } from 'react';
8+
import { FormattedMessage } from '@kbn/i18n/react';
9+
import { EuiCallOut, EuiSpacer } from '@elastic/eui';
10+
import { ToastInput } from '../../../../../src/core/public';
11+
12+
export const getGeneralErrorToast = (errorText: string, err: Error): ToastInput => ({
13+
text: (
14+
<Fragment>
15+
<EuiCallOut title={errorText} color="danger" iconType="alert">
16+
{err.toString()}
17+
</EuiCallOut>
18+
19+
<EuiSpacer />
20+
21+
<FormattedMessage
22+
id="xpack.reportingNotifier.error.tryRefresh"
23+
defaultMessage="Try refreshing the page."
24+
></FormattedMessage>
25+
</Fragment>
26+
),
27+
iconType: undefined,
28+
});

x-pack/plugins/reporting_notifier/public/components/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ export { getSuccessToast } from './job_success';
88
export { getFailureToast } from './job_failure';
99
export { getWarningFormulasToast } from './job_warning_formulas';
1010
export { getWarningMaxSizeToast } from './job_warning_max_size';
11+
export { getGeneralErrorToast } from './general_error';

x-pack/plugins/reporting_notifier/public/components/job_failure.tsx

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
*/
66

77
import React, { Fragment } from 'react';
8+
import { i18n } from '@kbn/i18n';
89
import { FormattedMessage } from '@kbn/i18n/react';
10+
import { EuiCallOut, EuiSpacer } from '@elastic/eui';
911
import { ToastInput } from '../../../../../src/core/public';
1012
import { JobSummary, ManagementLinkFn } from '../../index.d';
1113

@@ -24,13 +26,19 @@ export const getFailureToast = (
2426
),
2527
text: (
2628
<Fragment>
27-
<p>
28-
<FormattedMessage
29-
id="xpack.reportingNotifier.error.failedWithMessage"
30-
defaultMessage="The reporting job failed with the message: '{errorText}'"
31-
values={{ errorText }}
32-
/>
33-
</p>
29+
<EuiCallOut
30+
size="m"
31+
title={i18n.translate('xpack.reportingNotifier.error.calloutTitle', {
32+
defaultMessage: 'The reporting job failed',
33+
})}
34+
color="danger"
35+
iconType="alert"
36+
>
37+
{errorText}
38+
</EuiCallOut>
39+
40+
<EuiSpacer />
41+
3442
<p>
3543
<FormattedMessage
3644
id="xpack.reportingNotifier.error.checkManagement"
@@ -49,6 +57,7 @@ export const getFailureToast = (
4957
</p>
5058
</Fragment>
5159
),
60+
iconType: undefined,
5261
'data-test-subj': 'completeReportFailure',
5362
};
5463
};

x-pack/plugins/reporting_notifier/public/components/job_success.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ export const getSuccessToast = (
2626
color: 'success',
2727
text: (
2828
<Fragment>
29-
<ReportLink getUrl={getReportLink} />
29+
<p>
30+
<ReportLink getUrl={getReportLink} />
31+
</p>
3032
<DownloadButton getUrl={getDownloadLink} job={job} />
3133
</Fragment>
3234
),

x-pack/plugins/reporting_notifier/public/components/job_warning_formulas.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ export const getWarningFormulasToast = (
3131
defaultMessage="The report contains characters which spreadsheet applications can interpret as formulas."
3232
/>
3333
</p>
34-
<ReportLink getUrl={getReportLink} />
34+
<p>
35+
<ReportLink getUrl={getReportLink} />
36+
</p>
3537
<DownloadButton getUrl={getDownloadLink} job={job} />
3638
</Fragment>
3739
),

x-pack/plugins/reporting_notifier/public/components/job_warning_max_size.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ export const getWarningMaxSizeToast = (
3131
defaultMessage="The report reached the max size and contains partial data."
3232
/>
3333
</p>
34-
<ReportLink getUrl={getReportLink} />
34+
<p>
35+
<ReportLink getUrl={getReportLink} />
36+
</p>
3537
<DownloadButton getUrl={getDownloadLink} job={job} />
3638
</Fragment>
3739
),

x-pack/plugins/reporting_notifier/public/lib/stream_handler.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import {
2929
getFailureToast,
3030
getWarningFormulasToast,
3131
getWarningMaxSizeToast,
32+
getGeneralErrorToast,
3233
} from '../components';
3334
import { jobQueueClient } from './job_queue';
3435

@@ -124,12 +125,14 @@ export class ReportingNotifierStreamHandler {
124125
}),
125126
catchError(err => {
126127
// show connection refused toast
127-
this.notificationsFn().toasts.addDanger({
128-
text: i18n.translate('xpack.reportingNotifier.httpErrorMessage', {
129-
defaultMessage: 'Could not check the Kibana server for updated Reporting jobs! Try refreshing the page. {err}',
130-
values: { err: err.toString() }
131-
}),
132-
}); // prettier-ignore
128+
this.notificationsFn().toasts.addDanger(
129+
getGeneralErrorToast(
130+
i18n.translate('xpack.reportingNotifier.httpErrorMessage', {
131+
defaultMessage: 'Could not check Reporting job status!',
132+
}),
133+
err
134+
)
135+
); // prettier-ignore
133136
window.console.error(err);
134137
return Rx.of({ completed: [], failed: [] }); // log the error and resume
135138
})

x-pack/plugins/reporting_notifier/public/plugin.tsx

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
JOB_COMPLETION_NOTIFICATIONS_SESSION_KEY,
1919
} from '../constants';
2020
import { JobId, JobStatusBuckets } from '../index.d';
21+
import { getGeneralErrorToast } from './components';
2122
import { ReportingNotifierStreamHandler as StreamHandler } from './lib/stream_handler';
2223

2324
const {
@@ -55,12 +56,14 @@ export class ReportingNotifierPublicPlugin implements Plugin<any, any> {
5556
}),
5657
catchError(err => {
5758
// show general toast, log the error and resume
58-
notificationsFn().toasts.addDanger({
59-
text: i18n.translate('xpack.reportingNotifier.pollingErrorMessage', {
60-
defaultMessage: 'Reporting notifier error! Try refreshing the page. {err}',
61-
values: { err: err.toString() }
62-
}),
63-
}); // prettier-ignore
59+
notificationsFn().toasts.addDanger(
60+
getGeneralErrorToast(
61+
i18n.translate('xpack.reportingNotifier.pollingErrorMessage', {
62+
defaultMessage: 'Reporting notifier error!',
63+
}),
64+
err
65+
)
66+
);
6467
window.console.error(err);
6568
return Rx.of({ completed: [], failed: [] });
6669
})

0 commit comments

Comments
 (0)