Skip to content

Commit

Permalink
Merge pull request elastic#7903 from tsullivan/notifications-custom-t…
Browse files Browse the repository at this point in the history
…runcation

notifications: allow custom truncation length
  • Loading branch information
tsullivan authored Aug 4, 2016
2 parents 57f338a + ed4b2c7 commit c154346
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 9 deletions.
32 changes: 25 additions & 7 deletions src/ui/public/notify/__tests__/notifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 () {
Expand Down Expand Up @@ -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);
});
Expand Down
8 changes: 7 additions & 1 deletion src/ui/public/notify/notifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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);
Expand Down Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion src/ui/public/notify/partials/toaster.html
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c154346

Please sign in to comment.