From 4cd093aaa8ff118495e721d04ad4fe1c4df84239 Mon Sep 17 00:00:00 2001 From: Brett Sun Date: Thu, 10 Mar 2016 12:45:21 +0100 Subject: [PATCH] Ignore global notifications that do not contain a message --- js/components/ascribe_forms/create_editions_form.js | 8 +++++--- js/models/global_notification_model.js | 13 ++++++++----- js/stores/global_notification_store.js | 8 +++++--- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/js/components/ascribe_forms/create_editions_form.js b/js/components/ascribe_forms/create_editions_form.js index b2bf3c1c..47715d3d 100644 --- a/js/components/ascribe_forms/create_editions_form.js +++ b/js/components/ascribe_forms/create_editions_form.js @@ -26,11 +26,13 @@ let CreateEditionsForm = React.createClass({ }, handleSuccess(response) { - let notification = new GlobalNotificationModel(response.notification, 'success', 10000); + const { handleSuccess } = this.props; + + const notification = new GlobalNotificationModel(response.notification, 'success', 10000); GlobalNotificationActions.appendGlobalNotification(notification); - if(this.props.handleSuccess) { - this.props.handleSuccess(response); + if (typeof handleSuccess === 'function') { + handleSuccess(response); } }, diff --git a/js/models/global_notification_model.js b/js/models/global_notification_model.js index 49a82934..40f9c4f4 100644 --- a/js/models/global_notification_model.js +++ b/js/models/global_notification_model.js @@ -2,18 +2,21 @@ export default class GlobalNotificationModel { constructor(message, type = 'info', dismissAfter = 5000) { - if(message) { + if (message) { this.message = message; } else { - throw new Error('A notifications message must be defined.'); + console.logGlobal(new Error('Global notification did not contain a message and was ignored'), { + dismissAfter, + type + }); } - if(type === 'info' || type === 'success' || type === 'warning' || type === 'danger') { + if (type === 'info' || type === 'success' || type === 'warning' || type === 'danger') { this.type = type; } else { - throw new Error('A notification\'s type either has to be info, success, warning, danger. Not: ' + type); + throw new Error(`A notification's type either has to be info, success, warning, danger. Not: ${type}`); } this.dismissAfter = dismissAfter; } -} \ No newline at end of file +} diff --git a/js/stores/global_notification_store.js b/js/stores/global_notification_store.js index 7414812b..5cdb5c69 100644 --- a/js/stores/global_notification_store.js +++ b/js/stores/global_notification_store.js @@ -16,10 +16,12 @@ class GlobalNotificationStore { } onAppendGlobalNotification(newNotification) { - this.notificationQueue.push(newNotification); + if (newNotification && newNotification.message) { + this.notificationQueue.push(newNotification); - if (!this.notificationsPaused && this.notificationStatus === 'ready') { - this.showNextNotification(); + if (!this.notificationsPaused && this.notificationStatus === 'ready') { + this.showNextNotification(); + } } }