Skip to content

Feature add props default notification #38

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
272 changes: 189 additions & 83 deletions dist/react-notification-system-redux.js

Large diffs are not rendered by default.

9 changes: 8 additions & 1 deletion lib/notifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ var Notifications = function (_React$Component) {

var _props = this.props,
notifications = _props.notifications,
store = _props.store;
store = _props.store,
defaults = _props.defaults;

var notificationIds = notifications.map(function (notification) {
return notification.uid;
Expand All @@ -84,6 +85,11 @@ var Notifications = function (_React$Component) {
});

notifications.forEach(function (notification) {
if (defaults) {
// assign defaultNotification for notification
notification = Object.assign(defaults, notification);
}

_this2.system().addNotification(_extends({}, notification, {
onRemove: function () {
function onRemove() {
Expand Down Expand Up @@ -133,6 +139,7 @@ var Notifications = function (_React$Component) {
}(_react2['default'].Component);

Notifications.propTypes = {
defaultNotification: _propTypes2['default'].object,
notifications: _propTypes2['default'].array,
store: _propTypes2['default'].shape({
dispatch: _propTypes2['default'].func.isRequired
Expand Down
8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"eslint": "^1.6.0",
"eslint-plugin-react": "^3.5.1",
"gulp": "^3.9.0",
"gulp-git": "^2.4.1",
"jest-cli": "^14.1.0",
"jsdom": "^9.8.3",
"lodash": "^4.14.2",
Expand All @@ -47,14 +48,18 @@
},
"dependencies": {
"prop-types": "^15.6.0",
"react-notification-system": "^0.2.x"
"react-notification-system": "^0.2.x",
"require-dir": "1.0.0"
},
"peerDependencies": {
"react": "^16.4.0-0",
"react-dom": "^16.4.0-0",
"react-redux": "^6.0.0",
"redux": "^3.6.0 || ^4.0.0"
},
"resolutions": {
"require-dir": "1.0.0"
},
"browserify-shim": {
"react": "global:React"
},
Expand All @@ -69,6 +74,7 @@
"test-dev": "mocha test/__tests__/**/* --watch",
"watch": "gulp watch:lib"
},

"keywords": [
"react-notification-system",
"redux"
Expand Down
8 changes: 7 additions & 1 deletion src/notifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Notifications extends React.Component {
}

componentDidUpdate(prevProps) {
const {notifications, store} = this.props;
const {notifications, store, defaults} = this.props;
const notificationIds = notifications.map(notification => notification.uid);
const systemNotifications = this.system().state.notifications || [];

Expand All @@ -34,6 +34,11 @@ class Notifications extends React.Component {
});

notifications.forEach(notification => {
if(defaults) {
// assign defaultNotification for notification
notification = Object.assign(defaults, notification);
}

this.system().addNotification({
...notification,
onRemove: () => {
Expand Down Expand Up @@ -63,6 +68,7 @@ class Notifications extends React.Component {
}

Notifications.propTypes = {
defaultNotification: PropTypes.object,
notifications: PropTypes.array,
store: PropTypes.shape({
dispatch: PropTypes.func.isRequired
Expand Down
24 changes: 24 additions & 0 deletions test/__tests__/notifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,4 +227,28 @@ describe('NotificationsComponent', () => {
done();
}, 50);
});
it('should assign defaultNotification for notifications', (done) => {
const wrapper = mountComponent({
defaults: { autoDismiss: 1 }
});
const onRemove = sinon.spy();
const shortNotification = {
title: 'test',
message: 'test message',
level: 'info',
onRemove
};

wrapper.setProps({
notifications: [shortNotification]
});

expect(wrapper.html()).to.have.string(shortNotification.title);
expect(wrapper.html()).to.have.string(shortNotification.message);

setTimeout(() => {
expect(onRemove.called).to.be.true;
done();
}, 1100);
});
});
Loading