Commit 5ffd5769 by Torkel Ödegaard

feat(table): added support for column units overriding style units for table

parent 6dc24ab2
...@@ -36,7 +36,7 @@ export class TableRenderer { ...@@ -36,7 +36,7 @@ export class TableRenderer {
return v; return v;
} }
createColumnFormater(style) { createColumnFormater(style, column) {
if (!style) { if (!style) {
return this.defaultCellFormater; return this.defaultCellFormater;
} }
...@@ -53,7 +53,7 @@ export class TableRenderer { ...@@ -53,7 +53,7 @@ export class TableRenderer {
} }
if (style.type === 'number') { if (style.type === 'number') {
let valueFormater = kbn.valueFormats[style.unit]; let valueFormater = kbn.valueFormats[column.unit || style.unit];
return v => { return v => {
if (v === null || v === void 0) { if (v === null || v === void 0) {
...@@ -85,7 +85,7 @@ export class TableRenderer { ...@@ -85,7 +85,7 @@ export class TableRenderer {
let column = this.table.columns[colIndex]; let column = this.table.columns[colIndex];
var regex = kbn.stringToJsRegex(style.pattern); var regex = kbn.stringToJsRegex(style.pattern);
if (column.text.match(regex)) { if (column.text.match(regex)) {
this.formaters[colIndex] = this.createColumnFormater(style); this.formaters[colIndex] = this.createColumnFormater(style, column);
return this.formaters[colIndex](value); return this.formaters[colIndex](value);
} }
} }
......
...@@ -11,7 +11,8 @@ describe('when rendering table', () => { ...@@ -11,7 +11,8 @@ describe('when rendering table', () => {
{text: 'Value'}, {text: 'Value'},
{text: 'Colored'}, {text: 'Colored'},
{text: 'Undefined'}, {text: 'Undefined'},
{text: 'String'} {text: 'String'},
{text: 'United', unit: 'bps'},
]; ];
var panel = { var panel = {
...@@ -40,6 +41,12 @@ describe('when rendering table', () => { ...@@ -40,6 +41,12 @@ describe('when rendering table', () => {
{ {
pattern: 'String', pattern: 'String',
type: 'string', type: 'string',
},
{
pattern: 'United',
type: 'number',
unit: 'ms',
decimals: 2,
} }
] ]
}; };
...@@ -51,6 +58,11 @@ describe('when rendering table', () => { ...@@ -51,6 +58,11 @@ describe('when rendering table', () => {
expect(html).to.be('<td>2014-01-01T06:06:06+00:00</td>'); expect(html).to.be('<td>2014-01-01T06:06:06+00:00</td>');
}); });
it('number column with unit specified should ignore style unit', () => {
var html = renderer.renderCell(5, 1230);
expect(html).to.be('<td>1.23 kbps</td>');
});
it('number column should be formated', () => { it('number column should be formated', () => {
var html = renderer.renderCell(1, 1230); var html = renderer.renderCell(1, 1230);
expect(html).to.be('<td>1.230 s</td>'); expect(html).to.be('<td>1.230 s</td>');
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment