Migrate dashboard save error from old toast message to new EUI toast (#19956)

* Migrate dashboard save error from old toast message to new EUI toast

* save function does not need to exist on  anymore

* account for error in onSave

* update clone

* lint errors
This commit is contained in:
Nathan Reese 2018-06-18 11:03:04 -06:00 committed by GitHub
parent 0945154302
commit e40e64126b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 17 deletions

View file

@ -58,7 +58,6 @@ const app = uiModules.get('app/dashboard', [
'react',
'kibana/courier',
'kibana/config',
'kibana/notify',
'kibana/typeahead',
]);
@ -67,7 +66,6 @@ app.directive('dashboardViewportProvider', function (reactDirective) {
});
app.directive('dashboardApp', function ($injector) {
const Notifier = $injector.get('Notifier');
const courier = $injector.get('courier');
const AppState = $injector.get('AppState');
const timefilter = $injector.get('timefilter');
@ -83,7 +81,6 @@ app.directive('dashboardApp', function ($injector) {
const filterManager = Private(FilterManagerProvider);
const filterBar = Private(FilterBarQueryFilterProvider);
const docTitle = Private(DocTitleProvider);
const notify = new Notifier({ location: 'Dashboard' });
const embeddableFactories = Private(EmbeddableFactoriesRegistryProvider);
const panelActionsRegistry = Private(DashboardPanelActionsRegistryProvider);
@ -288,7 +285,7 @@ app.directive('dashboardApp', function ($injector) {
* @return {Promise}
* @resolved {String} - The id of the doc
*/
$scope.save = function (saveOptions) {
function save(saveOptions) {
return saveDashboard(angular.toJson, timefilter, dashboardStateManager, saveOptions)
.then(function (id) {
$scope.kbnTopNav.close('save');
@ -305,9 +302,15 @@ app.directive('dashboardApp', function ($injector) {
updateViewMode(DashboardViewMode.VIEW);
}
}
return id;
}).catch(notify.error);
};
return { id };
}).catch((error) => {
toastNotifications.addDanger({
title: `Dashboard '${dash.title}' was not saved. Error: ${error.message}`,
'data-test-subj': 'saveDashboardFailure',
});
return { error };
});
}
$scope.showFilterBar = () => filterBar.getFilters().length > 0 || !dashboardStateManager.getFullScreenMode();
@ -338,14 +341,14 @@ app.directive('dashboardApp', function ($injector) {
isTitleDuplicateConfirmed,
onTitleDuplicate,
};
return $scope.save(saveOptions).then(id => {
return save(saveOptions).then(({ id, error }) => {
// If the save wasn't successful, put the original values back.
if (!id) {
if (!id || error) {
dashboardStateManager.setTitle(currentTitle);
dashboardStateManager.setDescription(currentDescription);
dashboardStateManager.setTimeRestore(currentTimeRestore);
}
return id;
return { id, error };
});
};
@ -367,12 +370,12 @@ app.directive('dashboardApp', function ($injector) {
isTitleDuplicateConfirmed,
onTitleDuplicate,
};
return $scope.save(saveOptions).then(id => {
return save(saveOptions).then(({ id, error }) => {
// If the save wasn't successful, put the original title back.
if (!id) {
if (!id || error) {
dashboardStateManager.setTitle(currentTitle);
}
return id;
return { id, error };
});
};

View file

@ -29,8 +29,8 @@ export function showCloneModal(onClone, title) {
};
const onCloneConfirmed = (newTitle, isTitleDuplicateConfirmed, onTitleDuplicate) => {
onClone(newTitle, isTitleDuplicateConfirmed, onTitleDuplicate).then(id => {
if (id) {
onClone(newTitle, isTitleDuplicateConfirmed, onTitleDuplicate).then(({ id, error }) => {
if (id || error) {
closeModal();
}
});

View file

@ -29,8 +29,8 @@ export function showSaveModal({ onSave, title, description, timeRestore, showCop
};
const onSaveConfirmed = (...args) => {
onSave(...args).then(id => {
if (id) {
onSave(...args).then(({ id, error }) => {
if (id || error) {
closeModal();
}
});