Skip to content

Commit

Permalink
Convert usage of notify.error to toastNotifications.addDanger for str…
Browse files Browse the repository at this point in the history
…ing messages (#22243) (#22309)

* Update buildHierarchicalData test.
  • Loading branch information
cjcenizal committed Aug 23, 2018
1 parent 4fe840e commit 8ed3b1e
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 26 deletions.
7 changes: 5 additions & 2 deletions src/core_plugins/kibana/public/home/load_tutorials.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import _ from 'lodash';
import chrome from 'ui/chrome';
import { notify } from 'ui/notify';
import { toastNotifications } from 'ui/notify';

const baseUrl = chrome.addBasePath('/api/kibana/home/tutorials');
const headers = new Headers();
Expand All @@ -44,7 +44,10 @@ async function loadTutorials() {
tutorials = await response.json();
tutorialsLoaded = true;
} catch(err) {
notify.error(`Unable to load tutorials, ${err}`);
toastNotifications.addDanger({
title: 'Unable to load tutorials',
text: err.message,
});
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import './index_header';
import './create_edit_field';
import { KbnUrlProvider } from 'ui/url';
import { IndicesEditSectionsProvider } from './edit_sections';
import { fatalError } from 'ui/notify';
import { fatalError, toastNotifications } from 'ui/notify';
import uiRoutes from 'ui/routes';
import { uiModules } from 'ui/modules';
import template from './edit_index_pattern.html';
Expand Down Expand Up @@ -181,8 +181,7 @@ uiRoutes

uiModules.get('apps/management')
.controller('managementIndicesEdit', function (
$scope, $location, $route, config, indexPatterns, Notifier, Private, AppState, docTitle, confirmModal) {
const notify = new Notifier();
$scope, $location, $route, config, indexPatterns, Private, AppState, docTitle, confirmModal) {
const $state = $scope.state = new AppState();
const { fieldWildcardMatcher } = Private(FieldWildcardProvider);

Expand Down Expand Up @@ -292,7 +291,7 @@ uiModules.get('apps/management')
const errorMessage = i18n.translate('kbn.management.editIndexPattern.notDateErrorMessage', {
defaultMessage: 'That field is a {fieldType} not a date.', values: { fieldType: field.type }
});
notify.error(errorMessage);
toastNotifications.addDanger(errorMessage);
return;
}
$scope.indexPattern.timeFieldName = field.name;
Expand Down
6 changes: 3 additions & 3 deletions src/core_plugins/status_page/public/lib/load_status.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import _ from 'lodash';

import chrome from 'ui/chrome';
import { notify } from 'ui/notify';
import { toastNotifications } from 'ui/notify';
import { i18n } from '@kbn/i18n';

// Module-level error returned by notify.error
Expand Down Expand Up @@ -130,7 +130,7 @@ async function loadStatus(fetchFn = fetchData) {
},
);

errorNotif = notify.error(serverIsDownErrorMessage);
errorNotif = toastNotifications.addDanger(serverIsDownErrorMessage);
return e;
}

Expand All @@ -144,7 +144,7 @@ async function loadStatus(fetchFn = fetchData) {
},
);

errorNotif = notify.error(serverStatusCodeErrorMessage);
errorNotif = toastNotifications.addDanger(serverStatusCodeErrorMessage);
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import fixtures from 'fixtures/fake_hierarchical_data';
import sinon from 'sinon';
import expect from 'expect.js';
import ngMock from 'ng_mock';
import { toastNotifications } from 'ui/notify';
import { VisProvider } from '../../../vis';
import FixturesStubbedLogstashIndexPatternProvider from 'fixtures/stubbed_logstash_index_pattern';
import { BuildHierarchicalDataProvider } from '../build_hierarchical_data';
Expand Down Expand Up @@ -276,6 +277,9 @@ describe('buildHierarchicalData', function () {
let results;

beforeEach(function () {
// Clear existing toasts.
toastNotifications.list.splice(0);

let id = 1;
vis = new Vis(indexPattern, {
type: 'pie',
Expand All @@ -299,10 +303,11 @@ describe('buildHierarchicalData', function () {
});

it('should set the hits attribute for the results', function () {
const errCall = Notifier.prototype.error.getCall(0);
expect(errCall).to.be.ok();
expect(errCall.args[0]).to.contain('not supported');

// Ideally, buildHierarchicalData shouldn't be tightly coupled to toastNotifications. Instead,
// it should notify its consumer of this error and the consumer should be responsible for
// notifying the user. This test verifies the side effect of the error until we can remove
// this coupling.
expect(toastNotifications.list).to.have.length(1);
expect(results).to.have.property('slices');
expect(results).to.have.property('names');
expect(results.names).to.have.length(2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,18 @@
*/

import _ from 'lodash';
import { toastNotifications } from 'ui/notify';
import { extractBuckets } from './_extract_buckets';
import { createRawData } from './_create_raw_data';
import { arrayToLinkedList } from './_array_to_linked_list';
import AggConfigResult from '../../vis/agg_config_result';
import { AggResponseHierarchicalBuildSplitProvider } from './_build_split';
import { HierarchicalTooltipFormatterProvider } from './_hierarchical_tooltip_formatter';

export function BuildHierarchicalDataProvider(Private, Notifier) {
export function BuildHierarchicalDataProvider(Private) {
const buildSplit = Private(AggResponseHierarchicalBuildSplitProvider);
const tooltipFormatter = Private(HierarchicalTooltipFormatterProvider);


const notify = new Notifier({
location: 'Pie chart response converter'
});

return function (vis, resp) {
// Create a reference to the buckets
let buckets = vis.getAggConfig().bySchemaGroup.buckets;
Expand Down Expand Up @@ -73,7 +69,10 @@ export function BuildHierarchicalDataProvider(Private, Notifier) {
const aggData = resp.aggregations ? resp.aggregations[firstAgg.id] : null;

if (!firstAgg._next && firstAgg.schema.name === 'split') {
notify.error('Splitting charts without splitting slices is not supported. Pretending that we are just splitting slices.');
toastNotifications.addDanger({
title: 'Splitting charts without splitting slices is not supported',
text: 'Pretending that we are just splitting slices.'
});
}

// start with splitting slices
Expand Down
6 changes: 2 additions & 4 deletions src/ui/public/scripting_languages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@
*/

import chrome from '../chrome';
import { Notifier } from '../notify';

const notify = new Notifier({ location: 'Scripting Language Service' });
import { toastNotifications } from '../notify';

export function getSupportedScriptingLanguages() {
return ['painless'];
Expand All @@ -35,7 +33,7 @@ export function GetEnabledScriptingLanguagesProvider($http) {
return $http.get(chrome.addBasePath('/api/kibana/scripts/languages'))
.then((res) => res.data)
.catch(() => {
notify.error('Error getting available scripting languages from Elasticsearch');
toastNotifications.addDanger('Error getting available scripting languages from Elasticsearch');
return [];
});
};
Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/graph/public/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ uiRoutes
return savedGraphWorkspaces.get($route.current.params.id)
.catch(
function () {
notify.error('Missing workspace');
toastNotifications.addDanger('Missing workspace');
}
);

Expand Down Expand Up @@ -830,7 +830,7 @@ app.controller('graphuiPlugin', function ($scope, $route, $interval, $http, kbnU
}
});
if(!savedObjectIndexPattern) {
notify.error('Missing index pattern:' + wsObj.indexPattern);
toastNotifications.addDanger(`'Missing index pattern ${wsObj.indexPattern}`);
return;
}

Expand Down

0 comments on commit 8ed3b1e

Please sign in to comment.