diff --git a/src/kibana/components/config/defaults.js b/src/kibana/components/config/defaults.js index c70d4d336d028..ba3ca50d25041 100644 --- a/src/kibana/components/config/defaults.js +++ b/src/kibana/components/config/defaults.js @@ -47,7 +47,7 @@ define(function (require) { description: 'Shorten long fields, for example, instead of foo.bar.baz, show f.b.baz', }, 'truncate:maxHeight': { - value: 100, + value: 115, description: 'The maximum height that a cell in a table should occupy. Set to 0 to disable truncation.' } }; diff --git a/src/kibana/plugins/discover/directives/table_row.js b/src/kibana/plugins/discover/directives/table_row.js index 9207da116facf..4e51cae92b60b 100644 --- a/src/kibana/plugins/discover/directives/table_row.js +++ b/src/kibana/plugins/discover/directives/table_row.js @@ -1,9 +1,13 @@ define(function (require) { var _ = require('lodash'); var $ = require('jquery'); - var htmlEscape = require('utils/html_escape'); + var addWordBreaks = require('utils/add_word_breaks'); + var noWhiteSpace = require('utils/no_white_space'); var module = require('modules').get('app/discover'); + // guestimate at the minimum number of chars wide cells in the table should be + var MIN_LINE_LENGTH = 20; + /** * kbnTableRow directive * @@ -17,7 +21,7 @@ define(function (require) { var detailsHtml = require('text!plugins/discover/partials/table_row/details.html'); var cellTemplate = _.template(require('text!plugins/discover/partials/table_row/cell.html')); var truncateByHeightTemplate = _.template(require('text!partials/truncate_by_height.html')); - var sourceTemplate = _.template(require('text!plugins/discover/partials/table_row/_source.html')); + var sourceTemplate = _.template(noWhiteSpace(require('text!plugins/discover/partials/table_row/_source.html'))); return { restrict: 'A', @@ -124,7 +128,9 @@ define(function (require) { var formatted; if (column === '_source') { formatted = sourceTemplate({ - source: row._formatted + source: _.mapValues(row._formatted, function (val) { + return addWordBreaks(val, MIN_LINE_LENGTH); + }) }); } else { formatted = _displayField(row, column, true); @@ -171,46 +177,15 @@ define(function (require) { */ function _displayField(row, field, breakWords) { var text = _getValForField(row, field); - var minLineLength = 20; - if (breakWords) { - text = htmlEscape(text); - var lineSize = 0; - var newText = ''; - for (var i = 0, len = text.length; i < len; i++) { - var chr = text.charAt(i); - newText += chr; - - switch (chr) { - case ' ': - case '&': - case ';': - case ':': - case ',': - // natural line break, reset line size - lineSize = 0; - break; - default: - lineSize++; - break; - } - - if (lineSize > minLineLength) { - // continuous text is longer then we want, - // so break it up with a - lineSize = 0; - newText += ''; - } - } + text = addWordBreaks(text, MIN_LINE_LENGTH); - if (text.length > minLineLength) { + if (text.length > MIN_LINE_LENGTH) { return truncateByHeightTemplate({ - body: newText + body: text }); } - - text = newText; } return text; diff --git a/src/kibana/plugins/discover/partials/table_row/_source.html b/src/kibana/plugins/discover/partials/table_row/_source.html index 4a130657bd3ec..04bc577161f77 100644 --- a/src/kibana/plugins/discover/partials/table_row/_source.html +++ b/src/kibana/plugins/discover/partials/table_row/_source.html @@ -1,6 +1,7 @@ -
- <% _.each(source, function (value, field) { %> - <%- field %>: - <%- value %> - <% }); %> -
\ No newline at end of file +
+ <% _.each(source, function (value, field) { %> +
<%= field %>:
+
<%= value %>
+ <%= ' ' %> + <% }); %> +
diff --git a/src/kibana/styles/_table.less b/src/kibana/styles/_table.less index 6901f9815b021..4969855785407 100644 --- a/src/kibana/styles/_table.less +++ b/src/kibana/styles/_table.less @@ -21,20 +21,23 @@ kbn-table,tbody[kbn-rows] { padding-right: 15px; } - .source { - line-height: 1.8em; + dl.source { + line-height: 2em; + margin-bottom: 0; - .source-field { - background: lightgray; + dt { + display: inline; + background: #ECECEC; padding: 0.15em 0.2em 0.15em 0.7em; + margin-right: 0.3em; font-weight: bold; - margin: 0 0 0 5px; - color: dimgray; - font-size: 0.85em; + color: #5F5F5F; + font-family: monospace; } - .source-value { - padding: 0 5px; + dd { + display: inline; + margin-right: 0.75em; } } } \ No newline at end of file diff --git a/src/kibana/utils/add_word_breaks.js b/src/kibana/utils/add_word_breaks.js new file mode 100644 index 0000000000000..e59f132f5502a --- /dev/null +++ b/src/kibana/utils/add_word_breaks.js @@ -0,0 +1,37 @@ +define(function (require) { + var _ = require('lodash'); + + return function addWordBreaks(text, minLineLength) { + text = _.escape(text); + var lineSize = 0; + var newText = ''; + + for (var i = 0, len = text.length; i < len; i++) { + var chr = text.charAt(i); + newText += chr; + + switch (chr) { + case ' ': + case '&': + case ';': + case ':': + case ',': + // natural line break, reset line size + lineSize = 0; + break; + default: + lineSize++; + break; + } + + if (lineSize > minLineLength) { + // continuous text is longer then we want, + // so break it up with a + lineSize = 0; + newText += ''; + } + } + + return newText; + }; +}); \ No newline at end of file diff --git a/src/kibana/utils/no_white_space.js b/src/kibana/utils/no_white_space.js new file mode 100644 index 0000000000000..65ea5dd9f2892 --- /dev/null +++ b/src/kibana/utils/no_white_space.js @@ -0,0 +1,20 @@ +define(function (require) { + var TAGS_WITH_WS = />\s+<'); + }; +}); \ No newline at end of file diff --git a/test/unit/specs/apps/discover/directives/table.js b/test/unit/specs/apps/discover/directives/table.js index 6bcde4de82983..ccfd8da5936bb 100644 --- a/test/unit/specs/apps/discover/directives/table.js +++ b/test/unit/specs/apps/discover/directives/table.js @@ -439,7 +439,7 @@ define(function (require) { expect($before).to.have.length(3); expect($before.eq(0).text().trim()).to.be(''); expect($before.eq(1).text().trim()).to.match(/^timestamp_formatted/); - expect($before.eq(2).find('.source-field').length).to.be(4); + expect($before.eq(2).find('dl dt').length).to.be(4); })); afterEach(function () { diff --git a/test/unit/specs/utils/html_escape.js b/test/unit/specs/utils/html_escape.js deleted file mode 100644 index 3b6e4d45559c2..0000000000000 --- a/test/unit/specs/utils/html_escape.js +++ /dev/null @@ -1,19 +0,0 @@ -define(function (require) { - describe('HTML Escape Util', function () { - var htmlEscape = require('utils/html_escape'); - - it('removes tags by replacing their angle-brackets', function () { - expect(htmlEscape('

header

')).to.eql('<h1>header</h1>'); - }); - - it('removes attributes from tags using " and '', function () { - expect(htmlEscape('

header

')) - .to.eql('<h1 onclick="alert('hi');">header</h1>'); - }); - - it('escapes existing html entities by escaping their leading &', function () { - expect(htmlEscape('<h1>header</h1>')) - .to.eql('&lt;h1&gt;header&lt;/h1&gt;'); - }); - }); -}); \ No newline at end of file