Merge pull request #7903 from tsullivan/notifications-custom-truncation

notifications: allow custom truncation length
This commit is contained in:
Tim Sullivan 2016-08-04 15:18:26 -07:00 committed by GitHub
commit c1543464fb
3 changed files with 33 additions and 9 deletions

View file

@ -66,6 +66,10 @@ describe('Notifier', function () {
expect(notify('error').lifetime).to.equal(300000);
});
it('sets truncation length to 250', function () {
expect(notify('error').truncationLength).to.equal(250);
});
it('sets timeRemaining and decrements', function () {
let notif = notify('error');
@ -143,6 +147,10 @@ describe('Notifier', function () {
expect(notify('warning').lifetime).to.equal(10000);
});
it('sets truncation length to 250', function () {
expect(notify('warning').truncationLength).to.equal(250);
});
it('does not allow reporting', function () {
let includesReport = _.includes(notify('warning').actions, 'report');
expect(includesReport).to.false;
@ -181,6 +189,10 @@ describe('Notifier', function () {
expect(notify('info').lifetime).to.equal(5000);
});
it('sets truncation length to 250', function () {
expect(notify('info').truncationLength).to.equal(250);
});
it('does not allow reporting', function () {
let includesReport = _.includes(notify('info').actions, 'report');
expect(includesReport).to.false;
@ -229,16 +241,18 @@ describe('Notifier', function () {
// destroy the default custom notification, avoid duplicate handling
customNotification.clear();
const explicitLifetimeParams = _.defaults({ lifetime: 20000 }, customParams);
customNotification = notifier.custom(customText, explicitLifetimeParams);
const overrideParams = _.defaults({ lifetime: 20000, truncationLength: 1000 }, customParams);
customNotification = notifier.custom(customText, overrideParams);
expect(customNotification).to.have.property('type', 'info'); // default
expect(customNotification).to.have.property('title', explicitLifetimeParams.title); // passed in
expect(customNotification).to.have.property('lifetime', explicitLifetimeParams.lifetime); // passed in
expect(customNotification).to.have.property('title', overrideParams.title); // passed in thru customParams
expect(customNotification).to.have.property('truncationLength', overrideParams.truncationLength); // passed in thru overrideParams
expect(customNotification).to.have.property('lifetime', overrideParams.lifetime); // passed in thru overrideParams
expect(explicitLifetimeParams.type).to.be(undefined);
expect(explicitLifetimeParams.title).to.be.a('string');
expect(explicitLifetimeParams.lifetime).to.be.a('number');
expect(overrideParams.type).to.be(undefined);
expect(overrideParams.title).to.be.a('string');
expect(overrideParams.truncationLength).to.be.a('number');
expect(overrideParams.lifetime).to.be.a('number');
});
it('sets the content', function () {
@ -340,6 +354,10 @@ describe('Notifier', function () {
expect(notify('banner').title).to.equal('Attention');
});
it('sets truncation length to 250 by default', function () {
expect(notify('banner').truncationLength).to.equal(250);
});
it('sets lifetime to 3000000 by default', function () {
expect(notify('banner').lifetime).to.equal(3000000);
});

View file

@ -188,7 +188,8 @@ Notifier.config = {
warningLifetime: 10000,
infoLifetime: 5000,
setInterval: window.setInterval,
clearInterval: window.clearInterval
clearInterval: window.clearInterval,
defaultTruncationLength: 250
};
Notifier.applyConfig = function (config) {
@ -331,6 +332,7 @@ Notifier.prototype.error = function (err, opts, cb) {
const config = _.assign({
type: 'danger',
content: formatMsg(err, this.from),
truncationLength: Notifier.config.defaultTruncationLength,
icon: 'warning',
title: 'Error',
lifetime: Notifier.config.errorLifetime,
@ -354,6 +356,7 @@ Notifier.prototype.warning = function (msg, opts, cb) {
const config = _.assign({
type: 'warning',
content: formatMsg(msg, this.from),
truncationLength: Notifier.config.defaultTruncationLength,
icon: 'warning',
title: 'Warning',
lifetime: Notifier.config.warningLifetime,
@ -376,6 +379,7 @@ Notifier.prototype.info = function (msg, opts, cb) {
const config = _.assign({
type: 'info',
content: formatMsg(msg, this.from),
truncationLength: Notifier.config.defaultTruncationLength,
icon: 'info-circle',
title: 'Debug',
lifetime: Notifier.config.infoLifetime,
@ -394,6 +398,7 @@ Notifier.prototype.banner = function (msg, cb) {
type: 'banner',
title: 'Attention',
content: formatMsg(msg, this.from),
truncationLength: Notifier.config.defaultTruncationLength,
lifetime: Notifier.config.bannerLifetime,
actions: ['accept']
}, cb);
@ -448,6 +453,7 @@ Notifier.prototype.custom = function (msg, config, cb) {
type: 'info',
title: 'Notification',
content: formatMsg(msg, this.from),
truncationLength: config.truncationLength || Notifier.config.defaultTruncationLength,
lifetime: getLifetime(config.type)
}, config);

View file

@ -7,7 +7,7 @@
<i class="fa" ng-class="'fa-' + notif.icon" tooltip="{{notif.title}}"></i>
<kbn-truncated source="{{notif.content | markdown}}" is-html="true" length="250" class="toast-message" /></kbn-truncated>
<kbn-truncated source="{{notif.content | markdown}}" is-html="true" length="{{notif.truncationLength}}" class="toast-message" /></kbn-truncated>
<div class="btn-group pull-right toast-controls">
<button