Implement template notifications#7781
Conversation
|
Sent you some changes. tsullivan#1 |
|
Assigning myself as a reviewer. |
src/ui/public/notify/notifier.js
Outdated
There was a problem hiding this comment.
I left comments on a PR that was merged into this one about these conditions. This is helping to get the blocker issue fixed by not breaking an API, but I dug around and can't really see anywhere that error info and warning notifications actually use the callback param anywhere.
There was a problem hiding this comment.
Left a comment back there too, but I'll re-post it here.
I didn't see any in our code either, but it's possible plugins use it. I figured it best not to break the API until we take a bigger stab at updating Notifications.
There was a problem hiding this comment.
👍 Good point about plugins, and that we're planning to re-do Notifications as a whole in the near future.
5976468 to
f30ef66
Compare
src/ui/public/notify/notifier.js
Outdated
There was a problem hiding this comment.
Since the other "helper" methods take 2 parameters, this one should probably throw if config here isn't an object, so that nobody tries to pass a callback as the second parameter. For the custom notification, not passing a config object doesn't make a lot of sense...
|
I updated the description in this PR to reflect the modified API of the custom method. |
…ol over notifications
just run all content through the markdown parser, and add margin to alight text correctly
check value types, more tests with less concerns, clean up notifications after each test
Apparently, to get the "error" type as we call it, the type passed must be I think that inconsistency was never noticed because previously
|
I'd at least attempt this option first. If there are no conflicts, I think this is the saner option, for consistency sake. |
Looks like the keyword Trying to make this usage consistent with how we think of it as an Therefore, I think option 1 is the right way to go. Even though if you put |
|
Thanks for looking into option 2 @tsullivan. Sounds like option 1 it is! |
|
One thing I would like to do with the custom notification is to have a config option that can change the truncation length of the message. I think that is out of scope for this PR because it doesn't target the blocker this PR is meant to address. So that will be in a future PR. |
|
@ycombinator @cjcenizal @w33ble ready for another review |
|
Functionality (still) looks great! Reviewing code again... |
|
LGTM! |
| type="button" | ||
| class="btn" | ||
| ng-repeat="action in notif.customActions" | ||
| ng-class="'btn-' + notif.type" |
There was a problem hiding this comment.
This may be beyond the scope of this PR, but I think it will need to be done someday: I think we should be more explicit in our class assignment, e.g. via methods like getButtonClass(notif.type) and getToastClass(notif.type). This will uncouple the type from the class names for these elements, which will let us remove the 'error'/'danger' substitution on line 431. This will also give us to change the implementation details of these different types without having to change the type values in the future.
These methods could look something like this:
// In kbnNotifications directive's link function
const typeToButtonClassMap = {
info: 'btn-info',
warning: 'btn-warning',
error: 'btn-danger',
};
const typeToToastClassMap = {
info: 'alert-info',
warning: 'alert-warning',
error: 'alert-danger',
};
scope.getButtonClass(type) {
return typeToButtonClassMap[type] || 'btn-info';
}
scope.getToastClass(type) {
return typeToToastClassMap[type] || 'alert-info';
}
There was a problem hiding this comment.
I plan to have a follow-up PR that will allow custom control over the truncation length of the message. I can add a minor clean-up task there in that PR.
It could also be a standalone PR though - no reason for it not to be
|
I only had one small suggestion. LGTM otherwise! |
|
Sure thing, @w33ble. I forgot to squash commits before merge though. Whoops. |
--------- **Commit 1:** [Notifier] Added a custom notify function which allows complete control over notifications * Original sha: 33bf38f * Authored by Khalah Jones Golden <khalah@elastic.co> on 2016-07-07T20:40:08Z * Committed by Timothy Sullivan <tsullivan@elastic.co> on 2016-07-27T19:08:49Z **Commit 2:** custom notifications: use `text` as property for action button label * Original sha: 3c42f2d * Authored by Timothy Sullivan <tsullivan@elastic.co> on 2016-07-20T22:10:53Z **Commit 3:** remove distinction between content and markdown just run all content through the markdown parser, and add margin to alight text correctly * Original sha: 864cf9d * Authored by Joe Fleming <joe.fleming@gmail.com> on 2016-07-25T21:58:11Z * Committed by Timothy Sullivan <tsullivan@elastic.co> on 2016-07-27T19:08:49Z **Commit 4:** fix timeout starting at 0 bug * Original sha: 702c09a * Authored by Joe Fleming <joe.fleming@gmail.com> on 2016-07-25T22:11:04Z * Committed by Timothy Sullivan <tsullivan@elastic.co> on 2016-07-27T19:08:49Z **Commit 5:** allow 0 to be used to disable timeout * Original sha: eeeb94e * Authored by Joe Fleming <joe.fleming@gmail.com> on 2016-07-25T22:12:06Z * Committed by Timothy Sullivan <tsullivan@elastic.co> on 2016-07-27T19:08:49Z **Commit 6:** allow property overrides on helper methods * Original sha: b0584ef * Authored by Joe Fleming <joe.fleming@gmail.com> on 2016-07-25T22:46:22Z * Committed by Timothy Sullivan <tsullivan@elastic.co> on 2016-07-27T19:08:49Z **Commit 7:** make custom notify api closer to other helper apis * Original sha: 932751a * Authored by Joe Fleming <joe.fleming@gmail.com> on 2016-07-25T22:54:56Z * Committed by Timothy Sullivan <tsullivan@elastic.co> on 2016-07-27T19:08:49Z **Commit 8:** update custom notification tests * Original sha: 7055f6c * Authored by Joe Fleming <joe.fleming@gmail.com> on 2016-07-25T22:57:21Z * Committed by Timothy Sullivan <tsullivan@elastic.co> on 2016-07-27T19:08:49Z **Commit 9:** punch up the tests check value types, more tests with less concerns, clean up notifications after each test * Original sha: 47edbfd * Authored by Joe Fleming <joe.fleming@gmail.com> on 2016-07-26T00:12:29Z * Committed by Timothy Sullivan <tsullivan@elastic.co> on 2016-07-27T19:08:49Z **Commit 10:** fix issue with custom notification handling * Original sha: 507429f * Authored by Joe Fleming <joe.fleming@gmail.com> on 2016-07-26T00:12:46Z * Committed by Timothy Sullivan <tsullivan@elastic.co> on 2016-07-27T19:08:49Z **Commit 11:** update the docblock * Original sha: a9a0362 * Authored by Joe Fleming <joe.fleming@gmail.com> on 2016-07-26T00:19:57Z * Committed by Timothy Sullivan <tsullivan@elastic.co> on 2016-07-27T19:08:49Z **Commit 12:** Custom notification: throw error if config object is invalid * Original sha: d138de1 * Authored by Timothy Sullivan <tsullivan@elastic.co> on 2016-07-27T21:38:39Z **Commit 13:** Notifier Config: move overridableOptions to higher level * Original sha: 3ccde29 * Authored by Timothy Sullivan <tsullivan@elastic.co> on 2016-07-27T22:59:29Z **Commit 14:** switch order of negative/postive condition blocks * Original sha: 7ea3eee * Authored by Timothy Sullivan <tsullivan@elastic.co> on 2016-07-27T23:12:53Z **Commit 15:** remove unecessary ng-if * Original sha: 33c41e2 * Authored by Timothy Sullivan <tsullivan@elastic.co> on 2016-07-27T23:21:13Z **Commit 16:** remove limit of number of actions * Original sha: 259c480 * Authored by Timothy Sullivan <tsullivan@elastic.co> on 2016-07-27T23:27:11Z **Commit 17:** custom notifier dynamic lifetime based on type * Original sha: 03aa6b8 * Authored by Timothy Sullivan <tsullivan@elastic.co> on 2016-07-27T23:49:39Z **Commit 18:** test cleanup per feedback * Original sha: dbea052 * Authored by Timothy Sullivan <tsullivan@elastic.co> on 2016-07-28T00:20:44Z **Commit 19:** allow passing of `type: ‘error’` * Original sha: 0c7c339 * Authored by Timothy Sullivan <tsullivan@elastic.co> on 2016-07-28T01:55:55Z **Commit 20:** add tests for latest enhancements * Original sha: 7e99d6c * Authored by Timothy Sullivan <tsullivan@elastic.co> on 2016-07-28T23:10:48Z
…ications Implement template notifications Former-commit-id: 2adb8d4

Replaces #7670
Fixes #6933.
In order to use these notifications one must do something similar to the following code
All of the callbacks are wrapped in a close function. If you wish to display new information as a result of the action, make a new notification by calling
notify.type_of_notification()in the callback.