Replace Notifier usage by toastNotifications (#40764)
* Replace Notifier usage by toastNotifications * Fix $http errors
This commit is contained in:
parent
cef7fb614d
commit
c985c69f0c
4 changed files with 37 additions and 19 deletions
|
@ -24,7 +24,7 @@ import { i18n } from '@kbn/i18n';
|
|||
import { capabilities } from 'ui/capabilities';
|
||||
import { docTitle } from 'ui/doc_title';
|
||||
import { SavedObjectRegistryProvider } from 'ui/saved_objects/saved_object_registry';
|
||||
import { notify, fatalError, toastNotifications } from 'ui/notify';
|
||||
import { fatalError, toastNotifications } from 'ui/notify';
|
||||
import { timezoneProvider } from 'ui/vis/lib/timezone';
|
||||
import { recentlyAccessed } from 'ui/persisted_log';
|
||||
import { timefilter } from 'ui/timefilter';
|
||||
|
@ -66,8 +66,6 @@ require('./vis');
|
|||
|
||||
SavedObjectRegistryProvider.register(require('plugins/timelion/services/saved_sheet_register'));
|
||||
|
||||
const unsafeNotifications = notify._notifs;
|
||||
|
||||
require('ui/routes').enable();
|
||||
|
||||
require('ui/routes')
|
||||
|
@ -392,7 +390,6 @@ app.controller('timelion', function (
|
|||
|
||||
httpResult
|
||||
.then(function (resp) {
|
||||
dismissNotifications();
|
||||
$scope.stats = resp.stats;
|
||||
$scope.sheet = resp.sheet;
|
||||
_.each(resp.sheet, function (cell) {
|
||||
|
@ -461,9 +458,5 @@ app.controller('timelion', function (
|
|||
});
|
||||
}
|
||||
|
||||
function dismissNotifications() {
|
||||
unsafeNotifications.splice(0, unsafeNotifications.length);
|
||||
}
|
||||
|
||||
init();
|
||||
});
|
||||
|
|
|
@ -31,9 +31,6 @@ jest.mock('../../registry/field_formats', () => ({
|
|||
}));
|
||||
|
||||
jest.mock('../../notify', () => ({
|
||||
Notifier: jest.fn().mockImplementation(() => ({
|
||||
error: jest.fn(),
|
||||
})),
|
||||
toastNotifications: {
|
||||
addDanger: jest.fn(),
|
||||
}
|
||||
|
|
|
@ -24,7 +24,8 @@ import 'ui/saved_objects/ui/saved_object_save_as_checkbox';
|
|||
import chrome from 'ui/chrome';
|
||||
import { uiModules } from 'ui/modules';
|
||||
import uiRoutes from 'ui/routes';
|
||||
import { notify, addAppRedirectMessageToUrl, fatalError, toastNotifications } from 'ui/notify';
|
||||
import { addAppRedirectMessageToUrl, fatalError, toastNotifications } from 'ui/notify';
|
||||
import { formatAngularHttpError } from 'ui/notify/lib';
|
||||
import { IndexPatternsProvider } from 'ui/index_patterns/index_patterns';
|
||||
import { SavedObjectsClientProvider } from 'ui/saved_objects';
|
||||
import { KibanaParsedUrl } from 'ui/url/kibana_parsed_url';
|
||||
|
@ -173,7 +174,29 @@ app.controller('graphuiPlugin', function (
|
|||
|
||||
function handleError(err) {
|
||||
return checkLicense(Promise, kbnBaseUrl)
|
||||
.then(() => notify.error(err));
|
||||
.then(() => {
|
||||
const toastTitle = i18n.translate('xpack.graph.errorToastTitle', {
|
||||
defaultMessage: 'Graph Error',
|
||||
description: '"Graph" is a product name and should not be translated.',
|
||||
});
|
||||
if (err instanceof Error) {
|
||||
toastNotifications.addError(err, {
|
||||
title: toastTitle,
|
||||
});
|
||||
} else {
|
||||
toastNotifications.addDanger({
|
||||
title: toastTitle,
|
||||
text: String(err),
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function handleHttpError(error) {
|
||||
return checkLicense(Promise, kbnBaseUrl)
|
||||
.then(() => {
|
||||
toastNotifications.addDanger(formatAngularHttpError(error));
|
||||
});
|
||||
}
|
||||
|
||||
$scope.title = 'Graph';
|
||||
|
@ -432,7 +455,7 @@ app.controller('graphuiPlugin', function (
|
|||
}
|
||||
responseHandler(resp.data.resp);
|
||||
})
|
||||
.catch(handleError);
|
||||
.catch(handleHttpError);
|
||||
}
|
||||
|
||||
|
||||
|
@ -446,7 +469,7 @@ app.controller('graphuiPlugin', function (
|
|||
.then(function (resp) {
|
||||
responseHandler(resp.data.resp);
|
||||
})
|
||||
.catch(handleError);
|
||||
.catch(handleHttpError);
|
||||
};
|
||||
|
||||
$scope.submit = function () {
|
||||
|
|
|
@ -10,7 +10,8 @@ import { uiModules } from 'ui/modules';
|
|||
import { i18n } from '@kbn/i18n';
|
||||
import uiRoutes from 'ui/routes';
|
||||
import 'ui/capabilities/route_setup';
|
||||
import { notify } from 'ui/notify';
|
||||
import { toastNotifications } from 'ui/notify';
|
||||
import { formatAngularHttpError } from 'ui/notify/lib';
|
||||
|
||||
// License
|
||||
import { xpackInfo } from 'plugins/xpack_main/services/xpack_info';
|
||||
|
@ -98,7 +99,11 @@ function profileVizController($scope, $http, HighlightService) {
|
|||
$scope.resetHighlightPanel();
|
||||
let json = checkForParseErrors($scope.query);
|
||||
if (json.status === false) {
|
||||
notify.error(json.error);
|
||||
toastNotifications.addError(json.error, {
|
||||
title: i18n.translate('xpack.searchProfiler.errorToastTitle', {
|
||||
defaultMessage: 'JSON parse error',
|
||||
}),
|
||||
});
|
||||
return;
|
||||
}
|
||||
json = json.parsed;
|
||||
|
@ -127,7 +132,7 @@ function profileVizController($scope, $http, HighlightService) {
|
|||
$scope.executeRemoteQuery = requestBody => {
|
||||
$http.post('../api/searchprofiler/profile', requestBody).then(resp => {
|
||||
if (!resp.data.ok) {
|
||||
notify.error(resp.data.err.msg);
|
||||
toastNotifications.addDanger(resp.data.err.msg);
|
||||
|
||||
try {
|
||||
const regex = /line=([0-9]+) col=([0-9]+)/g;
|
||||
|
@ -143,7 +148,7 @@ function profileVizController($scope, $http, HighlightService) {
|
|||
}
|
||||
|
||||
$scope.renderProfile(resp.data.resp.profile.shards);
|
||||
}).catch(notify.error);
|
||||
}).catch(reason => toastNotifications.addDanger(formatAngularHttpError(reason)));
|
||||
};
|
||||
|
||||
$scope.renderProfile = data => {
|
||||
|
|
Loading…
Reference in a new issue