-
Notifications
You must be signed in to change notification settings - Fork 8.5k
Custom Notifications #7670
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
Closed
Closed
Custom Notifications #7670
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
f32b1f8
[Notifier] Added a custom notify function which allows complete contr…
de495e5
Merge remote-tracking branch 'upstream/master' into feature/custom-no…
bc80c36
[Notifier] Some code cleanup, and minimization, and added a default a…
9313102
[Tests] Added some tests, also made the check for actions stricter
f62094a
[Notify] Bug fix to no action logic
86d1516
[Notifier] increased the limit on number of custom actions
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -93,6 +93,12 @@ function add(notif, cb) { | |
| notif.actions.forEach(function (action) { | ||
| notif[action] = closeNotif(notif, cb, action); | ||
| }); | ||
| } else if (notif.customActions) { | ||
| // wrap all of the custom functions in a close | ||
| notif.customActions = notif.customActions.map(action => { | ||
| action.callback = closeNotif(notif, action.callback, action.key); | ||
| return action; | ||
| }); | ||
| } | ||
|
|
||
| notif.count = (notif.count || 0) + 1; | ||
|
|
@@ -364,6 +370,41 @@ Notifier.prototype.banner = function (msg, cb) { | |
| }, cb); | ||
| }; | ||
|
|
||
| /** | ||
| * Display a custom message | ||
| * @param {Object} config | ||
| * config = { | ||
| * title: 'Some Title here', | ||
| * markdown: 'Some markdown content', | ||
| * type: 'info', | ||
| * customActions: [{ | ||
| * key: 'next', | ||
| * callback: function() { next(); } | ||
| * }, { | ||
| * key: 'prev', | ||
| * callback: function() { prev(); } | ||
| * }] | ||
| * } | ||
| */ | ||
| Notifier.prototype.custom = function (config) { | ||
| const customActionMax = 3; | ||
| const mergedConfig = _.assign({}, { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You don't need to assign to an empty object here, you can just mutate the default settings object. |
||
| type: 'banner', | ||
| markdown: '', | ||
| lifetime: Notifier.config.bannerLifetime, | ||
| }, config); | ||
|
|
||
| const hasActions = _.get(mergedConfig, 'customActions.length') || _.get(mergedConfig, 'actions.length'); | ||
| // Add an ok if there are no actions, so you don't end up with a orphan notification | ||
| if (!hasActions) { | ||
| mergedConfig.actions = ['accept']; | ||
| } else if (mergedConfig.customActions) { | ||
| mergedConfig.customActions = mergedConfig.customActions.slice(0, customActionMax); | ||
| } | ||
|
|
||
| return add(mergedConfig); | ||
| }; | ||
|
|
||
| Notifier.prototype.describeError = formatMsg.describeError; | ||
|
|
||
| if (log === _.noop) { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why use
keyin the definition? From the outside, that parameter is really just defining the button text, isn't it? Couldn't it betext, like:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed I'll change this