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 {
return v;
}
createColumnFormater(style) {
createColumnFormater(style, column) {
if (!style) {
return this.defaultCellFormater;
}
......@@ -53,7 +53,7 @@ export class TableRenderer {
}
if (style.type === 'number') {
let valueFormater = kbn.valueFormats[style.unit];
let valueFormater = kbn.valueFormats[column.unit || style.unit];
return v => {
if (v === null || v === void 0) {
......@@ -85,7 +85,7 @@ export class TableRenderer {
let column = this.table.columns[colIndex];
var regex = kbn.stringToJsRegex(style.pattern);
if (column.text.match(regex)) {
this.formaters[colIndex] = this.createColumnFormater(style);
this.formaters[colIndex] = this.createColumnFormater(style, column);
return this.formaters[colIndex](value);
}
}
......
......@@ -11,7 +11,8 @@ describe('when rendering table', () => {
{text: 'Value'},
{text: 'Colored'},
{text: 'Undefined'},
{text: 'String'}
{text: 'String'},
{text: 'United', unit: 'bps'},
];
var panel = {
......@@ -40,6 +41,12 @@ describe('when rendering table', () => {
{
pattern: 'String',
type: 'string',
},
{
pattern: 'United',
type: 'number',
unit: 'ms',
decimals: 2,
}
]
};
......@@ -51,6 +58,11 @@ describe('when rendering table', () => {
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', () => {
var html = renderer.renderCell(1, 1230);
expect(html).to.be('<td>1.230 s</td>');
......@@ -62,8 +74,8 @@ describe('when rendering table', () => {
});
it('colored cell should have style', () => {
var html = renderer.renderCell(2, 40);
expect(html).to.be('<td style="color:green">40.0</td>');
var html = renderer.renderCell(2, 40);
expect(html).to.be('<td style="color:green">40.0</td>');
});
it('colored cell should have style', () => {
......
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