From cf5dab741afd16eeafbfa24e27b8b7146ca2cbd5 Mon Sep 17 00:00:00 2001 From: Robert Clayburn Date: Tue, 9 Aug 2016 11:32:44 +0100 Subject: [PATCH 1/2] added: deleteNotification method which instantly removes notification, rather than removeNotification() which applies animation. Useful when a loading and a success message follow each other in quick succession, as the loading notificaitons animation had not yet terminated, causing an odd slide in and down to occur --- src/NotificationSystem.jsx | 14 ++++++++++++++ test/notification-system.test.js | 24 ++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/src/NotificationSystem.jsx b/src/NotificationSystem.jsx index c11b4e1..2d6d5f4 100644 --- a/src/NotificationSystem.jsx +++ b/src/NotificationSystem.jsx @@ -162,6 +162,20 @@ var NotificationSystem = React.createClass({ }); }, + deleteNotification: function(notification) { + var self = this; + Object.keys(this.refs).forEach(function(container) { + if (container.indexOf('container') > -1) { + Object.keys(self.refs[container].refs).forEach(function(_notification) { + var uid = notification.uid ? notification.uid : notification; + if (_notification === 'notification-' + uid) { + self.refs[container].refs[_notification]._removeNotification(); + } + }); + } + }); + }, + componentDidMount: function() { this._getStyles.setOverrideStyle(this.props.style); }, diff --git a/test/notification-system.test.js b/test/notification-system.test.js index e3aab6f..ea81859 100644 --- a/test/notification-system.test.js +++ b/test/notification-system.test.js @@ -164,6 +164,30 @@ describe('Notification Component', function() { done(); }); + it('should delete a notification using returned object', done => { + let notificationCreated = component.addNotification(defaultNotification); + let notification = TestUtils.scryRenderedDOMComponentsWithClass(instance, 'notification'); + expect(notification.length).toEqual(1); + + component.deleteNotification(notificationCreated); + //clock.tick(1000); + let notificationDeleted = TestUtils.scryRenderedDOMComponentsWithClass(instance, 'notification'); + expect(notificationDeleted.length).toEqual(0); + done(); + }); + + it('should delete a notification using uid', done => { + let notificationCreated = component.addNotification(defaultNotification); + let notification = TestUtils.scryRenderedDOMComponentsWithClass(instance, 'notification'); + expect(notification.length).toEqual(1); + + component.deleteNotification(notificationCreated.uid); + //clock.tick(200); + let notificationDeleted = TestUtils.scryRenderedDOMComponentsWithClass(instance, 'notification'); + expect(notificationDeleted.length).toEqual(0); + done(); + }); + it('should dismiss notification on click', done => { component.addNotification(notificationObj); let notification = TestUtils.findRenderedDOMComponentWithClass(instance, 'notification'); From b134504b4d627da7a243ae5f92c5a4485dca2f65 Mon Sep 17 00:00:00 2001 From: Robert Clayburn Date: Tue, 9 Aug 2016 12:24:04 +0100 Subject: [PATCH 2/2] seemly need to remove notification from state as well ; --- src/NotificationSystem.jsx | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/NotificationSystem.jsx b/src/NotificationSystem.jsx index 2d6d5f4..f5c944f 100644 --- a/src/NotificationSystem.jsx +++ b/src/NotificationSystem.jsx @@ -164,16 +164,22 @@ var NotificationSystem = React.createClass({ deleteNotification: function(notification) { var self = this; + var uid = notification.uid ? notification.uid : notification; Object.keys(this.refs).forEach(function(container) { if (container.indexOf('container') > -1) { Object.keys(self.refs[container].refs).forEach(function(_notification) { - var uid = notification.uid ? notification.uid : notification; if (_notification === 'notification-' + uid) { + console.log('remove ', _notification); self.refs[container].refs[_notification]._removeNotification(); } }); } }); + this.state.notifications.forEach(function(item, index) { + if (item.uid === uid) { + self.state.notifications.splice(index, 1); + } + }); }, componentDidMount: function() {